eslint-plugin-react-naming-convention 1.34.0-next.0 → 1.34.0-next.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 +173 -168
  2. package/dist/index.mjs +173 -168
  3. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -49,7 +49,7 @@ var rules = {};
49
49
 
50
50
  // package.json
51
51
  var name2 = "eslint-plugin-react-naming-convention";
52
- var version = "1.34.0-next.0";
52
+ var version = "1.34.0-next.1";
53
53
  var createRule = shared.createRuleForPlugin("naming-convention");
54
54
 
55
55
  // src/utils/regexp.ts
@@ -117,44 +117,45 @@ var component_name_default = createRule({
117
117
  schema
118
118
  },
119
119
  name: RULE_NAME,
120
- create(context) {
121
- const options = normalizeOptions(context.options);
122
- const { rule } = options;
123
- const collector = core.useComponentCollector(context);
124
- const collectorLegacy = core.useComponentCollectorLegacy();
125
- return {
126
- ...collector.listeners,
127
- ...collectorLegacy.listeners,
128
- "Program:exit"(node) {
129
- const functionComponents = collector.ctx.getAllComponents(node);
130
- const classComponents = collectorLegacy.ctx.getAllComponents(node);
131
- for (const { node: component } of functionComponents.values()) {
132
- const id = AST__namespace.getFunctionIdentifier(component);
133
- if (id?.name == null) continue;
134
- const name3 = id.name;
135
- if (isValidName(name3, options)) return;
136
- context.report({
137
- messageId: "invalid",
138
- node: id,
139
- data: { name: name3, rule }
140
- });
141
- }
142
- for (const { node: component } of classComponents.values()) {
143
- const id = AST__namespace.getClassIdentifier(component);
144
- if (id?.name == null) continue;
145
- const name3 = id.name;
146
- if (isValidName(name3, options)) continue;
147
- context.report({
148
- messageId: "invalid",
149
- node: id,
150
- data: { name: name3, rule }
151
- });
152
- }
153
- }
154
- };
155
- },
120
+ create,
156
121
  defaultOptions
157
122
  });
123
+ function create(context) {
124
+ const options = normalizeOptions(context.options);
125
+ const { rule } = options;
126
+ const collector = core.useComponentCollector(context);
127
+ const collectorLegacy = core.useComponentCollectorLegacy();
128
+ return {
129
+ ...collector.listeners,
130
+ ...collectorLegacy.listeners,
131
+ "Program:exit"(node) {
132
+ const functionComponents = collector.ctx.getAllComponents(node);
133
+ const classComponents = collectorLegacy.ctx.getAllComponents(node);
134
+ for (const { node: component } of functionComponents.values()) {
135
+ const id = AST__namespace.getFunctionIdentifier(component);
136
+ if (id?.name == null) continue;
137
+ const name3 = id.name;
138
+ if (isValidName(name3, options)) return;
139
+ context.report({
140
+ messageId: "invalid",
141
+ node: id,
142
+ data: { name: name3, rule }
143
+ });
144
+ }
145
+ for (const { node: component } of classComponents.values()) {
146
+ const id = AST__namespace.getClassIdentifier(component);
147
+ if (id?.name == null) continue;
148
+ const name3 = id.name;
149
+ if (isValidName(name3, options)) continue;
150
+ context.report({
151
+ messageId: "invalid",
152
+ node: id,
153
+ data: { name: name3, rule }
154
+ });
155
+ }
156
+ }
157
+ };
158
+ }
158
159
  function normalizeOptions(options) {
159
160
  const opts = options[0];
160
161
  const defaultOpts = defaultOptions[0];
@@ -194,24 +195,25 @@ var context_name_default = createRule({
194
195
  schema: []
195
196
  },
196
197
  name: RULE_NAME2,
197
- create(context) {
198
- if (!context.sourceCode.text.includes("createContext")) return {};
199
- return {
200
- CallExpression(node) {
201
- if (!core.isCreateContextCall(context, node)) return;
202
- const id = core.getInstanceId(node);
203
- if (id == null) return;
204
- 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._);
205
- if (name3 != null && core.isComponentName(name3) && name3.endsWith("Context")) return;
206
- context.report({
207
- messageId: "invalid",
208
- node: id
209
- });
210
- }
211
- };
212
- },
198
+ create: create2,
213
199
  defaultOptions: []
214
200
  });
