eslint 6.5.0 → 6.7.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 +115 -0
- package/README.md +10 -9
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/cascading-config-array-factory.js +40 -14
- package/lib/cli-engine/cli-engine.js +49 -21
- package/lib/cli-engine/config-array/config-array.js +13 -4
- package/lib/cli-engine/config-array/config-dependency.js +2 -0
- package/lib/cli-engine/config-array/extracted-config.js +27 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
- package/lib/cli-engine/config-array/index.js +2 -0
- package/lib/cli-engine/config-array/override-tester.js +2 -0
- package/lib/cli-engine/config-array-factory.js +120 -2
- package/lib/cli-engine/file-enumerator.js +51 -30
- package/lib/cli-engine/formatters/html.js +1 -0
- package/lib/init/autoconfig.js +1 -11
- package/lib/init/config-file.js +0 -1
- package/lib/init/config-initializer.js +4 -4
- package/lib/init/config-rule.js +1 -5
- package/lib/init/npm-utils.js +0 -5
- package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
- package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
- package/lib/linter/code-path-analysis/code-path-state.js +40 -81
- package/lib/linter/code-path-analysis/code-path.js +10 -11
- package/lib/linter/code-path-analysis/debug-helpers.js +8 -12
- package/lib/linter/code-path-analysis/fork-context.js +23 -34
- package/lib/linter/code-path-analysis/id-generator.js +2 -2
- package/lib/linter/linter.js +121 -95
- package/lib/linter/node-event-generator.js +3 -2
- package/lib/linter/report-translator.js +73 -7
- package/lib/rule-tester/rule-tester.js +46 -14
- package/lib/rules/accessor-pairs.js +8 -8
- package/lib/rules/array-bracket-newline.js +12 -15
- package/lib/rules/array-bracket-spacing.js +12 -12
- package/lib/rules/array-callback-return.js +6 -11
- package/lib/rules/array-element-newline.js +5 -8
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/block-scoped-var.js +3 -3
- package/lib/rules/block-spacing.js +4 -4
- package/lib/rules/camelcase.js +19 -6
- package/lib/rules/capitalized-comments.js +0 -7
- package/lib/rules/class-methods-use-this.js +3 -3
- package/lib/rules/comma-dangle.js +20 -25
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/computed-property-spacing.js +14 -14
- package/lib/rules/consistent-return.js +4 -5
- package/lib/rules/consistent-this.js +5 -5
- package/lib/rules/constructor-super.js +14 -16
- package/lib/rules/curly.js +12 -9
- package/lib/rules/default-param-last.js +1 -0
- package/lib/rules/dot-location.js +11 -12
- package/lib/rules/func-names.js +6 -6
- package/lib/rules/function-call-argument-newline.js +8 -6
- package/lib/rules/generator-star-spacing.js +4 -9
- package/lib/rules/getter-return.js +4 -7
- package/lib/rules/grouped-accessor-pairs.js +224 -0
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +5 -0
- package/lib/rules/init-declarations.js +2 -2
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/keyword-spacing.js +32 -56
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/max-len.js +0 -5
- package/lib/rules/max-statements-per-line.js +3 -7
- package/lib/rules/multiline-comment-style.js +237 -106
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/newline-after-var.js +6 -7
- package/lib/rules/newline-before-return.js +8 -9
- package/lib/rules/newline-per-chained-call.js +2 -4
- package/lib/rules/no-class-assign.js +2 -2
- package/lib/rules/no-compare-neg-zero.js +1 -2
- package/lib/rules/no-cond-assign.js +14 -4
- package/lib/rules/no-confusing-arrow.js +2 -2
- package/lib/rules/no-console.js +4 -8
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constructor-return.js +62 -0
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +3 -4
- package/lib/rules/no-dupe-else-if.js +122 -0
- package/lib/rules/no-dupe-keys.js +6 -5
- package/lib/rules/no-duplicate-imports.js +14 -18
- package/lib/rules/no-else-return.js +0 -8
- package/lib/rules/no-empty-function.js +2 -4
- package/lib/rules/no-eval.js +10 -18
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extra-bind.js +5 -12
- package/lib/rules/no-extra-boolean-cast.js +0 -2
- package/lib/rules/no-extra-label.js +4 -9
- package/lib/rules/no-extra-parens.js +17 -15
- package/lib/rules/no-extra-semi.js +5 -6
- package/lib/rules/no-fallthrough.js +6 -6
- package/lib/rules/no-func-assign.js +3 -3
- package/lib/rules/no-global-assign.js +4 -4
- package/lib/rules/no-implicit-coercion.js +10 -10
- package/lib/rules/no-implicit-globals.js +90 -8
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-inline-comments.js +25 -11
- package/lib/rules/no-invalid-this.js +17 -5
- package/lib/rules/no-labels.js +3 -6
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-loop-func.js +6 -11
- package/lib/rules/no-magic-numbers.js +6 -6
- package/lib/rules/no-misleading-character-class.js +14 -7
- package/lib/rules/no-mixed-operators.js +13 -22
- package/lib/rules/no-mixed-requires.js +0 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-native-reassign.js +4 -4
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-param-reassign.js +28 -7
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-imports.js +11 -11
- package/lib/rules/no-self-assign.js +12 -13
- package/lib/rules/no-sequences.js +3 -3
- package/lib/rules/no-setter-return.js +227 -0
- package/lib/rules/no-shadow.js +1 -4
- package/lib/rules/no-tabs.js +8 -2
- package/lib/rules/no-this-before-super.js +12 -13
- package/lib/rules/no-trailing-spaces.js +19 -7
- package/lib/rules/no-underscore-dangle.js +23 -4
- package/lib/rules/no-unmodified-loop-condition.js +16 -29
- package/lib/rules/no-unneeded-ternary.js +3 -3
- package/lib/rules/no-unreachable.js +7 -7
- package/lib/rules/no-unsafe-finally.js +4 -7
- package/lib/rules/no-unsafe-negation.js +32 -9
- package/lib/rules/no-unused-expressions.js +11 -7
- package/lib/rules/no-unused-labels.js +3 -6
- package/lib/rules/no-unused-vars.js +22 -29
- package/lib/rules/no-use-before-define.js +10 -15
- package/lib/rules/no-useless-call.js +4 -4
- package/lib/rules/no-useless-computed-key.js +60 -33
- package/lib/rules/no-useless-concat.js +4 -4
- package/lib/rules/no-useless-constructor.js +14 -22
- package/lib/rules/no-useless-escape.js +29 -8
- package/lib/rules/no-useless-rename.js +15 -7
- package/lib/rules/no-useless-return.js +8 -15
- package/lib/rules/no-var.js +12 -25
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +3 -3
- package/lib/rules/object-curly-newline.js +7 -10
- package/lib/rules/object-curly-spacing.js +21 -22
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +2 -2
- package/lib/rules/operator-assignment.js +33 -3
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -16
- package/lib/rules/prefer-arrow-callback.js +6 -6
- package/lib/rules/prefer-const.js +27 -28
- package/lib/rules/prefer-destructuring.js +1 -7
- package/lib/rules/prefer-exponentiation-operator.js +189 -0
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +32 -4
- package/lib/rules/prefer-object-spread.js +7 -7
- package/lib/rules/prefer-rest-params.js +3 -6
- package/lib/rules/prefer-spread.js +4 -4
- package/lib/rules/prefer-template.js +5 -6
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +5 -6
- package/lib/rules/radix.js +5 -10
- package/lib/rules/require-await.js +10 -5
- package/lib/rules/require-yield.js +2 -2
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi.js +6 -3
- package/lib/rules/sort-imports.js +3 -4
- package/lib/rules/sort-keys.js +1 -3
- package/lib/rules/space-before-blocks.js +1 -2
- package/lib/rules/space-in-parens.js +4 -4
- package/lib/rules/space-infix-ops.js +6 -6
- package/lib/rules/spaced-comment.js +20 -22
- package/lib/rules/strict.js +2 -4
- package/lib/rules/symbol-description.js +1 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +40 -3
- package/lib/rules/utils/ast-utils.js +84 -85
- package/lib/rules/utils/fix-tracker.js +0 -6
- package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
- package/lib/rules/vars-on-top.js +11 -11
- package/lib/shared/config-ops.js +2 -2
- package/lib/shared/runtime-info.js +8 -8
- package/lib/shared/traverser.js +2 -0
- package/lib/shared/types.js +9 -0
- package/lib/source-code/source-code.js +62 -17
- package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/backward-token-cursor.js +5 -5
- package/lib/source-code/token-store/cursors.js +17 -19
- package/lib/source-code/token-store/decorative-cursor.js +1 -1
- package/lib/source-code/token-store/filter-cursor.js +2 -2
- package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
- package/lib/source-code/token-store/forward-token-cursor.js +5 -5
- package/lib/source-code/token-store/index.js +86 -92
- package/lib/source-code/token-store/limit-cursor.js +2 -2
- package/lib/source-code/token-store/padded-token-cursor.js +7 -7
- package/lib/source-code/token-store/skip-cursor.js +2 -2
- package/lib/source-code/token-store/utils.js +9 -13
- package/package.json +9 -7
- package/lib/cli-engine/ignored-paths.js +0 -362
@@ -17,8 +17,7 @@ const debug = require("./debug-helpers");
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Checks whether or not a given segment is reachable.
|
20
|
-
*
|
21
|
-
* @param {CodePathSegment} segment - A segment to check.
|
20
|
+
* @param {CodePathSegment} segment A segment to check.
|
22
21
|
* @returns {boolean} `true` if the segment is reachable.
|
23
22
|
*/
|
24
23
|
function isReachable(segment) {
|
@@ -34,11 +33,12 @@ function isReachable(segment) {
|
|
34
33
|
*/
|
35
34
|
class CodePathSegment {
|
36
35
|
|
36
|
+
// eslint-disable-next-line jsdoc/require-description
|
37
37
|
/**
|
38
|
-
* @param {string} id
|
39
|
-
* @param {CodePathSegment[]} allPrevSegments
|
38
|
+
* @param {string} id An identifier.
|
39
|
+
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
|
40
40
|
* This array includes unreachable segments.
|
41
|
-
* @param {boolean} reachable
|
41
|
+
* @param {boolean} reachable A flag which shows this is reachable.
|
42
42
|
*/
|
43
43
|
constructor(id, allPrevSegments, reachable) {
|
44
44
|
|
@@ -98,8 +98,7 @@ class CodePathSegment {
|
|
98
98
|
|
99
99
|
/**
|
100
100
|
* Checks a given previous segment is coming from the end of a loop.
|
101
|
-
*
|
102
|
-
* @param {CodePathSegment} segment - A previous segment to check.
|
101
|
+
* @param {CodePathSegment} segment A previous segment to check.
|
103
102
|
* @returns {boolean} `true` if the segment is coming from the end of a loop.
|
104
103
|
*/
|
105
104
|
isLoopedPrevSegment(segment) {
|
@@ -108,8 +107,7 @@ class CodePathSegment {
|
|
108
107
|
|
109
108
|
/**
|
110
109
|
* Creates the root segment.
|
111
|
-
*
|
112
|
-
* @param {string} id - An identifier.
|
110
|
+
* @param {string} id An identifier.
|
113
111
|
* @returns {CodePathSegment} The created segment.
|
114
112
|
*/
|
115
113
|
static newRoot(id) {
|
@@ -118,9 +116,8 @@ class CodePathSegment {
|
|
118
116
|
|
119
117
|
/**
|
120
118
|
* Creates a segment that follows given segments.
|
121
|
-
*
|
122
|
-
* @param {
|
123
|
-
* @param {CodePathSegment[]} allPrevSegments - An array of the previous segments.
|
119
|
+
* @param {string} id An identifier.
|
120
|
+
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
|
124
121
|
* @returns {CodePathSegment} The created segment.
|
125
122
|
*/
|
126
123
|
static newNext(id, allPrevSegments) {
|
@@ -133,9 +130,8 @@ class CodePathSegment {
|
|
133
130
|
|
134
131
|
/**
|
135
132
|
* Creates an unreachable segment that follows given segments.
|
136
|
-
*
|
137
|
-
* @param {
|
138
|
-
* @param {CodePathSegment[]} allPrevSegments - An array of the previous segments.
|
133
|
+
* @param {string} id An identifier.
|
134
|
+
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
|
139
135
|
* @returns {CodePathSegment} The created segment.
|
140
136
|
*/
|
141
137
|
static newUnreachable(id, allPrevSegments) {
|
@@ -154,9 +150,8 @@ class CodePathSegment {
|
|
154
150
|
* Creates a segment that follows given segments.
|
155
151
|
* This factory method does not connect with `allPrevSegments`.
|
156
152
|
* But this inherits `reachable` flag.
|
157
|
-
*
|
158
|
-
* @param {
|
159
|
-
* @param {CodePathSegment[]} allPrevSegments - An array of the previous segments.
|
153
|
+
* @param {string} id An identifier.
|
154
|
+
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
|
160
155
|
* @returns {CodePathSegment} The created segment.
|
161
156
|
*/
|
162
157
|
static newDisconnected(id, allPrevSegments) {
|
@@ -167,8 +162,7 @@ class CodePathSegment {
|
|
167
162
|
* Makes a given segment being used.
|
168
163
|
*
|
169
164
|
* And this function registers the segment into the previous segments as a next.
|
170
|
-
*
|
171
|
-
* @param {CodePathSegment} segment - A segment to mark.
|
165
|
+
* @param {CodePathSegment} segment A segment to mark.
|
172
166
|
* @returns {void}
|
173
167
|
*/
|
174
168
|
static markUsed(segment) {
|
@@ -195,9 +189,8 @@ class CodePathSegment {
|
|
195
189
|
|
196
190
|
/**
|
197
191
|
* Marks a previous segment as looped.
|
198
|
-
*
|
199
|
-
* @param {CodePathSegment}
|
200
|
-
* @param {CodePathSegment} prevSegment - A previous segment to mark.
|
192
|
+
* @param {CodePathSegment} segment A segment.
|
193
|
+
* @param {CodePathSegment} prevSegment A previous segment to mark.
|
201
194
|
* @returns {void}
|
202
195
|
*/
|
203
196
|
static markPrevSegmentAsLooped(segment, prevSegment) {
|
@@ -206,8 +199,7 @@ class CodePathSegment {
|
|
206
199
|
|
207
200
|
/**
|
208
201
|
* Replaces unused segments with the previous segments of each unused segment.
|
209
|
-
*
|
210
|
-
* @param {CodePathSegment[]} segments - An array of segments to replace.
|
202
|
+
* @param {CodePathSegment[]} segments An array of segments to replace.
|
211
203
|
* @returns {CodePathSegment[]} The replaced array.
|
212
204
|
*/
|
213
205
|
static flattenUnusedSegments(segments) {
|
@@ -22,11 +22,10 @@ const CodePathSegment = require("./code-path-segment"),
|
|
22
22
|
* array as well.
|
23
23
|
*
|
24
24
|
* This adds only reachable and used segments.
|
25
|
-
*
|
26
|
-
* @param {CodePathSegment[]}
|
27
|
-
* @param {CodePathSegment[]}
|
28
|
-
* @param {CodePathSegment[]}
|
29
|
-
* @param {CodePathSegment[]} segments - Segments to add.
|
25
|
+
* @param {CodePathSegment[]} dest A destination array (`returnedSegments` or `thrownSegments`).
|
26
|
+
* @param {CodePathSegment[]} others Another destination array (`returnedSegments` or `thrownSegments`).
|
27
|
+
* @param {CodePathSegment[]} all The unified destination array (`finalSegments`).
|
28
|
+
* @param {CodePathSegment[]} segments Segments to add.
|
30
29
|
* @returns {void}
|
31
30
|
*/
|
32
31
|
function addToReturnedOrThrown(dest, others, all, segments) {
|
@@ -42,9 +41,8 @@ function addToReturnedOrThrown(dest, others, all, segments) {
|
|
42
41
|
|
43
42
|
/**
|
44
43
|
* Gets a loop-context for a `continue` statement.
|
45
|
-
*
|
46
|
-
* @param {
|
47
|
-
* @param {string} label - The label of a `continue` statement.
|
44
|
+
* @param {CodePathState} state A state to get.
|
45
|
+
* @param {string} label The label of a `continue` statement.
|
48
46
|
* @returns {LoopContext} A loop-context for a `continue` statement.
|
49
47
|
*/
|
50
48
|
function getContinueContext(state, label) {
|
@@ -67,9 +65,8 @@ function getContinueContext(state, label) {
|
|
67
65
|
|
68
66
|
/**
|
69
67
|
* Gets a context for a `break` statement.
|
70
|
-
*
|
71
|
-
* @param {
|
72
|
-
* @param {string} label - The label of a `break` statement.
|
68
|
+
* @param {CodePathState} state A state to get.
|
69
|
+
* @param {string} label The label of a `break` statement.
|
73
70
|
* @returns {LoopContext|SwitchContext} A context for a `break` statement.
|
74
71
|
*/
|
75
72
|
function getBreakContext(state, label) {
|
@@ -88,8 +85,7 @@ function getBreakContext(state, label) {
|
|
88
85
|
|
89
86
|
/**
|
90
87
|
* Gets a context for a `return` statement.
|
91
|
-
*
|
92
|
-
* @param {CodePathState} state - A state to get.
|
88
|
+
* @param {CodePathState} state A state to get.
|
93
89
|
* @returns {TryContext|CodePathState} A context for a `return` statement.
|
94
90
|
*/
|
95
91
|
function getReturnContext(state) {
|
@@ -107,8 +103,7 @@ function getReturnContext(state) {
|
|
107
103
|
|
108
104
|
/**
|
109
105
|
* Gets a context for a `throw` statement.
|
110
|
-
*
|
111
|
-
* @param {CodePathState} state - A state to get.
|
106
|
+
* @param {CodePathState} state A state to get.
|
112
107
|
* @returns {TryContext|CodePathState} A context for a `throw` statement.
|
113
108
|
*/
|
114
109
|
function getThrowContext(state) {
|
@@ -128,9 +123,8 @@ function getThrowContext(state) {
|
|
128
123
|
|
129
124
|
/**
|
130
125
|
* Removes a given element from a given array.
|
131
|
-
*
|
132
|
-
* @param {any
|
133
|
-
* @param {any} x - An element to be removed.
|
126
|
+
* @param {any[]} xs An array to remove the specific element.
|
127
|
+
* @param {any} x An element to be removed.
|
134
128
|
* @returns {void}
|
135
129
|
*/
|
136
130
|
function remove(xs, x) {
|
@@ -143,9 +137,8 @@ function remove(xs, x) {
|
|
143
137
|
* This is used in a process for switch statements.
|
144
138
|
* If there is the "default" chunk before other cases, the order is different
|
145
139
|
* between node's and running's.
|
146
|
-
*
|
147
|
-
* @param {CodePathSegment[]}
|
148
|
-
* @param {CodePathSegment[]} nextSegments - Backward segments to disconnect.
|
140
|
+
* @param {CodePathSegment[]} prevSegments Forward segments to disconnect.
|
141
|
+
* @param {CodePathSegment[]} nextSegments Backward segments to disconnect.
|
149
142
|
* @returns {void}
|
150
143
|
*/
|
151
144
|
function removeConnection(prevSegments, nextSegments) {
|
@@ -162,10 +155,9 @@ function removeConnection(prevSegments, nextSegments) {
|
|
162
155
|
|
163
156
|
/**
|
164
157
|
* Creates looping path.
|
165
|
-
*
|
166
|
-
* @param {
|
167
|
-
* @param {CodePathSegment[]}
|
168
|
-
* @param {CodePathSegment[]} unflattenedToSegments - Segments which are destination.
|
158
|
+
* @param {CodePathState} state The instance.
|
159
|
+
* @param {CodePathSegment[]} unflattenedFromSegments Segments which are source.
|
160
|
+
* @param {CodePathSegment[]} unflattenedToSegments Segments which are destination.
|
169
161
|
* @returns {void}
|
170
162
|
*/
|
171
163
|
function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) {
|
@@ -200,10 +192,9 @@ function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) {
|
|
200
192
|
*
|
201
193
|
* - Adds `false` paths to paths which are leaving from the loop.
|
202
194
|
* - Sets `true` paths to paths which go to the body.
|
203
|
-
*
|
204
|
-
* @param {
|
205
|
-
* @param {
|
206
|
-
* @param {CodePathSegment[]} head - The current head paths.
|
195
|
+
* @param {LoopContext} context A loop context to modify.
|
196
|
+
* @param {ChoiceContext} choiceContext A choice context of this loop.
|
197
|
+
* @param {CodePathSegment[]} head The current head paths.
|
207
198
|
* @returns {void}
|
208
199
|
*/
|
209
200
|
function finalizeTestSegmentsOfFor(context, choiceContext, head) {
|
@@ -227,10 +218,11 @@ function finalizeTestSegmentsOfFor(context, choiceContext, head) {
|
|
227
218
|
*/
|
228
219
|
class CodePathState {
|
229
220
|
|
221
|
+
// eslint-disable-next-line jsdoc/require-description
|
230
222
|
/**
|
231
|
-
* @param {IdGenerator} idGenerator
|
223
|
+
* @param {IdGenerator} idGenerator An id generator to generate id for code
|
232
224
|
* path segments.
|
233
|
-
* @param {Function} onLooped
|
225
|
+
* @param {Function} onLooped A callback function to notify looping.
|
234
226
|
*/
|
235
227
|
constructor(idGenerator, onLooped) {
|
236
228
|
this.idGenerator = idGenerator;
|
@@ -275,8 +267,7 @@ class CodePathState {
|
|
275
267
|
|
276
268
|
/**
|
277
269
|
* Creates and stacks new forking context.
|
278
|
-
*
|
279
|
-
* @param {boolean} forkLeavingPath - A flag which shows being in a
|
270
|
+
* @param {boolean} forkLeavingPath A flag which shows being in a
|
280
271
|
* "finally" block.
|
281
272
|
* @returns {ForkContext} The created context.
|
282
273
|
*/
|
@@ -313,7 +304,6 @@ class CodePathState {
|
|
313
304
|
/**
|
314
305
|
* Creates a bypass path.
|
315
306
|
* This is used for such as IfStatement which does not have "else" chunk.
|
316
|
-
*
|
317
307
|
* @returns {void}
|
318
308
|
*/
|
319
309
|
forkBypassPath() {
|
@@ -346,12 +336,11 @@ class CodePathState {
|
|
346
336
|
* a -> foo();
|
347
337
|
* a -> b -> foo();
|
348
338
|
* a -> b -> bar();
|
349
|
-
*
|
350
|
-
* @param {string} kind - A kind string.
|
339
|
+
* @param {string} kind A kind string.
|
351
340
|
* If the new context is LogicalExpression's, this is `"&&"` or `"||"`.
|
352
341
|
* If it's IfStatement's or ConditionalExpression's, this is `"test"`.
|
353
342
|
* Otherwise, this is `"loop"`.
|
354
|
-
* @param {boolean} isForkingAsResult
|
343
|
+
* @param {boolean} isForkingAsResult A flag that shows that goes different
|
355
344
|
* paths between `true` and `false`.
|
356
345
|
* @returns {void}
|
357
346
|
*/
|
@@ -368,7 +357,6 @@ class CodePathState {
|
|
368
357
|
|
369
358
|
/**
|
370
359
|
* Pops the last choice context and finalizes it.
|
371
|
-
*
|
372
360
|
* @returns {ChoiceContext} The popped context.
|
373
361
|
*/
|
374
362
|
popChoiceContext() {
|
@@ -456,7 +444,6 @@ class CodePathState {
|
|
456
444
|
/**
|
457
445
|
* Makes a code path segment of the right-hand operand of a logical
|
458
446
|
* expression.
|
459
|
-
*
|
460
447
|
* @returns {void}
|
461
448
|
*/
|
462
449
|
makeLogicalRight() {
|
@@ -500,7 +487,6 @@ class CodePathState {
|
|
500
487
|
|
501
488
|
/**
|
502
489
|
* Makes a code path segment of the `if` block.
|
503
|
-
*
|
504
490
|
* @returns {void}
|
505
491
|
*/
|
506
492
|
makeIfConsequent() {
|
@@ -527,7 +513,6 @@ class CodePathState {
|
|
527
513
|
|
528
514
|
/**
|
529
515
|
* Makes a code path segment of the `else` block.
|
530
|
-
*
|
531
516
|
* @returns {void}
|
532
517
|
*/
|
533
518
|
makeIfAlternate() {
|
@@ -554,10 +539,9 @@ class CodePathState {
|
|
554
539
|
|
555
540
|
/**
|
556
541
|
* Creates a context object of SwitchStatement and stacks it.
|
557
|
-
*
|
558
|
-
* @param {boolean} hasCase - `true` if the switch statement has one or more
|
542
|
+
* @param {boolean} hasCase `true` if the switch statement has one or more
|
559
543
|
* case parts.
|
560
|
-
* @param {string|null} label
|
544
|
+
* @param {string|null} label The label text.
|
561
545
|
* @returns {void}
|
562
546
|
*/
|
563
547
|
pushSwitchContext(hasCase, label) {
|
@@ -581,7 +565,6 @@ class CodePathState {
|
|
581
565
|
* - Creates the next code path segment from `context.brokenForkContext`.
|
582
566
|
* - If the last `SwitchCase` node is not a `default` part, creates a path
|
583
567
|
* to the `default` body.
|
584
|
-
*
|
585
568
|
* @returns {void}
|
586
569
|
*/
|
587
570
|
popSwitchContext() {
|
@@ -655,9 +638,8 @@ class CodePathState {
|
|
655
638
|
|
656
639
|
/**
|
657
640
|
* Makes a code path segment for a `SwitchCase` node.
|
658
|
-
*
|
659
|
-
* @param {boolean}
|
660
|
-
* @param {boolean} isDefault - `true` if the body is the default case.
|
641
|
+
* @param {boolean} isEmpty `true` if the body is empty.
|
642
|
+
* @param {boolean} isDefault `true` if the body is the default case.
|
661
643
|
* @returns {void}
|
662
644
|
*/
|
663
645
|
makeSwitchCaseBody(isEmpty, isDefault) {
|
@@ -706,8 +688,7 @@ class CodePathState {
|
|
706
688
|
|
707
689
|
/**
|
708
690
|
* Creates a context object of TryStatement and stacks it.
|
709
|
-
*
|
710
|
-
* @param {boolean} hasFinalizer - `true` if the try statement has a
|
691
|
+
* @param {boolean} hasFinalizer `true` if the try statement has a
|
711
692
|
* `finally` block.
|
712
693
|
* @returns {void}
|
713
694
|
*/
|
@@ -729,7 +710,6 @@ class CodePathState {
|
|
729
710
|
|
730
711
|
/**
|
731
712
|
* Pops the last context of TryStatement and finalizes it.
|
732
|
-
*
|
733
713
|
* @returns {void}
|
734
714
|
*/
|
735
715
|
popTryContext() {
|
@@ -785,7 +765,6 @@ class CodePathState {
|
|
785
765
|
|
786
766
|
/**
|
787
767
|
* Makes a code path segment for a `catch` block.
|
788
|
-
*
|
789
768
|
* @returns {void}
|
790
769
|
*/
|
791
770
|
makeCatchBlock() {
|
@@ -814,7 +793,6 @@ class CodePathState {
|
|
814
793
|
* In the `finally` block, parallel paths are created. The parallel paths
|
815
794
|
* are used as leaving-paths. The leaving-paths are paths from `return`
|
816
795
|
* statements and `throw` statements in a `try` block or a `catch` block.
|
817
|
-
*
|
818
796
|
* @returns {void}
|
819
797
|
*/
|
820
798
|
makeFinallyBlock() {
|
@@ -874,7 +852,6 @@ class CodePathState {
|
|
874
852
|
/**
|
875
853
|
* Makes a code path segment from the first throwable node to the `catch`
|
876
854
|
* block or the `finally` block.
|
877
|
-
*
|
878
855
|
* @returns {void}
|
879
856
|
*/
|
880
857
|
makeFirstThrowablePathInTryBlock() {
|
@@ -903,11 +880,10 @@ class CodePathState {
|
|
903
880
|
|
904
881
|
/**
|
905
882
|
* Creates a context object of a loop statement and stacks it.
|
906
|
-
*
|
907
|
-
* @param {string} type - The type of the node which was triggered. One of
|
883
|
+
* @param {string} type The type of the node which was triggered. One of
|
908
884
|
* `WhileStatement`, `DoWhileStatement`, `ForStatement`, `ForInStatement`,
|
909
885
|
* and `ForStatement`.
|
910
|
-
* @param {string|null} label
|
886
|
+
* @param {string|null} label A label of the node which was triggered.
|
911
887
|
* @returns {void}
|
912
888
|
*/
|
913
889
|
pushLoopContext(type, label) {
|
@@ -979,7 +955,6 @@ class CodePathState {
|
|
979
955
|
|
980
956
|
/**
|
981
957
|
* Pops the last context of a loop statement and finalizes it.
|
982
|
-
*
|
983
958
|
* @returns {void}
|
984
959
|
*/
|
985
960
|
popLoopContext() {
|
@@ -1051,8 +1026,7 @@ class CodePathState {
|
|
1051
1026
|
|
1052
1027
|
/**
|
1053
1028
|
* Makes a code path segment for the test part of a WhileStatement.
|
1054
|
-
*
|
1055
|
-
* @param {boolean|undefined} test - The test value (only when constant).
|
1029
|
+
* @param {boolean|undefined} test The test value (only when constant).
|
1056
1030
|
* @returns {void}
|
1057
1031
|
*/
|
1058
1032
|
makeWhileTest(test) {
|
@@ -1068,7 +1042,6 @@ class CodePathState {
|
|
1068
1042
|
|
1069
1043
|
/**
|
1070
1044
|
* Makes a code path segment for the body part of a WhileStatement.
|
1071
|
-
*
|
1072
1045
|
* @returns {void}
|
1073
1046
|
*/
|
1074
1047
|
makeWhileBody() {
|
@@ -1090,7 +1063,6 @@ class CodePathState {
|
|
1090
1063
|
|
1091
1064
|
/**
|
1092
1065
|
* Makes a code path segment for the body part of a DoWhileStatement.
|
1093
|
-
*
|
1094
1066
|
* @returns {void}
|
1095
1067
|
*/
|
1096
1068
|
makeDoWhileBody() {
|
@@ -1105,8 +1077,7 @@ class CodePathState {
|
|
1105
1077
|
|
1106
1078
|
/**
|
1107
1079
|
* Makes a code path segment for the test part of a DoWhileStatement.
|
1108
|
-
*
|
1109
|
-
* @param {boolean|undefined} test - The test value (only when constant).
|
1080
|
+
* @param {boolean|undefined} test The test value (only when constant).
|
1110
1081
|
* @returns {void}
|
1111
1082
|
*/
|
1112
1083
|
makeDoWhileTest(test) {
|
@@ -1126,8 +1097,7 @@ class CodePathState {
|
|
1126
1097
|
|
1127
1098
|
/**
|
1128
1099
|
* Makes a code path segment for the test part of a ForStatement.
|
1129
|
-
*
|
1130
|
-
* @param {boolean|undefined} test - The test value (only when constant).
|
1100
|
+
* @param {boolean|undefined} test The test value (only when constant).
|
1131
1101
|
* @returns {void}
|
1132
1102
|
*/
|
1133
1103
|
makeForTest(test) {
|
@@ -1145,7 +1115,6 @@ class CodePathState {
|
|
1145
1115
|
|
1146
1116
|
/**
|
1147
1117
|
* Makes a code path segment for the update part of a ForStatement.
|
1148
|
-
*
|
1149
1118
|
* @returns {void}
|
1150
1119
|
*/
|
1151
1120
|
makeForUpdate() {
|
@@ -1173,7 +1142,6 @@ class CodePathState {
|
|
1173
1142
|
|
1174
1143
|
/**
|
1175
1144
|
* Makes a code path segment for the body part of a ForStatement.
|
1176
|
-
*
|
1177
1145
|
* @returns {void}
|
1178
1146
|
*/
|
1179
1147
|
makeForBody() {
|
@@ -1227,7 +1195,6 @@ class CodePathState {
|
|
1227
1195
|
/**
|
1228
1196
|
* Makes a code path segment for the left part of a ForInStatement and a
|
1229
1197
|
* ForOfStatement.
|
1230
|
-
*
|
1231
1198
|
* @returns {void}
|
1232
1199
|
*/
|
1233
1200
|
makeForInOfLeft() {
|
@@ -1244,7 +1211,6 @@ class CodePathState {
|
|
1244
1211
|
/**
|
1245
1212
|
* Makes a code path segment for the right part of a ForInStatement and a
|
1246
1213
|
* ForOfStatement.
|
1247
|
-
*
|
1248
1214
|
* @returns {void}
|
1249
1215
|
*/
|
1250
1216
|
makeForInOfRight() {
|
@@ -1263,7 +1229,6 @@ class CodePathState {
|
|
1263
1229
|
/**
|
1264
1230
|
* Makes a code path segment for the body part of a ForInStatement and a
|
1265
1231
|
* ForOfStatement.
|
1266
|
-
*
|
1267
1232
|
* @returns {void}
|
1268
1233
|
*/
|
1269
1234
|
makeForInOfBody() {
|
@@ -1288,10 +1253,9 @@ class CodePathState {
|
|
1288
1253
|
|
1289
1254
|
/**
|
1290
1255
|
* Creates new context for BreakStatement.
|
1291
|
-
*
|
1292
|
-
* @param {boolean} breakable - The flag to indicate it can break by
|
1256
|
+
* @param {boolean} breakable The flag to indicate it can break by
|
1293
1257
|
* an unlabeled BreakStatement.
|
1294
|
-
* @param {string|null} label
|
1258
|
+
* @param {string|null} label The label of this context.
|
1295
1259
|
* @returns {Object} The new context.
|
1296
1260
|
*/
|
1297
1261
|
pushBreakContext(breakable, label) {
|
@@ -1306,7 +1270,6 @@ class CodePathState {
|
|
1306
1270
|
|
1307
1271
|
/**
|
1308
1272
|
* Removes the top item of the break context stack.
|
1309
|
-
*
|
1310
1273
|
* @returns {Object} The removed context.
|
1311
1274
|
*/
|
1312
1275
|
popBreakContext() {
|
@@ -1333,8 +1296,7 @@ class CodePathState {
|
|
1333
1296
|
*
|
1334
1297
|
* It registers the head segment to a context of `break`.
|
1335
1298
|
* It makes new unreachable segment, then it set the head with the segment.
|
1336
|
-
*
|
1337
|
-
* @param {string} label - A label of the break statement.
|
1299
|
+
* @param {string} label A label of the break statement.
|
1338
1300
|
* @returns {void}
|
1339
1301
|
*/
|
1340
1302
|
makeBreak(label) {
|
@@ -1359,8 +1321,7 @@ class CodePathState {
|
|
1359
1321
|
*
|
1360
1322
|
* It makes a looping path.
|
1361
1323
|
* It makes new unreachable segment, then it set the head with the segment.
|
1362
|
-
*
|
1363
|
-
* @param {string} label - A label of the continue statement.
|
1324
|
+
* @param {string} label A label of the continue statement.
|
1364
1325
|
* @returns {void}
|
1365
1326
|
*/
|
1366
1327
|
makeContinue(label) {
|
@@ -1395,7 +1356,6 @@ class CodePathState {
|
|
1395
1356
|
*
|
1396
1357
|
* It registers the head segment to a context of `return`.
|
1397
1358
|
* It makes new unreachable segment, then it set the head with the segment.
|
1398
|
-
*
|
1399
1359
|
* @returns {void}
|
1400
1360
|
*/
|
1401
1361
|
makeReturn() {
|
@@ -1412,7 +1372,6 @@ class CodePathState {
|
|
1412
1372
|
*
|
1413
1373
|
* It registers the head segment to a context of `throw`.
|
1414
1374
|
* It makes new unreachable segment, then it set the head with the segment.
|
1415
|
-
*
|
1416
1375
|
* @returns {void}
|
1417
1376
|
*/
|
1418
1377
|
makeThrow() {
|
@@ -21,10 +21,11 @@ const IdGenerator = require("./id-generator");
|
|
21
21
|
*/
|
22
22
|
class CodePath {
|
23
23
|
|
24
|
+
// eslint-disable-next-line jsdoc/require-description
|
24
25
|
/**
|
25
|
-
* @param {string} id
|
26
|
-
* @param {CodePath|null} upper
|
27
|
-
* @param {Function} onLooped
|
26
|
+
* @param {string} id An identifier.
|
27
|
+
* @param {CodePath|null} upper The code path of the upper function scope.
|
28
|
+
* @param {Function} onLooped A callback function to notify looping.
|
28
29
|
*/
|
29
30
|
constructor(id, upper, onLooped) {
|
30
31
|
|
@@ -62,8 +63,7 @@ class CodePath {
|
|
62
63
|
|
63
64
|
/**
|
64
65
|
* Gets the state of a given code path.
|
65
|
-
*
|
66
|
-
* @param {CodePath} codePath - A code path to get.
|
66
|
+
* @param {CodePath} codePath A code path to get.
|
67
67
|
* @returns {CodePathState} The state of the code path.
|
68
68
|
*/
|
69
69
|
static getState(codePath) {
|
@@ -126,11 +126,10 @@ class CodePath {
|
|
126
126
|
*
|
127
127
|
* - `controller.skip()` - Skip the following segments in this branch.
|
128
128
|
* - `controller.break()` - Skip all following segments.
|
129
|
-
*
|
130
|
-
* @param {
|
131
|
-
* @param {CodePathSegment} [options.
|
132
|
-
* @param {
|
133
|
-
* @param {Function} callback - A callback function.
|
129
|
+
* @param {Object} [options] Omittable.
|
130
|
+
* @param {CodePathSegment} [options.first] The first segment to traverse.
|
131
|
+
* @param {CodePathSegment} [options.last] The last segment to traverse.
|
132
|
+
* @param {Function} callback A callback function.
|
134
133
|
* @returns {void}
|
135
134
|
*/
|
136
135
|
traverseSegments(options, callback) {
|
@@ -171,7 +170,7 @@ class CodePath {
|
|
171
170
|
|
172
171
|
/**
|
173
172
|
* Checks a given previous segment has been visited.
|
174
|
-
* @param {CodePathSegment} prevSegment
|
173
|
+
* @param {CodePathSegment} prevSegment A previous segment to check.
|
175
174
|
* @returns {boolean} `true` if the segment has been visited.
|
176
175
|
*/
|
177
176
|
function isVisited(prevSegment) {
|
@@ -17,7 +17,7 @@ const debug = require("debug")("eslint:code-path");
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Gets id of a given segment.
|
20
|
-
* @param {CodePathSegment} segment
|
20
|
+
* @param {CodePathSegment} segment A segment to get.
|
21
21
|
* @returns {string} Id of the segment.
|
22
22
|
*/
|
23
23
|
/* istanbul ignore next */
|
@@ -39,18 +39,16 @@ module.exports = {
|
|
39
39
|
|
40
40
|
/**
|
41
41
|
* Dumps given objects.
|
42
|
-
*
|
43
|
-
* @param {...any} args - objects to dump.
|
42
|
+
* @param {...any} args objects to dump.
|
44
43
|
* @returns {void}
|
45
44
|
*/
|
46
45
|
dump: debug,
|
47
46
|
|
48
47
|
/**
|
49
48
|
* Dumps the current analyzing state.
|
50
|
-
*
|
51
|
-
* @param {
|
52
|
-
* @param {
|
53
|
-
* @param {boolean} leaving - A flag whether or not it's leaving
|
49
|
+
* @param {ASTNode} node A node to dump.
|
50
|
+
* @param {CodePathState} state A state to dump.
|
51
|
+
* @param {boolean} leaving A flag whether or not it's leaving
|
54
52
|
* @returns {void}
|
55
53
|
*/
|
56
54
|
dumpState: !debug.enabled ? debug : /* istanbul ignore next */ function(node, state, leaving) {
|
@@ -73,8 +71,7 @@ module.exports = {
|
|
73
71
|
/**
|
74
72
|
* Dumps a DOT code of a given code path.
|
75
73
|
* The DOT code can be visialized with Graphvis.
|
76
|
-
*
|
77
|
-
* @param {CodePath} codePath - A code path to dump.
|
74
|
+
* @param {CodePath} codePath A code path to dump.
|
78
75
|
* @returns {void}
|
79
76
|
* @see http://www.graphviz.org
|
80
77
|
* @see http://www.webgraphviz.com
|
@@ -139,9 +136,8 @@ module.exports = {
|
|
139
136
|
/**
|
140
137
|
* Makes a DOT code of a given code path.
|
141
138
|
* The DOT code can be visialized with Graphvis.
|
142
|
-
*
|
143
|
-
* @param {
|
144
|
-
* @param {Object} traceMap - Optional. A map to check whether or not segments had been done.
|
139
|
+
* @param {CodePath} codePath A code path to make DOT.
|
140
|
+
* @param {Object} traceMap Optional. A map to check whether or not segments had been done.
|
145
141
|
* @returns {string} A DOT code of the code path.
|
146
142
|
*/
|
147
143
|
makeDotArrows(codePath, traceMap) {
|