Skip to content
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

[naming-convention] camelCase format doesn't work if prefix is configured #2187

Closed
villelahdenvuo opened this issue Jun 8, 2020 · 2 comments
Labels
fix: user error issue was fixed by correcting the configuration / correcting the code package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@villelahdenvuo
Copy link
Contributor

Repro

{
  "rules": {
	"@typescript-eslint/naming-convention": [
		"error",
		{
			"selector": "variable",
			"types": ["boolean"],
			"format": ["camelCase"],
			"prefix": ["is", "should", "has", "can", "did", "will"]
		}
	]
  }
}
const isStore = isPlainObject(store) && isPlainObject(store.storefront) && isPlainObject(store.locale);

Expected Result

No error.

Actual Result

Variable name isStore must match one of the following formats: camelCase eslint@typescript-eslint/naming-convention

Additional Info

image

If I remove the prefix option the format rule works.

Versions

package version
@typescript-eslint/eslint-plugin 3.1.0
@typescript-eslint/parser 3.1.0
TypeScript 3.8.3
ESLint 7.2.0
node 13.13.0
npm 6.14.5
@villelahdenvuo villelahdenvuo added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jun 8, 2020
@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended and removed triage Waiting for team members to take a look labels Jun 8, 2020
@bradzacher
Copy link
Member

This is intentional. See: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md#format-options

If you define a prefix, it is removed from the name before checking the format. This is done because otherwise you cannot do something like StrictPascalCase with a prefix (i.e. TMyType would never be able to match StrictPascalCase, due to the two capitals).

This is also shown in the example for configuring boolean names are prefixed with a verb:
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md#enforce-that-boolean-variables-are-prefixed-with-an-allowed-verb

@villelahdenvuo
Copy link
Contributor Author

@bradzacher Thanks, that definitely makes sense. To avoid this issue in the future I made a PR to note this more visibly in the docs. ✨

@github-actions GitHub Actions bot locked as resolved and limited conversation to collaborators Jul 10, 2020
@bradzacher bradzacher added fix: user error issue was fixed by correcting the configuration / correcting the code and removed working as intended Issues that are closed as they are working as intended labels Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fix: user error issue was fixed by correcting the configuration / correcting the code package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants