eslint-plugin-react-naming-convention 2.0.0-next.146 → 2.0.0-next.147
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.ts +69 -64
- package/dist/index.js +442 -456
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,71 +1,76 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
type MessageID$2 = "missingDestructuring" | "invalidSetterNaming";
|
|
1
|
+
import { RulePreset } from "@eslint-react/kit";
|
|
2
|
+
import "@eslint-react/eff";
|
|
3
|
+
import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
5
4
|
|
|
5
|
+
//#region src/rules/filename.d.ts
|
|
6
|
+
type MessageID$2 = "filenameEmpty" | "filenameInvalid";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/rules/filename-extension.d.ts
|
|
6
9
|
type MessageID$1 = "useJsxFileExtension" | "useNonJsxFileExtension";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/rules/use-state.d.ts
|
|
12
|
+
type MessageID = "missingDestructuring" | "invalidSetterNaming";
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/index.d.ts
|
|
10
15
|
declare const _default: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
name: string;
|
|
40
|
-
rules: RulePreset;
|
|
16
|
+
configs: {
|
|
17
|
+
recommended: {
|
|
18
|
+
plugins: {
|
|
19
|
+
"react-naming-convention": {
|
|
20
|
+
readonly meta: {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly version: string;
|
|
23
|
+
};
|
|
24
|
+
readonly rules: {
|
|
25
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint0.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
26
|
+
allowAllCaps?: boolean;
|
|
27
|
+
excepts?: readonly string[];
|
|
28
|
+
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
29
|
+
} | undefined], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
30
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint0.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
31
|
+
readonly filename: _typescript_eslint_utils_ts_eslint0.RuleModule<MessageID$2, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
32
|
+
excepts?: readonly string[];
|
|
33
|
+
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
34
|
+
} | undefined], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
35
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint0.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
36
|
+
allow?: "always" | "as-needed";
|
|
37
|
+
extensions?: readonly string[];
|
|
38
|
+
ignoreFilesWithoutCode?: boolean;
|
|
39
|
+
} | undefined], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
40
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint0.RuleModule<MessageID, [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
41
|
+
};
|
|
41
42
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
meta: {
|
|
48
|
-
readonly name: string;
|
|
49
|
-
readonly version: string;
|
|
43
|
+
};
|
|
44
|
+
name: string;
|
|
45
|
+
rules: RulePreset;
|
|
50
46
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
excepts?: readonly string[];
|
|
55
|
-
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
56
|
-
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
57
|
-
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
58
|
-
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
59
|
-
excepts?: readonly string[];
|
|
60
|
-
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
61
|
-
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
62
|
-
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
63
|
-
allow?: "always" | "as-needed";
|
|
64
|
-
extensions?: readonly string[];
|
|
65
|
-
ignoreFilesWithoutCode?: boolean;
|
|
66
|
-
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
67
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$2, [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
47
|
+
"recommended-legacy": {
|
|
48
|
+
plugins: string[];
|
|
49
|
+
rules: RulePreset;
|
|
68
50
|
};
|
|
51
|
+
};
|
|
52
|
+
meta: {
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly version: string;
|
|
55
|
+
};
|
|
56
|
+
rules: {
|
|
57
|
+
readonly "component-name": _typescript_eslint_utils_ts_eslint0.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
|
|
58
|
+
allowAllCaps?: boolean;
|
|
59
|
+
excepts?: readonly string[];
|
|
60
|
+
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
61
|
+
} | undefined], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
62
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint0.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
63
|
+
readonly filename: _typescript_eslint_utils_ts_eslint0.RuleModule<MessageID$2, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
64
|
+
excepts?: readonly string[];
|
|
65
|
+
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
|
|
66
|
+
} | undefined], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
67
|
+
readonly "filename-extension": _typescript_eslint_utils_ts_eslint0.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
|
|
68
|
+
allow?: "always" | "as-needed";
|
|
69
|
+
extensions?: readonly string[];
|
|
70
|
+
ignoreFilesWithoutCode?: boolean;
|
|
71
|
+
} | undefined], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
72
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint0.RuleModule<MessageID, [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
73
|
+
};
|
|
69
74
|
};
|
|
70
|
-
|
|
71
|
-
export { _default as default };
|
|
75
|
+
//#endregion
|
|
76
|
+
export { _default as default };
|
package/dist/index.js
CHANGED
|
@@ -1,493 +1,479 @@
|
|
|
1
|
-
import * as AST from
|
|
2
|
-
import * as
|
|
3
|
-
import { RegExp } from
|
|
4
|
-
import { getDocsUrl, getSettingsFromContext } from
|
|
5
|
-
import { ESLintUtils } from
|
|
6
|
-
import { identity, isObject } from
|
|
7
|
-
import { AST_NODE_TYPES } from
|
|
8
|
-
import {
|
|
9
|
-
import path from
|
|
10
|
-
import {
|
|
1
|
+
import * as AST from "@eslint-react/ast";
|
|
2
|
+
import * as ER from "@eslint-react/core";
|
|
3
|
+
import { RegExp } from "@eslint-react/kit";
|
|
4
|
+
import { getDocsUrl, getSettingsFromContext } from "@eslint-react/shared";
|
|
5
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
6
|
+
import { identity, isObject } from "@eslint-react/eff";
|
|
7
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
8
|
+
import { P, match } from "ts-pattern";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { camelCase, kebabCase, pascalCase, snakeCase } from "string-ts";
|
|
11
11
|
|
|
12
|
+
//#region rolldown:runtime
|
|
12
13
|
var __defProp = Object.defineProperty;
|
|
13
14
|
var __export = (target, all) => {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
for (var name$2 in all) __defProp(target, name$2, {
|
|
16
|
+
get: all[name$2],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
16
19
|
};
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/configs/recommended.ts
|
|
19
23
|
var recommended_exports = {};
|
|
20
24
|
__export(recommended_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
name: () => name$1,
|
|
26
|
+
rules: () => rules
|
|
23
27
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const name$1 = "react-naming-convention/recommended";
|
|
29
|
+
const rules = { "react-naming-convention/context-name": "warn" };
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region package.json
|
|
33
|
+
var name = "eslint-plugin-react-naming-convention";
|
|
34
|
+
var version = "2.0.0-next.147";
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var createRule = ESLintUtils.RuleCreator(getDocsUrl("naming-convention"));
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/utils/create-rule.ts
|
|
38
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl("naming-convention"));
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
]
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
var RULE_NAME = "component-name";
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/rules/component-name.ts
|
|
42
|
+
const defaultOptions$2 = [{
|
|
43
|
+
allowAllCaps: false,
|
|
44
|
+
excepts: [],
|
|
45
|
+
rule: "PascalCase"
|
|
46
|
+
}];
|
|
47
|
+
const schema$2 = [{ anyOf: [{
|
|
48
|
+
type: "string",
|
|
49
|
+
enum: ["PascalCase", "CONSTANT_CASE"]
|
|
50
|
+
}, {
|
|
51
|
+
type: "object",
|
|
52
|
+
additionalProperties: false,
|
|
53
|
+
properties: {
|
|
54
|
+
allowAllCaps: { type: "boolean" },
|
|
55
|
+
excepts: {
|
|
56
|
+
type: "array",
|
|
57
|
+
items: {
|
|
58
|
+
type: "string",
|
|
59
|
+
format: "regex"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
rule: {
|
|
63
|
+
type: "string",
|
|
64
|
+
enum: ["PascalCase", "CONSTANT_CASE"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}] }];
|
|
68
|
+
const RULE_NAME$4 = "component-name";
|
|
69
69
|
var component_name_default = createRule({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
name: RULE_NAME,
|
|
82
|
-
create,
|
|
83
|
-
defaultOptions
|
|
70
|
+
meta: {
|
|
71
|
+
type: "problem",
|
|
72
|
+
defaultOptions: [...defaultOptions$2],
|
|
73
|
+
docs: { description: "Enforces naming conventions for components." },
|
|
74
|
+
messages: { invalid: "A component name '{{name}}' does not match {{rule}}." },
|
|
75
|
+
schema: schema$2
|
|
76
|
+
},
|
|
77
|
+
name: RULE_NAME$4,
|
|
78
|
+
create: create$4,
|
|
79
|
+
defaultOptions: defaultOptions$2
|
|
84
80
|
});
|
|
85
|
-
function create(context) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
81
|
+
function create$4(context) {
|
|
82
|
+
const options = normalizeOptions(context.options);
|
|
83
|
+
const { rule } = options;
|
|
84
|
+
const collector = ER.useComponentCollector(context);
|
|
85
|
+
const collectorLegacy = ER.useComponentCollectorLegacy();
|
|
86
|
+
return {
|
|
87
|
+
...collector.listeners,
|
|
88
|
+
...collectorLegacy.listeners,
|
|
89
|
+
"Program:exit"(program) {
|
|
90
|
+
const functionComponents = collector.ctx.getAllComponents(program);
|
|
91
|
+
const classComponents = collectorLegacy.ctx.getAllComponents(program);
|
|
92
|
+
for (const { node: component } of functionComponents.values()) {
|
|
93
|
+
const id = AST.getFunctionId(component);
|
|
94
|
+
if (id?.name == null) continue;
|
|
95
|
+
const name$2 = id.name;
|
|
96
|
+
if (isValidName(name$2, options)) continue;
|
|
97
|
+
context.report({
|
|
98
|
+
messageId: "invalid",
|
|
99
|
+
node: id,
|
|
100
|
+
data: {
|
|
101
|
+
name: name$2,
|
|
102
|
+
rule
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
for (const { node: component } of classComponents.values()) {
|
|
107
|
+
const id = AST.getClassId(component);
|
|
108
|
+
if (id?.name == null) continue;
|
|
109
|
+
const name$2 = id.name;
|
|
110
|
+
if (isValidName(name$2, options)) continue;
|
|
111
|
+
context.report({
|
|
112
|
+
messageId: "invalid",
|
|
113
|
+
node: id,
|
|
114
|
+
data: {
|
|
115
|
+
name: name$2,
|
|
116
|
+
rule
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
120
122
|
}
|
|
121
123
|
function normalizeOptions(options) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
const opts = options[0];
|
|
125
|
+
const defaultOpts = defaultOptions$2[0];
|
|
126
|
+
if (opts == null) return defaultOpts;
|
|
127
|
+
return {
|
|
128
|
+
...defaultOpts,
|
|
129
|
+
...typeof opts === "string" ? { rule: opts } : {
|
|
130
|
+
...opts,
|
|
131
|
+
excepts: opts.excepts?.map((s) => RegExp.toRegExp(s)) ?? []
|
|
132
|
+
}
|
|
133
|
+
};
|
|
132
134
|
}
|
|
133
|
-
function isValidName(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
return RegExp.PASCAL_CASE.test(normalized);
|
|
145
|
-
}
|
|
135
|
+
function isValidName(name$2, options) {
|
|
136
|
+
if (name$2 == null) return true;
|
|
137
|
+
if (options.excepts.some((regex) => regex.test(name$2))) return true;
|
|
138
|
+
const normalized = name$2.split(".").at(-1) ?? name$2;
|
|
139
|
+
switch (options.rule) {
|
|
140
|
+
case "CONSTANT_CASE": return RegExp.CONSTANT_CASE.test(normalized);
|
|
141
|
+
case "PascalCase":
|
|
142
|
+
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) return options.allowAllCaps;
|
|
143
|
+
return RegExp.PASCAL_CASE.test(normalized);
|
|
144
|
+
}
|
|
146
145
|
}
|
|
147
|
-
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/rules/context-name.ts
|
|
149
|
+
const RULE_NAME$3 = "context-name";
|
|
148
150
|
var context_name_default = createRule({
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
},
|
|
159
|
-
name: RULE_NAME2,
|
|
160
|
-
create: create2,
|
|
161
|
-
defaultOptions: []
|
|
151
|
+
meta: {
|
|
152
|
+
type: "problem",
|
|
153
|
+
docs: { description: "Enforces context name to be a valid component name with the suffix `Context`." },
|
|
154
|
+
messages: { invalid: "A context name must be a valid component name with the suffix 'Context'." },
|
|
155
|
+
schema: []
|
|
156
|
+
},
|
|
157
|
+
name: RULE_NAME$3,
|
|
158
|
+
create: create$3,
|
|
159
|
+
defaultOptions: []
|
|
162
160
|
});
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
161
|
+
function create$3(context) {
|
|
162
|
+
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
163
|
+
return { CallExpression(node) {
|
|
164
|
+
if (!ER.isCreateContextCall(context, node)) return;
|
|
165
|
+
const id = ER.getInstanceId(node);
|
|
166
|
+
if (id == null) return;
|
|
167
|
+
const name$2 = match(id).with({
|
|
168
|
+
type: AST_NODE_TYPES.Identifier,
|
|
169
|
+
name: P.select()
|
|
170
|
+
}, identity).with({
|
|
171
|
+
type: AST_NODE_TYPES.MemberExpression,
|
|
172
|
+
property: { name: P.select(P.string) }
|
|
173
|
+
}, identity).otherwise(() => null);
|
|
174
|
+
if (name$2 != null && ER.isComponentName(name$2) && name$2.endsWith("Context")) return;
|
|
175
|
+
context.report({
|
|
176
|
+
messageId: "invalid",
|
|
177
|
+
node: id
|
|
178
|
+
});
|
|
179
|
+
} };
|
|
178
180
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/rules/filename.ts
|
|
184
|
+
const RULE_NAME$2 = "filename";
|
|
185
|
+
const defaultOptions$1 = [{
|
|
186
|
+
excepts: [
|
|
187
|
+
"index",
|
|
188
|
+
"/^_/",
|
|
189
|
+
"/^\\$/",
|
|
190
|
+
"/^[0-9]+$/",
|
|
191
|
+
"/^\\[[^\\]]+\\]$/"
|
|
192
|
+
],
|
|
193
|
+
rule: "PascalCase"
|
|
194
|
+
}];
|
|
195
|
+
const schema$1 = [{ anyOf: [{
|
|
196
|
+
type: "string",
|
|
197
|
+
enum: [
|
|
198
|
+
"PascalCase",
|
|
199
|
+
"camelCase",
|
|
200
|
+
"kebab-case",
|
|
201
|
+
"snake_case"
|
|
202
|
+
]
|
|
203
|
+
}, {
|
|
204
|
+
type: "object",
|
|
205
|
+
additionalProperties: false,
|
|
206
|
+
properties: {
|
|
207
|
+
excepts: {
|
|
208
|
+
type: "array",
|
|
209
|
+
items: {
|
|
210
|
+
type: "string",
|
|
211
|
+
format: "regex"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
extensions: {
|
|
215
|
+
type: "array",
|
|
216
|
+
items: { type: "string" },
|
|
217
|
+
uniqueItems: true
|
|
218
|
+
},
|
|
219
|
+
rule: {
|
|
220
|
+
type: "string",
|
|
221
|
+
enum: [
|
|
222
|
+
"PascalCase",
|
|
223
|
+
"camelCase",
|
|
224
|
+
"kebab-case",
|
|
225
|
+
"snake_case"
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}] }];
|
|
221
230
|
var filename_default = createRule({
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
create: create3,
|
|
236
|
-
defaultOptions: defaultOptions2
|
|
231
|
+
meta: {
|
|
232
|
+
type: "problem",
|
|
233
|
+
defaultOptions: [...defaultOptions$1],
|
|
234
|
+
docs: { description: "Enforces consistent file naming conventions." },
|
|
235
|
+
messages: {
|
|
236
|
+
filenameEmpty: "A file must have non-empty name.",
|
|
237
|
+
filenameInvalid: "A file with name '{{name}}' does not match {{rule}}. Rename it to '{{suggestion}}'."
|
|
238
|
+
},
|
|
239
|
+
schema: schema$1
|
|
240
|
+
},
|
|
241
|
+
name: RULE_NAME$2,
|
|
242
|
+
create: create$2,
|
|
243
|
+
defaultOptions: defaultOptions$1
|
|
237
244
|
});
|
|
238
|
-
function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
};
|
|
245
|
+
function create$2(context) {
|
|
246
|
+
const options = context.options[0] ?? defaultOptions$1[0];
|
|
247
|
+
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
248
|
+
const excepts = typeof options === "string" ? [] : (options.excepts ?? []).map((s) => RegExp.toRegExp(s));
|
|
249
|
+
function validate(name$2, casing = rule, ignores = excepts) {
|
|
250
|
+
if (ignores.some((pattern) => pattern.test(name$2))) return true;
|
|
251
|
+
const filteredName = name$2.match(/[\w-]/gu)?.join("") ?? "";
|
|
252
|
+
if (filteredName.length === 0) return true;
|
|
253
|
+
return match(casing).with("PascalCase", () => RegExp.PASCAL_CASE.test(filteredName)).with("camelCase", () => RegExp.CAMEL_CASE.test(filteredName)).with("kebab-case", () => RegExp.KEBAB_CASE.test(filteredName)).with("snake_case", () => RegExp.SNAKE_CASE.test(filteredName)).exhaustive();
|
|
254
|
+
}
|
|
255
|
+
function getSuggestion(name$2, casing = rule) {
|
|
256
|
+
return match(casing).with("PascalCase", () => pascalCase(name$2)).with("camelCase", () => camelCase(name$2)).with("kebab-case", () => kebabCase(name$2)).with("snake_case", () => snakeCase(name$2)).exhaustive();
|
|
257
|
+
}
|
|
258
|
+
return { Program(node) {
|
|
259
|
+
const [basename = "", ...rest] = path.basename(context.filename).split(".");
|
|
260
|
+
if (basename.length === 0) {
|
|
261
|
+
context.report({
|
|
262
|
+
messageId: "filenameEmpty",
|
|
263
|
+
node
|
|
264
|
+
});
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (validate(basename)) return;
|
|
268
|
+
context.report({
|
|
269
|
+
messageId: "filenameInvalid",
|
|
270
|
+
node,
|
|
271
|
+
data: {
|
|
272
|
+
name: context.filename,
|
|
273
|
+
rule,
|
|
274
|
+
suggestion: [getSuggestion(basename), ...rest].join(".")
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
} };
|
|
272
278
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/rules/filename-extension.ts
|
|
282
|
+
const RULE_NAME$1 = "filename-extension";
|
|
283
|
+
const defaultOptions = [{
|
|
284
|
+
allow: "as-needed",
|
|
285
|
+
extensions: [".jsx", ".tsx"],
|
|
286
|
+
ignoreFilesWithoutCode: false
|
|
278
287
|
}];
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
},
|
|
299
|
-
uniqueItems: true
|
|
300
|
-
},
|
|
301
|
-
ignoreFilesWithoutCode: {
|
|
302
|
-
type: "boolean"
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
]
|
|
307
|
-
}
|
|
308
|
-
];
|
|
288
|
+
const schema = [{ anyOf: [{
|
|
289
|
+
type: "string",
|
|
290
|
+
enum: ["always", "as-needed"]
|
|
291
|
+
}, {
|
|
292
|
+
type: "object",
|
|
293
|
+
additionalProperties: false,
|
|
294
|
+
properties: {
|
|
295
|
+
allow: {
|
|
296
|
+
type: "string",
|
|
297
|
+
enum: ["always", "as-needed"]
|
|
298
|
+
},
|
|
299
|
+
extensions: {
|
|
300
|
+
type: "array",
|
|
301
|
+
items: { type: "string" },
|
|
302
|
+
uniqueItems: true
|
|
303
|
+
},
|
|
304
|
+
ignoreFilesWithoutCode: { type: "boolean" }
|
|
305
|
+
}
|
|
306
|
+
}] }];
|
|
309
307
|
var filename_extension_default = createRule({
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
create: create4,
|
|
324
|
-
defaultOptions: defaultOptions3
|
|
308
|
+
meta: {
|
|
309
|
+
type: "problem",
|
|
310
|
+
defaultOptions: [...defaultOptions],
|
|
311
|
+
docs: { description: "Enforces consistent file naming conventions." },
|
|
312
|
+
messages: {
|
|
313
|
+
useJsxFileExtension: "Use {{extensions}} file extension for JSX files.",
|
|
314
|
+
useNonJsxFileExtension: "Do not use {{extensions}} file extension for files without JSX."
|
|
315
|
+
},
|
|
316
|
+
schema
|
|
317
|
+
},
|
|
318
|
+
name: RULE_NAME$1,
|
|
319
|
+
create: create$1,
|
|
320
|
+
defaultOptions
|
|
325
321
|
});
|
|
326
|
-
function
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
node: program,
|
|
362
|
-
data: {
|
|
363
|
-
extensions: extensionsString
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
};
|
|
322
|
+
function create$1(context) {
|
|
323
|
+
const options = context.options[0] ?? defaultOptions[0];
|
|
324
|
+
const allow = isObject(options) ? options.allow : options;
|
|
325
|
+
const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions[0].extensions;
|
|
326
|
+
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
|
|
327
|
+
const filename = context.filename;
|
|
328
|
+
let hasJSXNode = false;
|
|
329
|
+
return {
|
|
330
|
+
JSXElement() {
|
|
331
|
+
hasJSXNode = true;
|
|
332
|
+
},
|
|
333
|
+
JSXFragment() {
|
|
334
|
+
hasJSXNode = true;
|
|
335
|
+
},
|
|
336
|
+
"Program:exit"(program) {
|
|
337
|
+
const fileNameExt = filename.slice(filename.lastIndexOf("."));
|
|
338
|
+
const isJSXExt = extensions.includes(fileNameExt);
|
|
339
|
+
if (hasJSXNode && !isJSXExt) {
|
|
340
|
+
context.report({
|
|
341
|
+
messageId: "useJsxFileExtension",
|
|
342
|
+
node: program,
|
|
343
|
+
data: { extensions: extensionsString }
|
|
344
|
+
});
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const hasCode = program.body.length > 0;
|
|
348
|
+
const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode === true;
|
|
349
|
+
if (!hasCode && ignoreFilesWithoutCode) return;
|
|
350
|
+
if (!hasJSXNode && isJSXExt && allow === "as-needed") context.report({
|
|
351
|
+
messageId: "useNonJsxFileExtension",
|
|
352
|
+
node: program,
|
|
353
|
+
data: { extensions: extensionsString }
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
};
|
|
369
357
|
}
|
|
370
|
-
|
|
371
|
-
|
|
358
|
+
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/rules/use-state.ts
|
|
361
|
+
const RULE_NAME = "use-state";
|
|
362
|
+
const RULE_FEATURES = [];
|
|
372
363
|
var use_state_default = createRule({
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
364
|
+
meta: {
|
|
365
|
+
type: "problem",
|
|
366
|
+
docs: {
|
|
367
|
+
description: "Enforces destructuring and symmetric naming of `useState` hook value and setter.",
|
|
368
|
+
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
369
|
+
},
|
|
370
|
+
messages: {
|
|
371
|
+
invalidSetterNaming: "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'.",
|
|
372
|
+
missingDestructuring: "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...)."
|
|
373
|
+
},
|
|
374
|
+
schema: []
|
|
375
|
+
},
|
|
376
|
+
name: RULE_NAME,
|
|
377
|
+
create,
|
|
378
|
+
defaultOptions: []
|
|
388
379
|
});
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
node: setter
|
|
448
|
-
});
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
};
|
|
380
|
+
function create(context) {
|
|
381
|
+
const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
382
|
+
const isUseStateCall = ER.isReactHookCallWithNameAlias(context, "useState", alias);
|
|
383
|
+
return { CallExpression(node) {
|
|
384
|
+
if (!isUseStateCall(node)) return;
|
|
385
|
+
if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
386
|
+
context.report({
|
|
387
|
+
messageId: "missingDestructuring",
|
|
388
|
+
node
|
|
389
|
+
});
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const id = ER.getInstanceId(node);
|
|
393
|
+
if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
394
|
+
context.report({
|
|
395
|
+
messageId: "missingDestructuring",
|
|
396
|
+
node: id ?? node
|
|
397
|
+
});
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const [value, setter] = id.elements;
|
|
401
|
+
if (value == null || setter == null) {
|
|
402
|
+
context.report({
|
|
403
|
+
messageId: "missingDestructuring",
|
|
404
|
+
node: id
|
|
405
|
+
});
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id$1) => id$1.name).otherwise(() => null);
|
|
409
|
+
if (setterName == null || !setterName.startsWith("set")) {
|
|
410
|
+
context.report({
|
|
411
|
+
messageId: "invalidSetterNaming",
|
|
412
|
+
node: setter
|
|
413
|
+
});
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name$2 }) => snakeCase(name$2)).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
|
|
417
|
+
const values = properties.reduce((acc, prop) => {
|
|
418
|
+
if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) return [...acc, prop.key.name];
|
|
419
|
+
return acc;
|
|
420
|
+
}, []);
|
|
421
|
+
return values.join("_");
|
|
422
|
+
}).otherwise(() => null);
|
|
423
|
+
if (valueName == null) {
|
|
424
|
+
context.report({
|
|
425
|
+
messageId: "invalidSetterNaming",
|
|
426
|
+
node: value
|
|
427
|
+
});
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (snakeCase(setterName) !== `set_${valueName}`) {
|
|
431
|
+
context.report({
|
|
432
|
+
messageId: "invalidSetterNaming",
|
|
433
|
+
node: setter
|
|
434
|
+
});
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
} };
|
|
453
438
|
}
|
|
454
439
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/plugin.ts
|
|
442
|
+
const plugin = {
|
|
443
|
+
meta: {
|
|
444
|
+
name,
|
|
445
|
+
version
|
|
446
|
+
},
|
|
447
|
+
rules: {
|
|
448
|
+
["component-name"]: component_name_default,
|
|
449
|
+
["context-name"]: context_name_default,
|
|
450
|
+
["filename"]: filename_default,
|
|
451
|
+
["filename-extension"]: filename_extension_default,
|
|
452
|
+
["use-state"]: use_state_default
|
|
453
|
+
}
|
|
468
454
|
};
|
|
469
455
|
|
|
470
|
-
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/index.ts
|
|
471
458
|
function makeConfig(config) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
};
|
|
459
|
+
return {
|
|
460
|
+
...config,
|
|
461
|
+
plugins: { "react-naming-convention": plugin }
|
|
462
|
+
};
|
|
478
463
|
}
|
|
479
|
-
function makeLegacyConfig({ rules:
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
464
|
+
function makeLegacyConfig({ rules: rules$1 }) {
|
|
465
|
+
return {
|
|
466
|
+
plugins: ["react-naming-convention"],
|
|
467
|
+
rules: rules$1
|
|
468
|
+
};
|
|
484
469
|
}
|
|
485
|
-
var
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
470
|
+
var src_default = {
|
|
471
|
+
...plugin,
|
|
472
|
+
configs: {
|
|
473
|
+
["recommended"]: makeConfig(recommended_exports),
|
|
474
|
+
["recommended-legacy"]: makeLegacyConfig(recommended_exports)
|
|
475
|
+
}
|
|
491
476
|
};
|
|
492
477
|
|
|
493
|
-
|
|
478
|
+
//#endregion
|
|
479
|
+
export { src_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.147",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
"@typescript-eslint/utils": "^8.40.0",
|
|
42
42
|
"string-ts": "^2.2.1",
|
|
43
43
|
"ts-pattern": "^5.8.0",
|
|
44
|
-
"@eslint-react/ast": "2.0.0-next.
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/
|
|
44
|
+
"@eslint-react/ast": "2.0.0-next.147",
|
|
45
|
+
"@eslint-react/core": "2.0.0-next.147",
|
|
46
|
+
"@eslint-react/kit": "2.0.0-next.147",
|
|
47
|
+
"@eslint-react/eff": "2.0.0-next.147",
|
|
48
|
+
"@eslint-react/shared": "2.0.0-next.147",
|
|
49
|
+
"@eslint-react/var": "2.0.0-next.147"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/react": "^19.1.11",
|
|
53
53
|
"@types/react-dom": "^19.1.7",
|
|
54
|
-
"
|
|
54
|
+
"tsdown": "^0.14.2",
|
|
55
55
|
"@local/configs": "0.0.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"access": "public"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
|
-
"build": "
|
|
76
|
+
"build": "tsdown --dts-resolve",
|
|
77
77
|
"lint:publish": "publint",
|
|
78
78
|
"lint:ts": "tsc --noEmit"
|
|
79
79
|
}
|