201
+ function create2(context) {
202
+ if (!context.sourceCode.text.includes("createContext")) return {};
203
+ return {
204
+ CallExpression(node) {
205
+ if (!core.isCreateContextCall(context, node)) return;
206
+ const id = core.getInstanceId(node);
207
+ if (id == null) return;
208
+ 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._);
209
+ if (name3 != null && core.isComponentName(name3) && name3.endsWith("Context")) return;
210
+ context.report({
211
+ messageId: "invalid",
212
+ node: id
213
+ });
214
+ }
215
+ };
216
+ }
215
217
  var RULE_NAME3 = "filename";
216
218
  var defaultOptions2 = [
217
219
  {
@@ -263,42 +265,43 @@ var filename_default = createRule({
263
265
  schema: schema2
264
266
  },
265
267
  name: RULE_NAME3,
266
- create(context) {
267
- const options = context.options[0] ?? defaultOptions2[0];
268
- const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
269
- const excepts = typeof options === "string" ? [] : options.excepts ?? [];
270
- function validate(name3, casing = rule, ignores = excepts) {
271
- const shouldIgnore = ignores.map(toRegExp).some((pattern) => pattern.test(name3));
272
- if (shouldIgnore) return true;
273
- return tsPattern.match(casing).with("PascalCase", () => shared.RE_PASCAL_CASE.test(name3)).with("camelCase", () => shared.RE_CAMEL_CASE.test(name3)).with("kebab-case", () => shared.RE_KEBAB_CASE.test(name3)).with("snake_case", () => shared.RE_SNAKE_CASE.test(name3)).exhaustive();
274
- }
275
- function getSuggestion(name3, casing = rule) {
276
- return tsPattern.match(casing).with("PascalCase", () => stringTs.pascalCase(name3)).with("camelCase", () => stringTs.camelCase(name3)).with("kebab-case", () => stringTs.kebabCase(name3)).with("snake_case", () => stringTs.snakeCase(name3)).exhaustive();
277
- }
278
- return {
279
- Program(node) {
280
- const [basename = "", ...rest] = path__default.default.basename(context.filename).split(".");
281
- if (basename.length === 0) {
282
- context.report({ messageId: "filenameEmpty", node });
283
- return;
284
- }
285
- if (validate(basename)) {
286
- return;
287
- }
288
- context.report({
289
- messageId: "filenameInvalid",
290
- node,
291
- data: {
292
- name: context.filename,
293
- rule,
294
- suggestion: [getSuggestion(basename), ...rest].join(".")
295
- }
296
- });
297
- }
298
- };
299
- },
268
+ create: create3,
300
269
  defaultOptions: defaultOptions2
301
270
  });
271
+ function create3(context) {
272
+ const options = context.options[0] ?? defaultOptions2[0];
273
+ const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
274
+ const excepts = typeof options === "string" ? [] : options.excepts ?? [];
275
+ function validate(name3, casing = rule, ignores = excepts) {
276
+ const shouldIgnore = ignores.map(toRegExp).some((pattern) => pattern.test(name3));
277
+ if (shouldIgnore) return true;
278
+ return tsPattern.match(casing).with("PascalCase", () => shared.RE_PASCAL_CASE.test(name3)).with("camelCase", () => shared.RE_CAMEL_CASE.test(name3)).with("kebab-case", () => shared.RE_KEBAB_CASE.test(name3)).with("snake_case", () => shared.RE_SNAKE_CASE.test(name3)).exhaustive();
279
+ }
280
+ function getSuggestion(name3, casing = rule) {
281
+ return tsPattern.match(casing).with("PascalCase", () => stringTs.pascalCase(name3)).with("camelCase", () => stringTs.camelCase(name3)).with("kebab-case", () => stringTs.kebabCase(name3)).with("snake_case", () => stringTs.snakeCase(name3)).exhaustive();
282
+ }
283
+ return {
284
+ Program(node) {
285
+ const [basename = "", ...rest] = path__default.default.basename(context.filename).split(".");
286
+ if (basename.length === 0) {
287
+ context.report({ messageId: "filenameEmpty", node });
288
+ return;
289
+ }
290
+ if (validate(basename)) {
291
+ return;
292
+ }
293
+ context.report({
294
+ messageId: "filenameInvalid",
295
+ node,
296
+ data: {
297
+ name: context.filename,
298
+ rule,
299
+ suggestion: [getSuggestion(basename), ...rest].join(".")
300
+ }
301
+ });
302
+ }
303
+ };
304
+ }
302
305
  var RULE_NAME4 = "filename-extension";
303
306
  var defaultOptions3 = [{
304
307
  allow: "as-needed",
@@ -349,52 +352,53 @@ var filename_extension_default = createRule({
349
352
  schema: schema3
350
353
  },
351
354
  name: RULE_NAME4,
352
- create(context) {
353
- const options = context.options[0] ?? defaultOptions3[0];
354
- const allow = eff.isObject(options) ? options.allow : options;
355
- const extensions = eff.isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
356
- const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
357
- const filename = context.filename;
358
- let hasJSXNode = false;
359
- return {
360
- JSXElement() {
361
- hasJSXNode = true;
362
- },
363
- JSXFragment() {
364
- hasJSXNode = true;
365
- },
366
- "Program:exit"(node) {
367
- const fileNameExt = filename.slice(filename.lastIndexOf("."));
368
- const isJSXExt = extensions.includes(fileNameExt);
369
- if (hasJSXNode && !isJSXExt) {
370
- context.report({
371
- messageId: "useJsxFileExtension",
372
- node,
373
- data: {
374
- extensions: extensionsString
375
- }
376
- });
377
- return;
378
- }
379
- const hasCode = node.body.length > 0;
380
- const ignoreFilesWithoutCode = eff.isObject(options) && options.ignoreFilesWithoutCode === true;
381
- if (!hasCode && ignoreFilesWithoutCode) {
382
- return;
383
- }
384
- if (!hasJSXNode && isJSXExt && allow === "as-needed") {
385
- context.report({
386
- messageId: "useNonJsxFileExtension",
387
- node,
388
- data: {
389
- extensions: extensionsString
390
- }
391
- });
392
- }
393
- }
394
- };
395
- },
355
+ create: create4,
396
356
  defaultOptions: defaultOptions3
397
357
  });
358
+ function create4(context) {
359
+ const options = context.options[0] ?? defaultOptions3[0];
360
+ const allow = eff.isObject(options) ? options.allow : options;
361
+ const extensions = eff.isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
362
+ const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
363
+ const filename = context.filename;
364
+ let hasJSXNode = false;
365
+ return {
366
+ JSXElement() {
367
+ hasJSXNode = true;
368
+ },
369
+ JSXFragment() {
370
+ hasJSXNode = true;
371
+ },
372
+ "Program:exit"(node) {
373
+ const fileNameExt = filename.slice(filename.lastIndexOf("."));
374
+ const isJSXExt = extensions.includes(fileNameExt);
375
+ if (hasJSXNode && !isJSXExt) {
376
+ context.report({
377
+ messageId: "useJsxFileExtension",
378
+ node,
379
+ data: {
380
+ extensions: extensionsString
381
+ }
382
+ });
383
+ return;
384
+ }
385
+ const hasCode = node.body.length > 0;
386
+ const ignoreFilesWithoutCode = eff.isObject(options) && options.ignoreFilesWithoutCode === true;
387
+ if (!hasCode && ignoreFilesWithoutCode) {
388
+ return;
389
+ }
390
+ if (!hasJSXNode && isJSXExt && allow === "as-needed") {
391
+ context.report({
392
+ messageId: "useNonJsxFileExtension",
393
+ node,
394
+ data: {
395
+ extensions: extensionsString
396
+ }
397
+ });
398
+ }
399
+ }
400
+ };
401
+ }
398
402
  var RULE_NAME5 = "use-state";
399
403
  var RULE_FEATURES = [
400
404
  "CHK"
@@ -412,45 +416,46 @@ var use_state_default = createRule({
412
416
  schema: []
413
417
  },
414
418
  name: RULE_NAME5,
415
- create(context) {
416
- return {
417
- "CallExpression[callee.name='useState']"(node) {
418
- if (node.parent.type !== types.AST_NODE_TYPES.VariableDeclarator) {
419
- context.report({ messageId: "invalid", node });
420
- }
421
- const id = core.getInstanceId(node);
422
- if (id?.type !== types.AST_NODE_TYPES.ArrayPattern) {
423
- context.report({ messageId: "invalid", node });
424
- return;
425
- }
426
- const [value, setter] = id.elements;
427
- if (value == null || setter == null) {
428
- context.report({ messageId: "invalid", node });
429
- return;
430
- }
431
- const setterName = tsPattern.match(setter).with({ type: types.AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => eff._);
432
- if (setterName == null || !setterName.startsWith("set")) {
433
- context.report({ messageId: "invalid", node });
434
- return;
435
- }
436
- const valueName = tsPattern.match(value).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name3 }) => stringTs.snakeCase(name3)).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
437
- const values = properties.reduce((acc, prop) => {
438
- if (prop.type === types.AST_NODE_TYPES.Property && prop.key.type === types.AST_NODE_TYPES.Identifier) {
439
- return [...acc, prop.key.name];
440
- }
441
- return acc;
442
- }, []);
443
- return values.join("_");
444
- }).otherwise(() => eff._);
445
- if (valueName == null || `set_${valueName}` !== stringTs.snakeCase(setterName)) {
446
- context.report({ messageId: "invalid", node });
447
- return;
448
- }
449
- }
450
- };
451
- },
419
+ create: create5,
452
420
  defaultOptions: []
453
421
  });
422
+ function create5(context) {
423
+ return {
424
+ "CallExpression[callee.name='useState']"(node) {
425
+ if (node.parent.type !== types.AST_NODE_TYPES.VariableDeclarator) {
426
+ context.report({ messageId: "invalid", node });
427
+ }
428
+ const id = core.getInstanceId(node);
429
+ if (id?.type !== types.AST_NODE_TYPES.ArrayPattern) {
430
+ context.report({ messageId: "invalid", node });
431
+ return;
432
+ }
433
+ const [value, setter] = id.elements;
434
+ if (value == null || setter == null) {
435
+ context.report({ messageId: "invalid", node });
436
+ return;
437
+ }
438
+ const setterName = tsPattern.match(setter).with({ type: types.AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => eff._);
439
+ if (setterName == null || !setterName.startsWith("set")) {
440
+ context.report({ messageId: "invalid", node });
441
+ return;
442
+ }
443
+ const valueName = tsPattern.match(value).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name3 }) => stringTs.snakeCase(name3)).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
444
+ const values = properties.reduce((acc, prop) => {
445
+ if (prop.type === types.AST_NODE_TYPES.Property && prop.key.type === types.AST_NODE_TYPES.Identifier) {
446
+ return [...acc, prop.key.name];
447
+ }
448
+ return acc;
449
+ }, []);
450
+ return values.join("_");
451
+ }).otherwise(() => eff._);
452
+ if (valueName == null || `set_${valueName}` !== stringTs.snakeCase(setterName)) {
453
+ context.report({ messageId: "invalid", node });
454
+ return;
455
+ }
456
+ }
457
+ };
458
+ }
454
459
 
455
460
  // src/plugin.ts
456
461
  var plugin = {
package/dist/index.mjs CHANGED
@@ -24,7 +24,7 @@ var rules = {};
24
24
 
25
25
  // package.json
26
26
  var name2 = "eslint-plugin-react-naming-convention";
27
- var version = "1.34.0-next.0";
27
+ var version = "1.34.0-next.1";
28
28
  var createRule = createRuleForPlugin("naming-convention");
29
29
 
30
30
  // src/utils/regexp.ts
@@ -92,44 +92,45 @@ var component_name_default = createRule({
92
92
  schema
93
93
  },
94
94
  name: RULE_NAME,
95
- create(context) {
96
- const options = normalizeOptions(context.options);
97
- const { rule } = options;
98
- const collector = useComponentCollector(context);
99
- const collectorLegacy = useComponentCollectorLegacy();
100
- return {
101
- ...collector.listeners,
102
- ...collectorLegacy.listeners,
103
- "Program:exit"(node) {
104
- const functionComponents = collector.ctx.getAllComponents(node);
105
- const classComponents = collectorLegacy.ctx.getAllComponents(node);
106
- for (const { node: component } of functionComponents.values()) {
107
- const id = AST.getFunctionIdentifier(component);
108
- if (id?.name == null) continue;
109
- const name3 = id.name;
110
- if (isValidName(name3, options)) return;
111
- context.report({
112
- messageId: "invalid",
113
- node: id,
114
- data: { name: name3, rule }
115
- });
116
- }
117
- for (const { node: component } of classComponents.values()) {
118
- const id = AST.getClassIdentifier(component);
119
- if (id?.name == null) continue;
120
- const name3 = id.name;
121
- if (isValidName(name3, options)) continue;
122
- context.report({
123
- messageId: "invalid",
124
- node: id,
125
- data: { name: name3, rule }
126
- });
127
- }
128
- }
129
- };
130
- },
95
+ create,
131
96
  defaultOptions
132
97
  });
