Skip to content

Commit 73d6d0d

Browse files
committed
fix(#36): the value of rule configuration object of rule filename-blocklist can be empty string
1 parent a28a4cc commit 73d6d0d

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed

lib/rules/filename-blocklist.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { getDocUrl } from '../utils/doc.js';
1212
import { getFilePath, getFilename } from '../utils/filename.js';
1313
import { matchRule } from '../utils/rule.js';
14-
import { isNotEmpty } from '../utils/utility.js';
14+
import { isEmpty, isNotEmpty } from '../utils/utility.js';
1515
import {
1616
validateNamingPatternObject,
1717
globPatternValidator,
@@ -58,7 +58,7 @@ export default {
5858
const error = validateNamingPatternObject(
5959
rules,
6060
globPatternValidator,
61-
globPatternValidator
61+
isEmpty(errorMessage) ? globPatternValidator : () => true
6262
);
6363

6464
if (error) {

tests/lib/rules/filename-blocklist.posix.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,65 @@ ruleTester.run(
278278
],
279279
}
280280
);
281+
282+
ruleTester.run(
283+
"filename-blocklist with option: [{'*.models.ts': ''}, { errorMessage: 'The file \"{{ target }}\" is blocked since it since it matches the blocklisted pattern \"{{ pattern }}\", see contribute.md for details' }]",
284+
rule,
285+
{
286+
valid: [
287+
{
288+
code: "var foo = 'bar';",
289+
filename: 'src/foo.apis.ts',
290+
options: [
291+
{ '*.models.ts': '' },
292+
{
293+
errorMessage:
294+
'The file "{{ target }}" is blocked since it since it matches the blocklisted pattern "{{ pattern }}", see contribute.md for details',
295+
},
296+
],
297+
},
298+
],
299+
300+
invalid: [
301+
{
302+
code: "var foo = 'bar';",
303+
filename: 'src/foo.models.ts',
304+
options: [
305+
{ '*.models.ts': '' },
306+
{
307+
errorMessage:
308+
'The file "{{ target }}" is blocked since it since it matches the blocklisted pattern "{{ pattern }}", see contribute.md for details',
309+
},
310+
],
311+
errors: [
312+
{
313+
message:
314+
'The file "foo.models.ts" is blocked since it since it matches the blocklisted pattern "*.models.ts", see contribute.md for details',
315+
column: 1,
316+
line: 1,
317+
},
318+
],
319+
},
320+
],
321+
}
322+
);
323+
324+
ruleTester.run("filename-blocklist with option: [{'*.models.ts': ''}]", rule, {
325+
valid: [],
326+
327+
invalid: [
328+
{
329+
code: "var foo = 'bar';",
330+
filename: 'src/foo.models.ts',
331+
options: [{ '*.models.ts': '' }],
332+
errors: [
333+
{
334+
message:
335+
'There is an invalid pattern "", please double-check it and try again',
336+
column: 1,
337+
line: 1,
338+
},
339+
],
340+
},
341+
],
342+
});

tests/lib/rules/filename-blocklist.windows.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,69 @@ ruleTester.run(
206206
],
207207
}
208208
);
209+
210+
ruleTester.run(
211+
"filename-blocklist with option on Windows: [{'*.models.ts': ''}, { errorMessage: 'The file \"{{ target }}\" is blocked since it since it matches the blocklisted pattern \"{{ pattern }}\", see contribute.md for details' }]",
212+
rule,
213+
{
214+
valid: [
215+
{
216+
code: "var foo = 'bar';",
217+
filename: 'src\\foo.apis.ts',
218+
options: [
219+
{ '*.models.ts': '' },
220+
{
221+
errorMessage:
222+
'The file "{{ target }}" is blocked since it since it matches the blocklisted pattern "{{ pattern }}", see contribute.md for details',
223+
},
224+
],
225+
},
226+
],
227+
228+
invalid: [
229+
{
230+
code: "var foo = 'bar';",
231+
filename: 'src\\foo.models.ts',
232+
options: [
233+
{ '*.models.ts': '' },
234+
{
235+
errorMessage:
236+
'The file "{{ target }}" is blocked since it since it matches the blocklisted pattern "{{ pattern }}", see contribute.md for details',
237+
},
238+
],
239+
errors: [
240+
{
241+
message:
242+
'The file "foo.models.ts" is blocked since it since it matches the blocklisted pattern "*.models.ts", see contribute.md for details',
243+
column: 1,
244+
line: 1,
245+
},
246+
],
247+
},
248+
],
249+
}
250+
);
251+
252+
ruleTester.run(
253+
"filename-blocklist with option on Windows: [{'*.models.ts': ''}]",
254+
rule,
255+
{
256+
valid: [],
257+
258+
invalid: [
259+
{
260+
code: "var foo = 'bar';",
261+
filename: 'src\\foo.models.ts',
262+
options: [{ '*.models.ts': '' }],
263+
errors: [
264+
{
265+
message:
266+
'There is an invalid pattern "", please double-check it and try again',
267+
column: 1,
268+
line: 1,
269+
},
270+
],
271+
},
272+
],
273+
}
274+
);

0 commit comments

Comments
 (0)