eslint-plugin-react-naming-convention 1.26.3-beta.7 → 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 +43 -57
- package/dist/index.mjs +44 -58
- 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
|
};
|
|
@@ -245,7 +238,7 @@ var filename_default = createRule({
|
|
|
245
238
|
const options = context.options[0] ?? defaultOptions2[0];
|
|
246
239
|
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
247
240
|
const excepts = typeof options === "string" ? [] : options.excepts ?? [];
|
|
248
|
-
function
|
|
241
|
+
function validate2(name2, casing = rule, ignores = excepts) {
|
|
249
242
|
const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
|
|
250
243
|
if (shouldIgnore) return true;
|
|
251
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();
|
|
@@ -260,7 +253,7 @@ var filename_default = createRule({
|
|
|
260
253
|
context.report({ messageId: "filenameEmpty", node });
|
|
261
254
|
return;
|
|
262
255
|
}
|
|
263
|
-
if (
|
|
256
|
+
if (validate2(basename)) {
|
|
264
257
|
return;
|
|
265
258
|
}
|
|
266
259
|
context.report({
|
|
@@ -321,8 +314,8 @@ var filename_extension_default = createRule({
|
|
|
321
314
|
description: "enforce naming convention for JSX file extensions"
|
|
322
315
|
},
|
|
323
316
|
messages: {
|
|
324
|
-
|
|
325
|
-
|
|
317
|
+
filenameExtensionInvalid: "The JSX file extension is required.",
|
|
318
|
+
filenameExtensionUnexpected: "Use JSX file extension as needed."
|
|
326
319
|
},
|
|
327
320
|
schema: schema3
|
|
328
321
|
},
|
|
@@ -331,7 +324,6 @@ var filename_extension_default = createRule({
|
|
|
331
324
|
const options = context.options[0] ?? defaultOptions3[0];
|
|
332
325
|
const allow = eff.isObject(options) ? options.allow : options;
|
|
333
326
|
const extensions = eff.isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
|
|
334
|
-
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
|
|
335
327
|
const filename = context.filename;
|
|
336
328
|
let hasJSXNode = false;
|
|
337
329
|
return {
|
|
@@ -346,11 +338,8 @@ var filename_extension_default = createRule({
|
|
|
346
338
|
const isJSXExt = extensions.includes(fileNameExt);
|
|
347
339
|
if (hasJSXNode && !isJSXExt) {
|
|
348
340
|
context.report({
|
|
349
|
-
messageId: "
|
|
350
|
-
node
|
|
351
|
-
data: {
|
|
352
|
-
extensions: extensionsString
|
|
353
|
-
}
|
|
341
|
+
messageId: "filenameExtensionInvalid",
|
|
342
|
+
node
|
|
354
343
|
});
|
|
355
344
|
return;
|
|
356
345
|
}
|
|
@@ -361,11 +350,8 @@ var filename_extension_default = createRule({
|
|
|
361
350
|
}
|
|
362
351
|
if (!hasJSXNode && isJSXExt && allow === "as-needed") {
|
|
363
352
|
context.report({
|
|
364
|
-
messageId: "
|
|
365
|
-
node
|
|
366
|
-
data: {
|
|
367
|
-
extensions: extensionsString
|
|
368
|
-
}
|
|
353
|
+
messageId: "filenameExtensionUnexpected",
|
|
354
|
+
node
|
|
369
355
|
});
|
|
370
356
|
}
|
|
371
357
|
}
|
|
@@ -385,11 +371,11 @@ var use_state_default = createRule({
|
|
|
385
371
|
meta: {
|
|
386
372
|
type: "problem",
|
|
387
373
|
docs: {
|
|
388
|
-
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",
|
|
389
375
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
390
376
|
},
|
|
391
377
|
messages: {
|
|
392
|
-
|
|
378
|
+
useState: "An useState call is not destructured into value + setter pair."
|
|
393
379
|
},
|
|
394
380
|
schema: []
|
|
395
381
|
},
|
|
@@ -425,14 +411,14 @@ var use_state_default = createRule({
|
|
|
425
411
|
const { id } = hookCall.parent;
|
|
426
412
|
switch (id.type) {
|
|
427
413
|
case types.AST_NODE_TYPES.Identifier: {
|
|
428
|
-
context.report({ messageId: "
|
|
414
|
+
context.report({ messageId: "useState", node: id });
|
|
429
415
|
break;
|
|
430
416
|
}
|
|
431
417
|
case types.AST_NODE_TYPES.ArrayPattern: {
|
|
432
418
|
const [state, setState] = id.elements;
|
|
433
419
|
if (state?.type === types.AST_NODE_TYPES.ObjectPattern && setState?.type === types.AST_NODE_TYPES.Identifier) {
|
|
434
420
|
if (!isSetterNameLoose(setState.name)) {
|
|
435
|
-
context.report({ messageId: "
|
|
421
|
+
context.report({ messageId: "useState", node: id });
|
|
436
422
|
}
|
|
437
423
|
break;
|
|
438
424
|
}
|
|
@@ -444,7 +430,7 @@ var use_state_default = createRule({
|
|
|
444
430
|
if (setStateName === expectedSetterName) {
|
|
445
431
|
return;
|
|
446
432
|
}
|
|
447
|
-
context.report({ messageId: "
|
|
433
|
+
context.report({ messageId: "useState", node: id });
|
|
448
434
|
}
|
|
449
435
|
}
|
|
450
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
|
};
|
|
@@ -219,7 +212,7 @@ var filename_default = createRule({
|
|
|
219
212
|
const options = context.options[0] ?? defaultOptions2[0];
|
|
220
213
|
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
221
214
|
const excepts = typeof options === "string" ? [] : options.excepts ?? [];
|
|
222
|
-
function
|
|
215
|
+
function validate2(name2, casing = rule, ignores = excepts) {
|
|
223
216
|
const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
|
|
224
217
|
if (shouldIgnore) return true;
|
|
225
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();
|
|
@@ -234,7 +227,7 @@ var filename_default = createRule({
|
|
|
234
227
|
context.report({ messageId: "filenameEmpty", node });
|
|
235
228
|
return;
|
|
236
229
|
}
|
|
237
|
-
if (
|
|
230
|
+
if (validate2(basename)) {
|
|
238
231
|
return;
|
|
239
232
|
}
|
|
240
233
|
context.report({
|
|
@@ -295,8 +288,8 @@ var filename_extension_default = createRule({
|
|
|
295
288
|
description: "enforce naming convention for JSX file extensions"
|
|
296
289
|
},
|
|
297
290
|
messages: {
|
|
298
|
-
|
|
299
|
-
|
|
291
|
+
filenameExtensionInvalid: "The JSX file extension is required.",
|
|
292
|
+
filenameExtensionUnexpected: "Use JSX file extension as needed."
|
|
300
293
|
},
|
|
301
294
|
schema: schema3
|
|
302
295
|
},
|
|
@@ -305,7 +298,6 @@ var filename_extension_default = createRule({
|
|
|
305
298
|
const options = context.options[0] ?? defaultOptions3[0];
|
|
306
299
|
const allow = isObject(options) ? options.allow : options;
|
|
307
300
|
const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
|
|
308
|
-
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
|
|
309
301
|
const filename = context.filename;
|
|
310
302
|
let hasJSXNode = false;
|
|
311
303
|
return {
|
|
@@ -320,11 +312,8 @@ var filename_extension_default = createRule({
|
|
|
320
312
|
const isJSXExt = extensions.includes(fileNameExt);
|
|
321
313
|
if (hasJSXNode && !isJSXExt) {
|
|
322
314
|
context.report({
|
|
323
|
-
messageId: "
|
|
324
|
-
node
|
|
325
|
-
data: {
|
|
326
|
-
extensions: extensionsString
|
|
327
|
-
}
|
|
315
|
+
messageId: "filenameExtensionInvalid",
|
|
316
|
+
node
|
|
328
317
|
});
|
|
329
318
|
return;
|
|
330
319
|
}
|
|
@@ -335,11 +324,8 @@ var filename_extension_default = createRule({
|
|
|
335
324
|
}
|
|
336
325
|
if (!hasJSXNode && isJSXExt && allow === "as-needed") {
|
|
337
326
|
context.report({
|
|
338
|
-
messageId: "
|
|
339
|
-
node
|
|
340
|
-
data: {
|
|
341
|
-
extensions: extensionsString
|
|
342
|
-
}
|
|
327
|
+
messageId: "filenameExtensionUnexpected",
|
|
328
|
+
node
|
|
343
329
|
});
|
|
344
330
|
}
|
|
345
331
|
}
|
|
@@ -359,11 +345,11 @@ var use_state_default = createRule({
|
|
|
359
345
|
meta: {
|
|
360
346
|
type: "problem",
|
|
361
347
|
docs: {
|
|
362
|
-
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",
|
|
363
349
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
364
350
|
},
|
|
365
351
|
messages: {
|
|
366
|
-
|
|
352
|
+
useState: "An useState call is not destructured into value + setter pair."
|
|
367
353
|
},
|
|
368
354
|
schema: []
|
|
369
355
|
},
|
|
@@ -399,14 +385,14 @@ var use_state_default = createRule({
|
|
|
399
385
|
const { id } = hookCall.parent;
|
|
400
386
|
switch (id.type) {
|
|
401
387
|
case AST_NODE_TYPES.Identifier: {
|
|
402
|
-
context.report({ messageId: "
|
|
388
|
+
context.report({ messageId: "useState", node: id });
|
|
403
389
|
break;
|
|
404
390
|
}
|
|
405
391
|
case AST_NODE_TYPES.ArrayPattern: {
|
|
406
392
|
const [state, setState] = id.elements;
|
|
407
393
|
if (state?.type === AST_NODE_TYPES.ObjectPattern && setState?.type === AST_NODE_TYPES.Identifier) {
|
|
408
394
|
if (!isSetterNameLoose(setState.name)) {
|
|
409
|
-
context.report({ messageId: "
|
|
395
|
+
context.report({ messageId: "useState", node: id });
|
|
410
396
|
}
|
|
411
397
|
break;
|
|
412
398
|
}
|
|
@@ -418,7 +404,7 @@ var use_state_default = createRule({
|
|
|
418
404
|
if (setStateName === expectedSetterName) {
|
|
419
405
|
return;
|
|
420
406
|
}
|
|
421
|
-
context.report({ messageId: "
|
|
407
|
+
context.report({ messageId: "useState", node: id });
|
|
422
408
|
}
|
|
423
409
|
}
|
|
424
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/
|
|
56
|
-
"@eslint-react/
|
|
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",
|