Skip to content

Latest commit

Β 

History

History
84 lines (58 loc) Β· 1.72 KB

File metadata and controls

84 lines (58 loc) Β· 1.72 KB

no-keyword-prefix

πŸ“ 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.

Examples

// ❌
const newFoo = 'foo';

// ❌
const classFoo = 'foo';

// βœ…
const foo = 'foo';

// βœ…
const _newFoo = 'foo';

// βœ…
const new_foo = 'foo';

// βœ…
const fooNew = 'foo';

Options

disallowedPrefixes

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"].

checkProperties

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; // pass

onlyCamelCase

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";
/* eslint unicorn/no-keyword-prefix: ["error", {"onlyCamelCase": false}] */
// ❌
const new_foo = "foo";