eslint 3.15.0 → 3.17.1
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 +79 -0
- package/conf/{eslint.json → eslint-recommended.js} +87 -71
- package/lib/ast-utils.js +182 -80
- package/lib/code-path-analysis/code-path-state.js +2 -2
- package/lib/config/autoconfig.js +3 -3
- package/lib/config/config-file.js +14 -7
- package/lib/config/config-initializer.js +1 -1
- package/lib/config.js +3 -2
- package/lib/eslint.js +4 -4
- package/lib/internal-rules/internal-no-invalid-meta.js +2 -40
- package/lib/rules/array-callback-return.js +15 -5
- package/lib/rules/arrow-body-style.js +7 -4
- package/lib/rules/arrow-spacing.js +7 -6
- package/lib/rules/block-spacing.js +2 -2
- package/lib/rules/brace-style.js +2 -6
- package/lib/rules/capitalized-comments.js +8 -7
- package/lib/rules/comma-spacing.js +3 -3
- package/lib/rules/complexity.js +14 -8
- package/lib/rules/consistent-return.js +18 -11
- package/lib/rules/constructor-super.js +3 -3
- package/lib/rules/curly.js +11 -7
- package/lib/rules/default-case.js +3 -3
- package/lib/rules/eqeqeq.js +15 -6
- package/lib/rules/func-call-spacing.js +10 -13
- package/lib/rules/func-names.js +20 -5
- package/lib/rules/generator-star-spacing.js +18 -19
- package/lib/rules/id-blacklist.js +2 -2
- package/lib/rules/id-length.js +3 -3
- package/lib/rules/id-match.js +2 -2
- package/lib/rules/indent.js +7 -6
- package/lib/rules/key-spacing.js +12 -16
- package/lib/rules/keyword-spacing.js +21 -17
- package/lib/rules/line-comment-position.js +16 -6
- package/lib/rules/linebreak-style.js +7 -1
- package/lib/rules/lines-around-comment.js +23 -4
- package/lib/rules/lines-around-directive.js +3 -3
- package/lib/rules/max-lines.js +2 -2
- package/lib/rules/max-params.js +17 -4
- package/lib/rules/max-statements-per-line.js +7 -6
- package/lib/rules/max-statements.js +11 -10
- package/lib/rules/newline-after-var.js +7 -2
- package/lib/rules/newline-per-chained-call.js +3 -1
- package/lib/rules/no-compare-neg-zero.js +53 -0
- package/lib/rules/no-cond-assign.js +3 -3
- package/lib/rules/no-else-return.js +13 -1
- package/lib/rules/no-empty-function.js +9 -16
- package/lib/rules/no-extend-native.js +3 -3
- package/lib/rules/no-extra-bind.js +3 -4
- package/lib/rules/no-extra-boolean-cast.js +8 -0
- package/lib/rules/no-extra-parens.js +1 -2
- package/lib/rules/no-extra-semi.js +13 -1
- package/lib/rules/no-inner-declarations.js +4 -4
- package/lib/rules/no-invalid-regexp.js +2 -1
- package/lib/rules/no-irregular-whitespace.js +7 -1
- package/lib/rules/no-lone-blocks.js +10 -10
- package/lib/rules/no-mixed-operators.js +1 -7
- package/lib/rules/no-multi-spaces.js +4 -1
- package/lib/rules/no-multi-str.js +7 -3
- package/lib/rules/no-multiple-empty-lines.js +2 -4
- package/lib/rules/no-param-reassign.js +29 -6
- package/lib/rules/no-restricted-properties.js +2 -0
- package/lib/rules/no-return-assign.js +7 -14
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-sequences.js +7 -6
- package/lib/rules/no-trailing-spaces.js +8 -2
- package/lib/rules/no-undefined.js +45 -6
- package/lib/rules/no-unexpected-multiline.js +9 -8
- package/lib/rules/no-unneeded-ternary.js +5 -1
- package/lib/rules/no-unused-labels.js +17 -2
- package/lib/rules/no-unused-vars.js +13 -27
- package/lib/rules/no-use-before-define.js +1 -1
- package/lib/rules/no-useless-computed-key.js +8 -3
- package/lib/rules/no-useless-concat.js +10 -7
- package/lib/rules/no-useless-escape.js +2 -2
- package/lib/rules/no-useless-return.js +14 -9
- package/lib/rules/no-var.js +1 -3
- package/lib/rules/no-whitespace-before-property.js +5 -16
- package/lib/rules/nonblock-statement-body-position.js +114 -0
- package/lib/rules/object-curly-newline.js +2 -2
- package/lib/rules/object-curly-spacing.js +7 -25
- package/lib/rules/object-property-newline.js +3 -3
- package/lib/rules/object-shorthand.js +4 -3
- package/lib/rules/operator-assignment.js +2 -2
- package/lib/rules/operator-linebreak.js +8 -10
- package/lib/rules/padded-blocks.js +39 -30
- package/lib/rules/prefer-destructuring.js +1 -1
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +10 -6
- package/lib/rules/semi-spacing.js +4 -0
- package/lib/rules/semi.js +13 -1
- package/lib/rules/space-before-function-paren.js +8 -5
- package/lib/rules/space-unary-ops.js +19 -1
- package/lib/rules/spaced-comment.js +2 -2
- package/lib/rules/strict.js +10 -4
- package/lib/rules/unicode-bom.js +1 -1
- package/lib/rules/wrap-iife.js +5 -5
- package/lib/rules/yoda.js +4 -9
- package/lib/testers/rule-tester.js +46 -9
- package/lib/token-store/backward-token-comment-cursor.js +57 -0
- package/lib/token-store/backward-token-cursor.js +56 -0
- package/lib/token-store/cursor.js +76 -0
- package/lib/token-store/cursors.js +92 -0
- package/lib/token-store/decorative-cursor.js +39 -0
- package/lib/token-store/filter-cursor.js +43 -0
- package/lib/token-store/forward-token-comment-cursor.js +57 -0
- package/lib/token-store/forward-token-cursor.js +61 -0
- package/lib/token-store/index.js +604 -0
- package/lib/token-store/limit-cursor.js +40 -0
- package/lib/token-store/padded-token-cursor.js +38 -0
- package/lib/token-store/skip-cursor.js +42 -0
- package/lib/token-store/utils.js +100 -0
- package/lib/util/fix-tracker.js +121 -0
- package/lib/util/source-code-fixer.js +35 -39
- package/lib/util/source-code.js +129 -16
- package/messages/extend-config-missing.txt +3 -0
- package/package.json +5 -6
- package/lib/token-store.js +0 -203
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,82 @@
|
|
1
|
+
v3.17.1 - March 6, 2017
|
2
|
+
|
3
|
+
* f8c8e6e Build: change mock-fs path without SSH (fixes #8207) (#8208) (Toru Nagashima)
|
4
|
+
* f713f11 Fix: nonblock-statement-body-position multiline error (fixes #8202) (#8203) (Teddy Katz)
|
5
|
+
* 41e3d9c Fix: `operator-assignment` with parenthesized expression (fixes #8190) (#8197) (alberto)
|
6
|
+
* 5e3bca7 Chore: add eslint-plugin-eslint-plugin (#8198) (Teddy Katz)
|
7
|
+
* 580da36 Chore: add missing `output` property to tests (#8195) (alberto)
|
8
|
+
|
9
|
+
v3.17.0 - March 3, 2017
|
10
|
+
|
11
|
+
* 4fdf6d7 Update: deprecate `applyDefaultPatterns` in `line-comment-position` (#8183) (alberto)
|
12
|
+
* 25e5817 Fix: Don't autofix `+ +a` to `++a` in space-unary-ops (#8176) (Alan Pierce)
|
13
|
+
* a6ce8f9 Build: Sort rules before dumping them to doc files (#8154) (Danny Andrews)
|
14
|
+
* 0af9057 Chore: Upgrade to a patched version of mock-fs (fixes #8177) (#8188) (Teddy Katz)
|
15
|
+
* bf4d8cf Update: ignore eslint comments in lines-arount-comment (fixes #4345) (#8155) (alberto)
|
16
|
+
* dad20ad New: add SourceCode#getLocFromIndex and #getIndexFromLoc (fixes #8073) (#8158) (Teddy Katz)
|
17
|
+
* 18a519f Update: let RuleTester cases assert that no autofix occurs (fixes #8157) (#8163) (Teddy Katz)
|
18
|
+
* a30eb8d Docs: improve documentation for RuleTester cases (#8162) (Teddy Katz)
|
19
|
+
* a78ec9f Chore: upgrade `coveralls` to ^2.11.16 (#8161) (alberto)
|
20
|
+
* d02bd11 Fix: padded-blocks autofix problems with comments (#8149) (alberto)
|
21
|
+
* 9994889 Docs: Add missing space to `create` in `no-use-before-define` (#8166) (Justin Anastos)
|
22
|
+
* 4d542ba Docs: Remove unneeded statement about autofix (#8164) (alberto)
|
23
|
+
* 20daea5 New: no-compare-neg-zero rule (#8091) (薛定谔的猫)
|
24
|
+
* 4d35a81 Fix: Add a utility to avoid autofix conflicts (fixes #7928, fixes #8026) (#8067) (Alan Pierce)
|
25
|
+
* 287e882 New: nonblock-statement-body-position rule (fixes #6067) (#8108) (Teddy Katz)
|
26
|
+
* 7f1f4e5 Chore: remove unneeded devDeps `linefix` and `gh-got` (#8160) (alberto)
|
27
|
+
* ca1694b Update: ignore negative ranges in fixes (#8133) (alberto)
|
28
|
+
* 163d751 Docs: `lines-around-comment` doesn't disallow empty lines (#8151) (alberto)
|
29
|
+
* 1c84922 Chore: upgrade eslint-plugin-node (#8156) (alberto)
|
30
|
+
* 1ee5c27 Fix: Make RuleTester handle empty-string cases gracefully (fixes #8142) (#8143) (Teddy Katz)
|
31
|
+
* 044bc10 Docs: Add details about "--fix" option for "sort-imports" rule (#8077) (Olivier Audard)
|
32
|
+
* 3fec54a Add option to ignore property in no-param-reassign (#8087) (Christian Bundy)
|
33
|
+
* 4e52cfc Fix: Improve keyword-spacing typescript support (fixes #8110) (#8111) (Reyad Attiyat)
|
34
|
+
* 7ff42e8 New: Allow regexes in RuleTester (fixes #7837) (#8115) (Daniel Lo Nigro)
|
35
|
+
* cbd7ded Build: display rules’ meta data in their docs (fixes #5774) (#8127) (Wilson Kurniawan)
|
36
|
+
* da8e8af Update: include function name in report message if possible (fixes #7260) (#8058) (Dieter Luypaert)
|
37
|
+
* 8f91e32 Fix: `ignoreRestSiblings` option didn't cover arguments (fixes #8119) (#8120) (Toru Nagashima)
|
38
|
+
|
39
|
+
v3.16.1 - February 22, 2017
|
40
|
+
|
41
|
+
* ff8a80c Fix: duplicated autofix output for inverted fix ranges (fixes #8116) (#8117) (Teddy Katz)
|
42
|
+
* a421897 Docs: fix typo in arrow-parens.md (#8132) (Will Chen)
|
43
|
+
* 22d7fbf Chore: fix invalid redeclared variables in tests (#8130) (Teddy Katz)
|
44
|
+
* 8d95598 Chore: fix output assertion typos in rule tests (#8129) (Teddy Katz)
|
45
|
+
* 9fa2559 Docs: Add missing quotes in key-spacing rule (#8121) (Glenn Reyes)
|
46
|
+
* f3a6ced Build: package.json update for eslint-config-eslint release (ESLint Jenkins)
|
47
|
+
|
48
|
+
v3.16.0 - February 20, 2017
|
49
|
+
|
50
|
+
* d89d0b4 Update: fix quotes false negative for string literals as template tags (#8107) (Teddy Katz)
|
51
|
+
* 21be366 Chore: Ensuring eslint:recommended rules are sorted. (#8106) (Kevin Partington)
|
52
|
+
* 360dbe4 Update: Improve error message when extend config missing (fixes #6115) (#8100) (alberto)
|
53
|
+
* f62a724 Chore: use updated token iterator methods (#8103) (Kai Cataldo)
|
54
|
+
* daf6f26 Fix: check output in RuleTester when errors is a number (fixes #7640) (#8097) (alberto)
|
55
|
+
* cfb65c5 Update: make no-lone-blocks report blocks in switch cases (fixes #8047) (#8062) (Teddy Katz)
|
56
|
+
* 290fb1f Update: Add includeComments to getTokenByRangeStart (fixes #8068) (#8069) (Kai Cataldo)
|
57
|
+
* ff066dc Chore: Incorrect source code test text (#8096) (Jack Ford)
|
58
|
+
* 14d146d Docs: Clarify --ext only works with directories (fixes #7939) (#8095) (alberto)
|
59
|
+
* 013a454 Docs: Add TSC meeting quorum requirement (#8086) (Kevin Partington)
|
60
|
+
* 7516303 Fix: `sourceCode.getTokenAfter` shouldn't skip tokens after comments (#8055) (Toru Nagashima)
|
61
|
+
* c53e034 Fix: unicode-bom fixer insert BOM in appropriate location (fixes #8083) (#8084) (pantosha)
|
62
|
+
* 55ac302 Chore: fix the timing to define rules for tests (#8082) (Toru Nagashima)
|
63
|
+
* c7e64f3 Upgrade: mock-fs (#8070) (Toru Nagashima)
|
64
|
+
* acc3301 Update: handle uncommon linebreaks consistently in rules (fixes #7949) (#8049) (Teddy Katz)
|
65
|
+
* 591b74a Chore: enable operator-linebreak on ESLint codebase (#8064) (Teddy Katz)
|
66
|
+
* 6445d2a Docs: Add documentation for /* exported */ (fixes #7998) (#8065) (Lee Yi Min)
|
67
|
+
* fcc38db Chore: simplify and improve performance for autofix (#8035) (Toru Nagashima)
|
68
|
+
* b04fde7 Chore: improve performance of SourceCode constructor (#8054) (Teddy Katz)
|
69
|
+
* 90fd555 Update: improve null detection in eqeqeq for ES6 regexes (fixes #8020) (#8042) (Teddy Katz)
|
70
|
+
* 16248e2 Fix: no-extra-boolean-cast incorrect Boolean() autofixing (fixes #7977) (#8037) (Jonathan Wilsson)
|
71
|
+
* 834f45d Update: rewrite TokenStore (fixes #7810) (#7936) (Toru Nagashima)
|
72
|
+
* 329dcdc Chore: unify checks for statement list parents (#8048) (Teddy Katz)
|
73
|
+
* c596690 Docs: Clarify generator-star-spacing config example (fixes #8027) (#8034) (Hòa Trần)
|
74
|
+
* a11d4a6 Docs: fix a typo in shareable configs documentation (#8036) (Dan Homola)
|
75
|
+
* 1e3d4c6 Update: add fixer for no-unused-labels (#7841) (Teddy Katz)
|
76
|
+
* f47fb98 Update: ensure semi-spacing checks import/export declarations (#8033) (Teddy Katz)
|
77
|
+
* e228d56 Update: no-undefined handles properties/classes/modules (fixes #7964) (#7966) (Kevin Partington)
|
78
|
+
* 7bc92d9 Chore: fix invalid test cases (#8030) (Toru Nagashima)
|
79
|
+
|
1
80
|
v3.15.0 - February 3, 2017
|
2
81
|
|
3
82
|
* f2a3580 Fix: `no-extra-parens` incorrect precedence (fixes #7978) (#7999) (alberto)
|
@@ -1,7 +1,81 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
/**
|
2
|
+
* @fileoverview Configuration applied when a user configuration extends from
|
3
|
+
* eslint:recommended.
|
4
|
+
* @author Nicholas C. Zakas
|
5
|
+
*/
|
6
|
+
|
7
|
+
"use strict";
|
8
|
+
|
9
|
+
/* eslint sort-keys: ["error", "asc"], quote-props: ["error", "consistent"] */
|
10
|
+
/* eslint-disable sort-keys */
|
11
|
+
|
12
|
+
module.exports = {
|
13
|
+
parser: "espree",
|
14
|
+
ecmaFeatures: {},
|
15
|
+
|
16
|
+
rules: {
|
17
|
+
|
18
|
+
/* eslint-enable sort-keys */
|
19
|
+
"accessor-pairs": "off",
|
20
|
+
"array-bracket-spacing": "off",
|
21
|
+
"array-callback-return": "off",
|
22
|
+
"arrow-body-style": "off",
|
23
|
+
"arrow-parens": "off",
|
24
|
+
"arrow-spacing": "off",
|
25
|
+
"block-scoped-var": "off",
|
26
|
+
"block-spacing": "off",
|
27
|
+
"brace-style": "off",
|
28
|
+
"callback-return": "off",
|
29
|
+
"camelcase": "off",
|
30
|
+
"capitalized-comments": "off",
|
31
|
+
"class-methods-use-this": "off",
|
32
|
+
"comma-dangle": "off",
|
33
|
+
"comma-spacing": "off",
|
34
|
+
"comma-style": "off",
|
35
|
+
"complexity": "off",
|
36
|
+
"computed-property-spacing": "off",
|
37
|
+
"consistent-return": "off",
|
38
|
+
"consistent-this": "off",
|
39
|
+
"constructor-super": "error",
|
40
|
+
"curly": "off",
|
41
|
+
"default-case": "off",
|
42
|
+
"dot-location": "off",
|
43
|
+
"dot-notation": "off",
|
44
|
+
"eol-last": "off",
|
45
|
+
"eqeqeq": "off",
|
46
|
+
"func-call-spacing": "off",
|
47
|
+
"func-name-matching": "off",
|
48
|
+
"func-names": "off",
|
49
|
+
"func-style": "off",
|
50
|
+
"generator-star-spacing": "off",
|
51
|
+
"global-require": "off",
|
52
|
+
"guard-for-in": "off",
|
53
|
+
"handle-callback-err": "off",
|
54
|
+
"id-blacklist": "off",
|
55
|
+
"id-length": "off",
|
56
|
+
"id-match": "off",
|
57
|
+
"indent": "off",
|
58
|
+
"init-declarations": "off",
|
59
|
+
"jsx-quotes": "off",
|
60
|
+
"key-spacing": "off",
|
61
|
+
"keyword-spacing": "off",
|
62
|
+
"line-comment-position": "off",
|
63
|
+
"linebreak-style": "off",
|
64
|
+
"lines-around-comment": "off",
|
65
|
+
"lines-around-directive": "off",
|
66
|
+
"max-depth": "off",
|
67
|
+
"max-len": "off",
|
68
|
+
"max-lines": "off",
|
69
|
+
"max-nested-callbacks": "off",
|
70
|
+
"max-params": "off",
|
71
|
+
"max-statements": "off",
|
72
|
+
"max-statements-per-line": "off",
|
73
|
+
"multiline-ternary": "off",
|
74
|
+
"new-cap": "off",
|
75
|
+
"new-parens": "off",
|
76
|
+
"newline-after-var": "off",
|
77
|
+
"newline-before-return": "off",
|
78
|
+
"newline-per-chained-call": "off",
|
5
79
|
"no-alert": "off",
|
6
80
|
"no-array-constructor": "off",
|
7
81
|
"no-await-in-loop": "off",
|
@@ -10,6 +84,7 @@
|
|
10
84
|
"no-case-declarations": "error",
|
11
85
|
"no-catch-shadow": "off",
|
12
86
|
"no-class-assign": "error",
|
87
|
+
"no-compare-neg-zero": "off",
|
13
88
|
"no-cond-assign": "error",
|
14
89
|
"no-confusing-arrow": "off",
|
15
90
|
"no-console": "error",
|
@@ -100,20 +175,20 @@
|
|
100
175
|
"no-sequences": "off",
|
101
176
|
"no-shadow": "off",
|
102
177
|
"no-shadow-restricted-names": "off",
|
103
|
-
"no-whitespace-before-property": "off",
|
104
178
|
"no-spaced-func": "off",
|
105
179
|
"no-sparse-arrays": "error",
|
106
180
|
"no-sync": "off",
|
107
181
|
"no-tabs": "off",
|
182
|
+
"no-template-curly-in-string": "off",
|
108
183
|
"no-ternary": "off",
|
109
|
-
"no-trailing-spaces": "off",
|
110
184
|
"no-this-before-super": "error",
|
111
185
|
"no-throw-literal": "off",
|
186
|
+
"no-trailing-spaces": "off",
|
112
187
|
"no-undef": "error",
|
113
188
|
"no-undef-init": "off",
|
114
189
|
"no-undefined": "off",
|
115
|
-
"no-unexpected-multiline": "error",
|
116
190
|
"no-underscore-dangle": "off",
|
191
|
+
"no-unexpected-multiline": "error",
|
117
192
|
"no-unmodified-loop-condition": "off",
|
118
193
|
"no-unneeded-ternary": "off",
|
119
194
|
"no-unreachable": "error",
|
@@ -130,70 +205,12 @@
|
|
130
205
|
"no-useless-escape": "off",
|
131
206
|
"no-useless-rename": "off",
|
132
207
|
"no-useless-return": "off",
|
133
|
-
"no-void": "off",
|
134
208
|
"no-var": "off",
|
209
|
+
"no-void": "off",
|
135
210
|
"no-warning-comments": "off",
|
211
|
+
"no-whitespace-before-property": "off",
|
136
212
|
"no-with": "off",
|
137
|
-
"
|
138
|
-
"array-callback-return": "off",
|
139
|
-
"arrow-body-style": "off",
|
140
|
-
"arrow-parens": "off",
|
141
|
-
"arrow-spacing": "off",
|
142
|
-
"accessor-pairs": "off",
|
143
|
-
"block-scoped-var": "off",
|
144
|
-
"block-spacing": "off",
|
145
|
-
"brace-style": "off",
|
146
|
-
"callback-return": "off",
|
147
|
-
"camelcase": "off",
|
148
|
-
"capitalized-comments": "off",
|
149
|
-
"class-methods-use-this": "off",
|
150
|
-
"comma-dangle": "off",
|
151
|
-
"comma-spacing": "off",
|
152
|
-
"comma-style": "off",
|
153
|
-
"complexity": "off",
|
154
|
-
"computed-property-spacing": "off",
|
155
|
-
"consistent-return": "off",
|
156
|
-
"consistent-this": "off",
|
157
|
-
"constructor-super": "error",
|
158
|
-
"curly": "off",
|
159
|
-
"default-case": "off",
|
160
|
-
"dot-location": "off",
|
161
|
-
"dot-notation": "off",
|
162
|
-
"eol-last": "off",
|
163
|
-
"eqeqeq": "off",
|
164
|
-
"func-call-spacing": "off",
|
165
|
-
"func-names": "off",
|
166
|
-
"func-name-matching": "off",
|
167
|
-
"func-style": "off",
|
168
|
-
"generator-star-spacing": "off",
|
169
|
-
"global-require": "off",
|
170
|
-
"guard-for-in": "off",
|
171
|
-
"handle-callback-err": "off",
|
172
|
-
"id-blacklist": "off",
|
173
|
-
"id-length": "off",
|
174
|
-
"id-match": "off",
|
175
|
-
"indent": "off",
|
176
|
-
"init-declarations": "off",
|
177
|
-
"jsx-quotes": "off",
|
178
|
-
"key-spacing": "off",
|
179
|
-
"keyword-spacing": "off",
|
180
|
-
"linebreak-style": "off",
|
181
|
-
"line-comment-position": "off",
|
182
|
-
"lines-around-comment": "off",
|
183
|
-
"lines-around-directive": "off",
|
184
|
-
"max-depth": "off",
|
185
|
-
"max-len": "off",
|
186
|
-
"max-lines": "off",
|
187
|
-
"max-nested-callbacks": "off",
|
188
|
-
"max-params": "off",
|
189
|
-
"max-statements": "off",
|
190
|
-
"max-statements-per-line": "off",
|
191
|
-
"multiline-ternary": "off",
|
192
|
-
"new-cap": "off",
|
193
|
-
"new-parens": "off",
|
194
|
-
"newline-after-var": "off",
|
195
|
-
"newline-before-return": "off",
|
196
|
-
"newline-per-chained-call": "off",
|
213
|
+
"nonblock-statement-body-position": "off",
|
197
214
|
"object-curly-newline": "off",
|
198
215
|
"object-curly-spacing": ["off", "never"],
|
199
216
|
"object-property-newline": "off",
|
@@ -221,8 +238,8 @@
|
|
221
238
|
"rest-spread-spacing": "off",
|
222
239
|
"semi": "off",
|
223
240
|
"semi-spacing": "off",
|
224
|
-
"sort-keys": "off",
|
225
241
|
"sort-imports": "off",
|
242
|
+
"sort-keys": "off",
|
226
243
|
"sort-vars": "off",
|
227
244
|
"space-before-blocks": "off",
|
228
245
|
"space-before-function-paren": "off",
|
@@ -241,8 +258,7 @@
|
|
241
258
|
"vars-on-top": "off",
|
242
259
|
"wrap-iife": "off",
|
243
260
|
"wrap-regex": "off",
|
244
|
-
"no-template-curly-in-string": "off",
|
245
261
|
"yield-star-spacing": "off",
|
246
262
|
"yoda": "off"
|
247
263
|
}
|
248
|
-
}
|
264
|
+
};
|
package/lib/ast-utils.js
CHANGED
@@ -10,7 +10,6 @@
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const esutils = require("esutils");
|
13
|
-
const lodash = require("lodash");
|
14
13
|
|
15
14
|
//------------------------------------------------------------------------------
|
16
15
|
// Helpers
|
@@ -24,6 +23,14 @@ const bindOrCallOrApplyPattern = /^(?:bind|call|apply)$/;
|
|
24
23
|
const breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/;
|
25
24
|
const thisTagPattern = /^[\s*]*@this/m;
|
26
25
|
|
26
|
+
|
27
|
+
const COMMENTS_IGNORE_PATTERN = /^\s*(?:eslint|jshint\s+|jslint\s+|istanbul\s+|globals?\s+|exported\s+|jscs)/;
|
28
|
+
const LINEBREAKS = new Set(["\r\n", "\r", "\n", "\u2028", "\u2029"]);
|
29
|
+
const LINEBREAK_MATCHER = /\r\n|[\r\n\u2028\u2029]/;
|
30
|
+
|
31
|
+
// A set of node types that can contain a list of statements
|
32
|
+
const STATEMENT_LIST_PARENTS = new Set(["Program", "BlockStatement", "SwitchCase"]);
|
33
|
+
|
27
34
|
/**
|
28
35
|
* Checks reference if is non initializer and writable.
|
29
36
|
* @param {Reference} reference - A reference to check.
|
@@ -142,7 +149,7 @@ function isInLoop(node) {
|
|
142
149
|
*/
|
143
150
|
function isNullOrUndefined(node) {
|
144
151
|
return (
|
145
|
-
(node
|
152
|
+
module.exports.isNullLiteral(node) ||
|
146
153
|
(node.type === "Identifier" && node.name === "undefined") ||
|
147
154
|
(node.type === "UnaryExpression" && node.operator === "void")
|
148
155
|
);
|
@@ -210,6 +217,15 @@ function isMethodWhichHasThisArg(node) {
|
|
210
217
|
return false;
|
211
218
|
}
|
212
219
|
|
220
|
+
/**
|
221
|
+
* Creates the negate function of the given function.
|
222
|
+
* @param {Function} f - The function to negate.
|
223
|
+
* @returns {Function} Negated function.
|
224
|
+
*/
|
225
|
+
function negate(f) {
|
226
|
+
return token => !f(token);
|
227
|
+
}
|
228
|
+
|
213
229
|
/**
|
214
230
|
* Checks whether or not a node has a `@this` tag in its comments.
|
215
231
|
* @param {ASTNode} node - A node to check.
|
@@ -247,71 +263,145 @@ function isParenthesised(sourceCode, node) {
|
|
247
263
|
}
|
248
264
|
|
249
265
|
/**
|
250
|
-
*
|
266
|
+
* Checks if the given token is an arrow token or not.
|
251
267
|
*
|
252
|
-
* @param {
|
253
|
-
* @
|
254
|
-
* @returns {Token} `=>` token.
|
268
|
+
* @param {Token} token - The token to check.
|
269
|
+
* @returns {boolean} `true` if the token is an arrow token.
|
255
270
|
*/
|
256
|
-
function
|
257
|
-
|
271
|
+
function isArrowToken(token) {
|
272
|
+
return token.value === "=>" && token.type === "Punctuator";
|
273
|
+
}
|
258
274
|
|
259
|
-
|
260
|
-
|
261
|
-
|
275
|
+
/**
|
276
|
+
* Checks if the given token is a comma token or not.
|
277
|
+
*
|
278
|
+
* @param {Token} token - The token to check.
|
279
|
+
* @returns {boolean} `true` if the token is a comma token.
|
280
|
+
*/
|
281
|
+
function isCommaToken(token) {
|
282
|
+
return token.value === "," && token.type === "Punctuator";
|
283
|
+
}
|
262
284
|
|
263
|
-
|
285
|
+
/**
|
286
|
+
* Checks if the given token is a semicolon token or not.
|
287
|
+
*
|
288
|
+
* @param {Token} token - The token to check.
|
289
|
+
* @returns {boolean} `true` if the token is a semicolon token.
|
290
|
+
*/
|
291
|
+
function isSemicolonToken(token) {
|
292
|
+
return token.value === ";" && token.type === "Punctuator";
|
264
293
|
}
|
265
294
|
|
266
295
|
/**
|
267
|
-
*
|
296
|
+
* Checks if the given token is a colon token or not.
|
268
297
|
*
|
269
|
-
* @param {
|
270
|
-
* @
|
271
|
-
* @returns {Token} `(` token.
|
298
|
+
* @param {Token} token - The token to check.
|
299
|
+
* @returns {boolean} `true` if the token is a colon token.
|
272
300
|
*/
|
273
|
-
function
|
274
|
-
|
301
|
+
function isColonToken(token) {
|
302
|
+
return token.value === ":" && token.type === "Punctuator";
|
303
|
+
}
|
275
304
|
|
276
|
-
|
277
|
-
|
278
|
-
|
305
|
+
/**
|
306
|
+
* Checks if the given token is an opening parenthesis token or not.
|
307
|
+
*
|
308
|
+
* @param {Token} token - The token to check.
|
309
|
+
* @returns {boolean} `true` if the token is an opening parenthesis token.
|
310
|
+
*/
|
311
|
+
function isOpeningParenToken(token) {
|
312
|
+
return token.value === "(" && token.type === "Punctuator";
|
313
|
+
}
|
279
314
|
|
280
|
-
|
315
|
+
/**
|
316
|
+
* Checks if the given token is a closing parenthesis token or not.
|
317
|
+
*
|
318
|
+
* @param {Token} token - The token to check.
|
319
|
+
* @returns {boolean} `true` if the token is a closing parenthesis token.
|
320
|
+
*/
|
321
|
+
function isClosingParenToken(token) {
|
322
|
+
return token.value === ")" && token.type === "Punctuator";
|
281
323
|
}
|
282
324
|
|
283
|
-
|
325
|
+
/**
|
326
|
+
* Checks if the given token is an opening square bracket token or not.
|
327
|
+
*
|
328
|
+
* @param {Token} token - The token to check.
|
329
|
+
* @returns {boolean} `true` if the token is an opening square bracket token.
|
330
|
+
*/
|
331
|
+
function isOpeningBracketToken(token) {
|
332
|
+
return token.value === "[" && token.type === "Punctuator";
|
333
|
+
}
|
284
334
|
|
285
335
|
/**
|
286
|
-
*
|
287
|
-
*
|
288
|
-
* @
|
336
|
+
* Checks if the given token is a closing square bracket token or not.
|
337
|
+
*
|
338
|
+
* @param {Token} token - The token to check.
|
339
|
+
* @returns {boolean} `true` if the token is a closing square bracket token.
|
289
340
|
*/
|
290
|
-
function
|
341
|
+
function isClosingBracketToken(token) {
|
342
|
+
return token.value === "]" && token.type === "Punctuator";
|
343
|
+
}
|
291
344
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
345
|
+
/**
|
346
|
+
* Checks if the given token is an opening brace token or not.
|
347
|
+
*
|
348
|
+
* @param {Token} token - The token to check.
|
349
|
+
* @returns {boolean} `true` if the token is an opening brace token.
|
350
|
+
*/
|
351
|
+
function isOpeningBraceToken(token) {
|
352
|
+
return token.value === "{" && token.type === "Punctuator";
|
353
|
+
}
|
296
354
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
355
|
+
/**
|
356
|
+
* Checks if the given token is a closing brace token or not.
|
357
|
+
*
|
358
|
+
* @param {Token} token - The token to check.
|
359
|
+
* @returns {boolean} `true` if the token is a closing brace token.
|
360
|
+
*/
|
361
|
+
function isClosingBraceToken(token) {
|
362
|
+
return token.value === "}" && token.type === "Punctuator";
|
363
|
+
}
|
306
364
|
|
307
|
-
|
308
|
-
|
309
|
-
|
365
|
+
/**
|
366
|
+
* Checks if the given token is a comment token or not.
|
367
|
+
*
|
368
|
+
* @param {Token} token - The token to check.
|
369
|
+
* @returns {boolean} `true` if the token is a comment token.
|
370
|
+
*/
|
371
|
+
function isCommentToken(token) {
|
372
|
+
return token.type === "Line" || token.type === "Block" || token.type === "Shebang";
|
373
|
+
}
|
310
374
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
375
|
+
/**
|
376
|
+
* Checks if the given token is a keyword token or not.
|
377
|
+
*
|
378
|
+
* @param {Token} token - The token to check.
|
379
|
+
* @returns {boolean} `true` if the token is a keyword token.
|
380
|
+
*/
|
381
|
+
function isKeywordToken(token) {
|
382
|
+
return token.type === "Keyword";
|
383
|
+
}
|
384
|
+
|
385
|
+
/**
|
386
|
+
* Gets the `(` token of the given function node.
|
387
|
+
*
|
388
|
+
* @param {ASTNode} node - The function node to get.
|
389
|
+
* @param {SourceCode} sourceCode - The source code object to get tokens.
|
390
|
+
* @returns {Token} `(` token.
|
391
|
+
*/
|
392
|
+
function getOpeningParenOfParams(node, sourceCode) {
|
393
|
+
return node.id
|
394
|
+
? sourceCode.getTokenAfter(node.id, isOpeningParenToken)
|
395
|
+
: sourceCode.getFirstToken(node, isOpeningParenToken);
|
396
|
+
}
|
397
|
+
|
398
|
+
/**
|
399
|
+
* Creates a version of the LINEBREAK_MATCHER regex with the global flag.
|
400
|
+
* Global regexes are mutable, so this needs to be a function instead of a constant.
|
401
|
+
* @returns {RegExp} A global regular expression that matches line terminators
|
402
|
+
*/
|
403
|
+
function createGlobalLinebreakMatcher() {
|
404
|
+
return new RegExp(LINEBREAK_MATCHER.source, "g");
|
315
405
|
}
|
316
406
|
|
317
407
|
//------------------------------------------------------------------------------
|
@@ -319,6 +409,10 @@ function getLineIndices(sourceCode) {
|
|
319
409
|
//------------------------------------------------------------------------------
|
320
410
|
|
321
411
|
module.exports = {
|
412
|
+
COMMENTS_IGNORE_PATTERN,
|
413
|
+
LINEBREAKS,
|
414
|
+
LINEBREAK_MATCHER,
|
415
|
+
STATEMENT_LIST_PARENTS,
|
322
416
|
|
323
417
|
/**
|
324
418
|
* Determines whether two adjacent tokens are on the same line.
|
@@ -340,6 +434,29 @@ module.exports = {
|
|
340
434
|
isInLoop,
|
341
435
|
isArrayFromMethod,
|
342
436
|
isParenthesised,
|
437
|
+
createGlobalLinebreakMatcher,
|
438
|
+
|
439
|
+
isArrowToken,
|
440
|
+
isClosingBraceToken,
|
441
|
+
isClosingBracketToken,
|
442
|
+
isClosingParenToken,
|
443
|
+
isColonToken,
|
444
|
+
isCommaToken,
|
445
|
+
isCommentToken,
|
446
|
+
isKeywordToken,
|
447
|
+
isNotClosingBraceToken: negate(isClosingBraceToken),
|
448
|
+
isNotClosingBracketToken: negate(isClosingBracketToken),
|
449
|
+
isNotClosingParenToken: negate(isClosingParenToken),
|
450
|
+
isNotColonToken: negate(isColonToken),
|
451
|
+
isNotCommaToken: negate(isCommaToken),
|
452
|
+
isNotOpeningBraceToken: negate(isOpeningBraceToken),
|
453
|
+
isNotOpeningBracketToken: negate(isOpeningBracketToken),
|
454
|
+
isNotOpeningParenToken: negate(isOpeningParenToken),
|
455
|
+
isNotSemicolonToken: negate(isSemicolonToken),
|
456
|
+
isOpeningBraceToken,
|
457
|
+
isOpeningBracketToken,
|
458
|
+
isOpeningParenToken,
|
459
|
+
isSemicolonToken,
|
343
460
|
|
344
461
|
/**
|
345
462
|
* Checks whether or not a given node is a string literal.
|
@@ -1040,7 +1157,7 @@ module.exports = {
|
|
1040
1157
|
let end = null;
|
1041
1158
|
|
1042
1159
|
if (node.type === "ArrowFunctionExpression") {
|
1043
|
-
const arrowToken =
|
1160
|
+
const arrowToken = sourceCode.getTokenBefore(node.body, isArrowToken);
|
1044
1161
|
|
1045
1162
|
start = arrowToken.loc.start;
|
1046
1163
|
end = arrowToken.loc.end;
|
@@ -1058,38 +1175,6 @@ module.exports = {
|
|
1058
1175
|
};
|
1059
1176
|
},
|
1060
1177
|
|
1061
|
-
/*
|
1062
|
-
* Converts a range index into a (line, column) pair.
|
1063
|
-
* @param {SourceCode} sourceCode A SourceCode object
|
1064
|
-
* @param {number} rangeIndex The range index of a character in a file
|
1065
|
-
* @returns {Object} A {line, column} location object with a 0-indexed column
|
1066
|
-
*/
|
1067
|
-
getLocationFromRangeIndex(sourceCode, rangeIndex) {
|
1068
|
-
const lineIndices = getLineIndices(sourceCode);
|
1069
|
-
|
1070
|
-
/*
|
1071
|
-
* lineIndices is a sorted list of indices of the first character of each line.
|
1072
|
-
* To figure out which line rangeIndex is on, determine the last index at which rangeIndex could
|
1073
|
-
* be inserted into lineIndices to keep the list sorted.
|
1074
|
-
*/
|
1075
|
-
const lineNumber = lodash.sortedLastIndex(lineIndices, rangeIndex);
|
1076
|
-
|
1077
|
-
return { line: lineNumber, column: rangeIndex - lineIndices[lineNumber - 1] };
|
1078
|
-
|
1079
|
-
},
|
1080
|
-
|
1081
|
-
/**
|
1082
|
-
* Converts a (line, column) pair into a range index.
|
1083
|
-
* @param {SourceCode} sourceCode A SourceCode object
|
1084
|
-
* @param {Object} loc A line/column location
|
1085
|
-
* @param {number} loc.line The line number of the location (1-indexed)
|
1086
|
-
* @param {number} loc.column The column number of the location (0-indexed)
|
1087
|
-
* @returns {number} The range index of the location in the file.
|
1088
|
-
*/
|
1089
|
-
getRangeIndexFromLocation(sourceCode, loc) {
|
1090
|
-
return getLineIndices(sourceCode)[loc.line - 1] + loc.column;
|
1091
|
-
},
|
1092
|
-
|
1093
1178
|
/**
|
1094
1179
|
* Gets the parenthesized text of a node. This is similar to sourceCode.getText(node), but it also includes any parentheses
|
1095
1180
|
* surrounding the node.
|
@@ -1150,5 +1235,22 @@ module.exports = {
|
|
1150
1235
|
default:
|
1151
1236
|
return false;
|
1152
1237
|
}
|
1238
|
+
},
|
1239
|
+
|
1240
|
+
/**
|
1241
|
+
* Determines whether the given node is a `null` literal.
|
1242
|
+
* @param {ASTNode} node The node to check
|
1243
|
+
* @returns {boolean} `true` if the node is a `null` literal
|
1244
|
+
*/
|
1245
|
+
isNullLiteral(node) {
|
1246
|
+
|
1247
|
+
/*
|
1248
|
+
* Checking `node.value === null` does not guarantee that a literal is a null literal.
|
1249
|
+
* When parsing values that cannot be represented in the current environment (e.g. unicode
|
1250
|
+
* regexes in Node 4), `node.value` is set to `null` because it wouldn't be possible to
|
1251
|
+
* set `node.value` to a unicode regex. To make sure a literal is actually `null`, check
|
1252
|
+
* `node.regex` instead. Also see: https://github.com/eslint/eslint/issues/8020
|
1253
|
+
*/
|
1254
|
+
return node.type === "Literal" && node.value === null && !node.regex;
|
1153
1255
|
}
|
1154
1256
|
};
|
@@ -467,8 +467,8 @@ class CodePathState {
|
|
467
467
|
* Creates the next path from own true/false fork context.
|
468
468
|
*/
|
469
469
|
const prevForkContext =
|
470
|
-
context.kind === "&&" ? context.trueForkContext
|
471
|
-
/* kind === "||" */ context.falseForkContext;
|
470
|
+
context.kind === "&&" ? context.trueForkContext
|
471
|
+
/* kind === "||" */ : context.falseForkContext;
|
472
472
|
|
473
473
|
forkContext.replaceHead(prevForkContext.makeNext(0, -1));
|
474
474
|
prevForkContext.clear();
|