@@ -4,6 +4,33 @@ import { getSvelteCompileWarnings } from '../shared/svelte-compile-warns/index.j
4
4
import { getSourceCode } from '../utils/compat.js' ;
5
5
import type { Position } from 'svelte-eslint-parser/lib/ast/common.js' ;
6
6
7
+ const ignores : string [ ] = [
8
+ 'missing-declaration' ,
9
+ // Svelte v4
10
+ 'dynamic-slot-name' ,
11
+ // Svelte v5
12
+ 'invalid-slot-name'
13
+ ] as const ;
14
+
15
+ const unusedSelectorWarnings : string [ ] = [ 'css_unused_selector' , 'css-unused-selector' ] as const ;
16
+
17
+ function isGlobalStyleNode (
18
+ globalStyleRanges : [ Position , Position ] [ ] ,
19
+ start ?: Position ,
20
+ end ?: Position
21
+ ) {
22
+ if ( start == null || end == null ) {
23
+ return false ;
24
+ }
25
+ return globalStyleRanges . some ( ( [ rangeStart , rangeEnd ] ) => {
26
+ return (
27
+ ( rangeStart . line < start . line ||
28
+ ( rangeStart . line === start . line && rangeStart . column <= start . column ) ) &&
29
+ ( end . line < rangeEnd . line || ( end . line === rangeEnd . line && end . column <= rangeEnd . column ) )
30
+ ) ;
31
+ } ) ;
32
+ }
33
+
7
34
export default createRule ( 'valid-compile' , {
8
35
meta : {
9
36
docs : {
@@ -40,32 +67,8 @@ export default createRule('valid-compile', {
40
67
: ( warning ) => warning ;
41
68
42
69
const ignoreWarnings = Boolean ( context . options [ 0 ] ?. ignoreWarnings ) ;
43
-
44
- const ignores = [
45
- 'missing-declaration' ,
46
- // Svelte v4
47
- 'dynamic-slot-name' ,
48
- // Svelte v5
49
- 'invalid-slot-name'
50
- ] ;
51
-
52
- const unusedSelectorWarnings = [ 'css_unused_selector' , 'css-unused-selector' ] ;
53
70
const globalStyleRanges : [ Position , Position ] [ ] = [ ] ;
54
71
55
- function isGlobalStyleNode ( start ?: Position , end ?: Position ) {
56
- if ( start == null || end == null ) {
57
- return false ;
58
- }
59
- return globalStyleRanges . some ( ( [ rangeStart , rangeEnd ] ) => {
60
- return (
61
- ( rangeStart . line < start . line ||
62
- ( rangeStart . line === start . line && rangeStart . column <= start . column ) ) &&
63
- ( end . line < rangeEnd . line ||
64
- ( end . line === rangeEnd . line && end . column <= rangeEnd . column ) )
65
- ) ;
66
- } ) ;
67
- }
68
-
69
72
/**
70
73
* report
71
74
*/
@@ -74,7 +77,8 @@ export default createRule('valid-compile', {
74
77
if (
75
78
warn . code &&
76
79
( ignores . includes ( warn . code ) ||
77
- ( isGlobalStyleNode ( warn . start , warn . end ) && unusedSelectorWarnings . includes ( warn . code ) ) )
80
+ ( isGlobalStyleNode ( globalStyleRanges , warn . start , warn . end ) &&
81
+ unusedSelectorWarnings . includes ( warn . code ) ) )
78
82
) {
79
83
continue ;
80
84
}
0 commit comments