@@ -36,17 +36,8 @@ mod lint_tests {
36
36
use swc_common:: SourceMap ;
37
37
use swc_ecmascript:: ast:: Program ;
38
38
39
- fn lint (
40
- source : & str ,
41
- unknown_rules : bool ,
42
- unused_dir : bool ,
43
- rules : Vec < Box < dyn LintRule > > ,
44
- ) -> Vec < LintDiagnostic > {
45
- let linter = LinterBuilder :: default ( )
46
- . lint_unknown_rules ( unknown_rules)
47
- . lint_unused_ignore_directives ( unused_dir)
48
- . rules ( rules)
49
- . build ( ) ;
39
+ fn lint ( source : & str , rules : Vec < Box < dyn LintRule > > ) -> Vec < LintDiagnostic > {
40
+ let linter = LinterBuilder :: default ( ) . rules ( rules) . build ( ) ;
50
41
51
42
let ( _, diagnostics) = linter
52
43
. lint ( "lint_test.ts" . to_string ( ) , source. to_string ( ) )
@@ -59,15 +50,9 @@ mod lint_tests {
59
50
comments : SingleThreadedComments ,
60
51
source_map : Rc < SourceMap > ,
61
52
tokens : Vec < TokenAndSpan > ,
62
- unknown_rules : bool ,
63
- unused_dir : bool ,
64
53
rules : Vec < Box < dyn LintRule > > ,
65
54
) -> Vec < LintDiagnostic > {
66
- let linter = LinterBuilder :: default ( )
67
- . lint_unknown_rules ( unknown_rules)
68
- . lint_unused_ignore_directives ( unused_dir)
69
- . rules ( rules)
70
- . build ( ) ;
55
+ let linter = LinterBuilder :: default ( ) . rules ( rules) . build ( ) ;
71
56
72
57
let ( _, diagnostics) = linter
73
58
. lint_with_ast (
@@ -81,78 +66,46 @@ mod lint_tests {
81
66
diagnostics
82
67
}
83
68
84
- fn lint_recommended_rules (
85
- source : & str ,
86
- unknown_rules : bool ,
87
- unused_dir : bool ,
88
- ) -> Vec < LintDiagnostic > {
89
- lint ( source, unknown_rules, unused_dir, get_recommended_rules ( ) )
69
+ fn lint_recommended_rules ( source : & str ) -> Vec < LintDiagnostic > {
70
+ lint ( source, get_recommended_rules ( ) )
90
71
}
91
72
92
73
fn lint_recommended_rules_with_ast (
93
74
ast : Program ,
94
75
comments : SingleThreadedComments ,
95
76
source_map : Rc < SourceMap > ,
96
77
tokens : Vec < TokenAndSpan > ,
97
- unknown_rules : bool ,
98
- unused_dir : bool ,
99
78
) -> Vec < LintDiagnostic > {
100
- lint_with_ast (
101
- ast,
102
- comments,
103
- source_map,
104
- tokens,
105
- unknown_rules,
106
- unused_dir,
107
- get_recommended_rules ( ) ,
108
- )
79
+ lint_with_ast ( ast, comments, source_map, tokens, get_recommended_rules ( ) )
109
80
}
110
81
111
82
fn lint_specified_rule < T : LintRule + ' static > (
112
83
source : & str ,
113
- unknown_rules : bool ,
114
- unused_dir : bool ,
115
84
) -> Vec < LintDiagnostic > {
116
- lint ( source, unknown_rules , unused_dir , vec ! [ T :: new( ) ] )
85
+ lint ( source, vec ! [ T :: new( ) ] )
117
86
}
118
87
119
88
#[ test]
120
89
fn empty_file ( ) {
121
- let diagnostics = lint_recommended_rules ( "" , true , false ) ;
90
+ let diagnostics = lint_recommended_rules ( "" ) ;
122
91
assert ! ( diagnostics. is_empty( ) ) ;
123
92
}
124
93
125
94
#[ test]
126
- fn warn_unknown_rules ( ) {
95
+ fn ban_unknown_rule_code ( ) {
127
96
let src = r#"
128
97
// deno-lint-ignore some-rule
129
98
function _foo() {
130
99
// deno-lint-ignore some-rule-2 some-rule-3
131
100
let _bar_foo = true
132
101
}
133
102
"# ;
134
- let diagnostics = lint_recommended_rules ( src, true , false ) ;
103
+ let diagnostics = lint_recommended_rules ( src) ;
135
104
136
105
assert_diagnostic ( & diagnostics[ 0 ] , "ban-unknown-rule-code" , 2 , 1 , src) ;
137
106
assert_diagnostic ( & diagnostics[ 1 ] , "ban-unknown-rule-code" , 4 , 3 , src) ;
138
107
}
139
108
140
- #[ test]
141
- fn ignore_unknown_rules ( ) {
142
- let diagnostics = lint_recommended_rules (
143
- r#"
144
- // deno-lint-ignore some-rule
145
- function _foo() {
146
- // pass
147
- }
148
- "# ,
149
- false ,
150
- false ,
151
- ) ;
152
-
153
- assert_eq ! ( diagnostics. len( ) , 0 ) ;
154
- }
155
-
156
109
#[ test]
157
110
fn unknown_rules_always_know_available_rules ( ) {
158
111
use crate :: rules:: camelcase:: Camelcase ;
@@ -161,15 +114,13 @@ mod lint_tests {
161
114
// deno-lint-ignore no-explicit-any
162
115
const fooBar: any = 42;
163
116
"# ,
164
- true ,
165
- false ,
166
117
) ;
167
118
168
119
assert ! ( diagnostics. is_empty( ) ) ;
169
120
}
170
121
171
122
#[ test]
172
- fn ban_unused_ignore_enabled ( ) {
123
+ fn ban_unused_ignore ( ) {
173
124
let src = r#"
174
125
// deno-lint-ignore no-explicit-any
175
126
function _bar(_p: boolean) {
@@ -178,31 +129,13 @@ const fooBar: any = 42;
178
129
}
179
130
"# ;
180
131
181
- let diagnostics = lint_recommended_rules (
182
- src, false , true , // enables `ban-unused-ignore`
183
- ) ;
132
+ let diagnostics = lint_recommended_rules ( src) ;
184
133
185
134
assert_eq ! ( diagnostics. len( ) , 2 ) ;
186
135
assert_diagnostic ( & diagnostics[ 0 ] , "ban-unused-ignore" , 2 , 1 , src) ;
187
136
assert_diagnostic ( & diagnostics[ 1 ] , "ban-unused-ignore" , 4 , 3 , src) ;
188
137
}
189
138
190
- #[ test]
191
- fn ban_unused_ignore_disabled ( ) {
192
- let diagnostics = lint_recommended_rules (
193
- r#"
194
- // deno-lint-ignore no-explicit-any
195
- function _bar(_p: boolean) {
196
- // pass
197
- }
198
- "# ,
199
- false ,
200
- false , // disables `ban-unused-ignore`
201
- ) ;
202
-
203
- assert_eq ! ( diagnostics. len( ) , 0 ) ;
204
- }
205
-
206
139
#[ test]
207
140
fn ban_unused_ignore_not_report_unexecuted_rule ( ) {
208
141
use crate :: rules:: camelcase:: Camelcase ;
@@ -211,8 +144,6 @@ const fooBar: any = 42;
211
144
// deno-lint-ignore no-explicit-any
212
145
const _fooBar = 42;
213
146
"# ,
214
- false ,
215
- true , // enables `ban-unused-ignore`
216
147
) ;
217
148
218
149
assert ! ( diagnostics. is_empty( ) ) ;
@@ -227,8 +158,6 @@ const _fooBar = 42;
227
158
// deno-lint-ignore no-explicit-any
228
159
const _foo = 42;
229
160
"# ,
230
- false ,
231
- true , // enables `ban-unused-ignore`
232
161
) ;
233
162
234
163
assert ! ( diagnostics. is_empty( ) ) ;
@@ -241,12 +170,15 @@ const _foo = 42;
241
170
// deno-lint-ignore no-explicit-any ban-unused-ignore
242
171
const _foo = 42;
243
172
"# ;
244
- let diagnostics = lint_recommended_rules (
245
- src, false , true , // enables `ban-unused-ignore`
246
- ) ;
173
+ let diagnostics = lint_recommended_rules ( src) ;
247
174
248
- assert_eq ! ( diagnostics. len( ) , 1 ) ;
175
+ assert_eq ! ( diagnostics. len( ) , 2 ) ;
176
+
177
+ // Both `no-explicit-any` and `ban-unused-ignore` are considered "unused"
178
+ // ignore directives in this case. Remember that `ban-unused-ignore`, if
179
+ // it's ignored at a line level, doesn't have any effect.
249
180
assert_diagnostic ( & diagnostics[ 0 ] , "ban-unused-ignore" , 2 , 0 , src) ;
181
+ assert_diagnostic ( & diagnostics[ 1 ] , "ban-unused-ignore" , 2 , 0 , src) ;
250
182
}
251
183
252
184
#[ test]
@@ -259,8 +191,6 @@ const _foo = 42;
259
191
// pass
260
192
}
261
193
"# ,
262
- false ,
263
- false ,
264
194
) ;
265
195
266
196
assert_eq ! ( diagnostics. len( ) , 0 ) ;
@@ -275,9 +205,7 @@ const _foo = 42;
275
205
// pass
276
206
}
277
207
"# ;
278
- let diagnostics = lint_recommended_rules (
279
- src, false , true , // enables `ban-unused-ignore`
280
- ) ;
208
+ let diagnostics = lint_recommended_rules ( src) ;
281
209
282
210
assert_eq ! ( diagnostics. len( ) , 1 ) ;
283
211
assert_diagnostic ( & diagnostics[ 0 ] , "ban-unused-ignore" , 2 , 1 , src) ;
@@ -293,7 +221,7 @@ const _foo = 42;
293
221
// pass
294
222
}
295
223
"# ;
296
- let diagnostics = lint_recommended_rules ( src, false , true ) ;
224
+ let diagnostics = lint_recommended_rules ( src) ;
297
225
298
226
assert_eq ! ( diagnostics. len( ) , 1 ) ;
299
227
assert_diagnostic ( & diagnostics[ 0 ] , "ban-unused-ignore" , 4 , 1 , src) ;
@@ -302,9 +230,8 @@ const _foo = 42;
302
230
#[ test]
303
231
fn empty_file_with_ast ( ) {
304
232
let ( ast, comments, source_map, tokens) = parse ( "" ) ;
305
- let diagnostics = lint_recommended_rules_with_ast (
306
- ast, comments, source_map, tokens, true , false ,
307
- ) ;
233
+ let diagnostics =
234
+ lint_recommended_rules_with_ast ( ast, comments, source_map, tokens) ;
308
235
assert ! ( diagnostics. is_empty( ) ) ;
309
236
}
310
237
}
0 commit comments