Skip to content

Commit b444988

Browse files
committed
chore: remove all eslint plugin eslint warnnings
1 parent cb6754a commit b444988

File tree

10 files changed

+121
-94
lines changed

10 files changed

+121
-94
lines changed

lib/constants/message.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,25 @@
33
* @author Huan Luo
44
*/
55

6-
import { template } from '../utils/utility.js';
6+
export const NAMING_PATTERN_OBJECT_ERROR_MESSAGE =
7+
'The naming pattern object "{{ value }}" does not appear to be an Object type, please double-check it and try again';
78

8-
export const NAMING_PATTERN_OBJECT_ERROR_MESSAGE = template(
9-
'The naming pattern object "$0" does not appear to be an Object type, please double-check it and try again'
10-
);
9+
export const PATTERN_ERROR_MESSAGE =
10+
'There is an invalid pattern "{{ value }}", please double-check it and try again';
1111

12-
export const PATTERN_ERROR_MESSAGE = template(
13-
'There is an invalid pattern "$0", please double-check it and try again'
14-
);
12+
export const PREFINED_MATCH_SYNTAX_ERROR_MESSAGE =
13+
'The prefined match "{{ namingPattern }}" is not found in the pattern "{{ filenamePattern }}", please double-check it and try again';
1514

16-
export const PREFINED_MATCH_SYNTAX_ERROR_MESSAGE = template(
17-
'The prefined match "$0" is not found in the pattern "$1", please double-check it and try again'
18-
);
15+
export const FILENAME_BLOCKLIST_ERROR_MESSAGE =
16+
'The filename "{{ filename }}" matches the blocklisted "{{ blockListPattern }}" pattern, use a pattern like "{{ useInsteadPattern }}" instead';
1917

20-
export const FILENAME_BLOCKLIST_ERROR_MESSAGE = template(
21-
'The filename "$0" matches the blocklisted "$1" pattern, use a pattern like "$2" instead'
22-
);
18+
export const FILENAME_NAMING_CONVENTION_ERROR_MESSAGE =
19+
'The filename "{{ filename }}" does not match the "{{ originalNamingPattern }}" pattern';
2320

24-
export const FILENAME_NAMING_CONVENTION_ERROR_MESSAGE = template(
25-
'The filename "$0" does not match the "$1" pattern'
26-
);
21+
export const FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE =
22+
'The folder of the file "{{ filenameWithPath }}" does not match the "{{ folderPattern }}" pattern';
2723

28-
export const FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE = template(
29-
'The folder of the file "$0" does not match the "$1" pattern'
30-
);
31-
32-
export const FOLDER_NAMING_CONVENTION_ERROR_MESSAGE = template(
33-
'The folder "$0" does not match the "$1" pattern'
34-
);
24+
export const FOLDER_NAMING_CONVENTION_ERROR_MESSAGE =
25+
'The folder "{{ folder }}" does not match the "{{ namingPattern }}" pattern';
3526

3627
export const NO_INDEX_ERROR_MESSAGE = 'The filename "index" is not allowed';

lib/constants/regex.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ export const PREFINED_MATCH_SYNTAX_REGEXP = /^<(\d+)>$/;
1212
* @example C:\
1313
*/
1414
export const WINDOWS_DRIVE_LETTER_REGEXP = /^[A-Za-z]:\\/;
15-
16-
/**
17-
* @example $0
18-
*/
19-
export const TEMPLATE_VARIABLE_REGEXP = /\$(\d*)/;

lib/rules/filename-blocklist.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* @author Florian Ehmke, Huan Luo
44
*/
55

6-
import { FILENAME_BLOCKLIST_ERROR_MESSAGE } from '../constants/message.js';
6+
import {
7+
FILENAME_BLOCKLIST_ERROR_MESSAGE,
8+
NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
9+
PATTERN_ERROR_MESSAGE,
10+
} from '../constants/message.js';
711
import { getDocUrl } from '../utils/doc.js';
812
import { getFilePath, getFilename } from '../utils/filename.js';
913
import { matchRule } from '../utils/rule.js';
@@ -32,22 +36,30 @@ export default {
3236
},
3337
},
3438
],
39+
messages: {
40+
invalidObject: NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
41+
invalidPattern: PATTERN_ERROR_MESSAGE,
42+
noMatch: FILENAME_BLOCKLIST_ERROR_MESSAGE,
43+
},
3544
},
3645

3746
create(context) {
3847
return {
3948
Program: (node) => {
4049
const rules = context.options[0];
41-
const message = validateNamingPatternObject(
50+
const error = validateNamingPatternObject(
4251
rules,
4352
globPatternValidator,
4453
globPatternValidator
4554
);
4655

47-
if (message) {
56+
if (error) {
4857
context.report({
4958
node,
50-
message,
59+
messageId: error.type,
60+
data: {
61+
value: error.payload,
62+
},
5163
});
5264
return;
5365
}
@@ -69,11 +81,12 @@ export default {
6981
if (matchResult) {
7082
context.report({
7183
node,
72-
message: FILENAME_BLOCKLIST_ERROR_MESSAGE(
84+
messageId: 'noMatch',
85+
data: {
7386
filename,
7487
blockListPattern,
75-
useInsteadPattern
76-
),
88+
useInsteadPattern,
89+
},
7790
});
7891
return;
7992
}

lib/rules/filename-naming-convention.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
* @author Huan Luo
44
*/
55

6-
import { FILENAME_NAMING_CONVENTION_ERROR_MESSAGE } from '../constants/message.js';
6+
import {
7+
FILENAME_NAMING_CONVENTION_ERROR_MESSAGE,
8+
NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
9+
PATTERN_ERROR_MESSAGE,
10+
PREFINED_MATCH_SYNTAX_ERROR_MESSAGE,
11+
} from '../constants/message.js';
712
import { getDocUrl } from '../utils/doc.js';
813
import { getBasename, getFilePath, getFilename } from '../utils/filename.js';
914
import {
@@ -42,22 +47,31 @@ export default {
4247
},
4348
},
4449
],
50+
messages: {
51+
invalidObject: NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
52+
invalidPattern: PATTERN_ERROR_MESSAGE,
53+
invalidPrefinedMatch: PREFINED_MATCH_SYNTAX_ERROR_MESSAGE,
54+
noMatch: FILENAME_NAMING_CONVENTION_ERROR_MESSAGE,
55+
},
4556
},
4657

4758
create(context) {
4859
return {
4960
Program: (node) => {
5061
const rules = context.options[0];
51-
const message = validateNamingPatternObject(
62+
const error = validateNamingPatternObject(
5263
rules,
5364
globPatternValidator,
5465
filenameNamingPatternValidator
5566
);
5667

57-
if (message) {
68+
if (error) {
5869
context.report({
5970
node,
60-
message,
71+
messageId: error.type,
72+
data: {
73+
value: error.payload,
74+
},
6175
});
6276
return;
6377
}
@@ -85,17 +99,19 @@ export default {
8599
);
86100

87101
if (matchResult) {
88-
throw new Error(
89-
FILENAME_NAMING_CONVENTION_ERROR_MESSAGE(
102+
throw {
103+
type: 'noMatch',
104+
payload: {
90105
filename,
91-
originalNamingPattern
92-
)
93-
);
106+
originalNamingPattern,
107+
},
108+
};
94109
}
95110
} catch (error) {
96111
context.report({
97112
node,
98-
message: error.message,
113+
messageId: error.type,
114+
data: error.payload,
99115
});
100116
}
101117
}

lib/rules/folder-match-with-fex.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* @author Huan Luo
44
*/
55

6-
import { FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE } from '../constants/message.js';
6+
import {
7+
FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE,
8+
NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
9+
PATTERN_ERROR_MESSAGE,
10+
} from '../constants/message.js';
711
import { getDocUrl } from '../utils/doc.js';
812
import { getFilePath, getFilename, getFolderPath } from '../utils/filename.js';
913
import { matchRule } from '../utils/rule.js';
@@ -33,22 +37,30 @@ export default {
3337
},
3438
},
3539
],
40+
messages: {
41+
invalidObject: NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
42+
invalidPattern: PATTERN_ERROR_MESSAGE,
43+
noMatch: FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE,
44+
},
3645
},
3746

3847
create(context) {
3948
return {
4049
Program: (node) => {
4150
const rules = context.options[0];
42-
const message = validateNamingPatternObject(
51+
const error = validateNamingPatternObject(
4352
rules,
4453
globPatternValidator,
4554
globPatternValidator
4655
);
4756

48-
if (message) {
57+
if (error) {
4958
context.report({
5059
node,
51-
message,
60+
messageId: error.type,
61+
data: {
62+
value: error.payload,
63+
},
5264
});
5365
return;
5466
}
@@ -68,10 +80,11 @@ export default {
6880
if (matchResult) {
6981
context.report({
7082
node,
71-
message: FOLDER_MATCH_WITH_FEX_ERROR_MESSAGE(
83+
messageId: 'noMatch',
84+
data: {
7285
filenameWithPath,
73-
folderPattern
74-
),
86+
folderPattern,
87+
},
7588
});
7689
return;
7790
}

lib/rules/folder-naming-convention.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
*/
55

66
import micromatch from 'micromatch';
7-
import { FOLDER_NAMING_CONVENTION_ERROR_MESSAGE } from '../constants/message.js';
7+
import {
8+
FOLDER_NAMING_CONVENTION_ERROR_MESSAGE,
9+
NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
10+
PATTERN_ERROR_MESSAGE,
11+
} from '../constants/message.js';
812
import * as BASIC_NAMING_CONVENTION from '../constants/naming-convention.js';
913
import * as NEXT_JS_NAMING_CONVENTION from '../constants/next-js-naming-convention.js';
1014
import { getDocUrl } from '../utils/doc.js';
@@ -41,22 +45,30 @@ export default {
4145
},
4246
},
4347
],
48+
messages: {
49+
invalidObject: NAMING_PATTERN_OBJECT_ERROR_MESSAGE,
50+
invalidPattern: PATTERN_ERROR_MESSAGE,
51+
noMatch: FOLDER_NAMING_CONVENTION_ERROR_MESSAGE,
52+
},
4453
},
4554

4655
create(context) {
4756
return {
4857
Program: (node) => {
4958
const rules = context.options[0];
50-
const message = validateNamingPatternObject(
59+
const error = validateNamingPatternObject(
5160
rules,
5261
globPatternValidator,
5362
folderNamingPatternValidator
5463
);
5564

56-
if (message) {
65+
if (error) {
5766
context.report({
5867
node,
59-
message,
68+
messageId: error.type,
69+
data: {
70+
value: error.payload,
71+
},
6072
});
6173
return;
6274
}
@@ -92,10 +104,11 @@ export default {
92104
) {
93105
context.report({
94106
node,
95-
message: FOLDER_NAMING_CONVENTION_ERROR_MESSAGE(
107+
messageId: 'noMatch',
108+
data: {
96109
folder,
97-
namingPattern
98-
),
110+
namingPattern,
111+
},
99112
});
100113
return;
101114
}

lib/rules/no-index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export default {
2828
},
2929
},
3030
],
31+
messages: {
32+
noIndex: NO_INDEX_ERROR_MESSAGE,
33+
},
3134
},
3235

3336
create(context) {
@@ -41,7 +44,7 @@ export default {
4144
if (basename === 'index') {
4245
context.report({
4346
node,
44-
message: NO_INDEX_ERROR_MESSAGE,
47+
messageId: 'noIndex',
4548
});
4649
return;
4750
}

lib/utils/rule.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import micromatch from 'micromatch';
7-
import { PREFINED_MATCH_SYNTAX_ERROR_MESSAGE } from '../constants/message.js';
87
import * as NAMING_CONVENTION from '../constants/naming-convention.js';
98
import { PREFINED_MATCH_SYNTAX_REGEXP } from '../constants/regex.js';
109
import { isEmpty, isNil } from './utility.js';
@@ -17,7 +16,7 @@ import { isEmpty, isNil } from './utility.js';
1716
* @param {rule} rule original rule
1817
* @param {string} filenameWithPath filename with path
1918
* @returns {rule} new rule
20-
* @throws {Error} if a prefined match syntax referenced in the naming pattern is not found in the filename pattern
19+
* @throws {import("./validation.js").ValidationError} if a prefined match syntax referenced in the naming pattern is not found in the filename pattern
2120
*/
2221
export const transformRuleWithPrefinedMatchSyntax = (
2322
[filenamePattern, namingPattern],
@@ -44,9 +43,13 @@ export const transformRuleWithPrefinedMatchSyntax = (
4443
const groupIndex = +group[1];
4544

4645
if (isNil(keyCaptureGroups[groupIndex])) {
47-
throw new Error(
48-
PREFINED_MATCH_SYNTAX_ERROR_MESSAGE(namingPattern, filenamePattern)
49-
);
46+
throw {
47+
type: 'invalidPrefinedMatch',
48+
payload: {
49+
namingPattern,
50+
filenamePattern,
51+
},
52+
};
5053
}
5154

5255
return value.replace(group[0], keyCaptureGroups[groupIndex]);

0 commit comments

Comments
 (0)