eslint 7.17.0 → 7.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/README.md +29 -8
- package/conf/default-cli-options.js +1 -0
- package/lib/cli-engine/cli-engine.js +2 -2
- package/lib/cli-engine/file-enumerator.js +7 -2
- package/lib/cli-engine/lint-result-cache.js +57 -7
- package/lib/cli.js +2 -0
- package/lib/eslint/eslint.js +9 -0
- package/lib/init/autoconfig.js +1 -1
- package/lib/init/config-initializer.js +2 -1
- package/lib/linter/linter.js +3 -1
- package/lib/linter/node-event-generator.js +4 -2
- package/lib/options.js +8 -0
- package/lib/rules/complexity.js +7 -1
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +1 -0
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/no-extra-parens.js +43 -23
- package/lib/rules/no-invalid-regexp.js +35 -8
- package/lib/rules/no-loss-of-precision.js +4 -4
- package/lib/rules/no-shadow.js +35 -3
- package/lib/rules/no-unused-expressions.js +12 -1
- package/lib/rules/no-useless-rename.js +22 -22
- package/lib/rules/prefer-const.js +17 -4
- package/lib/rules/prefer-destructuring.js +1 -1
- package/lib/rules/space-infix-ops.js +3 -1
- package/lib/rules/use-isnan.js +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,73 @@
|
|
1
|
+
v7.21.0 - February 27, 2021
|
2
|
+
|
3
|
+
* [`3cd5440`](https://github.com/eslint/eslint/commit/3cd5440b94d5fa4f11a09f50b685f6150f0c2d41) Upgrade: @eslint/eslintrc to 0.4.0 (#14147) (Brandon Mills)
|
4
|
+
* [`c0b8c71`](https://github.com/eslint/eslint/commit/c0b8c71df4d0b3f54b20587432d9133741985d5c) Upgrade: Puppeteer to 7.1.0 (#14122) (Tim van der Lippe)
|
5
|
+
* [`08ae31e`](https://github.com/eslint/eslint/commit/08ae31e539e381cd0eabf6393fa5c20f1d59125f) New: Implement cacheStrategy (refs eslint/rfcs#63) (#14119) (Manu Chambon)
|
6
|
+
* [`5e51fd2`](https://github.com/eslint/eslint/commit/5e51fd28dc773c11c924450d24088f97f2824f00) Update: do not ignore symbolic links (fixes #13551, fixes #13615) (#14126) (Pig Fang)
|
7
|
+
* [`87c43a5`](https://github.com/eslint/eslint/commit/87c43a5d7ea2018cffd6d9b5c431ecb60caaf0d6) Chore: improve a few comments and fix typos (#14125) (Tobias Nießen)
|
8
|
+
* [`e19c51e`](https://github.com/eslint/eslint/commit/e19c51ea2ef2cf666d94218c66f6b223bb2e9dae) Sponsors: Sync README with website (ESLint Jenkins)
|
9
|
+
* [`b8aea99`](https://github.com/eslint/eslint/commit/b8aea9988b6451b6a05af4f3ede8d6ed5c1d9926) Fix: pluralize 'line' to 'lines' in max-lines-per-function description (#14115) (Trevin Hofmann)
|
10
|
+
* [`f5b53e2`](https://github.com/eslint/eslint/commit/f5b53e285ab5286ea382d73b379b820f649c20d0) Sponsors: Sync README with website (ESLint Jenkins)
|
11
|
+
* [`eee1213`](https://github.com/eslint/eslint/commit/eee12134ce0956e9f825c1630776b1731551a948) Sponsors: Sync README with website (ESLint Jenkins)
|
12
|
+
* [`5c4d7ea`](https://github.com/eslint/eslint/commit/5c4d7ea8d2e8d137c42b918dc99a84b4a5fed9b3) Sponsors: Sync README with website (ESLint Jenkins)
|
13
|
+
|
14
|
+
v7.20.0 - February 12, 2021
|
15
|
+
|
16
|
+
* [`f4ac3b0`](https://github.com/eslint/eslint/commit/f4ac3b0e7072fbd3c14e9c64ff0c2c255a4eb730) Docs: fix sibling selector descriptions (#14099) (Milos Djermanovic)
|
17
|
+
* [`9d6063a`](https://github.com/eslint/eslint/commit/9d6063add931f0803cae1676d5df307baf114360) Fix: Crash with esquery when using JSX (fixes #13639) (#14072) (Yosuke Ota)
|
18
|
+
* [`a0871f1`](https://github.com/eslint/eslint/commit/a0871f1840060bd23cfe0952a096b107142db2f0) Docs: Triage process (#14014) (Nicholas C. Zakas)
|
19
|
+
* [`ad90761`](https://github.com/eslint/eslint/commit/ad9076183bc2c2029525edfc4596e403999348d1) Update: add enforceForJSX option to no-unused-expressions rule (#14012) (Duncan Beevers)
|
20
|
+
* [`d6c84af`](https://github.com/eslint/eslint/commit/d6c84af67318537177ffac0120a81af08e3e9df4) Fix: `--init` autoconfig shouldn't add deprecated rules (fixes #14017) (#14060) (Milos Djermanovic)
|
21
|
+
* [`9b277a1`](https://github.com/eslint/eslint/commit/9b277a16a7261e51b7ba36d6de7f996e9203a6a4) Fix: Support ENOTDIR error code in the folder existence checking utility (#13973) (Constantine Genchevsky)
|
22
|
+
* [`7aeb127`](https://github.com/eslint/eslint/commit/7aeb12798f2b9da706f3593f26a02e717929c9af) Upgrade: pin @babel/code-frame@7.12.11 (#14067) (Milos Djermanovic)
|
23
|
+
* [`b4e2af5`](https://github.com/eslint/eslint/commit/b4e2af5db1c29343ffec2cd104b04bf39b77ee56) Docs: Add more fields to bug report template (#14039) (Nicholas C. Zakas)
|
24
|
+
* [`96f1d49`](https://github.com/eslint/eslint/commit/96f1d49a4647e59f2fb918be096654e290513adc) Sponsors: Sync README with website (ESLint Jenkins)
|
25
|
+
* [`cb27b0a`](https://github.com/eslint/eslint/commit/cb27b0abeda6dfee55dd43b9cbe12afad321f55d) Build: package.json update for eslint-config-eslint release (ESLint Jenkins)
|
26
|
+
* [`4cab165`](https://github.com/eslint/eslint/commit/4cab165bf4e6e5e9f42a59a37a8ff2548c0af87d) Sponsors: Sync README with website (ESLint Jenkins)
|
27
|
+
|
28
|
+
v7.19.0 - January 30, 2021
|
29
|
+
|
30
|
+
* [`ce7f061`](https://github.com/eslint/eslint/commit/ce7f06121d9eb9cc2b3da24b4456b4d382e1413b) Update: add shadowed variable loc to message in no-shadow (fixes #13646) (#13841) (t-mangoe)
|
31
|
+
* [`c60e23f`](https://github.com/eslint/eslint/commit/c60e23ff306a14ca6eabcadb275ed27995fcc6e4) Update: fix `let` logic in for-in and for-of loops in no-extra-parens (#14011) (Milos Djermanovic)
|
32
|
+
* [`d76e8f6`](https://github.com/eslint/eslint/commit/d76e8f69bd791357c67ada7b5c55608acf29b622) Fix: no-useless-rename invalid autofix with parenthesized identifiers (#14032) (Milos Djermanovic)
|
33
|
+
* [`5800d92`](https://github.com/eslint/eslint/commit/5800d921144ec330b6ee7cd03364434007331354) Docs: Clarify stylistic rule update policy (#14052) (Brandon Mills)
|
34
|
+
* [`0ccf6d2`](https://github.com/eslint/eslint/commit/0ccf6d200147437b338cadb34546451972befd75) Docs: remove configuring.md (#14036) (Milos Djermanovic)
|
35
|
+
* [`65bb0ab`](https://github.com/eslint/eslint/commit/65bb0abde56f72586036fff151aa2d13f1b7be6c) Chore: Clean up new issue workflow (#14040) (Nicholas C. Zakas)
|
36
|
+
* [`e1da90f`](https://github.com/eslint/eslint/commit/e1da90fc414a3c9c16f52db4a5bd81bd4f9532a4) Fix: nested indenting for offsetTernaryExpressions: true (fixes #13971) (#13972) (Chris Brody)
|
37
|
+
* [`1a078b9`](https://github.com/eslint/eslint/commit/1a078b9166f29cb3760435ddbc1a0da4a0974d4a) Update: check ternary `:` even if `?` was reported in space-infix-ops (#13963) (Milos Djermanovic)
|
38
|
+
* [`fb27422`](https://github.com/eslint/eslint/commit/fb274226242eaebc1480fc9c901202986afc3c8a) Fix: extend prefer-const fixer range to whole declaration (fixes #13899) (#14033) (Nitin Kumar)
|
39
|
+
* [`e0b05c7`](https://github.com/eslint/eslint/commit/e0b05c704f3ce6f549d14718236d22fe49fcb611) Docs: add a correct example to no-unsafe-optional-chaining (refs #14029) (#14050) (armin yahya)
|
40
|
+
* [`46e836d`](https://github.com/eslint/eslint/commit/46e836d46442d2ec756038a2e12ba19b74394dbd) Sponsors: Sync README with website (ESLint Jenkins)
|
41
|
+
* [`3fc4fa4`](https://github.com/eslint/eslint/commit/3fc4fa485ca9ccd5e16dbc7e53ba31452d22dc4a) Docs: update configuring links (#14038) (Milos Djermanovic)
|
42
|
+
* [`8561c21`](https://github.com/eslint/eslint/commit/8561c2116ef89e53ebffb750066f1b00a4acdb76) Docs: fix broken links in configuring/README.md (#14046) (Milos Djermanovic)
|
43
|
+
* [`1c309eb`](https://github.com/eslint/eslint/commit/1c309ebca4a81a0faf397103dbc621019dea8c9c) Update: fix no-invalid-regexp false negatives with no flags specified (#14018) (Milos Djermanovic)
|
44
|
+
* [`f6602d5`](https://github.com/eslint/eslint/commit/f6602d569427e9e2a4f3b5ca3fc3a8bffb28d15e) Docs: Reorganize Configuration Documentation (#13837) (klkhan)
|
45
|
+
* [`c753b44`](https://github.com/eslint/eslint/commit/c753b442ef67867a178ffc2ad29b4e0534f72469) Sponsors: Sync README with website (ESLint Jenkins)
|
46
|
+
* [`a4fdb70`](https://github.com/eslint/eslint/commit/a4fdb7001aa41b9ad8bb92cc8a47b9135c94afc7) Docs: Fixed Typo (#14007) (Yash Singh)
|
47
|
+
* [`f7ca481`](https://github.com/eslint/eslint/commit/f7ca48165d025e01c38698352cff24d1de87cc8b) Docs: Explain why we disable lock files (refs eslint/tsc-meetings#234) (#14006) (Brandon Mills)
|
48
|
+
|
49
|
+
v7.18.0 - January 15, 2021
|
50
|
+
|
51
|
+
* [`e3264b2`](https://github.com/eslint/eslint/commit/e3264b26a625d926a1ea96df1c4b643af5c3797c) Upgrade: @eslint/eslintrc to improve error message for invalid extends (#14009) (Milos Djermanovic)
|
52
|
+
* [`f17c3c3`](https://github.com/eslint/eslint/commit/f17c3c371789ffa84f0cda57101e8193899adbe6) Update: check logical assignment operators in the complexity rule (#13979) (Milos Djermanovic)
|
53
|
+
* [`672deb0`](https://github.com/eslint/eslint/commit/672deb057a14a7acad8c669189870009f1edb8a6) Docs: fix no-invalid-regexp docs regarding ecmaVersion (#13991) (Milos Djermanovic)
|
54
|
+
* [`179a910`](https://github.com/eslint/eslint/commit/179a910b32e853bc12a9dd71f7c10e762cbeac44) Fix: --init crash on question to upgrade/downgrade ESLint (fixes #13978) (#13995) (Milos Djermanovic)
|
55
|
+
* [`292b1c0`](https://github.com/eslint/eslint/commit/292b1c0017bc442d399f67e01d699c59e6b71453) Fix: no-extra-parens false positive with `let` identifier in for-loop (#13981) (Milos Djermanovic)
|
56
|
+
* [`de61f94`](https://github.com/eslint/eslint/commit/de61f9444cf58a4d70e126ab3d10bf20851de7c9) Sponsors: Sync README with website (ESLint Jenkins)
|
57
|
+
* [`9250d16`](https://github.com/eslint/eslint/commit/9250d167ceb5684669eabe93dae326e33f0684f2) Upgrade: Bump lodash to fix security issue (#13993) (Frederik Prijck)
|
58
|
+
* [`75fea9b`](https://github.com/eslint/eslint/commit/75fea9bcdd3dde5a07e0089d9011a4df518cdbe3) Sponsors: Sync README with website (ESLint Jenkins)
|
59
|
+
* [`f2687e7`](https://github.com/eslint/eslint/commit/f2687e71f9e2a2773f821c4dc1a02abe95b97df4) Docs: update space-in-parens related rules (#13985) (Chris Brody)
|
60
|
+
* [`4a38bbe`](https://github.com/eslint/eslint/commit/4a38bbe81b4b29ca1a4e62d0a0cc8d525455b063) Docs: space-in-parens examples with no arguments etc. (#13987) (Chris Brody)
|
61
|
+
* [`3e49169`](https://github.com/eslint/eslint/commit/3e491698687aa08b3b798cee0931f0872ca1bc55) Sponsors: Sync README with website (ESLint Jenkins)
|
62
|
+
* [`c5bf1f2`](https://github.com/eslint/eslint/commit/c5bf1f2150a9fbbb9e74c04808dc3bfeda1ed321) Sponsors: Sync README with website (ESLint Jenkins)
|
63
|
+
* [`98a729c`](https://github.com/eslint/eslint/commit/98a729c9def54cee9e5478e75e8bd6f28167d5e8) Sponsors: Sync README with website (ESLint Jenkins)
|
64
|
+
* [`e83a696`](https://github.com/eslint/eslint/commit/e83a6962b51b05c2ddfe42b0748b405d515eeb9d) Sponsors: Sync README with website (ESLint Jenkins)
|
65
|
+
* [`78cb483`](https://github.com/eslint/eslint/commit/78cb48345c725e9f90fd0e631c476802244df4a4) Chore: test `foo( )` with space-in-parens option "always" (#13986) (Chris Brody)
|
66
|
+
* [`f6948f6`](https://github.com/eslint/eslint/commit/f6948f6bdc763dca0787bb2786bc9f6f9ed88f43) Docs: Update semantic versioning policy (#13970) (Nicholas C. Zakas)
|
67
|
+
* [`0688212`](https://github.com/eslint/eslint/commit/068821248e2d2eff11152f270102d537d8fa8126) Sponsors: Sync README with website (ESLint Jenkins)
|
68
|
+
* [`aeba5e5`](https://github.com/eslint/eslint/commit/aeba5e5e6062095a06d9b867d7e7ee75422f25b9) Chore: fix typo (#13975) (Nitin Kumar)
|
69
|
+
* [`4ee1134`](https://github.com/eslint/eslint/commit/4ee113414bdcbea240a5d9db27da6a10df472005) Sponsors: Sync README with website (ESLint Jenkins)
|
70
|
+
|
1
71
|
v7.17.0 - January 1, 2021
|
2
72
|
|
3
73
|
* [`e128e77`](https://github.com/eslint/eslint/commit/e128e775e9fa116a0ad68a071f1f0997589f8cd4) Update: check logical assignment in no-constant-condition (#13946) (Milos Djermanovic)
|
package/README.md
CHANGED
@@ -35,10 +35,11 @@ ESLint is a tool for identifying and reporting on patterns found in ECMAScript/J
|
|
35
35
|
6. [Releases](#releases)
|
36
36
|
7. [Security Policy](#security-policy)
|
37
37
|
8. [Semantic Versioning Policy](#semantic-versioning-policy)
|
38
|
-
9. [
|
39
|
-
10. [
|
40
|
-
11. [
|
41
|
-
12. [
|
38
|
+
9. [Stylistic Rule Updates](#stylistic-rule-updates)
|
39
|
+
10. [License](#license)
|
40
|
+
11. [Team](#team)
|
41
|
+
12. [Sponsors](#sponsors)
|
42
|
+
13. [Technology Sponsors](#technology-sponsors)
|
42
43
|
|
43
44
|
## <a name="installation-and-usage"></a>Installation and Usage
|
44
45
|
|
@@ -136,6 +137,16 @@ Once a language feature has been adopted into the ECMAScript standard (stage 4 a
|
|
136
137
|
|
137
138
|
Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://eslint.org/chat).
|
138
139
|
|
140
|
+
### Why doesn't ESLint lock dependency versions?
|
141
|
+
|
142
|
+
Lock files like `package-lock.json` are helpful for deployed applications. They ensure that dependencies are consistent between environments and across deployments.
|
143
|
+
|
144
|
+
Packages like `eslint` that get published to the npm registry do not include lock files. `npm install eslint` as a user will respect version constraints in ESLint's `package.json`. ESLint and its dependencies will be included in the user's lock file if one exists, but ESLint's own lock file would not be used.
|
145
|
+
|
146
|
+
We intentionally don't lock dependency versions so that we have the latest compatible dependency versions in development and CI that our users get when installing ESLint in a project.
|
147
|
+
|
148
|
+
The Twilio blog has a [deeper dive](https://www.twilio.com/blog/lockfiles-nodejs) to learn more.
|
149
|
+
|
139
150
|
## <a name="releases"></a>Releases
|
140
151
|
|
141
152
|
We have scheduled releases every two weeks on Friday or Saturday. You can follow a [release issue](https://github.com/eslint/eslint/issues?q=is%3Aopen+is%3Aissue+label%3Arelease) for updates about the scheduling of any particular release.
|
@@ -158,6 +169,7 @@ ESLint follows [semantic versioning](https://semver.org). However, due to the na
|
|
158
169
|
* A bug fix in a rule that results in ESLint reporting more linting errors.
|
159
170
|
* A new rule is created.
|
160
171
|
* A new option to an existing rule that does not result in ESLint reporting more linting errors by default.
|
172
|
+
* A new addition to an existing rule to support a newly-added language feature (within the last 12 months) that will result in ESLint reporting more linting errors by default.
|
161
173
|
* An existing rule is deprecated.
|
162
174
|
* A new CLI capability is created.
|
163
175
|
* New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
|
@@ -176,6 +188,15 @@ ESLint follows [semantic versioning](https://semver.org). However, due to the na
|
|
176
188
|
|
177
189
|
According to our policy, any minor update may report more linting errors than the previous release (ex: from a bug fix). As such, we recommend using the tilde (`~`) in `package.json` e.g. `"eslint": "~3.1.0"` to guarantee the results of your builds.
|
178
190
|
|
191
|
+
## <a name="stylistic-rule-updates"></a>Stylistic Rule Updates
|
192
|
+
|
193
|
+
Stylistic rules are frozen according to [our policy](https://eslint.org/blog/2020/05/changes-to-rules-policies) on how we evaluate new rules and rule changes.
|
194
|
+
This means:
|
195
|
+
|
196
|
+
* **Bug fixes**: We will still fix bugs in stylistic rules.
|
197
|
+
* **New ECMAScript features**: We will also make sure stylistic rules are compatible with new ECMAScript features.
|
198
|
+
* **New options**: We will **not** add any new options to stylistic rules unless an option is the only way to fix a bug or support a newly-added ECMAScript feature.
|
199
|
+
|
179
200
|
## <a name="license"></a>License
|
180
201
|
|
181
202
|
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint?ref=badge_large)
|
@@ -259,10 +280,10 @@ The following companies, organizations, and individuals support ESLint's ongoing
|
|
259
280
|
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
260
281
|
<!--sponsorsstart-->
|
261
282
|
<h3>Platinum Sponsors</h3>
|
262
|
-
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/photomatt/
|
263
|
-
<p><a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.shopify.com"><img src="https://images.opencollective.com/shopify/e780cd4/logo.png" alt="Shopify" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://aka.ms/microsoftfossfund"><img src="https://
|
264
|
-
<p><a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/amp/c8a3b25/logo.png" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
|
265
|
-
<p><a href="https://
|
283
|
+
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/photomatt/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
|
284
|
+
<p><a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="96"></a> <a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.shopify.com"><img src="https://images.opencollective.com/shopify/e780cd4/logo.png" alt="Shopify" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a> <a href="https://aka.ms/microsoftfossfund"><img src="https://avatars.githubusercontent.com/u/67931232?u=7fddc652a464d7151b97e8f108392af7d54fa3e8&v=4" alt="Microsoft FOSS Fund Sponsorships" height="96"></a></p><h3>Silver Sponsors</h3>
|
285
|
+
<p><a href="https://retool.com/"><img src="https://images.opencollective.com/retool/98ea68e/logo.png" alt="Retool" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/amp/c8a3b25/logo.png" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
|
286
|
+
<p><a href="https://papersowl.com/pay-for-research-paper"><img src="https://images.opencollective.com/papersowl2/9ef85ac/logo.png" alt="Papersowl" height="32"></a> <a href="https://writersperhour.com"><img src="https://images.opencollective.com/writersperhour/5787d4b/logo.png" alt="Writers Per Hour" height="32"></a> <a href="https://www.betacalendars.com/march-calendar.html"><img src="https://images.opencollective.com/betacalendars/9334b33/logo.png" alt="March 2021 calendar" height="32"></a> <a href="https://buy.fineproxy.org/eng/"><img src="https://images.opencollective.com/buy-fineproxy-org/b282e39/logo.png" alt="Buy.Fineproxy.Org" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="null"><img src="https://images.opencollective.com/bugsnag-stability-monitoring/c2cef36/logo.png" alt="Bugsnag Stability Monitoring" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a></p>
|
266
287
|
<!--sponsorsend-->
|
267
288
|
|
268
289
|
## <a name="technology-sponsors"></a>Technology Sponsors
|
@@ -531,7 +531,7 @@ function directoryExists(resolvedPath) {
|
|
531
531
|
try {
|
532
532
|
return fs.statSync(resolvedPath).isDirectory();
|
533
533
|
} catch (error) {
|
534
|
-
if (error && error.code === "ENOENT") {
|
534
|
+
if (error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
|
535
535
|
return false;
|
536
536
|
}
|
537
537
|
throw error;
|
@@ -589,7 +589,7 @@ class CLIEngine {
|
|
589
589
|
ignore: options.ignore
|
590
590
|
});
|
591
591
|
const lintResultCache =
|
592
|
-
options.cache ? new LintResultCache(cacheFilePath) : null;
|
592
|
+
options.cache ? new LintResultCache(cacheFilePath, options.cacheStrategy) : null;
|
593
593
|
const linter = new Linter({ cwd: options.cwd });
|
594
594
|
|
595
595
|
/** @type {ConfigArray[]} */
|
@@ -433,9 +433,14 @@ class FileEnumerator {
|
|
433
433
|
// Enumerate the files of this directory.
|
434
434
|
for (const entry of readdirSafeSync(directoryPath)) {
|
435
435
|
const filePath = path.join(directoryPath, entry.name);
|
436
|
+
const fileInfo = entry.isSymbolicLink() ? statSafeSync(filePath) : entry;
|
437
|
+
|
438
|
+
if (!fileInfo) {
|
439
|
+
continue;
|
440
|
+
}
|
436
441
|
|
437
442
|
// Check if the file is matched.
|
438
|
-
if (
|
443
|
+
if (fileInfo.isFile()) {
|
439
444
|
if (!config) {
|
440
445
|
config = configArrayFactory.getConfigArrayForFile(
|
441
446
|
filePath,
|
@@ -471,7 +476,7 @@ class FileEnumerator {
|
|
471
476
|
}
|
472
477
|
|
473
478
|
// Dive into the sub directory.
|
474
|
-
} else if (options.recursive &&
|
479
|
+
} else if (options.recursive && fileInfo.isDirectory()) {
|
475
480
|
if (!config) {
|
476
481
|
config = configArrayFactory.getConfigArrayForFile(
|
477
482
|
filePath,
|
@@ -15,6 +15,8 @@ const stringify = require("json-stable-stringify-without-jsonify");
|
|
15
15
|
const pkg = require("../../package.json");
|
16
16
|
const hash = require("./hash");
|
17
17
|
|
18
|
+
const debug = require("debug")("eslint:lint-result-cache");
|
19
|
+
|
18
20
|
//-----------------------------------------------------------------------------
|
19
21
|
// Helpers
|
20
22
|
//-----------------------------------------------------------------------------
|
@@ -22,6 +24,22 @@ const hash = require("./hash");
|
|
22
24
|
const configHashCache = new WeakMap();
|
23
25
|
const nodeVersion = process && process.version;
|
24
26
|
|
27
|
+
const validCacheStrategies = ["metadata", "content"];
|
28
|
+
const invalidCacheStrategyErrorMessage = `Cache strategy must be one of: ${validCacheStrategies
|
29
|
+
.map(strategy => `"${strategy}"`)
|
30
|
+
.join(", ")}`;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Tests whether a provided cacheStrategy is valid
|
34
|
+
* @param {string} cacheStrategy The cache strategy to use
|
35
|
+
* @returns {boolean} true if `cacheStrategy` is one of `validCacheStrategies`; false otherwise
|
36
|
+
*/
|
37
|
+
function isValidCacheStrategy(cacheStrategy) {
|
38
|
+
return (
|
39
|
+
validCacheStrategies.indexOf(cacheStrategy) !== -1
|
40
|
+
);
|
41
|
+
}
|
42
|
+
|
25
43
|
/**
|
26
44
|
* Calculates the hash of the config
|
27
45
|
* @param {ConfigArray} config The config.
|
@@ -50,11 +68,30 @@ class LintResultCache {
|
|
50
68
|
* Creates a new LintResultCache instance.
|
51
69
|
* @param {string} cacheFileLocation The cache file location.
|
52
70
|
* configuration lookup by file path).
|
71
|
+
* @param {"metadata" | "content"} cacheStrategy The cache strategy to use.
|
53
72
|
*/
|
54
|
-
constructor(cacheFileLocation) {
|
73
|
+
constructor(cacheFileLocation, cacheStrategy) {
|
55
74
|
assert(cacheFileLocation, "Cache file location is required");
|
56
|
-
|
57
|
-
|
75
|
+
assert(cacheStrategy, "Cache strategy is required");
|
76
|
+
assert(
|
77
|
+
isValidCacheStrategy(cacheStrategy),
|
78
|
+
invalidCacheStrategyErrorMessage
|
79
|
+
);
|
80
|
+
|
81
|
+
debug(`Caching results to ${cacheFileLocation}`);
|
82
|
+
|
83
|
+
const useChecksum = cacheStrategy === "content";
|
84
|
+
|
85
|
+
debug(
|
86
|
+
`Using "${cacheStrategy}" strategy to detect changes`
|
87
|
+
);
|
88
|
+
|
89
|
+
this.fileEntryCache = fileEntryCache.create(
|
90
|
+
cacheFileLocation,
|
91
|
+
void 0,
|
92
|
+
useChecksum
|
93
|
+
);
|
94
|
+
this.cacheFileLocation = cacheFileLocation;
|
58
95
|
}
|
59
96
|
|
60
97
|
/**
|
@@ -76,17 +113,28 @@ class LintResultCache {
|
|
76
113
|
* was previously linted
|
77
114
|
* If any of these are not true, we will not reuse the lint results.
|
78
115
|
*/
|
79
|
-
|
80
116
|
const fileDescriptor = this.fileEntryCache.getFileDescriptor(filePath);
|
81
117
|
const hashOfConfig = hashOfConfigFor(config);
|
82
|
-
const changed =
|
118
|
+
const changed =
|
119
|
+
fileDescriptor.changed ||
|
120
|
+
fileDescriptor.meta.hashOfConfig !== hashOfConfig;
|
121
|
+
|
122
|
+
if (fileDescriptor.notFound) {
|
123
|
+
debug(`File not found on the file system: ${filePath}`);
|
124
|
+
return null;
|
125
|
+
}
|
83
126
|
|
84
|
-
if (
|
127
|
+
if (changed) {
|
128
|
+
debug(`Cache entry not found or no longer valid: ${filePath}`);
|
85
129
|
return null;
|
86
130
|
}
|
87
131
|
|
88
132
|
// If source is present but null, need to reread the file from the filesystem.
|
89
|
-
if (
|
133
|
+
if (
|
134
|
+
fileDescriptor.meta.results &&
|
135
|
+
fileDescriptor.meta.results.source === null
|
136
|
+
) {
|
137
|
+
debug(`Rereading cached result source from filesystem: ${filePath}`);
|
90
138
|
fileDescriptor.meta.results.source = fs.readFileSync(filePath, "utf-8");
|
91
139
|
}
|
92
140
|
|
@@ -112,6 +160,7 @@ class LintResultCache {
|
|
112
160
|
const fileDescriptor = this.fileEntryCache.getFileDescriptor(filePath);
|
113
161
|
|
114
162
|
if (fileDescriptor && !fileDescriptor.notFound) {
|
163
|
+
debug(`Updating cached result: ${filePath}`);
|
115
164
|
|
116
165
|
// Serialize the result, except that we want to remove the file source if present.
|
117
166
|
const resultToSerialize = Object.assign({}, result);
|
@@ -135,6 +184,7 @@ class LintResultCache {
|
|
135
184
|
* @returns {void}
|
136
185
|
*/
|
137
186
|
reconcile() {
|
187
|
+
debug(`Persisting cached results: ${this.cacheFileLocation}`);
|
138
188
|
this.fileEntryCache.reconcile();
|
139
189
|
}
|
140
190
|
}
|
package/lib/cli.js
CHANGED
@@ -62,6 +62,7 @@ function translateOptions({
|
|
62
62
|
cache,
|
63
63
|
cacheFile,
|
64
64
|
cacheLocation,
|
65
|
+
cacheStrategy,
|
65
66
|
config,
|
66
67
|
env,
|
67
68
|
errorOnUnmatchedPattern,
|
@@ -88,6 +89,7 @@ function translateOptions({
|
|
88
89
|
allowInlineConfig: inlineConfig,
|
89
90
|
cache,
|
90
91
|
cacheLocation: cacheLocation || cacheFile,
|
92
|
+
cacheStrategy,
|
91
93
|
errorOnUnmatchedPattern,
|
92
94
|
extensions: ext,
|
93
95
|
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
|
package/lib/eslint/eslint.js
CHANGED
@@ -43,6 +43,7 @@ const { version } = require("../../package.json");
|
|
43
43
|
* @property {ConfigData} [baseConfig] Base config object, extended by all configs used with this instance
|
44
44
|
* @property {boolean} [cache] Enable result caching.
|
45
45
|
* @property {string} [cacheLocation] The cache file to use instead of .eslintcache.
|
46
|
+
* @property {"metadata" | "content"} [cacheStrategy] The strategy used to detect changed files.
|
46
47
|
* @property {string} [cwd] The value to use for the current working directory.
|
47
48
|
* @property {boolean} [errorOnUnmatchedPattern] If `false` then `ESLint#lintFiles()` doesn't throw even if no target files found. Defaults to `true`.
|
48
49
|
* @property {string[]} [extensions] An array of file extensions to check.
|
@@ -157,6 +158,7 @@ function processOptions({
|
|
157
158
|
baseConfig = null,
|
158
159
|
cache = false,
|
159
160
|
cacheLocation = ".eslintcache",
|
161
|
+
cacheStrategy = "metadata",
|
160
162
|
cwd = process.cwd(),
|
161
163
|
errorOnUnmatchedPattern = true,
|
162
164
|
extensions = null, // ← should be null by default because if it's an array then it suppresses RFC20 feature.
|
@@ -216,6 +218,12 @@ function processOptions({
|
|
216
218
|
if (!isNonEmptyString(cacheLocation)) {
|
217
219
|
errors.push("'cacheLocation' must be a non-empty string.");
|
218
220
|
}
|
221
|
+
if (
|
222
|
+
cacheStrategy !== "metadata" &&
|
223
|
+
cacheStrategy !== "content"
|
224
|
+
) {
|
225
|
+
errors.push("'cacheStrategy' must be any of \"metadata\", \"content\".");
|
226
|
+
}
|
219
227
|
if (!isNonEmptyString(cwd) || !path.isAbsolute(cwd)) {
|
220
228
|
errors.push("'cwd' must be an absolute path.");
|
221
229
|
}
|
@@ -284,6 +292,7 @@ function processOptions({
|
|
284
292
|
baseConfig,
|
285
293
|
cache,
|
286
294
|
cacheLocation,
|
295
|
+
cacheStrategy,
|
287
296
|
configFile: overrideConfigFile,
|
288
297
|
cwd,
|
289
298
|
errorOnUnmatchedPattern,
|
package/lib/init/autoconfig.js
CHANGED
@@ -85,7 +85,7 @@ class Registry {
|
|
85
85
|
* @returns {void}
|
86
86
|
*/
|
87
87
|
populateFromCoreRules() {
|
88
|
-
const rulesConfig = configRule.createCoreRuleConfigs();
|
88
|
+
const rulesConfig = configRule.createCoreRuleConfigs(/* noDeprecated = */ true);
|
89
89
|
|
90
90
|
this.rules = makeRegistryItems(rulesConfig);
|
91
91
|
}
|
@@ -565,7 +565,8 @@ function promptUser() {
|
|
565
565
|
{
|
566
566
|
type: "toggle",
|
567
567
|
name: "installESLint",
|
568
|
-
message(
|
568
|
+
message() {
|
569
|
+
const { answers } = this.state;
|
569
570
|
const verb = semver.ltr(answers.localESLintVersion, answers.requiredESLintVersionRange)
|
570
571
|
? "upgrade"
|
571
572
|
: "downgrade";
|
package/lib/linter/linter.js
CHANGED
@@ -942,7 +942,9 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
|
|
942
942
|
});
|
943
943
|
|
944
944
|
// only run code path analyzer if the top level node is "Program", skip otherwise
|
945
|
-
const eventGenerator = nodeQueue[0].node.type === "Program"
|
945
|
+
const eventGenerator = nodeQueue[0].node.type === "Program"
|
946
|
+
? new CodePathAnalyzer(new NodeEventGenerator(emitter, { visitorKeys: sourceCode.visitorKeys, fallback: Traverser.getKeys }))
|
947
|
+
: new NodeEventGenerator(emitter, { visitorKeys: sourceCode.visitorKeys, fallback: Traverser.getKeys });
|
946
948
|
|
947
949
|
nodeQueue.forEach(traversalInfo => {
|
948
950
|
currentNode = traversalInfo.node;
|
@@ -208,10 +208,12 @@ class NodeEventGenerator {
|
|
208
208
|
* An SafeEmitter which is the destination of events. This emitter must already
|
209
209
|
* have registered listeners for all of the events that it needs to listen for.
|
210
210
|
* (See lib/linter/safe-emitter.js for more details on `SafeEmitter`.)
|
211
|
+
* @param {ESQueryOptions} esqueryOptions `esquery` options for traversing custom nodes.
|
211
212
|
* @returns {NodeEventGenerator} new instance
|
212
213
|
*/
|
213
|
-
constructor(emitter) {
|
214
|
+
constructor(emitter, esqueryOptions) {
|
214
215
|
this.emitter = emitter;
|
216
|
+
this.esqueryOptions = esqueryOptions;
|
215
217
|
this.currentAncestry = [];
|
216
218
|
this.enterSelectorsByNodeType = new Map();
|
217
219
|
this.exitSelectorsByNodeType = new Map();
|
@@ -250,7 +252,7 @@ class NodeEventGenerator {
|
|
250
252
|
* @returns {void}
|
251
253
|
*/
|
252
254
|
applySelector(node, selector) {
|
253
|
-
if (esquery.matches(node, selector.parsedSelector, this.currentAncestry)) {
|
255
|
+
if (esquery.matches(node, selector.parsedSelector, this.currentAncestry, this.esqueryOptions)) {
|
254
256
|
this.emitter.emit(selector.rawSelector, node);
|
255
257
|
}
|
256
258
|
}
|
package/lib/options.js
CHANGED
@@ -214,6 +214,14 @@ module.exports = optionator({
|
|
214
214
|
type: "path::String",
|
215
215
|
description: "Path to the cache file or directory"
|
216
216
|
},
|
217
|
+
{
|
218
|
+
option: "cache-strategy",
|
219
|
+
dependsOn: ["cache"],
|
220
|
+
type: "String",
|
221
|
+
default: "metadata",
|
222
|
+
enum: ["metadata", "content"],
|
223
|
+
description: "Strategy to use for detecting changed files in the cache"
|
224
|
+
},
|
217
225
|
{
|
218
226
|
heading: "Miscellaneous"
|
219
227
|
},
|
package/lib/rules/complexity.js
CHANGED
@@ -153,7 +153,13 @@ module.exports = {
|
|
153
153
|
IfStatement: increaseComplexity,
|
154
154
|
SwitchCase: increaseSwitchComplexity,
|
155
155
|
WhileStatement: increaseComplexity,
|
156
|
-
DoWhileStatement: increaseComplexity
|
156
|
+
DoWhileStatement: increaseComplexity,
|
157
|
+
|
158
|
+
AssignmentExpression(node) {
|
159
|
+
if (astUtils.isLogicalAssignmentOperator(node.operator)) {
|
160
|
+
increaseComplexity();
|
161
|
+
}
|
162
|
+
}
|
157
163
|
};
|
158
164
|
|
159
165
|
}
|
package/lib/rules/indent.js
CHANGED
@@ -1178,6 +1178,7 @@ module.exports = {
|
|
1178
1178
|
offsets.setDesiredOffset(colonToken, firstToken, 1);
|
1179
1179
|
|
1180
1180
|
offsets.setDesiredOffset(firstConsequentToken, firstToken,
|
1181
|
+
firstConsequentToken.type === "Punctuator" &&
|
1181
1182
|
options.offsetTernaryExpressions ? 2 : 1);
|
1182
1183
|
|
1183
1184
|
/*
|
@@ -71,7 +71,7 @@ module.exports = {
|
|
71
71
|
type: "suggestion",
|
72
72
|
|
73
73
|
docs: {
|
74
|
-
description: "enforce a maximum number of
|
74
|
+
description: "enforce a maximum number of lines of code in a function",
|
75
75
|
category: "Stylistic Issues",
|
76
76
|
recommended: false,
|
77
77
|
url: "https://eslint.org/docs/rules/max-lines-per-function"
|
@@ -844,45 +844,49 @@ module.exports = {
|
|
844
844
|
ExportDefaultDeclaration: node => checkExpressionOrExportStatement(node.declaration),
|
845
845
|
ExpressionStatement: node => checkExpressionOrExportStatement(node.expression),
|
846
846
|
|
847
|
-
|
848
|
-
if (node.left.type !== "
|
847
|
+
ForInStatement(node) {
|
848
|
+
if (node.left.type !== "VariableDeclaration") {
|
849
849
|
const firstLeftToken = sourceCode.getFirstToken(node.left, astUtils.isNotOpeningParenToken);
|
850
850
|
|
851
851
|
if (
|
852
|
-
firstLeftToken.value === "let" &&
|
853
|
-
|
854
|
-
|
855
|
-
* If `let` is the only thing on the left side of the loop, it's the loop variable: `for ((let) of foo);`
|
856
|
-
* Removing it will cause a syntax error, because it will be parsed as the start of a VariableDeclarator.
|
857
|
-
*/
|
858
|
-
(firstLeftToken.range[1] === node.left.range[1] || /*
|
859
|
-
* If `let` is followed by a `[` token, it's a property access on the `let` value: `for ((let[foo]) of bar);`
|
860
|
-
* Removing it will cause the property access to be parsed as a destructuring declaration of `foo` instead.
|
861
|
-
*/
|
862
|
-
astUtils.isOpeningBracketToken(
|
863
|
-
sourceCode.getTokenAfter(firstLeftToken, astUtils.isNotClosingParenToken)
|
864
|
-
))
|
852
|
+
firstLeftToken.value === "let" &&
|
853
|
+
astUtils.isOpeningBracketToken(
|
854
|
+
sourceCode.getTokenAfter(firstLeftToken, astUtils.isNotClosingParenToken)
|
865
855
|
)
|
866
856
|
) {
|
857
|
+
|
858
|
+
// ForInStatement#left expression cannot start with `let[`.
|
867
859
|
tokensToIgnore.add(firstLeftToken);
|
868
860
|
}
|
869
861
|
}
|
870
862
|
|
871
|
-
if (node.
|
872
|
-
|
873
|
-
|
874
|
-
: hasExcessParens(node.right);
|
863
|
+
if (hasExcessParens(node.left)) {
|
864
|
+
report(node.left);
|
865
|
+
}
|
875
866
|
|
876
|
-
|
877
|
-
report(node.right);
|
878
|
-
}
|
879
|
-
} else if (hasExcessParens(node.right)) {
|
867
|
+
if (hasExcessParens(node.right)) {
|
880
868
|
report(node.right);
|
881
869
|
}
|
870
|
+
},
|
871
|
+
|
872
|
+
ForOfStatement(node) {
|
873
|
+
if (node.left.type !== "VariableDeclaration") {
|
874
|
+
const firstLeftToken = sourceCode.getFirstToken(node.left, astUtils.isNotOpeningParenToken);
|
875
|
+
|
876
|
+
if (firstLeftToken.value === "let") {
|
877
|
+
|
878
|
+
// ForOfStatement#left expression cannot start with `let`.
|
879
|
+
tokensToIgnore.add(firstLeftToken);
|
880
|
+
}
|
881
|
+
}
|
882
882
|
|
883
883
|
if (hasExcessParens(node.left)) {
|
884
884
|
report(node.left);
|
885
885
|
}
|
886
|
+
|
887
|
+
if (hasExcessParensWithPrecedence(node.right, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
|
888
|
+
report(node.right);
|
889
|
+
}
|
886
890
|
},
|
887
891
|
|
888
892
|
ForStatement(node) {
|
@@ -895,6 +899,22 @@ module.exports = {
|
|
895
899
|
}
|
896
900
|
|
897
901
|
if (node.init) {
|
902
|
+
|
903
|
+
if (node.init.type !== "VariableDeclaration") {
|
904
|
+
const firstToken = sourceCode.getFirstToken(node.init, astUtils.isNotOpeningParenToken);
|
905
|
+
|
906
|
+
if (
|
907
|
+
firstToken.value === "let" &&
|
908
|
+
astUtils.isOpeningBracketToken(
|
909
|
+
sourceCode.getTokenAfter(firstToken, astUtils.isNotClosingParenToken)
|
910
|
+
)
|
911
|
+
) {
|
912
|
+
|
913
|
+
// ForStatement#init expression cannot start with `let[`.
|
914
|
+
tokensToIgnore.add(firstToken);
|
915
|
+
}
|
916
|
+
}
|
917
|
+
|
898
918
|
startNewReportsBuffering();
|
899
919
|
|
900
920
|
if (hasExcessParens(node.init)) {
|
@@ -69,6 +69,28 @@ module.exports = {
|
|
69
69
|
return node && node.type === "Literal" && typeof node.value === "string";
|
70
70
|
}
|
71
71
|
|
72
|
+
/**
|
73
|
+
* Gets flags of a regular expression created by the given `RegExp()` or `new RegExp()` call
|
74
|
+
* Examples:
|
75
|
+
* new RegExp(".") // => ""
|
76
|
+
* new RegExp(".", "gu") // => "gu"
|
77
|
+
* new RegExp(".", flags) // => null
|
78
|
+
* @param {ASTNode} node `CallExpression` or `NewExpression` node
|
79
|
+
* @returns {string|null} flags if they can be determined, `null` otherwise
|
80
|
+
* @private
|
81
|
+
*/
|
82
|
+
function getFlags(node) {
|
83
|
+
if (node.arguments.length < 2) {
|
84
|
+
return "";
|
85
|
+
}
|
86
|
+
|
87
|
+
if (isString(node.arguments[1])) {
|
88
|
+
return node.arguments[1].value;
|
89
|
+
}
|
90
|
+
|
91
|
+
return null;
|
92
|
+
}
|
93
|
+
|
72
94
|
/**
|
73
95
|
* Check syntax error in a given pattern.
|
74
96
|
* @param {string} pattern The RegExp pattern to validate.
|
@@ -104,18 +126,23 @@ module.exports = {
|
|
104
126
|
return;
|
105
127
|
}
|
106
128
|
const pattern = node.arguments[0].value;
|
107
|
-
let flags =
|
129
|
+
let flags = getFlags(node);
|
108
130
|
|
109
|
-
if (allowedFlags) {
|
131
|
+
if (flags && allowedFlags) {
|
110
132
|
flags = flags.replace(allowedFlags, "");
|
111
133
|
}
|
112
134
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
135
|
+
const message =
|
136
|
+
(
|
137
|
+
flags && validateRegExpFlags(flags)
|
138
|
+
) ||
|
139
|
+
(
|
140
|
+
|
141
|
+
// If flags are unknown, report the regex only if its pattern is invalid both with and without the "u" flag
|
142
|
+
flags === null
|
143
|
+
? validateRegExpPattern(pattern, true) && validateRegExpPattern(pattern, false)
|
144
|
+
: validateRegExpPattern(pattern, flags.includes("u"))
|
145
|
+
);
|
119
146
|
|
120
147
|
if (message) {
|
121
148
|
context.report({
|
@@ -105,9 +105,9 @@ module.exports = {
|
|
105
105
|
}
|
106
106
|
|
107
107
|
/**
|
108
|
-
* Converts an integer to to an object containing the
|
108
|
+
* Converts an integer to to an object containing the integer's coefficient and order of magnitude
|
109
109
|
* @param {string} stringInteger the string representation of the integer being converted
|
110
|
-
* @returns {Object} the object containing the
|
110
|
+
* @returns {Object} the object containing the integer's coefficient and order of magnitude
|
111
111
|
*/
|
112
112
|
function normalizeInteger(stringInteger) {
|
113
113
|
const significantDigits = removeTrailingZeros(removeLeadingZeros(stringInteger));
|
@@ -120,9 +120,9 @@ module.exports = {
|
|
120
120
|
|
121
121
|
/**
|
122
122
|
*
|
123
|
-
* Converts a float to to an object containing the
|
123
|
+
* Converts a float to to an object containing the floats's coefficient and order of magnitude
|
124
124
|
* @param {string} stringFloat the string representation of the float being converted
|
125
|
-
* @returns {Object} the object containing the
|
125
|
+
* @returns {Object} the object containing the integer's coefficient and order of magnitude
|
126
126
|
*/
|
127
127
|
function normalizeFloat(stringFloat) {
|
128
128
|
const trimmedFloat = removeLeadingZeros(stringFloat);
|
package/lib/rules/no-shadow.js
CHANGED
@@ -44,7 +44,8 @@ module.exports = {
|
|
44
44
|
],
|
45
45
|
|
46
46
|
messages: {
|
47
|
-
noShadow: "'{{name}}' is already declared in the upper scope."
|
47
|
+
noShadow: "'{{name}}' is already declared in the upper scope on line {{shadowedLine}} column {{shadowedColumn}}.",
|
48
|
+
noShadowGlobal: "'{{name}}' is already a global variable."
|
48
49
|
}
|
49
50
|
},
|
50
51
|
|
@@ -117,6 +118,29 @@ module.exports = {
|
|
117
118
|
return def && def.name.range;
|
118
119
|
}
|
119
120
|
|
121
|
+
/**
|
122
|
+
* Get declared line and column of a variable.
|
123
|
+
* @param {eslint-scope.Variable} variable The variable to get.
|
124
|
+
* @returns {Object} The declared line and column of the variable.
|
125
|
+
*/
|
126
|
+
function getDeclaredLocation(variable) {
|
127
|
+
const identifier = variable.identifiers[0];
|
128
|
+
let obj;
|
129
|
+
|
130
|
+
if (identifier) {
|
131
|
+
obj = {
|
132
|
+
global: false,
|
133
|
+
line: identifier.loc.start.line,
|
134
|
+
column: identifier.loc.start.column + 1
|
135
|
+
};
|
136
|
+
} else {
|
137
|
+
obj = {
|
138
|
+
global: true
|
139
|
+
};
|
140
|
+
}
|
141
|
+
return obj;
|
142
|
+
}
|
143
|
+
|
120
144
|
/**
|
121
145
|
* Checks if a variable is in TDZ of scopeVar.
|
122
146
|
* @param {Object} variable The variable to check.
|
@@ -165,10 +189,18 @@ module.exports = {
|
|
165
189
|
!isOnInitializer(variable, shadowed) &&
|
166
190
|
!(options.hoist !== "all" && isInTdz(variable, shadowed))
|
167
191
|
) {
|
192
|
+
const location = getDeclaredLocation(shadowed);
|
193
|
+
const messageId = location.global ? "noShadowGlobal" : "noShadow";
|
194
|
+
const data = { name: variable.name };
|
195
|
+
|
196
|
+
if (!location.global) {
|
197
|
+
data.shadowedLine = location.line;
|
198
|
+
data.shadowedColumn = location.column;
|
199
|
+
}
|
168
200
|
context.report({
|
169
201
|
node: variable.identifiers[0],
|
170
|
-
messageId
|
171
|
-
data
|
202
|
+
messageId,
|
203
|
+
data
|
172
204
|
});
|
173
205
|
}
|
174
206
|
}
|
@@ -50,6 +50,10 @@ module.exports = {
|
|
50
50
|
allowTaggedTemplates: {
|
51
51
|
type: "boolean",
|
52
52
|
default: false
|
53
|
+
},
|
54
|
+
enforceForJSX: {
|
55
|
+
type: "boolean",
|
56
|
+
default: false
|
53
57
|
}
|
54
58
|
},
|
55
59
|
additionalProperties: false
|
@@ -65,7 +69,8 @@ module.exports = {
|
|
65
69
|
const config = context.options[0] || {},
|
66
70
|
allowShortCircuit = config.allowShortCircuit || false,
|
67
71
|
allowTernary = config.allowTernary || false,
|
68
|
-
allowTaggedTemplates = config.allowTaggedTemplates || false
|
72
|
+
allowTaggedTemplates = config.allowTaggedTemplates || false,
|
73
|
+
enforceForJSX = config.enforceForJSX || false;
|
69
74
|
|
70
75
|
// eslint-disable-next-line jsdoc/require-description
|
71
76
|
/**
|
@@ -140,6 +145,12 @@ module.exports = {
|
|
140
145
|
},
|
141
146
|
FunctionExpression: alwaysTrue,
|
142
147
|
Identifier: alwaysTrue,
|
148
|
+
JSXElement() {
|
149
|
+
return enforceForJSX;
|
150
|
+
},
|
151
|
+
JSXFragment() {
|
152
|
+
return enforceForJSX;
|
153
|
+
},
|
143
154
|
Literal: alwaysTrue,
|
144
155
|
LogicalExpression(node) {
|
145
156
|
if (allowShortCircuit) {
|
@@ -5,6 +5,12 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
|
+
|
8
14
|
//------------------------------------------------------------------------------
|
9
15
|
// Rule Definition
|
10
16
|
//------------------------------------------------------------------------------
|
@@ -54,11 +60,10 @@ module.exports = {
|
|
54
60
|
* Reports error for unnecessarily renamed assignments
|
55
61
|
* @param {ASTNode} node node to report
|
56
62
|
* @param {ASTNode} initial node with initial name value
|
57
|
-
* @param {ASTNode} result node with new name value
|
58
63
|
* @param {string} type the type of the offending node
|
59
64
|
* @returns {void}
|
60
65
|
*/
|
61
|
-
function reportError(node, initial,
|
66
|
+
function reportError(node, initial, type) {
|
62
67
|
const name = initial.type === "Identifier" ? initial.name : initial.value;
|
63
68
|
|
64
69
|
return context.report({
|
@@ -69,18 +74,21 @@ module.exports = {
|
|
69
74
|
type
|
70
75
|
},
|
71
76
|
fix(fixer) {
|
72
|
-
|
77
|
+
const replacementNode = node.type === "Property" ? node.value : node.local;
|
78
|
+
|
79
|
+
if (sourceCode.getCommentsInside(node).length > sourceCode.getCommentsInside(replacementNode).length) {
|
73
80
|
return null;
|
74
81
|
}
|
75
82
|
|
76
|
-
|
77
|
-
|
78
|
-
|
83
|
+
// Don't autofix code such as `({foo: (foo) = a} = obj);`, parens are not allowed in shorthand properties.
|
84
|
+
if (
|
85
|
+
replacementNode.type === "AssignmentPattern" &&
|
86
|
+
astUtils.isParenthesised(sourceCode, replacementNode.left)
|
87
|
+
) {
|
88
|
+
return null;
|
89
|
+
}
|
79
90
|
|
80
|
-
return fixer.
|
81
|
-
initial.range[0],
|
82
|
-
result.range[1]
|
83
|
-
], replacementText);
|
91
|
+
return fixer.replaceText(node, sourceCode.getText(replacementNode));
|
84
92
|
}
|
85
93
|
});
|
86
94
|
}
|
@@ -97,19 +105,11 @@ module.exports = {
|
|
97
105
|
|
98
106
|
for (const property of node.properties) {
|
99
107
|
|
100
|
-
/*
|
101
|
-
* TODO: Remove after babel-eslint removes ExperimentalRestProperty
|
102
|
-
* https://github.com/eslint/eslint/issues/12335
|
103
|
-
*/
|
104
|
-
if (property.type === "ExperimentalRestProperty") {
|
105
|
-
continue;
|
106
|
-
}
|
107
|
-
|
108
108
|
/**
|
109
109
|
* Properties using shorthand syntax and rest elements can not be renamed.
|
110
110
|
* If the property is computed, we have no idea if a rename is useless or not.
|
111
111
|
*/
|
112
|
-
if (property.
|
112
|
+
if (property.type !== "Property" || property.shorthand || property.computed) {
|
113
113
|
continue;
|
114
114
|
}
|
115
115
|
|
@@ -117,7 +117,7 @@ module.exports = {
|
|
117
117
|
const renamedKey = property.value.type === "AssignmentPattern" ? property.value.left.name : property.value.name;
|
118
118
|
|
119
119
|
if (key === renamedKey) {
|
120
|
-
reportError(property, property.key,
|
120
|
+
reportError(property, property.key, "Destructuring assignment");
|
121
121
|
}
|
122
122
|
}
|
123
123
|
}
|
@@ -134,7 +134,7 @@ module.exports = {
|
|
134
134
|
|
135
135
|
if (node.imported.name === node.local.name &&
|
136
136
|
node.imported.range[0] !== node.local.range[0]) {
|
137
|
-
reportError(node, node.imported,
|
137
|
+
reportError(node, node.imported, "Import");
|
138
138
|
}
|
139
139
|
}
|
140
140
|
|
@@ -150,7 +150,7 @@ module.exports = {
|
|
150
150
|
|
151
151
|
if (node.local.name === node.exported.name &&
|
152
152
|
node.local.range[0] !== node.exported.range[0]) {
|
153
|
-
reportError(node, node.local,
|
153
|
+
reportError(node, node.local, "Export");
|
154
154
|
}
|
155
155
|
|
156
156
|
}
|
@@ -5,6 +5,11 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
//------------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//------------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const FixTracker = require("./utils/fix-tracker");
|
8
13
|
const astUtils = require("./utils/ast-utils");
|
9
14
|
|
10
15
|
//------------------------------------------------------------------------------
|
@@ -451,10 +456,18 @@ module.exports = {
|
|
451
456
|
messageId: "useConst",
|
452
457
|
data: node,
|
453
458
|
fix: shouldFix
|
454
|
-
? fixer =>
|
455
|
-
sourceCode.getFirstToken(varDeclParent, t => t.value === varDeclParent.kind)
|
456
|
-
|
457
|
-
|
459
|
+
? fixer => {
|
460
|
+
const letKeywordToken = sourceCode.getFirstToken(varDeclParent, t => t.value === varDeclParent.kind);
|
461
|
+
|
462
|
+
/**
|
463
|
+
* Extend the replacement range to the whole declaration,
|
464
|
+
* in order to prevent other fixes in the same pass
|
465
|
+
* https://github.com/eslint/eslint/issues/13899
|
466
|
+
*/
|
467
|
+
return new FixTracker(fixer, sourceCode)
|
468
|
+
.retainRange(varDeclParent.range)
|
469
|
+
.replaceTextRange(letKeywordToken.range, "const");
|
470
|
+
}
|
458
471
|
: null
|
459
472
|
});
|
460
473
|
});
|
@@ -168,7 +168,7 @@ module.exports = {
|
|
168
168
|
* Assignment expression is not fixed.
|
169
169
|
* Array destructuring is not fixed.
|
170
170
|
* Renamed property is not fixed.
|
171
|
-
* @param {ASTNode} node the
|
171
|
+
* @param {ASTNode} node the node to evaluate
|
172
172
|
* @returns {boolean} whether or not the node should be fixed
|
173
173
|
*/
|
174
174
|
function shouldFix(node) {
|
package/lib/rules/use-isnan.js
CHANGED
@@ -101,7 +101,7 @@ module.exports = {
|
|
101
101
|
}
|
102
102
|
|
103
103
|
/**
|
104
|
-
* Checks the
|
104
|
+
* Checks the given `CallExpression` node for `.indexOf(NaN)` and `.lastIndexOf(NaN)`.
|
105
105
|
* @param {ASTNode} node The node to check.
|
106
106
|
* @returns {void}
|
107
107
|
*/
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.21.0",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -46,8 +46,8 @@
|
|
46
46
|
"homepage": "https://eslint.org",
|
47
47
|
"bugs": "https://github.com/eslint/eslint/issues/",
|
48
48
|
"dependencies": {
|
49
|
-
"@babel/code-frame": "
|
50
|
-
"@eslint/eslintrc": "^0.
|
49
|
+
"@babel/code-frame": "7.12.11",
|
50
|
+
"@eslint/eslintrc": "^0.4.0",
|
51
51
|
"ajv": "^6.10.0",
|
52
52
|
"chalk": "^4.0.0",
|
53
53
|
"cross-spawn": "^7.0.2",
|
@@ -58,9 +58,9 @@
|
|
58
58
|
"eslint-utils": "^2.1.0",
|
59
59
|
"eslint-visitor-keys": "^2.0.0",
|
60
60
|
"espree": "^7.3.1",
|
61
|
-
"esquery": "^1.
|
61
|
+
"esquery": "^1.4.0",
|
62
62
|
"esutils": "^2.0.2",
|
63
|
-
"file-entry-cache": "^6.0.
|
63
|
+
"file-entry-cache": "^6.0.1",
|
64
64
|
"functional-red-black-tree": "^1.0.1",
|
65
65
|
"glob-parent": "^5.0.0",
|
66
66
|
"globals": "^12.1.0",
|
@@ -71,7 +71,7 @@
|
|
71
71
|
"js-yaml": "^3.13.1",
|
72
72
|
"json-stable-stringify-without-jsonify": "^1.0.1",
|
73
73
|
"levn": "^0.4.1",
|
74
|
-
"lodash": "^4.17.
|
74
|
+
"lodash": "^4.17.20",
|
75
75
|
"minimatch": "^3.0.4",
|
76
76
|
"natural-compare": "^1.4.0",
|
77
77
|
"optionator": "^0.9.1",
|
@@ -123,7 +123,7 @@
|
|
123
123
|
"npm-license": "^0.3.3",
|
124
124
|
"nyc": "^15.0.1",
|
125
125
|
"proxyquire": "^2.0.1",
|
126
|
-
"puppeteer": "^
|
126
|
+
"puppeteer": "^7.1.0",
|
127
127
|
"recast": "^0.19.0",
|
128
128
|
"regenerator-runtime": "^0.13.2",
|
129
129
|
"shelljs": "^0.8.2",
|