Skip to content
Permalink
Browse files
Breaking: upgrade espree and support new class features (refs #14343) (
…#14591)

* update package.json (temporary)

* update ast-utils

- `getFunctionNameWithKind(node)` ... supports class fields and private
  identifier. And now it uses property names rather than function names
  if named function expressions are methods because the property name
  is exposed.
- `getFunctionHeadLoc(node)` ... supports class fields. And now returns
  the range of property names instead of the arrow locations if arrow
  functions are at method places.
- `isSameReference(l,r)` ... supports `PrivateIdentifier`.

* update camelcase

This commit includes a large refactoring.
Previously, the `Identifier` node listener handled all cases by
checking parent node types. But because the `Identifier` node has so
broad meanings, it's confusing about what kind of nodes it's handling.

Now it uses variables and references of `eslint-scope`. And it checks
properties, re-exported identifiers, and labels by detailed esqueries.
The property check newly supports class fields and private identifiers.

This fixes #13021 as well.

* update accessor-pairs (test-only)

* update class-methods-use-this

* update computed-property-spacing

* update dot-location (test-only)

* update dot-notation (test-only)

* update func-names

Function expressions at field initializers have inferred names.
Therefore the `as-needed` option should not report anonymous functions
at field initializers.

* update getter-return (test-only)

* update grouped-accessor-pairs (test-only)

* update indent

* update keyword-spacing

* update lines-between-class-members (test-only)

* update no-dupe-class-members

* update no-extra-semi

* update no-invalid-this

* update no-multi-assign

* update no-proto (test-only)

* update no-prototype-builtins (test-only)

* update no-restricted-properties (test-only)

* update no-self-assign

* update no-self-compare (test-only)

* update no-setter-return

* update no-shadow (test-only)

* update no-this-before-super (test-only)

* update no-throw-literal (test-only)

* update no-undef-init

* update no-underscore-dangle

* update no-unexpected-multiline (test-only)

* update no-unreachable

* update no-useless-call (test-only)

* update no-useless-computed-key

* update no-eval

* update operator-assignment (test-only)

* update operator-linebreak

* update padded-blocks (test-only)

* update prefer-exponentiation-operator

* update prefer-numeric-literals (test-only)

* update prefer-object-spread (test-only)

* update prefer-promise-reject-errors (test-only)

* update prefer-regex-literals (test-only)

* update prefer-spread (test-only)

* update quotes

* update radix (test-only)

* update require-atomic-updates (test-only)

* update require-unicode-regexp (test-only)

* update semi-spacing

* update semi-style

* update semi

* update space-infix-ops

* update strict (test-only)

* add more tests to no-unexpected-multiline

* fix some tests for 7345747

* fix no-invalid-this

* fix no-eval

* Update eslint-scope

* Upgrade Espree

* Fix eslint-scope references to parser test

* Fix: id-denylist

* Update comments

* Fix: id-match

* Fix: id-length

* Update: id-denylist for class fields

* Update: id-length

* Update: id-denylist code and docs

* Docs: id-denylist

* Update: id-match

Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
  • Loading branch information
mysticatea and nzakas committed Aug 5, 2021
1 parent 8cce06c commit b953a4ee12f120658a9ec27d1f8ca88dd3dfb599
Show file tree
Hide file tree
Showing 88 changed files with 2,563 additions and 352 deletions.
@@ -13,6 +13,8 @@ This rule will catch disallowed identifiers that are:
- variable declarations
- function declarations
- object properties assigned to during object creation
- class fields
- class methods

It will not catch disallowed identifiers that are:

@@ -49,6 +51,22 @@ element.callback = function() {
var itemSet = {
data: [...]
};
class Foo {
data = [];
}
class Foo {
#data = [];
}
class Foo {
callback( {);
}
class Foo {
#callback( {);
}
```
Examples of **correct** code for this rule with sample `"data", "callback"` restricted identifiers:
@@ -75,6 +93,22 @@ callback(); // all function calls are ignored
foo.callback(); // all function calls are ignored
foo.data; // all property names that are not assignments are ignored
class Foo {
items = [];
}
class Foo {
#items = [];
}
class Foo {
method( {);
}
class Foo {
#method( {);
}
```
## When Not To Use It
@@ -30,6 +30,9 @@ var myObj = { a: 1 };
(a) => { a * a };
class x { }
class Foo { x() {} }
class Foo { #x() {} }
class Foo { x = 1 }
class Foo { #x = 1 }
function foo(...x) { }
function foo([x]) { }
var [x] = arr;
@@ -61,6 +64,9 @@ var myObj = { apple: 1 };
function foo(num = 0) { }
class MyClass { }
class Foo { method() {} }
class Foo { #method() {} }
class Foo { field = 1 }
class Foo { #field = 1 }
function foo(...args) { }
function foo([longName]) { }
var { prop } = {};
@@ -35,9 +35,20 @@ var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
// ...
}
obj.do_something = function() {
// ...
};
class My_Class {}
class myClass {
do_something() {}
}
class myClass {
#do_something() {}
}
```

Examples of **correct** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$"` option:
@@ -52,13 +63,26 @@ do_something();
var obj = {
my_pref: 1
};
class myClass {}
class myClass {
doSomething() {}
}
class myClass {
#doSomething() {}
}
```

This rule has an object option:

* `"properties": true` requires object properties to match the specified regular expression
* `"properties": false` (default) does not check object properties
* `"properties": true` requires object literal properties and member expression assignment properties to match the specified regular expression
* `"classFields": false` (default) does not class field names
* `"classFields": true` requires class field names to match the specified regular expression
* `"onlyDeclarations": false` (default) requires all variable names to match the specified regular expression
* `"onlyDeclarations": true` requires only `var`, `function`, and `class` declarations to match the specified regular expression
* `"onlyDeclarations": false` requires all variable names to match the specified regular expression
* `"ignoreDestructuring": false` (default) enforces `id-match` for destructured identifiers
* `"ignoreDestructuring": true` does not check destructured identifiers

@@ -74,6 +98,22 @@ var obj = {
};
```

### classFields

Examples of **incorrect** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", { "classFields": true }` options:

```js
/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/
class myClass {
my_pref = 1;
}
class myClass {
#my_pref = 1;
}
```

### onlyDeclarations

Examples of **correct** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }` options:

0 comments on commit b953a4e

Please sign in to comment.