eslint-plugin-react-naming-convention 2.14.0-next.0 → 3.0.0-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.js +35 -216
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RE_CONSTANT_CASE, RE_PASCAL_CASE, WEBSITE_URL, defineRuleListener, getConfigAdapters, getSettingsFromContext, toRegExp } from "@eslint-react/shared";
|
|
2
2
|
import * as core from "@eslint-react/core";
|
|
3
3
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
4
4
|
import { findEnclosingAssignmentTarget } from "@eslint-react/var";
|
|
@@ -6,9 +6,7 @@ import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
|
6
6
|
import { compare } from "compare-versions";
|
|
7
7
|
import { P, match } from "ts-pattern";
|
|
8
8
|
import * as ast from "@eslint-react/ast";
|
|
9
|
-
import {
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import { isObject } from "@eslint-react/eff";
|
|
9
|
+
import { snakeCase } from "string-ts";
|
|
12
10
|
|
|
13
11
|
//#region \0rolldown/runtime.js
|
|
14
12
|
var __defProp = Object.defineProperty;
|
|
@@ -43,7 +41,7 @@ const rules = {
|
|
|
43
41
|
//#endregion
|
|
44
42
|
//#region package.json
|
|
45
43
|
var name = "eslint-plugin-react-naming-convention";
|
|
46
|
-
var version = "
|
|
44
|
+
var version = "3.0.0-next.0";
|
|
47
45
|
|
|
48
46
|
//#endregion
|
|
49
47
|
//#region src/utils/create-rule.ts
|
|
@@ -54,12 +52,12 @@ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
|
54
52
|
|
|
55
53
|
//#endregion
|
|
56
54
|
//#region src/rules/component-name.ts
|
|
57
|
-
const defaultOptions$
|
|
55
|
+
const defaultOptions$1 = [{
|
|
58
56
|
allowAllCaps: false,
|
|
59
57
|
excepts: [],
|
|
60
58
|
rule: "PascalCase"
|
|
61
59
|
}];
|
|
62
|
-
const schema$
|
|
60
|
+
const schema$1 = [{ anyOf: [{
|
|
63
61
|
type: "string",
|
|
64
62
|
enum: ["PascalCase", "CONSTANT_CASE"]
|
|
65
63
|
}, {
|
|
@@ -80,20 +78,20 @@ const schema$3 = [{ anyOf: [{
|
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
80
|
}] }];
|
|
83
|
-
const RULE_NAME$
|
|
81
|
+
const RULE_NAME$4 = "component-name";
|
|
84
82
|
var component_name_default = createRule({
|
|
85
83
|
meta: {
|
|
86
84
|
type: "problem",
|
|
87
|
-
defaultOptions: [...defaultOptions$
|
|
85
|
+
defaultOptions: [...defaultOptions$1],
|
|
88
86
|
docs: { description: "Enforces naming conventions for components." },
|
|
89
87
|
messages: { invalidComponentName: "A component name '{{name}}' does not match {{rule}}." },
|
|
90
|
-
schema: schema$
|
|
88
|
+
schema: schema$1
|
|
91
89
|
},
|
|
92
|
-
name: RULE_NAME$
|
|
93
|
-
create: create$
|
|
94
|
-
defaultOptions: defaultOptions$
|
|
90
|
+
name: RULE_NAME$4,
|
|
91
|
+
create: create$4,
|
|
92
|
+
defaultOptions: defaultOptions$1
|
|
95
93
|
});
|
|
96
|
-
function create$
|
|
94
|
+
function create$4(context) {
|
|
97
95
|
const options = normalizeOptions(context.options);
|
|
98
96
|
const { rule } = options;
|
|
99
97
|
const fCollector = core.useComponentCollector(context);
|
|
@@ -125,7 +123,7 @@ function create$6(context) {
|
|
|
125
123
|
}
|
|
126
124
|
function normalizeOptions(options) {
|
|
127
125
|
const opts = options[0];
|
|
128
|
-
const defaultOpts = defaultOptions$
|
|
126
|
+
const defaultOpts = defaultOptions$1[0];
|
|
129
127
|
if (opts == null) return defaultOpts;
|
|
130
128
|
return {
|
|
131
129
|
...defaultOpts,
|
|
@@ -149,7 +147,7 @@ function isValidName(name, options) {
|
|
|
149
147
|
|
|
150
148
|
//#endregion
|
|
151
149
|
//#region src/rules/context-name.ts
|
|
152
|
-
const RULE_NAME$
|
|
150
|
+
const RULE_NAME$3 = "context-name";
|
|
153
151
|
var context_name_default = createRule({
|
|
154
152
|
meta: {
|
|
155
153
|
type: "suggestion",
|
|
@@ -157,11 +155,11 @@ var context_name_default = createRule({
|
|
|
157
155
|
messages: { invalidContextName: "A context name must be a valid component name with the suffix 'Context'." },
|
|
158
156
|
schema: []
|
|
159
157
|
},
|
|
160
|
-
name: RULE_NAME$
|
|
161
|
-
create: create$
|
|
158
|
+
name: RULE_NAME$3,
|
|
159
|
+
create: create$3,
|
|
162
160
|
defaultOptions: []
|
|
163
161
|
});
|
|
164
|
-
function create$
|
|
162
|
+
function create$3(context) {
|
|
165
163
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
166
164
|
const { version } = getSettingsFromContext(context);
|
|
167
165
|
if (compare(version, "19.0.0", "<")) return {};
|
|
@@ -185,7 +183,7 @@ function create$5(context) {
|
|
|
185
183
|
|
|
186
184
|
//#endregion
|
|
187
185
|
//#region src/rules/id-name.ts
|
|
188
|
-
const RULE_NAME$
|
|
186
|
+
const RULE_NAME$2 = "id-name";
|
|
189
187
|
var id_name_default = createRule({
|
|
190
188
|
meta: {
|
|
191
189
|
type: "suggestion",
|
|
@@ -193,11 +191,11 @@ var id_name_default = createRule({
|
|
|
193
191
|
messages: { invalidIdName: "An identifier assigned from 'useId' must be named 'id' or end with 'Id'." },
|
|
194
192
|
schema: []
|
|
195
193
|
},
|
|
196
|
-
name: RULE_NAME$
|
|
197
|
-
create: create$
|
|
194
|
+
name: RULE_NAME$2,
|
|
195
|
+
create: create$2,
|
|
198
196
|
defaultOptions: []
|
|
199
197
|
});
|
|
200
|
-
function create$
|
|
198
|
+
function create$2(context) {
|
|
201
199
|
if (!context.sourceCode.text.includes("useId")) return {};
|
|
202
200
|
return { CallExpression(node) {
|
|
203
201
|
if (!core.isUseIdCall(node)) return;
|
|
@@ -219,7 +217,7 @@ function create$4(context) {
|
|
|
219
217
|
|
|
220
218
|
//#endregion
|
|
221
219
|
//#region src/rules/ref-name.ts
|
|
222
|
-
const RULE_NAME$
|
|
220
|
+
const RULE_NAME$1 = "ref-name";
|
|
223
221
|
var ref_name_default = createRule({
|
|
224
222
|
meta: {
|
|
225
223
|
type: "suggestion",
|
|
@@ -227,11 +225,11 @@ var ref_name_default = createRule({
|
|
|
227
225
|
messages: { invalidRefName: "A ref identifier must be named 'ref' or ending in 'Ref'." },
|
|
228
226
|
schema: []
|
|
229
227
|
},
|
|
230
|
-
name: RULE_NAME$
|
|
231
|
-
create: create$
|
|
228
|
+
name: RULE_NAME$1,
|
|
229
|
+
create: create$1,
|
|
232
230
|
defaultOptions: []
|
|
233
231
|
});
|
|
234
|
-
function create$
|
|
232
|
+
function create$1(context) {
|
|
235
233
|
if (!context.sourceCode.text.includes("useRef")) return {};
|
|
236
234
|
return { CallExpression(node) {
|
|
237
235
|
if (!core.isUseRefCall(node)) return;
|
|
@@ -254,12 +252,12 @@ function create$3(context) {
|
|
|
254
252
|
|
|
255
253
|
//#endregion
|
|
256
254
|
//#region src/rules/use-state.ts
|
|
257
|
-
const RULE_NAME
|
|
258
|
-
const defaultOptions
|
|
255
|
+
const RULE_NAME = "use-state";
|
|
256
|
+
const defaultOptions = [{
|
|
259
257
|
enforceAssignment: false,
|
|
260
258
|
enforceSetterName: true
|
|
261
259
|
}];
|
|
262
|
-
const schema
|
|
260
|
+
const schema = [{
|
|
263
261
|
type: "object",
|
|
264
262
|
additionalProperties: false,
|
|
265
263
|
properties: {
|
|
@@ -281,14 +279,14 @@ var use_state_default = createRule({
|
|
|
281
279
|
invalidAssignment: "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...).",
|
|
282
280
|
invalidSetterName: "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'."
|
|
283
281
|
},
|
|
284
|
-
schema
|
|
282
|
+
schema
|
|
285
283
|
},
|
|
286
|
-
name: RULE_NAME
|
|
287
|
-
create
|
|
288
|
-
defaultOptions
|
|
284
|
+
name: RULE_NAME,
|
|
285
|
+
create,
|
|
286
|
+
defaultOptions
|
|
289
287
|
});
|
|
290
|
-
function create
|
|
291
|
-
const { enforceAssignment = false, enforceSetterName = true } = context.options[0] ?? defaultOptions
|
|
288
|
+
function create(context) {
|
|
289
|
+
const { enforceAssignment = false, enforceSetterName = true } = context.options[0] ?? defaultOptions[0];
|
|
292
290
|
return { CallExpression(node) {
|
|
293
291
|
if (!core.isUseStateCall(node)) return;
|
|
294
292
|
if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
@@ -349,183 +347,6 @@ function create$2(context) {
|
|
|
349
347
|
} };
|
|
350
348
|
}
|
|
351
349
|
|
|
352
|
-
//#endregion
|
|
353
|
-
//#region src/rules-removed/filename.ts
|
|
354
|
-
const RULE_NAME$1 = "filename";
|
|
355
|
-
const defaultOptions$1 = [{
|
|
356
|
-
excepts: [
|
|
357
|
-
"index",
|
|
358
|
-
String.raw`/^_/`,
|
|
359
|
-
String.raw`/^\$/`,
|
|
360
|
-
String.raw`/^[0-9]+$/`,
|
|
361
|
-
String.raw`/^\[[^\]]+\]$/`
|
|
362
|
-
],
|
|
363
|
-
rule: "PascalCase"
|
|
364
|
-
}];
|
|
365
|
-
const schema$1 = [{ anyOf: [{
|
|
366
|
-
type: "string",
|
|
367
|
-
enum: [
|
|
368
|
-
"PascalCase",
|
|
369
|
-
"camelCase",
|
|
370
|
-
"kebab-case",
|
|
371
|
-
"snake_case"
|
|
372
|
-
]
|
|
373
|
-
}, {
|
|
374
|
-
type: "object",
|
|
375
|
-
additionalProperties: false,
|
|
376
|
-
properties: {
|
|
377
|
-
excepts: {
|
|
378
|
-
type: "array",
|
|
379
|
-
items: {
|
|
380
|
-
type: "string",
|
|
381
|
-
format: "regex"
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
extensions: {
|
|
385
|
-
type: "array",
|
|
386
|
-
items: { type: "string" },
|
|
387
|
-
uniqueItems: true
|
|
388
|
-
},
|
|
389
|
-
rule: {
|
|
390
|
-
type: "string",
|
|
391
|
-
enum: [
|
|
392
|
-
"PascalCase",
|
|
393
|
-
"camelCase",
|
|
394
|
-
"kebab-case",
|
|
395
|
-
"snake_case"
|
|
396
|
-
]
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}] }];
|
|
400
|
-
var filename_default = createRule({
|
|
401
|
-
meta: {
|
|
402
|
-
type: "suggestion",
|
|
403
|
-
defaultOptions: [...defaultOptions$1],
|
|
404
|
-
docs: { description: "Enforces consistent file-naming conventions." },
|
|
405
|
-
messages: {
|
|
406
|
-
fileNameEmpty: "A source file must have non-empty name.",
|
|
407
|
-
fileNameInvalidCase: "A source file with name '{{name}}' does not match {{rule}}. Rename it to '{{suggestion}}'."
|
|
408
|
-
},
|
|
409
|
-
schema: schema$1
|
|
410
|
-
},
|
|
411
|
-
name: RULE_NAME$1,
|
|
412
|
-
create: create$1,
|
|
413
|
-
defaultOptions: defaultOptions$1
|
|
414
|
-
});
|
|
415
|
-
function create$1(context) {
|
|
416
|
-
const options = context.options[0] ?? defaultOptions$1[0];
|
|
417
|
-
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
418
|
-
const excepts = typeof options === "string" ? [] : (options.excepts ?? []).map((s) => toRegExp(s));
|
|
419
|
-
function validate(name, casing = rule, ignores = excepts) {
|
|
420
|
-
if (ignores.some((pattern) => pattern.test(name))) return true;
|
|
421
|
-
const filteredName = name.match(/[\w.-]/gu)?.join("") ?? "";
|
|
422
|
-
if (filteredName.length === 0) return true;
|
|
423
|
-
return match(casing).with("PascalCase", () => RE_PASCAL_CASE.test(filteredName)).with("camelCase", () => RE_CAMEL_CASE.test(filteredName)).with("kebab-case", () => RE_KEBAB_CASE.test(filteredName)).with("snake_case", () => RE_SNAKE_CASE.test(filteredName)).exhaustive();
|
|
424
|
-
}
|
|
425
|
-
function getSuggestion(name, casing = rule) {
|
|
426
|
-
return match(casing).with("PascalCase", () => pascalCase(name)).with("camelCase", () => camelCase(name)).with("kebab-case", () => kebabCase(name)).with("snake_case", () => snakeCase(name)).exhaustive();
|
|
427
|
-
}
|
|
428
|
-
return { Program(node) {
|
|
429
|
-
const [basename = "", ...rest] = path.basename(context.filename).split(".");
|
|
430
|
-
if (basename.length === 0) {
|
|
431
|
-
context.report({
|
|
432
|
-
messageId: "fileNameEmpty",
|
|
433
|
-
node
|
|
434
|
-
});
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
if (validate(basename)) return;
|
|
438
|
-
context.report({
|
|
439
|
-
messageId: "fileNameInvalidCase",
|
|
440
|
-
node,
|
|
441
|
-
data: {
|
|
442
|
-
name: context.filename,
|
|
443
|
-
rule,
|
|
444
|
-
suggestion: [getSuggestion(basename), ...rest].join(".")
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
} };
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
//#endregion
|
|
451
|
-
//#region src/rules-removed/filename-extension.ts
|
|
452
|
-
const RULE_NAME = "filename-extension";
|
|
453
|
-
const defaultOptions = [{
|
|
454
|
-
allow: "as-needed",
|
|
455
|
-
extensions: [".jsx", ".tsx"],
|
|
456
|
-
ignoreFilesWithoutCode: false
|
|
457
|
-
}];
|
|
458
|
-
const schema = [{ anyOf: [{
|
|
459
|
-
type: "string",
|
|
460
|
-
enum: ["always", "as-needed"]
|
|
461
|
-
}, {
|
|
462
|
-
type: "object",
|
|
463
|
-
additionalProperties: false,
|
|
464
|
-
properties: {
|
|
465
|
-
allow: {
|
|
466
|
-
type: "string",
|
|
467
|
-
enum: ["always", "as-needed"]
|
|
468
|
-
},
|
|
469
|
-
extensions: {
|
|
470
|
-
type: "array",
|
|
471
|
-
items: { type: "string" },
|
|
472
|
-
uniqueItems: true
|
|
473
|
-
},
|
|
474
|
-
ignoreFilesWithoutCode: { type: "boolean" }
|
|
475
|
-
}
|
|
476
|
-
}] }];
|
|
477
|
-
var filename_extension_default = createRule({
|
|
478
|
-
meta: {
|
|
479
|
-
type: "suggestion",
|
|
480
|
-
defaultOptions: [...defaultOptions],
|
|
481
|
-
docs: { description: "Enforces consistent use of the JSX file extension." },
|
|
482
|
-
messages: {
|
|
483
|
-
missingJsxExtension: "Use {{extensions}} file extension for JSX files.",
|
|
484
|
-
unnecessaryJsxExtension: "Do not use {{extensions}} file extension for files without JSX."
|
|
485
|
-
},
|
|
486
|
-
schema
|
|
487
|
-
},
|
|
488
|
-
name: RULE_NAME,
|
|
489
|
-
create,
|
|
490
|
-
defaultOptions
|
|
491
|
-
});
|
|
492
|
-
function create(context) {
|
|
493
|
-
const options = context.options[0] ?? defaultOptions[0];
|
|
494
|
-
const allow = isObject(options) ? options.allow : options;
|
|
495
|
-
const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions[0].extensions;
|
|
496
|
-
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
|
|
497
|
-
const filename = context.filename;
|
|
498
|
-
let hasJSXNode = false;
|
|
499
|
-
return {
|
|
500
|
-
JSXElement() {
|
|
501
|
-
hasJSXNode = true;
|
|
502
|
-
},
|
|
503
|
-
JSXFragment() {
|
|
504
|
-
hasJSXNode = true;
|
|
505
|
-
},
|
|
506
|
-
"Program:exit"(program) {
|
|
507
|
-
const fileNameExt = filename.slice(filename.lastIndexOf("."));
|
|
508
|
-
const isJSXExt = extensions.includes(fileNameExt);
|
|
509
|
-
if (hasJSXNode && !isJSXExt) {
|
|
510
|
-
context.report({
|
|
511
|
-
messageId: "missingJsxExtension",
|
|
512
|
-
node: program,
|
|
513
|
-
data: { extensions: extensionsString }
|
|
514
|
-
});
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
const hasCode = program.body.length > 0;
|
|
518
|
-
const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode === true;
|
|
519
|
-
if (!hasCode && ignoreFilesWithoutCode) return;
|
|
520
|
-
if (!hasJSXNode && isJSXExt && allow === "as-needed") context.report({
|
|
521
|
-
messageId: "unnecessaryJsxExtension",
|
|
522
|
-
node: program,
|
|
523
|
-
data: { extensions: extensionsString }
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
|
|
529
350
|
//#endregion
|
|
530
351
|
//#region src/plugin.ts
|
|
531
352
|
const plugin = {
|
|
@@ -538,9 +359,7 @@ const plugin = {
|
|
|
538
359
|
["context-name"]: context_name_default,
|
|
539
360
|
["id-name"]: id_name_default,
|
|
540
361
|
["ref-name"]: ref_name_default,
|
|
541
|
-
["use-state"]: use_state_default
|
|
542
|
-
["filename"]: filename_default,
|
|
543
|
-
["filename-extension"]: filename_extension_default
|
|
362
|
+
["use-state"]: use_state_default
|
|
544
363
|
}
|
|
545
364
|
};
|
|
546
365
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.0",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
"./package.json"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
42
|
-
"@typescript-eslint/type-utils": "^8.
|
|
43
|
-
"@typescript-eslint/types": "^8.
|
|
44
|
-
"@typescript-eslint/utils": "^8.
|
|
41
|
+
"@typescript-eslint/scope-manager": "^8.56.0",
|
|
42
|
+
"@typescript-eslint/type-utils": "^8.56.0",
|
|
43
|
+
"@typescript-eslint/types": "^8.56.0",
|
|
44
|
+
"@typescript-eslint/utils": "^8.56.0",
|
|
45
45
|
"compare-versions": "^6.1.1",
|
|
46
46
|
"string-ts": "^2.3.1",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "
|
|
49
|
-
"@eslint-react/core": "
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/var": "
|
|
48
|
+
"@eslint-react/ast": "3.0.0-next.0",
|
|
49
|
+
"@eslint-react/core": "3.0.0-next.0",
|
|
50
|
+
"@eslint-react/eff": "3.0.0-next.0",
|
|
51
|
+
"@eslint-react/shared": "3.0.0-next.0",
|
|
52
|
+
"@eslint-react/var": "3.0.0-next.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"typescript": ">=4.8.4 <6.0.0"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
|
-
"node": ">=
|
|
65
|
+
"node": ">=22.0.0"
|
|
66
66
|
},
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|