eslint-plugin-react-naming-convention 1.26.3-beta.8 → 1.26.3-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +46 -59
- package/dist/index.mjs +47 -60
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
2
|
|
|
3
|
-
type MessageID$
|
|
3
|
+
type MessageID$1 = "filenameExtensionInvalid" | "filenameExtensionUnexpected";
|
|
4
4
|
|
|
5
|
-
type MessageID
|
|
6
|
-
|
|
7
|
-
type MessageID = "usePascalCase" | "useConstantCase";
|
|
5
|
+
type MessageID = "filenameCaseMismatchSuggestion" | "filenameEmpty";
|
|
8
6
|
|
|
9
7
|
declare const _default: {
|
|
10
8
|
readonly meta: {
|
|
@@ -12,24 +10,24 @@ declare const _default: {
|
|
|
12
10
|
readonly version: string;
|
|
13
11
|
};
|
|
14
12
|
readonly rules: {
|
|
15
|
-
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<
|
|
13
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"componentName", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
16
14
|
allowAllCaps?: boolean;
|
|
17
15
|
allowLeadingUnderscore?: boolean;
|
|
18
16
|
allowNamespace?: boolean;
|
|
19
17
|
excepts?: readonly string[];
|
|
20
18
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
21
19
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
22
|
-
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID
|
|
20
|
+
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
23
21
|
excepts?: readonly string[];
|
|
24
22
|
extensions?: readonly string[];
|
|
25
23
|
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
26
24
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
|
-
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$
|
|
25
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
28
26
|
allow?: "always" | "as-needed";
|
|
29
27
|
extensions?: readonly string[];
|
|
30
28
|
ignoreFilesWithoutCode?: boolean;
|
|
31
29
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
32
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
30
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"useState", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
33
31
|
};
|
|
34
32
|
};
|
|
35
33
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
2
|
|
|
3
|
-
type MessageID$
|
|
3
|
+
type MessageID$1 = "filenameExtensionInvalid" | "filenameExtensionUnexpected";
|
|
4
4
|
|
|
5
|
-
type MessageID
|
|
6
|
-
|
|
7
|
-
type MessageID = "usePascalCase" | "useConstantCase";
|
|
5
|
+
type MessageID = "filenameCaseMismatchSuggestion" | "filenameEmpty";
|
|
8
6
|
|
|
9
7
|
declare const _default: {
|
|
10
8
|
readonly meta: {
|
|
@@ -12,24 +10,24 @@ declare const _default: {
|
|
|
12
10
|
readonly version: string;
|
|
13
11
|
};
|
|
14
12
|
readonly rules: {
|
|
15
|
-
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<
|
|
13
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"componentName", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
16
14
|
allowAllCaps?: boolean;
|
|
17
15
|
allowLeadingUnderscore?: boolean;
|
|
18
16
|
allowNamespace?: boolean;
|
|
19
17
|
excepts?: readonly string[];
|
|
20
18
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
21
19
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
22
|
-
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID
|
|
20
|
+
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
23
21
|
excepts?: readonly string[];
|
|
24
22
|
extensions?: readonly string[];
|
|
25
23
|
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
26
24
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
|
-
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$
|
|
25
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
28
26
|
allow?: "always" | "as-needed";
|
|
29
27
|
extensions?: readonly string[];
|
|
30
28
|
ignoreFilesWithoutCode?: boolean;
|
|
31
29
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
32
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
30
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"useState", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
33
31
|
};
|
|
34
32
|
};
|
|
35
33
|
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
36
36
|
|
|
37
37
|
// package.json
|
|
38
38
|
var name = "eslint-plugin-react-naming-convention";
|
|
39
|
-
var version = "1.26.3-
|
|
39
|
+
var version = "1.26.3-next.0";
|
|
40
40
|
var createRule = shared.createRuleForPlugin("naming-convention");
|
|
41
41
|
|
|
42
42
|
// src/rules/component-name.ts
|
|
@@ -90,32 +90,26 @@ function normalizeOptions(options) {
|
|
|
90
90
|
excepts: opts.excepts?.map((pattern) => new RegExp(pattern, "u")) ?? []
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
if (name2 == null) return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
allowLeadingUnderscore = false,
|
|
98
|
-
allowNamespace = false,
|
|
99
|
-
excepts,
|
|
100
|
-
rule
|
|
101
|
-
} = options;
|
|
102
|
-
if (excepts.some((regex) => regex.test(name2))) {
|
|
103
|
-
return eff._;
|
|
93
|
+
function validate(name2, options) {
|
|
94
|
+
if (name2 == null) return false;
|
|
95
|
+
if (options.excepts.some((regex) => regex.test(name2))) {
|
|
96
|
+
return true;
|
|
104
97
|
}
|
|
105
98
|
let normalized = name2.normalize("NFKD").replace(/[\u0300-\u036F]/g, "");
|
|
106
99
|
normalized = normalized.split(".").at(-1) ?? normalized;
|
|
100
|
+
const { allowLeadingUnderscore = false, allowNamespace = false } = options;
|
|
107
101
|
if (allowNamespace) {
|
|
108
102
|
normalized = normalized.replace(":", "");
|
|
109
103
|
}
|
|
110
104
|
if (allowLeadingUnderscore) {
|
|
111
105
|
normalized = normalized.replace(/^_/, "");
|
|
112
106
|
}
|
|
113
|
-
return tsPattern.match(rule).with("CONSTANT_CASE", () => shared.RE_CONSTANT_CASE.test(normalized)
|
|
107
|
+
return tsPattern.match(options.rule).with("CONSTANT_CASE", () => shared.RE_CONSTANT_CASE.test(normalized)).with("PascalCase", () => {
|
|
114
108
|
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
|
|
115
|
-
return allowAllCaps
|
|
109
|
+
return options.allowAllCaps ?? false;
|
|
116
110
|
}
|
|
117
|
-
return shared.RE_PASCAL_CASE.test(normalized)
|
|
118
|
-
}).otherwise(
|
|
111
|
+
return shared.RE_PASCAL_CASE.test(normalized);
|
|
112
|
+
}).otherwise(eff.constFalse);
|
|
119
113
|
}
|
|
120
114
|
var component_name_default = createRule({
|
|
121
115
|
meta: {
|
|
@@ -125,8 +119,7 @@ var component_name_default = createRule({
|
|
|
125
119
|
description: "enforce component naming convention to 'PascalCase' or 'CONSTANT_CASE'"
|
|
126
120
|
},
|
|
127
121
|
messages: {
|
|
128
|
-
|
|
129
|
-
usePascalCase: "Component name '{{name}}' must be in PascalCase."
|
|
122
|
+
componentName: "A component name must be in {{case}}."
|
|
130
123
|
},
|
|
131
124
|
schema
|
|
132
125
|
},
|
|
@@ -143,13 +136,14 @@ var component_name_default = createRule({
|
|
|
143
136
|
if (/^[a-z]/u.test(name2)) {
|
|
144
137
|
return;
|
|
145
138
|
}
|
|
146
|
-
|
|
147
|
-
|
|
139
|
+
if (validate(name2, options)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
148
142
|
context.report({
|
|
149
|
-
messageId:
|
|
143
|
+
messageId: "componentName",
|
|
150
144
|
node,
|
|
151
145
|
data: {
|
|
152
|
-
|
|
146
|
+
case: options.rule
|
|
153
147
|
}
|
|
154
148
|
});
|
|
155
149
|
},
|
|
@@ -159,30 +153,29 @@ var component_name_default = createRule({
|
|
|
159
153
|
for (const { node: component } of functionComponents.values()) {
|
|
160
154
|
const id = AST__namespace.getFunctionIdentifier(component);
|
|
161
155
|
if (id?.name == null) continue;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
if (validate(id.name, options)) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
165
159
|
context.report({
|
|
166
|
-
messageId:
|
|
160
|
+
messageId: "componentName",
|
|
167
161
|
node: id,
|
|
168
162
|
data: {
|
|
169
|
-
|
|
163
|
+
case: options.rule
|
|
170
164
|
}
|
|
171
165
|
});
|
|
172
166
|
}
|
|
173
167
|
for (const { node: component } of classComponents.values()) {
|
|
174
168
|
const id = AST__namespace.getClassIdentifier(component);
|
|
175
169
|
if (id?.name == null) continue;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
});
|
|
170
|
+
if (!validate(id.name, options)) {
|
|
171
|
+
context.report({
|
|
172
|
+
messageId: "componentName",
|
|
173
|
+
node: id,
|
|
174
|
+
data: {
|
|
175
|
+
case: options.rule
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
186
179
|
}
|
|
187
180
|
}
|
|
188
181
|
};
|
|
@@ -234,7 +227,8 @@ var filename_default = createRule({
|
|
|
234
227
|
description: "enforce naming convention for JSX filenames"
|
|
235
228
|
},
|
|
236
229
|
messages: {
|
|
237
|
-
filenameCaseMismatch: "A file with name '{{name}}' does not match {{rule}}.
|
|
230
|
+
// filenameCaseMismatch: "A file with name '{{name}}' does not match {{rule}}.",
|
|
231
|
+
filenameCaseMismatchSuggestion: "A file with name '{{name}}' does not match {{rule}}. Should rename to '{{suggestion}}'.",
|
|
238
232
|
filenameEmpty: "A file must have non-empty name."
|
|
239
233
|
},
|
|
240
234
|
schema: schema2
|
|
@@ -244,7 +238,7 @@ var filename_default = createRule({
|
|
|
244
238
|
const options = context.options[0] ?? defaultOptions2[0];
|
|
245
239
|
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
246
240
|
const excepts = typeof options === "string" ? [] : options.excepts ?? [];
|
|
247
|
-
function
|
|
241
|
+
function validate2(name2, casing = rule, ignores = excepts) {
|
|
248
242
|
const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
|
|
249
243
|
if (shouldIgnore) return true;
|
|
250
244
|
return tsPattern.match(casing).with("PascalCase", () => shared.RE_PASCAL_CASE.test(name2)).with("camelCase", () => shared.RE_CAMEL_CASE.test(name2)).with("kebab-case", () => shared.RE_KEBAB_CASE.test(name2)).with("snake_case", () => shared.RE_SNAKE_CASE.test(name2)).exhaustive();
|
|
@@ -259,11 +253,11 @@ var filename_default = createRule({
|
|
|
259
253
|
context.report({ messageId: "filenameEmpty", node });
|
|
260
254
|
return;
|
|
261
255
|
}
|
|
262
|
-
if (
|
|
256
|
+
if (validate2(basename)) {
|
|
263
257
|
return;
|
|
264
258
|
}
|
|
265
259
|
context.report({
|
|
266
|
-
messageId: "
|
|
260
|
+
messageId: "filenameCaseMismatchSuggestion",
|
|
267
261
|
node,
|
|
268
262
|
data: {
|
|
269
263
|
name: context.filename,
|
|
@@ -320,8 +314,8 @@ var filename_extension_default = createRule({
|
|
|
320
314
|
description: "enforce naming convention for JSX file extensions"
|
|
321
315
|
},
|
|
322
316
|
messages: {
|
|
323
|
-
|
|
324
|
-
|
|
317
|
+
filenameExtensionInvalid: "The JSX file extension is required.",
|
|
318
|
+
filenameExtensionUnexpected: "Use JSX file extension as needed."
|
|
325
319
|
},
|
|
326
320
|
schema: schema3
|
|
327
321
|
},
|
|
@@ -330,7 +324,6 @@ var filename_extension_default = createRule({
|
|
|
330
324
|
const options = context.options[0] ?? defaultOptions3[0];
|
|
331
325
|
const allow = eff.isObject(options) ? options.allow : options;
|
|
332
326
|
const extensions = eff.isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
|
|
333
|
-
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
|
|
334
327
|
const filename = context.filename;
|
|
335
328
|
let hasJSXNode = false;
|
|
336
329
|
return {
|
|
@@ -345,11 +338,8 @@ var filename_extension_default = createRule({
|
|
|
345
338
|
const isJSXExt = extensions.includes(fileNameExt);
|
|
346
339
|
if (hasJSXNode && !isJSXExt) {
|
|
347
340
|
context.report({
|
|
348
|
-
messageId: "
|
|
349
|
-
node
|
|
350
|
-
data: {
|
|
351
|
-
extensions: extensionsString
|
|
352
|
-
}
|
|
341
|
+
messageId: "filenameExtensionInvalid",
|
|
342
|
+
node
|
|
353
343
|
});
|
|
354
344
|
return;
|
|
355
345
|
}
|
|
@@ -360,11 +350,8 @@ var filename_extension_default = createRule({
|
|
|
360
350
|
}
|
|
361
351
|
if (!hasJSXNode && isJSXExt && allow === "as-needed") {
|
|
362
352
|
context.report({
|
|
363
|
-
messageId: "
|
|
364
|
-
node
|
|
365
|
-
data: {
|
|
366
|
-
extensions: extensionsString
|
|
367
|
-
}
|
|
353
|
+
messageId: "filenameExtensionUnexpected",
|
|
354
|
+
node
|
|
368
355
|
});
|
|
369
356
|
}
|
|
370
357
|
}
|
|
@@ -384,11 +371,11 @@ var use_state_default = createRule({
|
|
|
384
371
|
meta: {
|
|
385
372
|
type: "problem",
|
|
386
373
|
docs: {
|
|
387
|
-
description: "enforce destructuring and symmetric naming of 'useState' hook value and setter",
|
|
374
|
+
description: "enforce destructuring and symmetric naming of 'useState' hook value and setter variables",
|
|
388
375
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
389
376
|
},
|
|
390
377
|
messages: {
|
|
391
|
-
|
|
378
|
+
useState: "An useState call is not destructured into value + setter pair."
|
|
392
379
|
},
|
|
393
380
|
schema: []
|
|
394
381
|
},
|
|
@@ -424,14 +411,14 @@ var use_state_default = createRule({
|
|
|
424
411
|
const { id } = hookCall.parent;
|
|
425
412
|
switch (id.type) {
|
|
426
413
|
case types.AST_NODE_TYPES.Identifier: {
|
|
427
|
-
context.report({ messageId: "
|
|
414
|
+
context.report({ messageId: "useState", node: id });
|
|
428
415
|
break;
|
|
429
416
|
}
|
|
430
417
|
case types.AST_NODE_TYPES.ArrayPattern: {
|
|
431
418
|
const [state, setState] = id.elements;
|
|
432
419
|
if (state?.type === types.AST_NODE_TYPES.ObjectPattern && setState?.type === types.AST_NODE_TYPES.Identifier) {
|
|
433
420
|
if (!isSetterNameLoose(setState.name)) {
|
|
434
|
-
context.report({ messageId: "
|
|
421
|
+
context.report({ messageId: "useState", node: id });
|
|
435
422
|
}
|
|
436
423
|
break;
|
|
437
424
|
}
|
|
@@ -443,7 +430,7 @@ var use_state_default = createRule({
|
|
|
443
430
|
if (setStateName === expectedSetterName) {
|
|
444
431
|
return;
|
|
445
432
|
}
|
|
446
|
-
context.report({ messageId: "
|
|
433
|
+
context.report({ messageId: "useState", node: id });
|
|
447
434
|
}
|
|
448
435
|
}
|
|
449
436
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
2
|
import { useComponentCollector, useComponentCollectorLegacy, DEFAULT_COMPONENT_HINT, isUseStateCall, isReactHookCallWithNameLoose } from '@eslint-react/core';
|
|
3
|
-
import { isObject,
|
|
3
|
+
import { isObject, constFalse } from '@eslint-react/eff';
|
|
4
4
|
import * as JSX from '@eslint-react/jsx';
|
|
5
5
|
import { createRuleForPlugin, getSettingsFromContext, RE_CONSTANT_CASE, RE_PASCAL_CASE, RE_CAMEL_CASE, RE_KEBAB_CASE, RE_SNAKE_CASE } from '@eslint-react/shared';
|
|
6
6
|
import { match } from 'ts-pattern';
|
|
@@ -10,7 +10,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
|
10
10
|
|
|
11
11
|
// package.json
|
|
12
12
|
var name = "eslint-plugin-react-naming-convention";
|
|
13
|
-
var version = "1.26.3-
|
|
13
|
+
var version = "1.26.3-next.0";
|
|
14
14
|
var createRule = createRuleForPlugin("naming-convention");
|
|
15
15
|
|
|
16
16
|
// src/rules/component-name.ts
|
|
@@ -64,32 +64,26 @@ function normalizeOptions(options) {
|
|
|
64
64
|
excepts: opts.excepts?.map((pattern) => new RegExp(pattern, "u")) ?? []
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
function
|
|
68
|
-
if (name2 == null) return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
allowLeadingUnderscore = false,
|
|
72
|
-
allowNamespace = false,
|
|
73
|
-
excepts,
|
|
74
|
-
rule
|
|
75
|
-
} = options;
|
|
76
|
-
if (excepts.some((regex) => regex.test(name2))) {
|
|
77
|
-
return _;
|
|
67
|
+
function validate(name2, options) {
|
|
68
|
+
if (name2 == null) return false;
|
|
69
|
+
if (options.excepts.some((regex) => regex.test(name2))) {
|
|
70
|
+
return true;
|
|
78
71
|
}
|
|
79
72
|
let normalized = name2.normalize("NFKD").replace(/[\u0300-\u036F]/g, "");
|
|
80
73
|
normalized = normalized.split(".").at(-1) ?? normalized;
|
|
74
|
+
const { allowLeadingUnderscore = false, allowNamespace = false } = options;
|
|
81
75
|
if (allowNamespace) {
|
|
82
76
|
normalized = normalized.replace(":", "");
|
|
83
77
|
}
|
|
84
78
|
if (allowLeadingUnderscore) {
|
|
85
79
|
normalized = normalized.replace(/^_/, "");
|
|
86
80
|
}
|
|
87
|
-
return match(rule).with("CONSTANT_CASE", () => RE_CONSTANT_CASE.test(normalized)
|
|
81
|
+
return match(options.rule).with("CONSTANT_CASE", () => RE_CONSTANT_CASE.test(normalized)).with("PascalCase", () => {
|
|
88
82
|
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
|
|
89
|
-
return allowAllCaps
|
|
83
|
+
return options.allowAllCaps ?? false;
|
|
90
84
|
}
|
|
91
|
-
return RE_PASCAL_CASE.test(normalized)
|
|
92
|
-
}).otherwise(
|
|
85
|
+
return RE_PASCAL_CASE.test(normalized);
|
|
86
|
+
}).otherwise(constFalse);
|
|
93
87
|
}
|
|
94
88
|
var component_name_default = createRule({
|
|
95
89
|
meta: {
|
|
@@ -99,8 +93,7 @@ var component_name_default = createRule({
|
|
|
99
93
|
description: "enforce component naming convention to 'PascalCase' or 'CONSTANT_CASE'"
|
|
100
94
|
},
|
|
101
95
|
messages: {
|
|
102
|
-
|
|
103
|
-
usePascalCase: "Component name '{{name}}' must be in PascalCase."
|
|
96
|
+
componentName: "A component name must be in {{case}}."
|
|
104
97
|
},
|
|
105
98
|
schema
|
|
106
99
|
},
|
|
@@ -117,13 +110,14 @@ var component_name_default = createRule({
|
|
|
117
110
|
if (/^[a-z]/u.test(name2)) {
|
|
118
111
|
return;
|
|
119
112
|
}
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
if (validate(name2, options)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
122
116
|
context.report({
|
|
123
|
-
messageId:
|
|
117
|
+
messageId: "componentName",
|
|
124
118
|
node,
|
|
125
119
|
data: {
|
|
126
|
-
|
|
120
|
+
case: options.rule
|
|
127
121
|
}
|
|
128
122
|
});
|
|
129
123
|
},
|
|
@@ -133,30 +127,29 @@ var component_name_default = createRule({
|
|
|
133
127
|
for (const { node: component } of functionComponents.values()) {
|
|
134
128
|
const id = AST.getFunctionIdentifier(component);
|
|
135
129
|
if (id?.name == null) continue;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
130
|
+
if (validate(id.name, options)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
139
133
|
context.report({
|
|
140
|
-
messageId:
|
|
134
|
+
messageId: "componentName",
|
|
141
135
|
node: id,
|
|
142
136
|
data: {
|
|
143
|
-
|
|
137
|
+
case: options.rule
|
|
144
138
|
}
|
|
145
139
|
});
|
|
146
140
|
}
|
|
147
141
|
for (const { node: component } of classComponents.values()) {
|
|
148
142
|
const id = AST.getClassIdentifier(component);
|
|
149
143
|
if (id?.name == null) continue;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
});
|
|
144
|
+
if (!validate(id.name, options)) {
|
|
145
|
+
context.report({
|
|
146
|
+
messageId: "componentName",
|
|
147
|
+
node: id,
|
|
148
|
+
data: {
|
|
149
|
+
case: options.rule
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
160
153
|
}
|
|
161
154
|
}
|
|
162
155
|
};
|
|
@@ -208,7 +201,8 @@ var filename_default = createRule({
|
|
|
208
201
|
description: "enforce naming convention for JSX filenames"
|
|
209
202
|
},
|
|
210
203
|
messages: {
|
|
211
|
-
filenameCaseMismatch: "A file with name '{{name}}' does not match {{rule}}.
|
|
204
|
+
// filenameCaseMismatch: "A file with name '{{name}}' does not match {{rule}}.",
|
|
205
|
+
filenameCaseMismatchSuggestion: "A file with name '{{name}}' does not match {{rule}}. Should rename to '{{suggestion}}'.",
|
|
212
206
|
filenameEmpty: "A file must have non-empty name."
|
|
213
207
|
},
|
|
214
208
|
schema: schema2
|
|
@@ -218,7 +212,7 @@ var filename_default = createRule({
|
|
|
218
212
|
const options = context.options[0] ?? defaultOptions2[0];
|
|
219
213
|
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
220
214
|
const excepts = typeof options === "string" ? [] : options.excepts ?? [];
|
|
221
|
-
function
|
|
215
|
+
function validate2(name2, casing = rule, ignores = excepts) {
|
|
222
216
|
const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
|
|
223
217
|
if (shouldIgnore) return true;
|
|
224
218
|
return match(casing).with("PascalCase", () => RE_PASCAL_CASE.test(name2)).with("camelCase", () => RE_CAMEL_CASE.test(name2)).with("kebab-case", () => RE_KEBAB_CASE.test(name2)).with("snake_case", () => RE_SNAKE_CASE.test(name2)).exhaustive();
|
|
@@ -233,11 +227,11 @@ var filename_default = createRule({
|
|
|
233
227
|
context.report({ messageId: "filenameEmpty", node });
|
|
234
228
|
return;
|
|
235
229
|
}
|
|
236
|
-
if (
|
|
230
|
+
if (validate2(basename)) {
|
|
237
231
|
return;
|
|
238
232
|
}
|
|
239
233
|
context.report({
|
|
240
|
-
messageId: "
|
|
234
|
+
messageId: "filenameCaseMismatchSuggestion",
|
|
241
235
|
node,
|
|
242
236
|
data: {
|
|
243
237
|
name: context.filename,
|
|
@@ -294,8 +288,8 @@ var filename_extension_default = createRule({
|
|
|
294
288
|
description: "enforce naming convention for JSX file extensions"
|
|
295
289
|
},
|
|
296
290
|
messages: {
|
|
297
|
-
|
|
298
|
-
|
|
291
|
+
filenameExtensionInvalid: "The JSX file extension is required.",
|
|
292
|
+
filenameExtensionUnexpected: "Use JSX file extension as needed."
|
|
299
293
|
},
|
|
300
294
|
schema: schema3
|
|
301
295
|
},
|
|
@@ -304,7 +298,6 @@ var filename_extension_default = createRule({
|
|
|
304
298
|
const options = context.options[0] ?? defaultOptions3[0];
|
|
305
299
|
const allow = isObject(options) ? options.allow : options;
|
|
306
300
|
const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
|
|
307
|
-
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
|
|
308
301
|
const filename = context.filename;
|
|
309
302
|
let hasJSXNode = false;
|
|
310
303
|
return {
|
|
@@ -319,11 +312,8 @@ var filename_extension_default = createRule({
|
|
|
319
312
|
const isJSXExt = extensions.includes(fileNameExt);
|
|
320
313
|
if (hasJSXNode && !isJSXExt) {
|
|
321
314
|
context.report({
|
|
322
|
-
messageId: "
|
|
323
|
-
node
|
|
324
|
-
data: {
|
|
325
|
-
extensions: extensionsString
|
|
326
|
-
}
|
|
315
|
+
messageId: "filenameExtensionInvalid",
|
|
316
|
+
node
|
|
327
317
|
});
|
|
328
318
|
return;
|
|
329
319
|
}
|
|
@@ -334,11 +324,8 @@ var filename_extension_default = createRule({
|
|
|
334
324
|
}
|
|
335
325
|
if (!hasJSXNode && isJSXExt && allow === "as-needed") {
|
|
336
326
|
context.report({
|
|
337
|
-
messageId: "
|
|
338
|
-
node
|
|
339
|
-
data: {
|
|
340
|
-
extensions: extensionsString
|
|
341
|
-
}
|
|
327
|
+
messageId: "filenameExtensionUnexpected",
|
|
328
|
+
node
|
|
342
329
|
});
|
|
343
330
|
}
|
|
344
331
|
}
|
|
@@ -358,11 +345,11 @@ var use_state_default = createRule({
|
|
|
358
345
|
meta: {
|
|
359
346
|
type: "problem",
|
|
360
347
|
docs: {
|
|
361
|
-
description: "enforce destructuring and symmetric naming of 'useState' hook value and setter",
|
|
348
|
+
description: "enforce destructuring and symmetric naming of 'useState' hook value and setter variables",
|
|
362
349
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
363
350
|
},
|
|
364
351
|
messages: {
|
|
365
|
-
|
|
352
|
+
useState: "An useState call is not destructured into value + setter pair."
|
|
366
353
|
},
|
|
367
354
|
schema: []
|
|
368
355
|
},
|
|
@@ -398,14 +385,14 @@ var use_state_default = createRule({
|
|
|
398
385
|
const { id } = hookCall.parent;
|
|
399
386
|
switch (id.type) {
|
|
400
387
|
case AST_NODE_TYPES.Identifier: {
|
|
401
|
-
context.report({ messageId: "
|
|
388
|
+
context.report({ messageId: "useState", node: id });
|
|
402
389
|
break;
|
|
403
390
|
}
|
|
404
391
|
case AST_NODE_TYPES.ArrayPattern: {
|
|
405
392
|
const [state, setState] = id.elements;
|
|
406
393
|
if (state?.type === AST_NODE_TYPES.ObjectPattern && setState?.type === AST_NODE_TYPES.Identifier) {
|
|
407
394
|
if (!isSetterNameLoose(setState.name)) {
|
|
408
|
-
context.report({ messageId: "
|
|
395
|
+
context.report({ messageId: "useState", node: id });
|
|
409
396
|
}
|
|
410
397
|
break;
|
|
411
398
|
}
|
|
@@ -417,7 +404,7 @@ var use_state_default = createRule({
|
|
|
417
404
|
if (setStateName === expectedSetterName) {
|
|
418
405
|
return;
|
|
419
406
|
}
|
|
420
|
-
context.report({ messageId: "
|
|
407
|
+
context.report({ messageId: "useState", node: id });
|
|
421
408
|
}
|
|
422
409
|
}
|
|
423
410
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "1.26.3-
|
|
3
|
+
"version": "1.26.3-next.0",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -49,17 +49,17 @@
|
|
|
49
49
|
"@typescript-eslint/utils": "^8.23.0",
|
|
50
50
|
"string-ts": "^2.2.1",
|
|
51
51
|
"ts-pattern": "^5.6.2",
|
|
52
|
-
"@eslint-react/ast": "1.26.3-
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/shared": "1.26.3-
|
|
56
|
-
"@eslint-react/eff": "1.26.3-
|
|
52
|
+
"@eslint-react/ast": "1.26.3-next.0",
|
|
53
|
+
"@eslint-react/jsx": "1.26.3-next.0",
|
|
54
|
+
"@eslint-react/core": "1.26.3-next.0",
|
|
55
|
+
"@eslint-react/shared": "1.26.3-next.0",
|
|
56
|
+
"@eslint-react/eff": "1.26.3-next.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/react": "^19.0.8",
|
|
60
60
|
"@types/react-dom": "^19.0.3",
|
|
61
61
|
"tsup": "^8.3.6",
|
|
62
|
-
"@
|
|
62
|
+
"@workspace/configs": "0.0.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"eslint": "^8.57.0 || ^9.0.0",
|