@@ -12,6 +12,7 @@ import { createRule } from '../utils/index.js';
12
12
import type { RuleContext , SourceCode } from '../types.js' ;
13
13
14
14
interface RuleGlobals {
15
+ checkGlobal : boolean ;
15
16
style : string [ ] ;
16
17
classSelections : Map < string , AST . SvelteHTMLElement [ ] > ;
17
18
idSelections : Map < string , AST . SvelteHTMLElement [ ] > ;
@@ -32,7 +33,9 @@ export default createRule('consistent-selector-style', {
32
33
{
33
34
type : 'object' ,
34
35
properties : {
35
- // TODO: Add option to include global selectors
36
+ checkGlobal : {
37
+ type : 'boolean'
38
+ } ,
36
39
style : {
37
40
type : 'array' ,
38
41
items : {
@@ -61,6 +64,7 @@ export default createRule('consistent-selector-style', {
61
64
return { } ;
62
65
}
63
66
67
+ const checkGlobal = context . options [ 0 ] ?. checkGlobal ?? false ;
64
68
const style = context . options [ 0 ] ?. style ?? [ 'type' , 'id' , 'class' ] ;
65
69
66
70
const classSelections : Map < string , AST . SvelteHTMLElement [ ] > = new Map ( ) ;
@@ -94,6 +98,7 @@ export default createRule('consistent-selector-style', {
94
98
return ;
95
99
}
96
100
checkSelectorsInPostCSSNode ( styleContext . sourceAst , {
101
+ checkGlobal,
97
102
style,
98
103
classSelections,
99
104
idSelections,
@@ -126,7 +131,7 @@ function checkSelectorsInPostCSSNode(node: AnyNode, ruleGlobals: RuleGlobals): v
126
131
}
127
132
if (
128
133
( node . type === 'root' ||
129
- ( node . type === 'rule' && node . selector !== ':global' ) ||
134
+ ( node . type === 'rule' && ( node . selector !== ':global' || ruleGlobals . checkGlobal ) ) ||
130
135
node . type === 'atrule' ) &&
131
136
node . nodes !== undefined
132
137
) {
@@ -148,7 +153,7 @@ function checkSelector(node: SelectorNode, ruleGlobals: RuleGlobals): void {
148
153
checkTypeSelector ( node , ruleGlobals ) ;
149
154
}
150
155
if (
151
- ( node . type === 'pseudo' && node . value !== ':global' ) ||
156
+ ( node . type === 'pseudo' && ( node . value !== ':global' || ruleGlobals . checkGlobal ) ) ||
152
157
node . type === 'root' ||
153
158
node . type === 'selector'
154
159
) {
0 commit comments