π Disallow identifiers starting with new or class.
π« This rule is disabled in the following configs: β
recommended, βοΈ unopinionated.
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";
// β
const forFoo = "a";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;/* eslint unicorn/no-keyword-prefix: ["error", {"checkProperties": false}] */
// β
var foo = {newFoo: 1}; // pass
// β
foo.newFoo = 2; // passThe 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";/* eslint unicorn/no-keyword-prefix: ["error", {"onlyCamelCase": false}] */
// β
const new_foo = "foo";