Skip to content

Commit

Permalink
Docs: Add enforceForClassMembers option to no-useless-computed-key
Browse files Browse the repository at this point in the history
  • Loading branch information
ark120202 committed Oct 8, 2019
1 parent e740e94 commit 90158b0
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions docs/rules/no-useless-computed-key.md
@@ -1,4 +1,4 @@
# Disallow unnecessary computed property keys on objects (no-useless-computed-key)
# Disallow unnecessary computed property keys (no-useless-computed-key)

It's unnecessary to use computed properties with literals such as:

Expand All @@ -16,8 +16,6 @@ var foo = {"a": "b"};

This rule disallows unnecessary usage of computed property keys.

## Examples

Examples of **incorrect** code for this rule:

```js
Expand All @@ -43,6 +41,35 @@ var c = { a: 0 };
var c = { '0+1,234': 0 };
```

## Options

This rule has an object option:

* `enforceForClassMembers` set to `true` additionally applies this rule to class members (Default `false`).

### enforceForClassMembers

By default, this rule does not check class declarations and class expressions,
as the default value for `enforceForClassMembers` is `false`.

When `enforceForClassMembers` is set to `true`, the rule will also disallow unnecessary computed
keys inside of class methods, getters and setters.

Examples of **incorrect** code for `{ "enforceForClassMembers": true }`:

```js
/*eslint no-useless-computed-key: ["error", { "enforceForClassMembers": true }]*/

class Foo {
[0]() {}
['a']() {}
get ['b']() {}
set ['c']() {}

static ['a']() {}
}
```

## When Not To Use It

If you don't want to be notified about unnecessary computed property keys, you can safely disable this rule.

0 comments on commit 90158b0

Please sign in to comment.