🚫 This rule is disabled in the ✅ recommended
config.
new Foo
and newFoo
look very similar. Use alternatives that do not look like keyword usage.
const newFoo = 'foo';
const classFoo = 'foo';
const foo = 'foo';
const _newFoo = 'foo';
const new_foo = 'foo';
const fooNew = 'foo';
If you want a custom list of disallowed prefixes you can set them with disallowedPrefixes
:
// eslint unicorn/no-keyword-prefix: ["error", {"disallowedPrefixes": ["new", "for"]}]
const classFoo = "a"; // pass
// eslint unicorn/no-keyword-prefix: ["error", {"disallowedPrefixes": ["new", "for"]}]
const forFoo = "a"; // fail
The default is ["new", "class"]
.
If you want to disable this rule for properties, set checkProperties
to false
:
// eslint unicorn/no-keyword-prefix: ["error", {"checkProperties": true}]
foo.newFoo = 2; // fail
// eslint unicorn/no-keyword-prefix: ["error", {"checkProperties": false}]
var foo = {newFoo: 1}; // pass
// eslint unicorn/no-keyword-prefix: ["error", {"checkProperties": false}]
foo.newFoo = 2; // pass
The default behavior is to check for camel case usage. If you want to disallow the prefix entirely, set onlyCamelCase
to false
:
// eslint unicorn/no-keyword-prefix: ["error", {"onlyCamelCase": true}]
const new_foo = "foo"; // pass
// eslint unicorn/no-keyword-prefix: ["error", {"onlyCamelCase": false}]
const new_foo = "foo"; // fail