eslint-plugin-react-naming-convention 1.29.1-next.5 → 1.29.1-next.6
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 +12 -14
- package/dist/index.d.ts +12 -14
- package/dist/index.js +34 -45
- package/dist/index.mjs +34 -45
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
2
|
import { RulePreset } from '@eslint-react/shared';
|
|
3
3
|
|
|
4
|
-
type MessageID$
|
|
4
|
+
type MessageID$1 = "useJsxFileExtension" | "useNonJsxFileExtension";
|
|
5
5
|
|
|
6
|
-
type MessageID
|
|
7
|
-
|
|
8
|
-
type MessageID = "usePascalCase" | "useConstantCase";
|
|
6
|
+
type MessageID = "filenameEmpty" | "filenameInvalid";
|
|
9
7
|
|
|
10
8
|
declare const _default: {
|
|
11
9
|
configs: {
|
|
@@ -17,25 +15,25 @@ declare const _default: {
|
|
|
17
15
|
readonly version: string;
|
|
18
16
|
};
|
|
19
17
|
readonly rules: {
|
|
20
|
-
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<
|
|
18
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
21
19
|
allowAllCaps?: boolean;
|
|
22
20
|
allowLeadingUnderscore?: boolean;
|
|
23
21
|
allowNamespace?: boolean;
|
|
24
22
|
excepts?: readonly string[];
|
|
25
23
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
26
24
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
|
-
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
28
|
-
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID
|
|
25
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
26
|
+
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
29
27
|
excepts?: readonly string[];
|
|
30
28
|
extensions?: readonly string[];
|
|
31
29
|
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
32
30
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
33
|
-
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$
|
|
31
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
34
32
|
allow?: "always" | "as-needed";
|
|
35
33
|
extensions?: readonly string[];
|
|
36
34
|
ignoreFilesWithoutCode?: boolean;
|
|
37
35
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
38
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
36
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
39
37
|
};
|
|
40
38
|
};
|
|
41
39
|
};
|
|
@@ -52,25 +50,25 @@ declare const _default: {
|
|
|
52
50
|
readonly version: string;
|
|
53
51
|
};
|
|
54
52
|
rules: {
|
|
55
|
-
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<
|
|
53
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
56
54
|
allowAllCaps?: boolean;
|
|
57
55
|
allowLeadingUnderscore?: boolean;
|
|
58
56
|
allowNamespace?: boolean;
|
|
59
57
|
excepts?: readonly string[];
|
|
60
58
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
61
59
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
62
|
-
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
63
|
-
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID
|
|
60
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
61
|
+
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
64
62
|
excepts?: readonly string[];
|
|
65
63
|
extensions?: readonly string[];
|
|
66
64
|
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
67
65
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
68
|
-
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$
|
|
66
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
69
67
|
allow?: "always" | "as-needed";
|
|
70
68
|
extensions?: readonly string[];
|
|
71
69
|
ignoreFilesWithoutCode?: boolean;
|
|
72
70
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
73
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
71
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
74
72
|
};
|
|
75
73
|
};
|
|
76
74
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
2
|
import { RulePreset } from '@eslint-react/shared';
|
|
3
3
|
|
|
4
|
-
type MessageID$
|
|
4
|
+
type MessageID$1 = "useJsxFileExtension" | "useNonJsxFileExtension";
|
|
5
5
|
|
|
6
|
-
type MessageID
|
|
7
|
-
|
|
8
|
-
type MessageID = "usePascalCase" | "useConstantCase";
|
|
6
|
+
type MessageID = "filenameEmpty" | "filenameInvalid";
|
|
9
7
|
|
|
10
8
|
declare const _default: {
|
|
11
9
|
configs: {
|
|
@@ -17,25 +15,25 @@ declare const _default: {
|
|
|
17
15
|
readonly version: string;
|
|
18
16
|
};
|
|
19
17
|
readonly rules: {
|
|
20
|
-
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<
|
|
18
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
21
19
|
allowAllCaps?: boolean;
|
|
22
20
|
allowLeadingUnderscore?: boolean;
|
|
23
21
|
allowNamespace?: boolean;
|
|
24
22
|
excepts?: readonly string[];
|
|
25
23
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
26
24
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
|
-
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
28
|
-
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID
|
|
25
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
26
|
+
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
29
27
|
excepts?: readonly string[];
|
|
30
28
|
extensions?: readonly string[];
|
|
31
29
|
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
32
30
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
33
|
-
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$
|
|
31
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
34
32
|
allow?: "always" | "as-needed";
|
|
35
33
|
extensions?: readonly string[];
|
|
36
34
|
ignoreFilesWithoutCode?: boolean;
|
|
37
35
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
38
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
36
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
39
37
|
};
|
|
40
38
|
};
|
|
41
39
|
};
|
|
@@ -52,25 +50,25 @@ declare const _default: {
|
|
|
52
50
|
readonly version: string;
|
|
53
51
|
};
|
|
54
52
|
rules: {
|
|
55
|
-
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<
|
|
53
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
56
54
|
allowAllCaps?: boolean;
|
|
57
55
|
allowLeadingUnderscore?: boolean;
|
|
58
56
|
allowNamespace?: boolean;
|
|
59
57
|
excepts?: readonly string[];
|
|
60
58
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
61
59
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
62
|
-
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
63
|
-
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID
|
|
60
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
61
|
+
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
64
62
|
excepts?: readonly string[];
|
|
65
63
|
extensions?: readonly string[];
|
|
66
64
|
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
67
65
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
68
|
-
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$
|
|
66
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
69
67
|
allow?: "always" | "as-needed";
|
|
70
68
|
extensions?: readonly string[];
|
|
71
69
|
ignoreFilesWithoutCode?: boolean;
|
|
72
70
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
73
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
71
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
74
72
|
};
|
|
75
73
|
};
|
|
76
74
|
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var AST = require('@eslint-react/ast');
|
|
4
4
|
var core = require('@eslint-react/core');
|
|
5
|
-
var eff = require('@eslint-react/eff');
|
|
6
5
|
var JSX = require('@eslint-react/jsx');
|
|
7
6
|
var shared = require('@eslint-react/shared');
|
|
7
|
+
var eff = require('@eslint-react/eff');
|
|
8
8
|
var types = require('@typescript-eslint/types');
|
|
9
9
|
var tsPattern = require('ts-pattern');
|
|
10
10
|
var path = require('path');
|
|
@@ -54,7 +54,7 @@ var rules = {
|
|
|
54
54
|
|
|
55
55
|
// package.json
|
|
56
56
|
var name2 = "eslint-plugin-react-naming-convention";
|
|
57
|
-
var version = "1.29.1-next.
|
|
57
|
+
var version = "1.29.1-next.6";
|
|
58
58
|
var createRule = shared.createRuleForPlugin("naming-convention");
|
|
59
59
|
|
|
60
60
|
// src/rules/component-name.ts
|
|
@@ -107,22 +107,20 @@ function normalizeOptions(options) {
|
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
if (name3 == null) return
|
|
112
|
-
if (options.excepts.some((regex) => regex.test(name3))) return
|
|
110
|
+
function isValidComponentName(name3, options) {
|
|
111
|
+
if (name3 == null) return true;
|
|
112
|
+
if (options.excepts.some((regex) => regex.test(name3))) return true;
|
|
113
113
|
let normalized = name3.split(".").at(-1) ?? name3;
|
|
114
114
|
if (options.allowNamespace) normalized = normalized.replace(":", "");
|
|
115
115
|
if (options.allowLeadingUnderscore) normalized = normalized.replace(/^_/, "");
|
|
116
116
|
switch (options.rule) {
|
|
117
117
|
case "CONSTANT_CASE":
|
|
118
|
-
return shared.RE_CONSTANT_CASE.test(normalized)
|
|
118
|
+
return shared.RE_CONSTANT_CASE.test(normalized);
|
|
119
119
|
case "PascalCase":
|
|
120
120
|
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
|
|
121
|
-
return options.allowAllCaps
|
|
121
|
+
return options.allowAllCaps;
|
|
122
122
|
}
|
|
123
|
-
return shared.RE_PASCAL_CASE.test(normalized)
|
|
124
|
-
default:
|
|
125
|
-
return eff._;
|
|
123
|
+
return shared.RE_PASCAL_CASE.test(normalized);
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
126
|
var component_name_default = createRule({
|
|
@@ -130,17 +128,17 @@ var component_name_default = createRule({
|
|
|
130
128
|
type: "problem",
|
|
131
129
|
defaultOptions: [...defaultOptions],
|
|
132
130
|
docs: {
|
|
133
|
-
description: "enforce
|
|
131
|
+
description: "enforce naming convention for components"
|
|
134
132
|
},
|
|
135
133
|
messages: {
|
|
136
|
-
|
|
137
|
-
usePascalCase: "Component name '{{name}}' must be in PascalCase."
|
|
134
|
+
invalid: "A component name '{{name}}' does not match {{rule}}."
|
|
138
135
|
},
|
|
139
136
|
schema
|
|
140
137
|
},
|
|
141
138
|
name: RULE_NAME,
|
|
142
139
|
create(context) {
|
|
143
140
|
const options = normalizeOptions(context.options);
|
|
141
|
+
const { rule } = options;
|
|
144
142
|
const collector = core.useComponentCollector(context);
|
|
145
143
|
const collectorLegacy = core.useComponentCollectorLegacy();
|
|
146
144
|
return {
|
|
@@ -151,14 +149,11 @@ var component_name_default = createRule({
|
|
|
151
149
|
if (/^[a-z]/u.test(name3)) {
|
|
152
150
|
return;
|
|
153
151
|
}
|
|
154
|
-
|
|
155
|
-
if (violation == null) return;
|
|
152
|
+
if (isValidComponentName(name3, options)) return;
|
|
156
153
|
context.report({
|
|
157
|
-
messageId:
|
|
154
|
+
messageId: "invalid",
|
|
158
155
|
node,
|
|
159
|
-
data: {
|
|
160
|
-
name: name3
|
|
161
|
-
}
|
|
156
|
+
data: { name: name3, rule }
|
|
162
157
|
});
|
|
163
158
|
},
|
|
164
159
|
"Program:exit"(node) {
|
|
@@ -168,28 +163,22 @@ var component_name_default = createRule({
|
|
|
168
163
|
const id = AST__namespace.getFunctionIdentifier(component);
|
|
169
164
|
if (id?.name == null) continue;
|
|
170
165
|
const name3 = id.name;
|
|
171
|
-
|
|
172
|
-
if (violation == null) continue;
|
|
166
|
+
if (isValidComponentName(name3, options)) return;
|
|
173
167
|
context.report({
|
|
174
|
-
messageId:
|
|
168
|
+
messageId: "invalid",
|
|
175
169
|
node: id,
|
|
176
|
-
data: {
|
|
177
|
-
name: name3
|
|
178
|
-
}
|
|
170
|
+
data: { name: name3, rule }
|
|
179
171
|
});
|
|
180
172
|
}
|
|
181
173
|
for (const { node: component } of classComponents.values()) {
|
|
182
174
|
const id = AST__namespace.getClassIdentifier(component);
|
|
183
175
|
if (id?.name == null) continue;
|
|
184
176
|
const name3 = id.name;
|
|
185
|
-
|
|
186
|
-
if (violation == null) continue;
|
|
177
|
+
if (isValidComponentName(name3, options)) continue;
|
|
187
178
|
context.report({
|
|
188
|
-
messageId:
|
|
179
|
+
messageId: "invalid",
|
|
189
180
|
node: id,
|
|
190
|
-
data: {
|
|
191
|
-
case: options.rule
|
|
192
|
-
}
|
|
181
|
+
data: { name: name3, rule }
|
|
193
182
|
});
|
|
194
183
|
}
|
|
195
184
|
}
|
|
@@ -202,10 +191,10 @@ var context_name_default = createRule({
|
|
|
202
191
|
meta: {
|
|
203
192
|
type: "problem",
|
|
204
193
|
docs: {
|
|
205
|
-
description: "
|
|
194
|
+
description: "enforce context name to be a valid component name with the suffix 'Context'"
|
|
206
195
|
},
|
|
207
196
|
messages: {
|
|
208
|
-
|
|
197
|
+
invalid: "A context name must be a valid component name with the suffix 'Context'."
|
|
209
198
|
},
|
|
210
199
|
schema: []
|
|
211
200
|
},
|
|
@@ -220,7 +209,7 @@ var context_name_default = createRule({
|
|
|
220
209
|
const name3 = tsPattern.match(id).with({ type: types.AST_NODE_TYPES.Identifier, name: tsPattern.P.select() }, eff.identity).with({ type: types.AST_NODE_TYPES.MemberExpression, property: { name: tsPattern.P.select(tsPattern.P.string) } }, eff.identity).otherwise(() => eff._);
|
|
221
210
|
if (name3 != null && /^[A-Z]/u.test(name3) && name3.endsWith("Context")) return;
|
|
222
211
|
context.report({
|
|
223
|
-
messageId: "
|
|
212
|
+
messageId: "invalid",
|
|
224
213
|
node: id
|
|
225
214
|
});
|
|
226
215
|
}
|
|
@@ -273,8 +262,8 @@ var filename_default = createRule({
|
|
|
273
262
|
description: "enforce naming convention for JSX filenames"
|
|
274
263
|
},
|
|
275
264
|
messages: {
|
|
276
|
-
|
|
277
|
-
|
|
265
|
+
filenameEmpty: "A file must have non-empty name.",
|
|
266
|
+
filenameInvalid: "A file with name '{{name}}' does not match {{rule}}. Rename it to '{{suggestion}}'."
|
|
278
267
|
},
|
|
279
268
|
schema: schema2
|
|
280
269
|
},
|
|
@@ -302,7 +291,7 @@ var filename_default = createRule({
|
|
|
302
291
|
return;
|
|
303
292
|
}
|
|
304
293
|
context.report({
|
|
305
|
-
messageId: "
|
|
294
|
+
messageId: "filenameInvalid",
|
|
306
295
|
node,
|
|
307
296
|
data: {
|
|
308
297
|
name: context.filename,
|
|
@@ -360,7 +349,7 @@ var filename_extension_default = createRule({
|
|
|
360
349
|
},
|
|
361
350
|
messages: {
|
|
362
351
|
useJsxFileExtension: "Use {{extensions}} file extension for JSX files.",
|
|
363
|
-
|
|
352
|
+
useNonJsxFileExtension: "Do not use {{extensions}} file extension for files without JSX."
|
|
364
353
|
},
|
|
365
354
|
schema: schema3
|
|
366
355
|
},
|
|
@@ -399,7 +388,7 @@ var filename_extension_default = createRule({
|
|
|
399
388
|
}
|
|
400
389
|
if (!hasJSXNode && isJSXExt && allow === "as-needed") {
|
|
401
390
|
context.report({
|
|
402
|
-
messageId: "
|
|
391
|
+
messageId: "useNonJsxFileExtension",
|
|
403
392
|
node,
|
|
404
393
|
data: {
|
|
405
394
|
extensions: extensionsString
|
|
@@ -423,7 +412,7 @@ var use_state_default = createRule({
|
|
|
423
412
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
424
413
|
},
|
|
425
414
|
messages: {
|
|
426
|
-
|
|
415
|
+
invalid: "An useState call is not destructured into value + setter pair."
|
|
427
416
|
},
|
|
428
417
|
schema: []
|
|
429
418
|
},
|
|
@@ -432,21 +421,21 @@ var use_state_default = createRule({
|
|
|
432
421
|
return {
|
|
433
422
|
"CallExpression[callee.name='useState']"(node) {
|
|
434
423
|
if (node.parent.type !== types.AST_NODE_TYPES.VariableDeclarator) {
|
|
435
|
-
context.report({ messageId: "
|
|
424
|
+
context.report({ messageId: "invalid", node });
|
|
436
425
|
}
|
|
437
426
|
const id = core.getInstanceId(node);
|
|
438
427
|
if (id?.type !== types.AST_NODE_TYPES.ArrayPattern) {
|
|
439
|
-
context.report({ messageId: "
|
|
428
|
+
context.report({ messageId: "invalid", node });
|
|
440
429
|
return;
|
|
441
430
|
}
|
|
442
431
|
const [value, setter] = id.elements;
|
|
443
432
|
if (value == null || setter == null) {
|
|
444
|
-
context.report({ messageId: "
|
|
433
|
+
context.report({ messageId: "invalid", node });
|
|
445
434
|
return;
|
|
446
435
|
}
|
|
447
436
|
const setterName = tsPattern.match(setter).with({ type: types.AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => eff._);
|
|
448
437
|
if (setterName == null || !setterName.startsWith("set")) {
|
|
449
|
-
context.report({ messageId: "
|
|
438
|
+
context.report({ messageId: "invalid", node });
|
|
450
439
|
return;
|
|
451
440
|
}
|
|
452
441
|
const valueName = tsPattern.match(value).with({ type: types.AST_NODE_TYPES.Identifier }, (id2) => id2.name).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
|
|
@@ -459,7 +448,7 @@ var use_state_default = createRule({
|
|
|
459
448
|
return values.join("_");
|
|
460
449
|
}).otherwise(() => eff._);
|
|
461
450
|
if (valueName == null || `set_${valueName}` !== stringTs.snakeCase(setterName)) {
|
|
462
|
-
context.report({ messageId: "
|
|
451
|
+
context.report({ messageId: "invalid", node });
|
|
463
452
|
return;
|
|
464
453
|
}
|
|
465
454
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
2
|
import { useComponentCollector, useComponentCollectorLegacy, isCreateContextCall, getInstanceId } from '@eslint-react/core';
|
|
3
|
-
import { identity, _, isObject } from '@eslint-react/eff';
|
|
4
3
|
import * as JSX from '@eslint-react/jsx';
|
|
5
4
|
import { createRuleForPlugin, RE_PASCAL_CASE, RE_CONSTANT_CASE, RE_CAMEL_CASE, RE_KEBAB_CASE, RE_SNAKE_CASE } from '@eslint-react/shared';
|
|
5
|
+
import { identity, _, isObject } from '@eslint-react/eff';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { match, P } from 'ts-pattern';
|
|
8
8
|
import path from 'node:path';
|
|
@@ -28,7 +28,7 @@ var rules = {
|
|
|
28
28
|
|
|
29
29
|
// package.json
|
|
30
30
|
var name2 = "eslint-plugin-react-naming-convention";
|
|
31
|
-
var version = "1.29.1-next.
|
|
31
|
+
var version = "1.29.1-next.6";
|
|
32
32
|
var createRule = createRuleForPlugin("naming-convention");
|
|
33
33
|
|
|
34
34
|
// src/rules/component-name.ts
|
|
@@ -81,22 +81,20 @@ function normalizeOptions(options) {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
if (name3 == null) return
|
|
86
|
-
if (options.excepts.some((regex) => regex.test(name3))) return
|
|
84
|
+
function isValidComponentName(name3, options) {
|
|
85
|
+
if (name3 == null) return true;
|
|
86
|
+
if (options.excepts.some((regex) => regex.test(name3))) return true;
|
|
87
87
|
let normalized = name3.split(".").at(-1) ?? name3;
|
|
88
88
|
if (options.allowNamespace) normalized = normalized.replace(":", "");
|
|
89
89
|
if (options.allowLeadingUnderscore) normalized = normalized.replace(/^_/, "");
|
|
90
90
|
switch (options.rule) {
|
|
91
91
|
case "CONSTANT_CASE":
|
|
92
|
-
return RE_CONSTANT_CASE.test(normalized)
|
|
92
|
+
return RE_CONSTANT_CASE.test(normalized);
|
|
93
93
|
case "PascalCase":
|
|
94
94
|
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
|
|
95
|
-
return options.allowAllCaps
|
|
95
|
+
return options.allowAllCaps;
|
|
96
96
|
}
|
|
97
|
-
return RE_PASCAL_CASE.test(normalized)
|
|
98
|
-
default:
|
|
99
|
-
return _;
|
|
97
|
+
return RE_PASCAL_CASE.test(normalized);
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
var component_name_default = createRule({
|
|
@@ -104,17 +102,17 @@ var component_name_default = createRule({
|
|
|
104
102
|
type: "problem",
|
|
105
103
|
defaultOptions: [...defaultOptions],
|
|
106
104
|
docs: {
|
|
107
|
-
description: "enforce
|
|
105
|
+
description: "enforce naming convention for components"
|
|
108
106
|
},
|
|
109
107
|
messages: {
|
|
110
|
-
|
|
111
|
-
usePascalCase: "Component name '{{name}}' must be in PascalCase."
|
|
108
|
+
invalid: "A component name '{{name}}' does not match {{rule}}."
|
|
112
109
|
},
|
|
113
110
|
schema
|
|
114
111
|
},
|
|
115
112
|
name: RULE_NAME,
|
|
116
113
|
create(context) {
|
|
117
114
|
const options = normalizeOptions(context.options);
|
|
115
|
+
const { rule } = options;
|
|
118
116
|
const collector = useComponentCollector(context);
|
|
119
117
|
const collectorLegacy = useComponentCollectorLegacy();
|
|
120
118
|
return {
|
|
@@ -125,14 +123,11 @@ var component_name_default = createRule({
|
|
|
125
123
|
if (/^[a-z]/u.test(name3)) {
|
|
126
124
|
return;
|
|
127
125
|
}
|
|
128
|
-
|
|
129
|
-
if (violation == null) return;
|
|
126
|
+
if (isValidComponentName(name3, options)) return;
|
|
130
127
|
context.report({
|
|
131
|
-
messageId:
|
|
128
|
+
messageId: "invalid",
|
|
132
129
|
node,
|
|
133
|
-
data: {
|
|
134
|
-
name: name3
|
|
135
|
-
}
|
|
130
|
+
data: { name: name3, rule }
|
|
136
131
|
});
|
|
137
132
|
},
|
|
138
133
|
"Program:exit"(node) {
|
|
@@ -142,28 +137,22 @@ var component_name_default = createRule({
|
|
|
142
137
|
const id = AST.getFunctionIdentifier(component);
|
|
143
138
|
if (id?.name == null) continue;
|
|
144
139
|
const name3 = id.name;
|
|
145
|
-
|
|
146
|
-
if (violation == null) continue;
|
|
140
|
+
if (isValidComponentName(name3, options)) return;
|
|
147
141
|
context.report({
|
|
148
|
-
messageId:
|
|
142
|
+
messageId: "invalid",
|
|
149
143
|
node: id,
|
|
150
|
-
data: {
|
|
151
|
-
name: name3
|
|
152
|
-
}
|
|
144
|
+
data: { name: name3, rule }
|
|
153
145
|
});
|
|
154
146
|
}
|
|
155
147
|
for (const { node: component } of classComponents.values()) {
|
|
156
148
|
const id = AST.getClassIdentifier(component);
|
|
157
149
|
if (id?.name == null) continue;
|
|
158
150
|
const name3 = id.name;
|
|
159
|
-
|
|
160
|
-
if (violation == null) continue;
|
|
151
|
+
if (isValidComponentName(name3, options)) continue;
|
|
161
152
|
context.report({
|
|
162
|
-
messageId:
|
|
153
|
+
messageId: "invalid",
|
|
163
154
|
node: id,
|
|
164
|
-
data: {
|
|
165
|
-
case: options.rule
|
|
166
|
-
}
|
|
155
|
+
data: { name: name3, rule }
|
|
167
156
|
});
|
|
168
157
|
}
|
|
169
158
|
}
|
|
@@ -176,10 +165,10 @@ var context_name_default = createRule({
|
|
|
176
165
|
meta: {
|
|
177
166
|
type: "problem",
|
|
178
167
|
docs: {
|
|
179
|
-
description: "
|
|
168
|
+
description: "enforce context name to be a valid component name with the suffix 'Context'"
|
|
180
169
|
},
|
|
181
170
|
messages: {
|
|
182
|
-
|
|
171
|
+
invalid: "A context name must be a valid component name with the suffix 'Context'."
|
|
183
172
|
},
|
|
184
173
|
schema: []
|
|
185
174
|
},
|
|
@@ -194,7 +183,7 @@ var context_name_default = createRule({
|
|
|
194
183
|
const name3 = match(id).with({ type: AST_NODE_TYPES.Identifier, name: P.select() }, identity).with({ type: AST_NODE_TYPES.MemberExpression, property: { name: P.select(P.string) } }, identity).otherwise(() => _);
|
|
195
184
|
if (name3 != null && /^[A-Z]/u.test(name3) && name3.endsWith("Context")) return;
|
|
196
185
|
context.report({
|
|
197
|
-
messageId: "
|
|
186
|
+
messageId: "invalid",
|
|
198
187
|
node: id
|
|
199
188
|
});
|
|
200
189
|
}
|
|
@@ -247,8 +236,8 @@ var filename_default = createRule({
|
|
|
247
236
|
description: "enforce naming convention for JSX filenames"
|
|
248
237
|
},
|
|
249
238
|
messages: {
|
|
250
|
-
|
|
251
|
-
|
|
239
|
+
filenameEmpty: "A file must have non-empty name.",
|
|
240
|
+
filenameInvalid: "A file with name '{{name}}' does not match {{rule}}. Rename it to '{{suggestion}}'."
|
|
252
241
|
},
|
|
253
242
|
schema: schema2
|
|
254
243
|
},
|
|
@@ -276,7 +265,7 @@ var filename_default = createRule({
|
|
|
276
265
|
return;
|
|
277
266
|
}
|
|
278
267
|
context.report({
|
|
279
|
-
messageId: "
|
|
268
|
+
messageId: "filenameInvalid",
|
|
280
269
|
node,
|
|
281
270
|
data: {
|
|
282
271
|
name: context.filename,
|
|
@@ -334,7 +323,7 @@ var filename_extension_default = createRule({
|
|
|
334
323
|
},
|
|
335
324
|
messages: {
|
|
336
325
|
useJsxFileExtension: "Use {{extensions}} file extension for JSX files.",
|
|
337
|
-
|
|
326
|
+
useNonJsxFileExtension: "Do not use {{extensions}} file extension for files without JSX."
|
|
338
327
|
},
|
|
339
328
|
schema: schema3
|
|
340
329
|
},
|
|
@@ -373,7 +362,7 @@ var filename_extension_default = createRule({
|
|
|
373
362
|
}
|
|
374
363
|
if (!hasJSXNode && isJSXExt && allow === "as-needed") {
|
|
375
364
|
context.report({
|
|
376
|
-
messageId: "
|
|
365
|
+
messageId: "useNonJsxFileExtension",
|
|
377
366
|
node,
|
|
378
367
|
data: {
|
|
379
368
|
extensions: extensionsString
|
|
@@ -397,7 +386,7 @@ var use_state_default = createRule({
|
|
|
397
386
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
398
387
|
},
|
|
399
388
|
messages: {
|
|
400
|
-
|
|
389
|
+
invalid: "An useState call is not destructured into value + setter pair."
|
|
401
390
|
},
|
|
402
391
|
schema: []
|
|
403
392
|
},
|
|
@@ -406,21 +395,21 @@ var use_state_default = createRule({
|
|
|
406
395
|
return {
|
|
407
396
|
"CallExpression[callee.name='useState']"(node) {
|
|
408
397
|
if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
409
|
-
context.report({ messageId: "
|
|
398
|
+
context.report({ messageId: "invalid", node });
|
|
410
399
|
}
|
|
411
400
|
const id = getInstanceId(node);
|
|
412
401
|
if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
413
|
-
context.report({ messageId: "
|
|
402
|
+
context.report({ messageId: "invalid", node });
|
|
414
403
|
return;
|
|
415
404
|
}
|
|
416
405
|
const [value, setter] = id.elements;
|
|
417
406
|
if (value == null || setter == null) {
|
|
418
|
-
context.report({ messageId: "
|
|
407
|
+
context.report({ messageId: "invalid", node });
|
|
419
408
|
return;
|
|
420
409
|
}
|
|
421
410
|
const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => _);
|
|
422
411
|
if (setterName == null || !setterName.startsWith("set")) {
|
|
423
|
-
context.report({ messageId: "
|
|
412
|
+
context.report({ messageId: "invalid", node });
|
|
424
413
|
return;
|
|
425
414
|
}
|
|
426
415
|
const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, (id2) => id2.name).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
|
|
@@ -433,7 +422,7 @@ var use_state_default = createRule({
|
|
|
433
422
|
return values.join("_");
|
|
434
423
|
}).otherwise(() => _);
|
|
435
424
|
if (valueName == null || `set_${valueName}` !== snakeCase(setterName)) {
|
|
436
|
-
context.report({ messageId: "
|
|
425
|
+
context.report({ messageId: "invalid", node });
|
|
437
426
|
return;
|
|
438
427
|
}
|
|
439
428
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "1.29.1-next.
|
|
3
|
+
"version": "1.29.1-next.6",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"@typescript-eslint/utils": "^8.25.0",
|
|
50
50
|
"string-ts": "^2.2.1",
|
|
51
51
|
"ts-pattern": "^5.6.2",
|
|
52
|
-
"@eslint-react/ast": "1.29.1-next.
|
|
53
|
-
"@eslint-react/eff": "1.29.1-next.
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/core": "1.29.1-next.
|
|
57
|
-
"@eslint-react/var": "1.29.1-next.
|
|
52
|
+
"@eslint-react/ast": "1.29.1-next.6",
|
|
53
|
+
"@eslint-react/eff": "1.29.1-next.6",
|
|
54
|
+
"@eslint-react/jsx": "1.29.1-next.6",
|
|
55
|
+
"@eslint-react/shared": "1.29.1-next.6",
|
|
56
|
+
"@eslint-react/core": "1.29.1-next.6",
|
|
57
|
+
"@eslint-react/var": "1.29.1-next.6"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/react": "^19.0.10",
|