Skip to content

Commit fd908a4

Browse files
committedJun 6, 2016
Add support for setting allowed file-name characters
Add support for customising the allowed characters (through passing a `string` or `RegExp`). Closes GH-63.
1 parent b8f52a9 commit fd908a4

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed
 

‎doc/rules.md

+8
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,14 @@ Options: `boolean`, default: `false`.
797797
Warn when file names contain irregular characters: characters other
798798
than alpha-numericals, dashes, and dots (full-stops).
799799

800+
Options: `RegExp` or `string`, default: `'\\.a-zA-Z0-9-'`.
801+
802+
If a string is given, it will be wrapped in
803+
`new RegExp('[^' + preferred + ']')`.
804+
805+
Any match by the wrapped or given expressions triggers a
806+
warning.
807+
800808
### no-file-name-mixed-case
801809

802810
```md

‎lib/rules/no-file-name-irregular-characters.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
* @fileoverview
77
* Warn when file names contain irregular characters: characters other
88
* than alpha-numericals, dashes, and dots (full-stops).
9+
*
10+
* Options: `RegExp` or `string`, default: `'\\.a-zA-Z0-9-'`.
11+
*
12+
* If a string is given, it will be wrapped in
13+
* `new RegExp('[^' + preferred + ']')`.
14+
*
15+
* Any match by the wrapped or given expressions triggers a
16+
* warning.
917
* @example
1018
* Invalid: plug_ins.md, plug ins.md.
1119
* Valid: plug-ins.md, plugins.md.
@@ -25,7 +33,14 @@
2533
* @param {Function} done - Callback.
2634
*/
2735
function noFileNameIrregularCharacters(ast, file, preferred, done) {
28-
var match = file.filename && file.filename.match(/[^.a-zA-Z0-9-]/);
36+
var expression = preferred || /[^\\.a-zA-Z0-9-]/;
37+
var match;
38+
39+
if (typeof expression === 'string') {
40+
expression = new RegExp('[^' + expression + ']');
41+
}
42+
43+
match = file.filename && file.filename.match(expression);
2944

3045
if (match) {
3146
file.warn('Do not use `' + match[0] + '` in a file name');

‎test/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@ describe('Rules', function () {
432432
'file-name characters.md:1:1: Do not use ` ` in a file name'
433433
]);
434434
});
435+
436+
describeSetting(/[^\\.aeiou]/, function () {
437+
assertFile('empty.md', [
438+
'empty.md:1:1: Do not use `m` in a file name'
439+
]);
440+
});
441+
442+
describeSetting('aeiou', function () {
443+
assertFile('empty.md', [
444+
'empty.md:1:1: Do not use `m` in a file name'
445+
]);
446+
});
435447
});
436448

437449
describeRule('no-file-name-consecutive-dashes', function () {

0 commit comments

Comments
 (0)
Please sign in to comment.