-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[naming-convention] camelCase allows kebab-case in property #4534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I was going to say that this was intentional, but then I noticed the examples I'd placed in the readme work via sheer dumb luck! The current checkers for pre-defined formats by design assume the name is a "valid identifier" (i.e. no spaces or dashes). typescript-eslint/packages/eslint-plugin/src/rules/naming-convention-utils/format.ts Lines 17 to 41 in 2794631
We should probably make each one also enforce that the string is also a valid identifier using this util: Perhaps we can just pass the pre-evaluated |
@bradzacher I was looking at the code and found the fix looks simple which makes me think that I didn't fully understand your approach. typescript-eslint/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts Lines 385 to 390 in 5b7d8df
like this. for (const format of formats) {
const checker = PredefinedFormatToCheckFunction[format];
if (!util.requiresQuoting(name) && checker(name)) {
return true;
}
} I can pass other tests and get this issue's expected result I could have guarded using or typescript-eslint/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts Lines 374 to 383 in 5b7d8df
typescript-eslint/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts Line 130 in 5b7d8df
somewhere at the front that it doesn't need to be iterated at all ? do you think this is the viable fix? if it is, then I'd make a PR for it |
Nope - you're right! It should be super simple to do! Given that where it counts we already add a modifier to the name which specifies whether or not it requires quotes: typescript-eslint/packages/eslint-plugin/src/rules/naming-convention.ts Lines 114 to 116 in 877cc48
typescript-eslint/packages/eslint-plugin/src/rules/naming-convention.ts Lines 423 to 425 in 877cc48
We know all of our pre-defined formats are valid identifier string (so don't require quoting). Which means all we should need to do is pass the It should be really simple! |
Hi there,
Repro
Expected Result
It is supposed to be error:
1: 3 error Type property name 'foo-bar' must match one of the following formats: camelCase @typescript-eslint/naming-convention
Actual Result
No error.
Additional Info
Versions
@typescript-eslint/eslint-plugin
5.10.0
@typescript-eslint/parser
5.10.0
TypeScript
4.5.4
ESLint
8.7.0
node
16.13.2
The text was updated successfully, but these errors were encountered: