eslint-plugin-react-naming-convention 3.0.0-next.4 → 3.0.0-next.41

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.
Files changed (2) hide show
  1. package/dist/index.js +35 -135
  2. package/package.json +11 -11
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ 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 { snakeCase } from "string-ts";
10
9
 
11
10
  //#region \0rolldown/runtime.js
12
11
  var __defProp = Object.defineProperty;
@@ -34,14 +33,13 @@ const name$1 = "react-naming-convention/recommended";
34
33
  const rules = {
35
34
  "react-naming-convention/context-name": "warn",
36
35
  "react-naming-convention/id-name": "warn",
37
- "react-naming-convention/ref-name": "warn",
38
- "react-naming-convention/use-state": "warn"
36
+ "react-naming-convention/ref-name": "warn"
39
37
  };
40
38
 
41
39
  //#endregion
42
40
  //#region package.json
43
41
  var name = "eslint-plugin-react-naming-convention";
44
- var version = "3.0.0-next.4";
42
+ var version = "3.0.0-next.41";
45
43
 
46
44
  //#endregion
47
45
  //#region src/utils/create-rule.ts
@@ -51,13 +49,13 @@ function getDocsUrl(ruleName) {
51
49
  const createRule = ESLintUtils.RuleCreator(getDocsUrl);
52
50
 
53
51
  //#endregion
54
- //#region src/rules/component-name.ts
55
- const defaultOptions$1 = [{
52
+ //#region src/rules/component-name/component-name.ts
53
+ const defaultOptions = [{
56
54
  allowAllCaps: false,
57
55
  excepts: [],
58
56
  rule: "PascalCase"
59
57
  }];
60
- const schema$1 = [{ anyOf: [{
58
+ const schema = [{ anyOf: [{
61
59
  type: "string",
62
60
  enum: ["PascalCase", "CONSTANT_CASE"]
63
61
  }, {
@@ -78,20 +76,20 @@ const schema$1 = [{ anyOf: [{
78
76
  }
79
77
  }
80
78
  }] }];
81
- const RULE_NAME$4 = "component-name";
79
+ const RULE_NAME$3 = "component-name";
82
80
  var component_name_default = createRule({
83
81
  meta: {
84
82
  type: "problem",
85
- defaultOptions: [...defaultOptions$1],
83
+ defaultOptions: [...defaultOptions],
86
84
  docs: { description: "Enforces naming conventions for components." },
87
85
  messages: { invalidComponentName: "A component name '{{name}}' does not match {{rule}}." },
88
- schema: schema$1
86
+ schema
89
87
  },
90
- name: RULE_NAME$4,
91
- create: create$4,
92
- defaultOptions: defaultOptions$1
88
+ name: RULE_NAME$3,
89
+ create: create$3,
90
+ defaultOptions
93
91
  });
94
- function create$4(context) {
92
+ function create$3(context) {
95
93
  const options = normalizeOptions(context.options);
96
94
  const { rule } = options;
97
95
  const fCollector = core.useComponentCollector(context);
@@ -123,7 +121,7 @@ function create$4(context) {
123
121
  }
124
122
  function normalizeOptions(options) {
125
123
  const opts = options[0];
126
- const defaultOpts = defaultOptions$1[0];
124
+ const defaultOpts = defaultOptions[0];
127
125
  if (opts == null) return defaultOpts;
128
126
  return {
129
127
  ...defaultOpts,
@@ -146,8 +144,8 @@ function isValidName(name, options) {
146
144
  }
147
145
 
148
146
  //#endregion
149
- //#region src/rules/context-name.ts
150
- const RULE_NAME$3 = "context-name";
147
+ //#region src/rules/context-name/context-name.ts
148
+ const RULE_NAME$2 = "context-name";
151
149
  var context_name_default = createRule({
152
150
  meta: {
153
151
  type: "suggestion",
@@ -155,15 +153,15 @@ var context_name_default = createRule({
155
153
  messages: { invalidContextName: "A context name must be a valid component name with the suffix 'Context'." },
156
154
  schema: []
157
155
  },
158
- name: RULE_NAME$3,
159
- create: create$3,
156
+ name: RULE_NAME$2,
157
+ create: create$2,
160
158
  defaultOptions: []
161
159
  });
162
- function create$3(context) {
160
+ function create$2(context) {
163
161
  if (!context.sourceCode.text.includes("createContext")) return {};
164
162
  const { version } = getSettingsFromContext(context);
165
163
  if (compare(version, "19.0.0", "<")) return {};
166
- return { CallExpression(node) {
164
+ return defineRuleListener({ CallExpression(node) {
167
165
  if (!core.isCreateContextCall(context, node)) return;
168
166
  const [id, name] = match(findEnclosingAssignmentTarget(node)).with({
169
167
  type: AST_NODE_TYPES.Identifier,
@@ -178,12 +176,12 @@ function create$3(context) {
178
176
  messageId: "invalidContextName",
179
177
  node: id
180
178
  });
181
- } };
179
+ } });
182
180
  }
183
181
 
184
182
  //#endregion
185
- //#region src/rules/id-name.ts
186
- const RULE_NAME$2 = "id-name";
183
+ //#region src/rules/id-name/id-name.ts
184
+ const RULE_NAME$1 = "id-name";
187
185
  var id_name_default = createRule({
188
186
  meta: {
189
187
  type: "suggestion",
@@ -191,13 +189,13 @@ var id_name_default = createRule({
191
189
  messages: { invalidIdName: "An identifier assigned from 'useId' must be named 'id' or end with 'Id'." },
192
190
  schema: []
193
191
  },
194
- name: RULE_NAME$2,
195
- create: create$2,
192
+ name: RULE_NAME$1,
193
+ create: create$1,
196
194
  defaultOptions: []
197
195
  });
198
- function create$2(context) {
196
+ function create$1(context) {
199
197
  if (!context.sourceCode.text.includes("useId")) return {};
200
- return { CallExpression(node) {
198
+ return defineRuleListener({ CallExpression(node) {
201
199
  if (!core.isUseIdCall(node)) return;
202
200
  const [id, name] = match(findEnclosingAssignmentTarget(node)).with({
203
201
  type: AST_NODE_TYPES.Identifier,
@@ -212,12 +210,12 @@ function create$2(context) {
212
210
  messageId: "invalidIdName",
213
211
  node: id
214
212
  });
215
- } };
213
+ } });
216
214
  }
217
215
 
218
216
  //#endregion
219
- //#region src/rules/ref-name.ts
220
- const RULE_NAME$1 = "ref-name";
217
+ //#region src/rules/ref-name/ref-name.ts
218
+ const RULE_NAME = "ref-name";
221
219
  var ref_name_default = createRule({
222
220
  meta: {
223
221
  type: "suggestion",
@@ -225,13 +223,13 @@ var ref_name_default = createRule({
225
223
  messages: { invalidRefName: "A ref identifier must be named 'ref' or ending in 'Ref'." },
226
224
  schema: []
227
225
  },
228
- name: RULE_NAME$1,
229
- create: create$1,
226
+ name: RULE_NAME,
227
+ create,
230
228
  defaultOptions: []
231
229
  });
232
- function create$1(context) {
230
+ function create(context) {
233
231
  if (!context.sourceCode.text.includes("useRef")) return {};
234
- return { CallExpression(node) {
232
+ return defineRuleListener({ CallExpression(node) {
235
233
  if (!core.isUseRefCall(node)) return;
236
234
  if (ast.getUnderlyingExpression(node.parent).type === AST_NODE_TYPES.MemberExpression) return;
237
235
  const [id, name] = match(findEnclosingAssignmentTarget(node)).with({
@@ -247,104 +245,7 @@ function create$1(context) {
247
245
  messageId: "invalidRefName",
248
246
  node: id
249
247
  });
250
- } };
251
- }
252
-
253
- //#endregion
254
- //#region src/rules/use-state.ts
255
- const RULE_NAME = "use-state";
256
- const defaultOptions = [{
257
- enforceAssignment: false,
258
- enforceSetterName: true
259
- }];
260
- const schema = [{
261
- type: "object",
262
- additionalProperties: false,
263
- properties: {
264
- enforceAssignment: {
265
- type: "boolean",
266
- default: false
267
- },
268
- enforceSetterName: {
269
- type: "boolean",
270
- default: true
271
- }
272
- }
273
- }];
274
- var use_state_default = createRule({
275
- meta: {
276
- type: "suggestion",
277
- docs: { description: "Enforces destructuring and symmetric naming of the 'useState' hook value and setter." },
278
- messages: {
279
- invalidAssignment: "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...).",
280
- invalidSetterName: "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'."
281
- },
282
- schema
283
- },
284
- name: RULE_NAME,
285
- create,
286
- defaultOptions
287
- });
288
- function create(context) {
289
- const { enforceAssignment = false, enforceSetterName = true } = context.options[0] ?? defaultOptions[0];
290
- return { CallExpression(node) {
291
- if (!core.isUseStateCall(node)) return;
292
- if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
293
- if (!enforceAssignment) return;
294
- context.report({
295
- messageId: "invalidAssignment",
296
- node
297
- });
298
- return;
299
- }
300
- const id = findEnclosingAssignmentTarget(node);
301
- if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
302
- if (!enforceAssignment) return;
303
- context.report({
304
- messageId: "invalidAssignment",
305
- node: id ?? node
306
- });
307
- return;
308
- }
309
- const [value, setter] = id.elements;
310
- if (value == null) {
311
- if (!enforceAssignment) return;
312
- context.report({
313
- messageId: "invalidAssignment",
314
- node: id
315
- });
316
- return;
317
- }
318
- if (setter == null || !enforceSetterName) return;
319
- const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id) => id.name).otherwise(() => null);
320
- if (setterName == null || !setterName.startsWith("set")) {
321
- context.report({
322
- messageId: "invalidSetterName",
323
- node: setter
324
- });
325
- return;
326
- }
327
- const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, ({ name }) => snakeCase(name)).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
328
- return properties.reduce((acc, prop) => {
329
- if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) return [...acc, prop.key.name];
330
- return acc;
331
- }, []).join("_");
332
- }).otherwise(() => null);
333
- if (valueName == null) {
334
- context.report({
335
- messageId: "invalidSetterName",
336
- node: value
337
- });
338
- return;
339
- }
340
- if (snakeCase(setterName) !== `set_${valueName}`) {
341
- context.report({
342
- messageId: "invalidSetterName",
343
- node: setter
344
- });
345
- return;
346
- }
347
- } };
248
+ } });
348
249
  }
349
250
 
350
251
  //#endregion
@@ -358,8 +259,7 @@ const plugin = {
358
259
  ["component-name"]: component_name_default,
359
260
  ["context-name"]: context_name_default,
360
261
  ["id-name"]: id_name_default,
361
- ["ref-name"]: ref_name_default,
362
- ["use-state"]: use_state_default
262
+ ["ref-name"]: ref_name_default
363
263
  }
364
264
  };
365
265
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-naming-convention",
3
- "version": "3.0.0-next.4",
3
+ "version": "3.0.0-next.41",
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.56.0",
42
- "@typescript-eslint/type-utils": "^8.56.0",
43
- "@typescript-eslint/types": "^8.56.0",
44
- "@typescript-eslint/utils": "^8.56.0",
41
+ "@typescript-eslint/scope-manager": "canary",
42
+ "@typescript-eslint/type-utils": "canary",
43
+ "@typescript-eslint/types": "canary",
44
+ "@typescript-eslint/utils": "canary",
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": "3.0.0-next.4",
49
- "@eslint-react/core": "3.0.0-next.4",
50
- "@eslint-react/eff": "3.0.0-next.4",
51
- "@eslint-react/shared": "3.0.0-next.4",
52
- "@eslint-react/var": "3.0.0-next.4"
48
+ "@eslint-react/ast": "3.0.0-next.41",
49
+ "@eslint-react/core": "3.0.0-next.41",
50
+ "@eslint-react/eff": "3.0.0-next.41",
51
+ "@eslint-react/shared": "3.0.0-next.41",
52
+ "@eslint-react/var": "3.0.0-next.41"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/react": "^19.2.14",
@@ -70,6 +70,6 @@
70
70
  "scripts": {
71
71
  "build": "tsdown",
72
72
  "lint:publish": "publint",
73
- "lint:ts": "tsc --noEmit"
73
+ "lint:ts": "tsl"
74
74
  }
75
75
  }