98
+ function create(context) {
99
+ const options = normalizeOptions(context.options);
100
+ const { rule } = options;
101
+ const collector = useComponentCollector(context);
102
+ const collectorLegacy = useComponentCollectorLegacy();
103
+ return {
104
+ ...collector.listeners,
105
+ ...collectorLegacy.listeners,
106
+ "Program:exit"(node) {
107
+ const functionComponents = collector.ctx.getAllComponents(node);
108
+ const classComponents = collectorLegacy.ctx.getAllComponents(node);
109
+ for (const { node: component } of functionComponents.values()) {
110
+ const id = AST.getFunctionIdentifier(component);
111
+ if (id?.name == null) continue;
112
+ const name3 = id.name;
113
+ if (isValidName(name3, options)) return;
114
+ context.report({
115
+ messageId: "invalid",
116
+ node: id,
117
+ data: { name: name3, rule }
118
+ });
119
+ }
120
+ for (const { node: component } of classComponents.values()) {
121
+ const id = AST.getClassIdentifier(component);
122
+ if (id?.name == null) continue;
123
+ const name3 = id.name;
124
+ if (isValidName(name3, options)) continue;
125
+ context.report({
126
+ messageId: "invalid",
127
+ node: id,
128
+ data: { name: name3, rule }
129
+ });
130
+ }
131
+ }
132
+ };
133
+ }
133
134
  function normalizeOptions(options) {
134
135
  const opts = options[0];
135
136
  const defaultOpts = defaultOptions[0];
@@ -169,24 +170,25 @@ var context_name_default = createRule({
169
170
  schema: []
170
171
  },
171
172
  name: RULE_NAME2,
172
- create(context) {
173
- if (!context.sourceCode.text.includes("createContext")) return {};
174
- return {
175
- CallExpression(node) {
176
- if (!isCreateContextCall(context, node)) return;
177
- const id = getInstanceId(node);
178
- if (id == null) return;
179
- 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(() => _);
180
- if (name3 != null && isComponentName(name3) && name3.endsWith("Context")) return;
181
- context.report({
182
- messageId: "invalid",
183
- node: id
184
- });
185
- }
186
- };
187
- },
173
+ create: create2,
188
174
  defaultOptions: []
189
175
  });
