Reports character classes that wrap a single element that does not require brackets.
✅ This rule is included in the ts logical and logicalStrict presets.
Reports character classes that wrap a single element that does not require brackets.
A character class like [a] or [\d] can be simplified to just a or \d.
A character class with a single character can be unwrapped.
AEcons B0patte AE < =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1 <1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[1/sp>1 <1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp> <3;d ivclassNa="meco">;d>/;d> 3;d>44AEco61B0pat 44 6 <88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">6111/><88Fa spans="tyle--0:#D9F5DD;--1:#11">188Fa><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>var e=class e extends HTMLElement{static#e=new Map;tabs;panels;#t;#n=`starlight-synced-tabs__`;constructor(){super();let t=this.querySelector(`[role="tablist"]`);if(this.tabs=[...t.querySelectorAll(`[role="tab"]`)],this.panels=[...this.querySelectorAll(`:scope > [role="tabpanel"]`)],this.#t=this.dataset.syncKey,this.#t){let t=e.#e.get(this.#t)??[];t.push(this),e.#e.set(this.#t,t)}this.tabs.forEach((e,n)=>{e.addEventListener(`click`,e=>{e.preventDefault();let r=t.querySelector(`[aria-selected="true"]`);e.currentTarget!==r&&this.switchTab(e.currentTarget,n)}),e.addEventListener(`keydown`,e=>{let t=this.tabs.indexOf(e.currentTarget),n=e.key===`ArrowLeft`?t-1:e.key===`ArrowRight`?t+1:e.key===`Home`?0:e.key===`End`?this.tabs.length-1:null;n!==null&&this.tabs[n]&&(e.preventDefault(),this.switchTab(this.tabs[n],n))})})}switchTab(t,n,r=!0){if(!t)return;let i=r?this.getBoundingClientRect().top:0;this.tabs.forEach(e=>{e.setAttribute(`aria-selected`,`false`),e.setAttribute(`tabindex`,`-1`)}),this.panels.forEach(e=>{e.hidden=!0});let a=this.panels[n];a&&(a.hidden=!1),t.removeAttribute(`tabindex`),t.setAttribute(`aria-selected`,`true`),r&&(t.focus(),e.#i(this,t),window.scrollTo({top:window.scrollY+(this.getBoundingClientRect().top-i),behavior:`instant`}))}#r(e){this.#t&&typeof localStorage<`u`&&localStorage.setItem(this.#n+this.#t,e)}static#i(t,n){let r=t.#t,i=e.#a(n);if(!r||!i)return;let a=e.#e.get(r);if(a){for(let n of a){if(n===t)continue;let r=n.tabs.findIndex(t=>e.#a(t)===i);r!==-1&&n.switchTab(n.tabs[r],r,!1)}t.#r(i)}}static#a(e){return e.textContent?.trim()}};customElements.define(`starlight-tabs`,e);
A character class with a single escape sequence can be unwrapped.
AEcons B0patte AE < =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1 <1/sp ansty="le--0:#82AAFF;--1:#3B61">B0[\1/sp>1 <1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp> <3;d ivclassNa="meco">;d>/;d> 3;d>44AEco61B0pat 44 6 <88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#82AAFF;--1:#3B">61111/>1 <111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><\d/>\d/>
The rule also checks regex patterns in RegExp constructor calls.
AEcons B0patte AE <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>A B0RegE 5 <3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4D[1"sp>1 <1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp> <);d ivclassNa="meco"><);d>);d> );d>44AEco61B0pat 44A 6E7 <2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Re4AE >3 1 <111" spans="tyle--0:#ECC48D;--1:#98">4111">1 <111" spans="tyle--0:#D6DEEB;--1:#40">3F111"> <53) ;divclass="Name"> 53)>
These cases are valid and will not be reported:
// Backspace escape (has special meaning in character class)
const backspace = / [ \b ] / ;
// Equals sign (commonly used in regex for readability)
This rule is not configurable.
If you prefer to use character classes for consistency or readability, even when they contain only a single element, you might prefer to disable this rule.