eslint-plugin-react-naming-convention 1.23.3-next.8 → 1.24.0-beta.1

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 (3) hide show
  1. package/dist/index.js +45 -45
  2. package/dist/index.mjs +46 -46
  3. package/package.json +12 -12
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
36
36
 
37
37
  // package.json
38
38
  var name = "eslint-plugin-react-naming-convention";
39
- var version = "1.23.3-next.8";
39
+ var version = "1.24.0-beta.1";
40
40
  var createRule = shared.createRuleForPlugin("naming-convention");
41
41
 
42
42
  // src/rules/component-name.ts
@@ -78,11 +78,11 @@ var schema = [
78
78
  }
79
79
  ];
80
80
  function normalizeOptions(options) {
81
- const [opts] = options;
82
- if (eff.isNullable(opts)) {
81
+ const opts = options[0];
82
+ if (opts == null) {
83
83
  return defaultOptions[0];
84
84
  }
85
- if (eff.isString(opts)) {
85
+ if (typeof opts === "string") {
86
86
  return { ...defaultOptions[0], rule: opts };
87
87
  }
88
88
  return {
@@ -91,23 +91,25 @@ function normalizeOptions(options) {
91
91
  };
92
92
  }
93
93
  function validate(name2, options) {
94
+ if (name2 == null) return false;
94
95
  if (options.excepts.some((regex) => regex.test(name2))) {
95
96
  return true;
96
97
  }
97
98
  let normalized = name2.normalize("NFKD").replace(/[\u0300-\u036F]/g, "");
98
99
  normalized = normalized.split(".").at(-1) ?? normalized;
99
- if (options.allowNamespace) {
100
+ const { allowLeadingUnderscore = false, allowNamespace = false } = options;
101
+ if (allowNamespace) {
100
102
  normalized = normalized.replace(":", "");
101
103
  }
102
- if (options.allowLeadingUnderscore) {
104
+ if (allowLeadingUnderscore) {
103
105
  normalized = normalized.replace(/^_/, "");
104
106
  }
105
107
  return tsPattern.match(options.rule).with("CONSTANT_CASE", () => shared.RE_CONSTANT_CASE.test(normalized)).with("PascalCase", () => {
106
108
  if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
107
- return options.allowAllCaps;
109
+ return options.allowAllCaps ?? false;
108
110
  }
109
111
  return shared.RE_PASCAL_CASE.test(normalized);
110
- }).otherwise(eff.F.constFalse);
112
+ }).otherwise(eff.returnFalse);
111
113
  }
112
114
  var component_name_default = createRule({
113
115
  meta: {
@@ -149,11 +151,8 @@ var component_name_default = createRule({
149
151
  const functionComponents = collector.ctx.getAllComponents(node);
150
152
  const classComponents = collectorLegacy.ctx.getAllComponents(node);
151
153
  for (const { node: component } of functionComponents.values()) {
152
- const mbId = AST__namespace.getFunctionIdentifier(component);
153
- if (eff.O.isNone(mbId)) {
154
- continue;
155
- }
156
- const id = mbId.value;
154
+ const id = AST__namespace.getFunctionIdentifier(component);
155
+ if (id?.name == null) continue;
157
156
  if (validate(id.name, options)) {
158
157
  continue;
159
158
  }
@@ -166,19 +165,17 @@ var component_name_default = createRule({
166
165
  });
167
166
  }
168
167
  for (const { node: component } of classComponents.values()) {
169
- eff.F.pipe(
170
- AST__namespace.getClassIdentifier(component),
171
- eff.O.filter((id) => !validate(id.name, options)),
172
- eff.O.map((id) => {
173
- context.report({
174
- messageId: "componentName",
175
- node: id,
176
- data: {
177
- case: options.rule
178
- }
179
- });
180
- })
181
- );
168
+ const id = AST__namespace.getClassIdentifier(component);
169
+ if (id?.name == null) continue;
170
+ if (!validate(id.name, options)) {
171
+ context.report({
172
+ messageId: "componentName",
173
+ node: id,
174
+ data: {
175
+ case: options.rule
176
+ }
177
+ });
178
+ }
182
179
  }
183
180
  }
184
181
  };
@@ -239,13 +236,11 @@ var filename_default = createRule({
239
236
  name: RULE_NAME2,
240
237
  create(context) {
241
238
  const options = context.options[0] ?? defaultOptions2[0];
242
- const rule = eff.isString(options) ? options : options.rule ?? "PascalCase";
243
- const excepts = eff.isString(options) ? [] : options.excepts ?? [];
244
- const filename = context.filename;
239
+ const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
240
+ const excepts = typeof options === "string" ? [] : options.excepts ?? [];
245
241
  function validate2(name2, casing = rule, ignores = excepts) {
246
- if (ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2))) {
247
- return true;
248
- }
242
+ const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
243
+ if (shouldIgnore) return true;
249
244
  return tsPattern.match(casing).with("PascalCase", () => shared.RE_PASCAL_CASE.test(name2)).with("camelCase", () => shared.RE_CAMEL_CASE.test(name2)).with("kebab-case", () => shared.RE_KEBAB_CASE.test(name2)).with("snake_case", () => shared.RE_SNAKE_CASE.test(name2)).exhaustive();
250
245
  }
251
246
  function getSuggestion(name2, casing = rule) {
@@ -265,7 +260,7 @@ var filename_default = createRule({
265
260
  messageId: "filenameCaseMismatchSuggestion",
266
261
  node,
267
262
  data: {
268
- name: filename,
263
+ name: context.filename,
269
264
  rule,
270
265
  suggestion: [getSuggestion(basename), ...rest].join(".")
271
266
  }
@@ -349,7 +344,7 @@ var filename_extension_default = createRule({
349
344
  return;
350
345
  }
351
346
  const hasCode = node.body.length > 0;
352
- const ignoreFilesWithoutCode = eff.isObject(options) && options.ignoreFilesWithoutCode;
347
+ const ignoreFilesWithoutCode = eff.isObject(options) && options.ignoreFilesWithoutCode === true;
353
348
  if (!hasCode && ignoreFilesWithoutCode) {
354
349
  return;
355
350
  }
@@ -404,25 +399,30 @@ var use_state_default = createRule({
404
399
  continue;
405
400
  }
406
401
  const { id } = hookCall.parent;
407
- const descriptor = eff.O.some({ messageId: "useState", node: id });
408
- eff.F.pipe(
409
- tsPattern.match(id).with({ type: types.AST_NODE_TYPES.Identifier }, eff.F.constant(descriptor)).with({ type: types.AST_NODE_TYPES.ArrayPattern }, (n) => {
410
- const [state, setState] = n.elements;
402
+ switch (id.type) {
403
+ case types.AST_NODE_TYPES.Identifier: {
404
+ context.report({ messageId: "useState", node: id });
405
+ break;
406
+ }
407
+ case types.AST_NODE_TYPES.ArrayPattern: {
408
+ const [state, setState] = id.elements;
411
409
  if (state?.type === types.AST_NODE_TYPES.ObjectPattern && setState?.type === types.AST_NODE_TYPES.Identifier) {
412
- return isSetterNameLoose(setState.name) ? eff.O.none() : descriptor;
410
+ if (!isSetterNameLoose(setState.name)) {
411
+ context.report({ messageId: "useState", node: id });
412
+ }
413
+ break;
413
414
  }
414
415
  if (state?.type !== types.AST_NODE_TYPES.Identifier || setState?.type !== types.AST_NODE_TYPES.Identifier) {
415
- return eff.O.none();
416
+ return;
416
417
  }
417
418
  const [stateName, setStateName] = [state.name, setState.name];
418
419
  const expectedSetterName = `set${stringTs.capitalize(stateName)}`;
419
420
  if (setStateName === expectedSetterName) {
420
- return eff.O.none();
421
+ return;
421
422
  }
422
- return descriptor;
423
- }).otherwise(eff.O.none),
424
- eff.O.map(context.report)
425
- );
423
+ context.report({ messageId: "useState", node: id });
424
+ }
425
+ }
426
426
  }
427
427
  }
428
428
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as AST from '@eslint-react/ast';
2
2
  import { useComponentCollector, useComponentCollectorLegacy, isUseStateCall, isReactHookCallWithNameLoose } from '@eslint-react/core';
3
- import { O, F, isString, isObject, isNullable } from '@eslint-react/eff';
3
+ import { isObject, returnFalse } from '@eslint-react/eff';
4
4
  import * as JSX from '@eslint-react/jsx';
5
5
  import { createRuleForPlugin, getSettingsFromContext, RE_CONSTANT_CASE, RE_PASCAL_CASE, RE_CAMEL_CASE, RE_KEBAB_CASE, RE_SNAKE_CASE } from '@eslint-react/shared';
6
6
  import { match } from 'ts-pattern';
@@ -10,7 +10,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/types';
10
10
 
11
11
  // package.json
12
12
  var name = "eslint-plugin-react-naming-convention";
13
- var version = "1.23.3-next.8";
13
+ var version = "1.24.0-beta.1";
14
14
  var createRule = createRuleForPlugin("naming-convention");
15
15
 
16
16
  // src/rules/component-name.ts
@@ -52,11 +52,11 @@ var schema = [
52
52
  }
53
53
  ];
54
54
  function normalizeOptions(options) {
55
- const [opts] = options;
56
- if (isNullable(opts)) {
55
+ const opts = options[0];
56
+ if (opts == null) {
57
57
  return defaultOptions[0];
58
58
  }
59
- if (isString(opts)) {
59
+ if (typeof opts === "string") {
60
60
  return { ...defaultOptions[0], rule: opts };
61
61
  }
62
62
  return {
@@ -65,23 +65,25 @@ function normalizeOptions(options) {
65
65
  };
66
66
  }
67
67
  function validate(name2, options) {
68
+ if (name2 == null) return false;
68
69
  if (options.excepts.some((regex) => regex.test(name2))) {
69
70
  return true;
70
71
  }
71
72
  let normalized = name2.normalize("NFKD").replace(/[\u0300-\u036F]/g, "");
72
73
  normalized = normalized.split(".").at(-1) ?? normalized;
73
- if (options.allowNamespace) {
74
+ const { allowLeadingUnderscore = false, allowNamespace = false } = options;
75
+ if (allowNamespace) {
74
76
  normalized = normalized.replace(":", "");
75
77
  }
76
- if (options.allowLeadingUnderscore) {
78
+ if (allowLeadingUnderscore) {
77
79
  normalized = normalized.replace(/^_/, "");
78
80
  }
79
81
  return match(options.rule).with("CONSTANT_CASE", () => RE_CONSTANT_CASE.test(normalized)).with("PascalCase", () => {
80
82
  if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
81
- return options.allowAllCaps;
83
+ return options.allowAllCaps ?? false;
82
84
  }
83
85
  return RE_PASCAL_CASE.test(normalized);
84
- }).otherwise(F.constFalse);
86
+ }).otherwise(returnFalse);
85
87
  }
86
88
  var component_name_default = createRule({
87
89
  meta: {
@@ -123,11 +125,8 @@ var component_name_default = createRule({
123
125
  const functionComponents = collector.ctx.getAllComponents(node);
124
126
  const classComponents = collectorLegacy.ctx.getAllComponents(node);
125
127
  for (const { node: component } of functionComponents.values()) {
126
- const mbId = AST.getFunctionIdentifier(component);
127
- if (O.isNone(mbId)) {
128
- continue;
129
- }
130
- const id = mbId.value;
128
+ const id = AST.getFunctionIdentifier(component);
129
+ if (id?.name == null) continue;
131
130
  if (validate(id.name, options)) {
132
131
  continue;
133
132
  }
@@ -140,19 +139,17 @@ var component_name_default = createRule({
140
139
  });
141
140
  }
142
141
  for (const { node: component } of classComponents.values()) {
143
- F.pipe(
144
- AST.getClassIdentifier(component),
145
- O.filter((id) => !validate(id.name, options)),
146
- O.map((id) => {
147
- context.report({
148
- messageId: "componentName",
149
- node: id,
150
- data: {
151
- case: options.rule
152
- }
153
- });
154
- })
155
- );
142
+ const id = AST.getClassIdentifier(component);
143
+ if (id?.name == null) continue;
144
+ if (!validate(id.name, options)) {
145
+ context.report({
146
+ messageId: "componentName",
147
+ node: id,
148
+ data: {
149
+ case: options.rule
150
+ }
151
+ });
152
+ }
156
153
  }
157
154
  }
158
155
  };
@@ -213,13 +210,11 @@ var filename_default = createRule({
213
210
  name: RULE_NAME2,
214
211
  create(context) {
215
212
  const options = context.options[0] ?? defaultOptions2[0];
216
- const rule = isString(options) ? options : options.rule ?? "PascalCase";
217
- const excepts = isString(options) ? [] : options.excepts ?? [];
218
- const filename = context.filename;
213
+ const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
214
+ const excepts = typeof options === "string" ? [] : options.excepts ?? [];
219
215
  function validate2(name2, casing = rule, ignores = excepts) {
220
- if (ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2))) {
221
- return true;
222
- }
216
+ const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
217
+ if (shouldIgnore) return true;
223
218
  return match(casing).with("PascalCase", () => RE_PASCAL_CASE.test(name2)).with("camelCase", () => RE_CAMEL_CASE.test(name2)).with("kebab-case", () => RE_KEBAB_CASE.test(name2)).with("snake_case", () => RE_SNAKE_CASE.test(name2)).exhaustive();
224
219
  }
225
220
  function getSuggestion(name2, casing = rule) {
@@ -239,7 +234,7 @@ var filename_default = createRule({
239
234
  messageId: "filenameCaseMismatchSuggestion",
240
235
  node,
241
236
  data: {
242
- name: filename,
237
+ name: context.filename,
243
238
  rule,
244
239
  suggestion: [getSuggestion(basename), ...rest].join(".")
245
240
  }
@@ -323,7 +318,7 @@ var filename_extension_default = createRule({
323
318
  return;
324
319
  }
325
320
  const hasCode = node.body.length > 0;
326
- const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode;
321
+ const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode === true;
327
322
  if (!hasCode && ignoreFilesWithoutCode) {
328
323
  return;
329
324
  }
@@ -378,25 +373,30 @@ var use_state_default = createRule({
378
373
  continue;
379
374
  }
380
375
  const { id } = hookCall.parent;
381
- const descriptor = O.some({ messageId: "useState", node: id });
382
- F.pipe(
383
- match(id).with({ type: AST_NODE_TYPES.Identifier }, F.constant(descriptor)).with({ type: AST_NODE_TYPES.ArrayPattern }, (n) => {
384
- const [state, setState] = n.elements;
376
+ switch (id.type) {
377
+ case AST_NODE_TYPES.Identifier: {
378
+ context.report({ messageId: "useState", node: id });
379
+ break;
380
+ }
381
+ case AST_NODE_TYPES.ArrayPattern: {
382
+ const [state, setState] = id.elements;
385
383
  if (state?.type === AST_NODE_TYPES.ObjectPattern && setState?.type === AST_NODE_TYPES.Identifier) {
386
- return isSetterNameLoose(setState.name) ? O.none() : descriptor;
384
+ if (!isSetterNameLoose(setState.name)) {
385
+ context.report({ messageId: "useState", node: id });
386
+ }
387
+ break;
387
388
  }
388
389
  if (state?.type !== AST_NODE_TYPES.Identifier || setState?.type !== AST_NODE_TYPES.Identifier) {
389
- return O.none();
390
+ return;
390
391
  }
391
392
  const [stateName, setStateName] = [state.name, setState.name];
392
393
  const expectedSetterName = `set${capitalize(stateName)}`;
393
394
  if (setStateName === expectedSetterName) {
394
- return O.none();
395
+ return;
395
396
  }
396
- return descriptor;
397
- }).otherwise(O.none),
398
- O.map(context.report)
399
- );
397
+ context.report({ messageId: "useState", node: id });
398
+ }
399
+ }
400
400
  }
401
401
  }
402
402
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-naming-convention",
3
- "version": "1.23.3-next.8",
3
+ "version": "1.24.0-beta.1",
4
4
  "description": "ESLint React's ESLint plugin for naming convention related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -10,13 +10,13 @@
10
10
  "eslint-plugin",
11
11
  "eslint-plugin-react-naming-convention"
12
12
  ],
13
- "homepage": "https://github.com/rEl1cx/eslint-react",
13
+ "homepage": "https://github.com/Rel1cx/eslint-react",
14
14
  "bugs": {
15
- "url": "https://github.com/rEl1cx/eslint-react/issues"
15
+ "url": "https://github.com/Rel1cx/eslint-react/issues"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "git+https://github.com/rEl1cx/eslint-react.git",
19
+ "url": "git+https://github.com/Rel1cx/eslint-react.git",
20
20
  "directory": "packages/plugins/eslint-plugin-react-naming-convention"
21
21
  },
22
22
  "license": "MIT",
@@ -47,16 +47,16 @@
47
47
  "@typescript-eslint/utils": "^8.19.1",
48
48
  "string-ts": "^2.2.0",
49
49
  "ts-pattern": "^5.6.0",
50
- "@eslint-react/ast": "1.23.3-next.8",
51
- "@eslint-react/core": "1.23.3-next.8",
52
- "@eslint-react/eff": "1.23.3-next.8",
53
- "@eslint-react/shared": "1.23.3-next.8",
54
- "@eslint-react/jsx": "1.23.3-next.8",
55
- "@eslint-react/types": "1.23.3-next.8"
50
+ "@eslint-react/ast": "1.24.0-beta.1",
51
+ "@eslint-react/core": "1.24.0-beta.1",
52
+ "@eslint-react/eff": "1.24.0-beta.1",
53
+ "@eslint-react/jsx": "1.24.0-beta.1",
54
+ "@eslint-react/shared": "1.24.0-beta.1",
55
+ "@eslint-react/types": "1.24.0-beta.1"
56
56
  },
57
57
  "devDependencies": {
58
- "@types/react": "^19.0.4",
59
- "@types/react-dom": "^19.0.2",
58
+ "@types/react": "^19.0.5",
59
+ "@types/react-dom": "^19.0.3",
60
60
  "tsup": "^8.3.5",
61
61
  "@workspace/configs": "0.0.0"
62
62
  },