176
+ function create2(context) {
177
+ if (!context.sourceCode.text.includes("createContext")) return {};
178
+ return {
179
+ CallExpression(node) {
180
+ if (!isCreateContextCall(context, node)) return;
181
+ const id = getInstanceId(node);
182
+ if (id == null) return;
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(() => _);
184
+ if (name3 != null && isComponentName(name3) && name3.endsWith("Context")) return;
185
+ context.report({
186
+ messageId: "invalid",
187
+ node: id
188
+ });
189
+ }
190
+ };
191
+ }
190
192
  var RULE_NAME3 = "filename";
191
193
  var defaultOptions2 = [
192
194
  {
@@ -238,42 +240,43 @@ var filename_default = createRule({
238
240
  schema: schema2
239
241
  },
240
242
  name: RULE_NAME3,
241
- create(context) {
242
- const options = context.options[0] ?? defaultOptions2[0];
243
- const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
244
- const excepts = typeof options === "string" ? [] : options.excepts ?? [];
245
- function validate(name3, casing = rule, ignores = excepts) {
246
- const shouldIgnore = ignores.map(toRegExp).some((pattern) => pattern.test(name3));
247
- if (shouldIgnore) return true;
248
- return match(casing).with("PascalCase", () => RE_PASCAL_CASE.test(name3)).with("camelCase", () => RE_CAMEL_CASE.test(name3)).with("kebab-case", () => RE_KEBAB_CASE.test(name3)).with("snake_case", () => RE_SNAKE_CASE.test(name3)).exhaustive();
249
- }
250
- function getSuggestion(name3, casing = rule) {
251
- return match(casing).with("PascalCase", () => pascalCase(name3)).with("camelCase", () => camelCase(name3)).with("kebab-case", () => kebabCase(name3)).with("snake_case", () => snakeCase(name3)).exhaustive();
252
- }
253
- return {
254
- Program(node) {
255
- const [basename = "", ...rest] = path.basename(context.filename).split(".");
256
- if (basename.length === 0) {
257
- context.report({ messageId: "filenameEmpty", node });
258
- return;
259
- }
260
- if (validate(basename)) {
261
- return;
262
- }
263
- context.report({
264
- messageId: "filenameInvalid",
265
- node,
266
- data: {
267
- name: context.filename,
268
- rule,
269
- suggestion: [getSuggestion(basename), ...rest].join(".")
270
- }
271
- });
272
- }
273
- };
274
- },
243
+ create: create3,
275
244
  defaultOptions: defaultOptions2
276
245
  });
246
+ function create3(context) {
247
+ const options = context.options[0] ?? defaultOptions2[0];
248
+ const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
249
+ const excepts = typeof options === "string" ? [] : options.excepts ?? [];
250
+ function validate(name3, casing = rule, ignores = excepts) {
251
+ const shouldIgnore = ignores.map(toRegExp).some((pattern) => pattern.test(name3));
252
+ if (shouldIgnore) return true;
253
+ return match(casing).with("PascalCase", () => RE_PASCAL_CASE.test(name3)).with("camelCase", () => RE_CAMEL_CASE.test(name3)).with("kebab-case", () => RE_KEBAB_CASE.test(name3)).with("snake_case", () => RE_SNAKE_CASE.test(name3)).exhaustive();
254
+ }
255
+ function getSuggestion(name3, casing = rule) {
256
+ return match(casing).with("PascalCase", () => pascalCase(name3)).with("camelCase", () => camelCase(name3)).with("kebab-case", () => kebabCase(name3)).with("snake_case", () => snakeCase(name3)).exhaustive();
257
+ }
258
+ return {
259
+ Program(node) {
260
+ const [basename = "", ...rest] = path.basename(context.filename).split(".");
261
+ if (basename.length === 0) {
262
+ context.report({ messageId: "filenameEmpty", node });
263
+ return;
264
+ }
265
+ if (validate(basename)) {
266
+ return;
267
+ }
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
+ }
278
+ };
279
+ }
277
280
  var RULE_NAME4 = "filename-extension";
278
281
  var defaultOptions3 = [{
279
282
  allow: "as-needed",
@@ -324,52 +327,53 @@ var filename_extension_default = createRule({
324
327
  schema: schema3
325
328
  },
326
329
  name: RULE_NAME4,
327
- create(context) {
328
- const options = context.options[0] ?? defaultOptions3[0];
329
- const allow = isObject(options) ? options.allow : options;
330
- const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
331
- const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
332
- const filename = context.filename;
333
- let hasJSXNode = false;
334
- return {
335
- JSXElement() {
336
- hasJSXNode = true;
337
- },
338
- JSXFragment() {
339
- hasJSXNode = true;
340
- },
341
- "Program:exit"(node) {
342
- const fileNameExt = filename.slice(filename.lastIndexOf("."));
343
- const isJSXExt = extensions.includes(fileNameExt);
344
- if (hasJSXNode && !isJSXExt) {
345
- context.report({
346
- messageId: "useJsxFileExtension",
347
- node,
348
- data: {
349
- extensions: extensionsString
350
- }
351
- });
352
- return;
353
- }
354
- const hasCode = node.body.length > 0;
355
- const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode === true;
356
- if (!hasCode && ignoreFilesWithoutCode) {
357
- return;
358
- }
359
- if (!hasJSXNode && isJSXExt && allow === "as-needed") {
360
- context.report({
361
- messageId: "useNonJsxFileExtension",
362
- node,
363
- data: {
364
- extensions: extensionsString
365
- }
366
- });
367
- }
368
- }
369
- };
370
- },
330
+ create: create4,
371
331
  defaultOptions: defaultOptions3
372
332
  });
333
+ function create4(context) {
334
+ const options = context.options[0] ?? defaultOptions3[0];
335
+ const allow = isObject(options) ? options.allow : options;
336
+ const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
337
+ const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
338
+ const filename = context.filename;
339
+ let hasJSXNode = false;
340
+ return {
341
+ JSXElement() {
342
+ hasJSXNode = true;
343
+ },
344
+ JSXFragment() {
345
+ hasJSXNode = true;
346
+ },
347
+ "Program:exit"(node) {
348
+ const fileNameExt = filename.slice(filename.lastIndexOf("."));
349
+ const isJSXExt = extensions.includes(fileNameExt);
350
+ if (hasJSXNode && !isJSXExt) {
351
+ context.report({
352
+ messageId: "useJsxFileExtension",
353
+ node,
354
+ data: {
355
+ extensions: extensionsString
356
+ }
357
+ });
358
+ return;
359
+ }
360
+ const hasCode = node.body.length > 0;
361
+ const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode === true;
362
+ if (!hasCode && ignoreFilesWithoutCode) {
363
+ return;
364
+ }
365
+ if (!hasJSXNode && isJSXExt && allow === "as-needed") {
366
+ context.report({
367
+ messageId: "useNonJsxFileExtension",
368
+ node,
369
+ data: {
370
+ extensions: extensionsString
371
+ }
372
+ });
373
+ }
374
+ }
375
+ };
376
+ }
373
377
  var RULE_NAME5 = "use-state";
374
378
  var RULE_FEATURES = [
375
379
  "CHK"
@@ -387,45 +391,46 @@ var use_state_default = createRule({
387
391
  schema: []
388
392
  },
389
393
  name: RULE_NAME5,
390
- create(context) {
391
- return {
392
- "CallExpression[callee.name='useState']"(node) {
393
- if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
394
- context.report({ messageId: "invalid", node });
395
- }
396
- const id = getInstanceId(node);
397
- if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
398
- context.report({ messageId: "invalid", node });
399
- return;
400
- }
401
- const [value, setter] = id.elements;
402
- if (value == null || setter == null) {
403
- context.report({ messageId: "invalid", node });
404
- return;
405
- }
406
- const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => _);
407
- if (setterName == null || !setterName.startsWith("set")) {
408
- context.report({ messageId: "invalid", node });
409
- return;
410
- }
411
- const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name3 }) => snakeCase(name3)).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
412
- const values = properties.reduce((acc, prop) => {
413
- if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) {
414
- return [...acc, prop.key.name];
415
- }
416
- return acc;
417
- }, []);
418
- return values.join("_");
419
- }).otherwise(() => _);
420
- if (valueName == null || `set_${valueName}` !== snakeCase(setterName)) {
421
- context.report({ messageId: "invalid", node });
422
- return;
423
- }
424
- }
425
- };
426
- },
394
+ create: create5,
427
395
  defaultOptions: []
428
396
  });
397
+ function create5(context) {
398
+ return {
399
+ "CallExpression[callee.name='useState']"(node) {
400
+ if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
401
+ context.report({ messageId: "invalid", node });
402
+ }
403
+ const id = getInstanceId(node);
404
+ if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
405
+ context.report({ messageId: "invalid", node });
406
+ return;
407
+ }
408
+ const [value, setter] = id.elements;
409
+ if (value == null || setter == null) {
410
+ context.report({ messageId: "invalid", node });
411
+ return;
412
+ }
413
+ const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => _);
414
+ if (setterName == null || !setterName.startsWith("set")) {
415
+ context.report({ messageId: "invalid", node });
416
+ return;
417
+ }
418
+ const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name3 }) => snakeCase(name3)).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
419
+ const values = properties.reduce((acc, prop) => {
420
+ if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) {
421
+ return [...acc, prop.key.name];
422
+ }
423
+ return acc;
424
+ }, []);
425
+ return values.join("_");
426
+ }).otherwise(() => _);
427
+ if (valueName == null || `set_${valueName}` !== snakeCase(setterName)) {
428
+ context.report({ messageId: "invalid", node });
429
+ return;
430
+ }
431
+ }
432
+ };
433
+ }
429
434
 
430
435
  // src/plugin.ts
431
436
  var plugin = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-naming-convention",
3
- "version": "1.34.0-next.0",
3
+ "version": "1.34.0-next.1",
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.26.1",
50
50
  "string-ts": "^2.2.1",
51
51
  "ts-pattern": "^5.6.2",
52
- "@eslint-react/ast": "1.34.0-next.0",
53
- "@eslint-react/core": "1.34.0-next.0",
54
- "@eslint-react/jsx": "1.34.0-next.0",
55
- "@eslint-react/shared": "1.34.0-next.0",
56
- "@eslint-react/eff": "1.34.0-next.0",
57
- "@eslint-react/var": "1.34.0-next.0"
52
+ "@eslint-react/ast": "1.34.0-next.1",
53
+ "@eslint-react/core": "1.34.0-next.1",
54
+ "@eslint-react/eff": "1.34.0-next.1",
55
+ "@eslint-react/jsx": "1.34.0-next.1",
56
+ "@eslint-react/shared": "1.34.0-next.1",
57
+ "@eslint-react/var": "1.34.0-next.1"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/react": "^19.0.10",