eslint-plugin-react-naming-convention
Advanced tools
Comparing version 1.26.3-beta.6 to 1.26.3-beta.7
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint'; | ||
type MessageID$1 = "filenameExtensionInvalid" | "filenameExtensionUnexpected"; | ||
type MessageID$2 = "useJsxFileExtension" | "useJsxFileExtensionAsNeeded"; | ||
type MessageID = "filenameCaseMismatchSuggestion" | "filenameEmpty"; | ||
type MessageID$1 = "filenameCaseMismatchSuggestion" | "filenameEmpty"; | ||
type MessageID = "usePascalCase" | "useConstantCase"; | ||
declare const _default: { | ||
@@ -13,3 +15,3 @@ readonly meta: { | ||
readonly rules: { | ||
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"componentName", readonly [("CONSTANT_CASE" | "PascalCase") | { | ||
readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("CONSTANT_CASE" | "PascalCase") | { | ||
allowAllCaps?: boolean; | ||
@@ -21,3 +23,3 @@ allowLeadingUnderscore?: boolean; | ||
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>; | ||
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | { | ||
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | { | ||
excepts?: readonly string[]; | ||
@@ -27,3 +29,3 @@ extensions?: readonly string[]; | ||
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>; | ||
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | { | ||
readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$2, readonly [("always" | "as-needed") | { | ||
allow?: "always" | "as-needed"; | ||
@@ -33,3 +35,3 @@ extensions?: readonly string[]; | ||
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>; | ||
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"useState", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>; | ||
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"unexpected", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>; | ||
}; | ||
@@ -36,0 +38,0 @@ }; |
@@ -39,3 +39,3 @@ 'use strict'; | ||
var name = "eslint-plugin-react-naming-convention"; | ||
var version = "1.26.3-beta.6"; | ||
var version = "1.26.3-beta.7"; | ||
var createRule = shared.createRuleForPlugin("naming-convention"); | ||
@@ -94,10 +94,16 @@ | ||
} | ||
function validate(name2, options) { | ||
if (name2 == null) return false; | ||
if (options.excepts.some((regex) => regex.test(name2))) { | ||
return true; | ||
function getViolationMessage(name2, options) { | ||
if (name2 == null) return eff._; | ||
const { | ||
allowAllCaps = false, | ||
allowLeadingUnderscore = false, | ||
allowNamespace = false, | ||
excepts, | ||
rule | ||
} = options; | ||
if (excepts.some((regex) => regex.test(name2))) { | ||
return eff._; | ||
} | ||
let normalized = name2.normalize("NFKD").replace(/[\u0300-\u036F]/g, ""); | ||
normalized = normalized.split(".").at(-1) ?? normalized; | ||
const { allowLeadingUnderscore = false, allowNamespace = false } = options; | ||
if (allowNamespace) { | ||
@@ -109,8 +115,8 @@ normalized = normalized.replace(":", ""); | ||
} | ||
return tsPattern.match(options.rule).with("CONSTANT_CASE", () => shared.RE_CONSTANT_CASE.test(normalized)).with("PascalCase", () => { | ||
return tsPattern.match(rule).with("CONSTANT_CASE", () => shared.RE_CONSTANT_CASE.test(normalized) ? eff._ : "useConstantCase").with("PascalCase", () => { | ||
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) { | ||
return options.allowAllCaps ?? false; | ||
return allowAllCaps ? eff._ : "usePascalCase"; | ||
} | ||
return shared.RE_PASCAL_CASE.test(normalized); | ||
}).otherwise(eff.constFalse); | ||
return shared.RE_PASCAL_CASE.test(normalized) ? eff._ : "usePascalCase"; | ||
}).otherwise(() => eff._); | ||
} | ||
@@ -125,3 +131,4 @@ var component_name_default = createRule({ | ||
messages: { | ||
componentName: "A component name must be in {{case}}." | ||
useConstantCase: "Component name '{{name}}' must be in CONSTANT_CASE.", | ||
usePascalCase: "Component name '{{name}}' must be in PascalCase." | ||
}, | ||
@@ -143,10 +150,9 @@ schema | ||
} | ||
if (validate(name2, options)) { | ||
return; | ||
} | ||
const violation = getViolationMessage(name2, options); | ||
if (violation == null) return; | ||
context.report({ | ||
messageId: "componentName", | ||
messageId: violation, | ||
node, | ||
data: { | ||
case: options.rule | ||
name: name2 | ||
} | ||
@@ -161,10 +167,10 @@ }); | ||
if (id?.name == null) continue; | ||
if (validate(id.name, options)) { | ||
continue; | ||
} | ||
const name2 = id.name; | ||
const violation = getViolationMessage(name2, options); | ||
if (violation == null) continue; | ||
context.report({ | ||
messageId: "componentName", | ||
messageId: violation, | ||
node: id, | ||
data: { | ||
case: options.rule | ||
name: name2 | ||
} | ||
@@ -176,11 +182,12 @@ }); | ||
if (id?.name == null) continue; | ||
if (!validate(id.name, options)) { | ||
context.report({ | ||
messageId: "componentName", | ||
node: id, | ||
data: { | ||
case: options.rule | ||
} | ||
}); | ||
} | ||
const name2 = id.name; | ||
const violation = getViolationMessage(name2, options); | ||
if (violation == null) continue; | ||
context.report({ | ||
messageId: violation, | ||
node: id, | ||
data: { | ||
case: options.rule | ||
} | ||
}); | ||
} | ||
@@ -248,3 +255,3 @@ } | ||
const excepts = typeof options === "string" ? [] : options.excepts ?? []; | ||
function validate2(name2, casing = rule, ignores = excepts) { | ||
function validate(name2, casing = rule, ignores = excepts) { | ||
const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2)); | ||
@@ -264,3 +271,3 @@ if (shouldIgnore) return true; | ||
} | ||
if (validate2(basename)) { | ||
if (validate(basename)) { | ||
return; | ||
@@ -326,4 +333,4 @@ } | ||
messages: { | ||
filenameExtensionInvalid: "The JSX file extension is required.", | ||
filenameExtensionUnexpected: "Use JSX file extension as needed." | ||
useJsxFileExtension: "Use {{extensions}} file extension for JSX files.", | ||
useJsxFileExtensionAsNeeded: "Do not use {{extensions}} file extension for files without JSX." | ||
}, | ||
@@ -337,2 +344,3 @@ schema: schema3 | ||
const extensions = eff.isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions; | ||
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", "); | ||
const filename = context.filename; | ||
@@ -352,4 +360,7 @@ let hasJSXNode = false; | ||
context.report({ | ||
messageId: "filenameExtensionInvalid", | ||
node | ||
messageId: "useJsxFileExtension", | ||
node, | ||
data: { | ||
extensions: extensionsString | ||
} | ||
}); | ||
@@ -365,4 +376,7 @@ return; | ||
context.report({ | ||
messageId: "filenameExtensionUnexpected", | ||
node | ||
messageId: "useJsxFileExtensionAsNeeded", | ||
node, | ||
data: { | ||
extensions: extensionsString | ||
} | ||
}); | ||
@@ -387,7 +401,7 @@ } | ||
docs: { | ||
description: "enforce destructuring and symmetric naming of 'useState' hook value and setter variables", | ||
description: "enforce destructuring and symmetric naming of 'useState' hook value and setter", | ||
[Symbol.for("rule_features")]: RULE_FEATURES | ||
}, | ||
messages: { | ||
useState: "An useState call is not destructured into value + setter pair." | ||
unexpected: "An useState call is not destructured into value + setter pair." | ||
}, | ||
@@ -428,3 +442,3 @@ schema: [] | ||
case types.AST_NODE_TYPES.Identifier: { | ||
context.report({ messageId: "useState", node: id }); | ||
context.report({ messageId: "unexpected", node: id }); | ||
break; | ||
@@ -436,3 +450,3 @@ } | ||
if (!isSetterNameLoose(setState.name)) { | ||
context.report({ messageId: "useState", node: id }); | ||
context.report({ messageId: "unexpected", node: id }); | ||
} | ||
@@ -449,3 +463,3 @@ break; | ||
} | ||
context.report({ messageId: "useState", node: id }); | ||
context.report({ messageId: "unexpected", node: id }); | ||
} | ||
@@ -452,0 +466,0 @@ } |
{ | ||
"name": "eslint-plugin-react-naming-convention", | ||
"version": "1.26.3-beta.6", | ||
"version": "1.26.3-beta.7", | ||
"description": "ESLint React's ESLint plugin for naming convention related rules.", | ||
@@ -52,7 +52,7 @@ "keywords": [ | ||
"ts-pattern": "^5.6.2", | ||
"@eslint-react/ast": "1.26.3-beta.6", | ||
"@eslint-react/core": "1.26.3-beta.6", | ||
"@eslint-react/jsx": "1.26.3-beta.6", | ||
"@eslint-react/shared": "1.26.3-beta.6", | ||
"@eslint-react/eff": "1.26.3-beta.6" | ||
"@eslint-react/ast": "1.26.3-beta.7", | ||
"@eslint-react/core": "1.26.3-beta.7", | ||
"@eslint-react/eff": "1.26.3-beta.7", | ||
"@eslint-react/jsx": "1.26.3-beta.7", | ||
"@eslint-react/shared": "1.26.3-beta.7" | ||
}, | ||
@@ -59,0 +59,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
36174
938
+ Added@eslint-react/ast@1.26.3-beta.7(transitive)
+ Added@eslint-react/core@1.26.3-beta.7(transitive)
+ Added@eslint-react/eff@1.26.3-beta.7(transitive)
+ Added@eslint-react/jsx@1.26.3-beta.7(transitive)
+ Added@eslint-react/shared@1.26.3-beta.7(transitive)
+ Added@eslint-react/var@1.26.3-beta.7(transitive)
- Removed@eslint-react/ast@1.26.3-beta.6(transitive)
- Removed@eslint-react/core@1.26.3-beta.6(transitive)
- Removed@eslint-react/eff@1.26.3-beta.6(transitive)
- Removed@eslint-react/jsx@1.26.3-beta.6(transitive)
- Removed@eslint-react/shared@1.26.3-beta.6(transitive)
- Removed@eslint-react/var@1.26.3-beta.6(transitive)