eslint-plugin-react-naming-convention
Advanced tools
Comparing version
@@ -5,3 +5,2 @@ 'use strict'; | ||
var core = require('@eslint-react/core'); | ||
var JSX = require('@eslint-react/jsx'); | ||
var shared = require('@eslint-react/shared'); | ||
@@ -35,3 +34,2 @@ var eff = require('@eslint-react/eff'); | ||
var AST__namespace = /*#__PURE__*/_interopNamespace(AST); | ||
var JSX__namespace = /*#__PURE__*/_interopNamespace(JSX); | ||
var path__default = /*#__PURE__*/_interopDefault(path); | ||
@@ -59,12 +57,9 @@ | ||
var name2 = "eslint-plugin-react-naming-convention"; | ||
var version = "1.29.1-next.6"; | ||
var version = "1.29.1-next.7"; | ||
var createRule = shared.createRuleForPlugin("naming-convention"); | ||
// src/rules/component-name.ts | ||
var RULE_NAME = "component-name"; | ||
var defaultOptions = [ | ||
{ | ||
allowAllCaps: false, | ||
allowLeadingUnderscore: false, | ||
allowNamespace: false, | ||
excepts: [], | ||
@@ -86,3 +81,11 @@ rule: "PascalCase" | ||
allowAllCaps: { type: "boolean" }, | ||
/** | ||
* @todo Remove in the next major version | ||
* @deprecated | ||
*/ | ||
allowLeadingUnderscore: { type: "boolean" }, | ||
/** | ||
* @todo Remove in the next major version | ||
* @deprecated | ||
*/ | ||
allowNamespace: { type: "boolean" }, | ||
@@ -102,30 +105,3 @@ excepts: { | ||
]; | ||
function normalizeOptions(options) { | ||
const opts = options[0]; | ||
const defaultOpts = defaultOptions[0]; | ||
if (opts == null) return defaultOpts; | ||
return { | ||
...defaultOpts, | ||
...typeof opts === "string" ? { rule: opts } : { | ||
...opts, | ||
excepts: opts.excepts?.map((pattern) => new RegExp(pattern, "u")) ?? [] | ||
} | ||
}; | ||
} | ||
function isValidComponentName(name3, options) { | ||
if (name3 == null) return true; | ||
if (options.excepts.some((regex) => regex.test(name3))) return true; | ||
let normalized = name3.split(".").at(-1) ?? name3; | ||
if (options.allowNamespace) normalized = normalized.replace(":", ""); | ||
if (options.allowLeadingUnderscore) normalized = normalized.replace(/^_/, ""); | ||
switch (options.rule) { | ||
case "CONSTANT_CASE": | ||
return shared.RE_CONSTANT_CASE.test(normalized); | ||
case "PascalCase": | ||
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) { | ||
return options.allowAllCaps; | ||
} | ||
return shared.RE_PASCAL_CASE.test(normalized); | ||
} | ||
} | ||
var RULE_NAME = "component-name"; | ||
var component_name_default = createRule({ | ||
@@ -152,14 +128,2 @@ meta: { | ||
...collectorLegacy.listeners, | ||
JSXOpeningElement(node) { | ||
const name3 = JSX__namespace.getElementName(node.parent); | ||
if (/^[a-z]/u.test(name3)) { | ||
return; | ||
} | ||
if (isValidComponentName(name3, options)) return; | ||
context.report({ | ||
messageId: "invalid", | ||
node, | ||
data: { name: name3, rule } | ||
}); | ||
}, | ||
"Program:exit"(node) { | ||
@@ -172,3 +136,3 @@ const functionComponents = collector.ctx.getAllComponents(node); | ||
const name3 = id.name; | ||
if (isValidComponentName(name3, options)) return; | ||
if (isValidName(name3, options)) return; | ||
context.report({ | ||
@@ -184,3 +148,3 @@ messageId: "invalid", | ||
const name3 = id.name; | ||
if (isValidComponentName(name3, options)) continue; | ||
if (isValidName(name3, options)) continue; | ||
context.report({ | ||
@@ -197,2 +161,28 @@ messageId: "invalid", | ||
}); | ||
function normalizeOptions(options) { | ||
const opts = options[0]; | ||
const defaultOpts = defaultOptions[0]; | ||
if (opts == null) return defaultOpts; | ||
return { | ||
...defaultOpts, | ||
...typeof opts === "string" ? { rule: opts } : { | ||
...opts, | ||
excepts: opts.excepts?.map((pattern) => new RegExp(pattern, "u")) ?? [] | ||
} | ||
}; | ||
} | ||
function isValidName(name3, options) { | ||
if (name3 == null) return true; | ||
if (options.excepts.some((regex) => regex.test(name3))) return true; | ||
const normalized = name3.split(".").at(-1) ?? name3; | ||
switch (options.rule) { | ||
case "CONSTANT_CASE": | ||
return shared.RE_CONSTANT_CASE.test(normalized); | ||
case "PascalCase": | ||
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) { | ||
return options.allowAllCaps; | ||
} | ||
return shared.RE_PASCAL_CASE.test(normalized); | ||
} | ||
} | ||
var RULE_NAME2 = "context-name"; | ||
@@ -476,7 +466,7 @@ var context_name_default = createRule({ | ||
rules: { | ||
"component-name": component_name_default, | ||
"context-name": context_name_default, | ||
filename: filename_default, | ||
"filename-extension": filename_extension_default, | ||
"use-state": use_state_default | ||
["component-name"]: component_name_default, | ||
["context-name"]: context_name_default, | ||
["filename"]: filename_default, | ||
["filename-extension"]: filename_extension_default, | ||
["use-state"]: use_state_default | ||
} | ||
@@ -483,0 +473,0 @@ }; |
{ | ||
"name": "eslint-plugin-react-naming-convention", | ||
"version": "1.29.1-next.6", | ||
"version": "1.29.1-next.7", | ||
"description": "ESLint React's ESLint plugin for naming convention related rules.", | ||
@@ -52,8 +52,8 @@ "keywords": [ | ||
"ts-pattern": "^5.6.2", | ||
"@eslint-react/ast": "1.29.1-next.6", | ||
"@eslint-react/eff": "1.29.1-next.6", | ||
"@eslint-react/jsx": "1.29.1-next.6", | ||
"@eslint-react/shared": "1.29.1-next.6", | ||
"@eslint-react/core": "1.29.1-next.6", | ||
"@eslint-react/var": "1.29.1-next.6" | ||
"@eslint-react/ast": "1.29.1-next.7", | ||
"@eslint-react/core": "1.29.1-next.7", | ||
"@eslint-react/jsx": "1.29.1-next.7", | ||
"@eslint-react/var": "1.29.1-next.7", | ||
"@eslint-react/eff": "1.29.1-next.7", | ||
"@eslint-react/shared": "1.29.1-next.7" | ||
}, | ||
@@ -60,0 +60,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
41556
-2.05%1005
-1.86%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed