eslint 9.22.0 → 9.24.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/README.md +48 -46
- package/bin/eslint.js +92 -90
- package/conf/default-cli-options.js +22 -22
- package/conf/ecma-version.js +1 -1
- package/conf/globals.js +97 -98
- package/conf/replacements.json +24 -20
- package/conf/rule-type-list.json +88 -92
- package/lib/api.js +12 -12
- package/lib/cli-engine/cli-engine.js +830 -810
- package/lib/cli-engine/file-enumerator.js +381 -387
- package/lib/cli-engine/formatters/formatters-meta.json +16 -16
- package/lib/cli-engine/formatters/html.js +107 -99
- package/lib/cli-engine/formatters/json-with-metadata.js +5 -5
- package/lib/cli-engine/formatters/json.js +2 -2
- package/lib/cli-engine/formatters/stylish.js +96 -75
- package/lib/cli-engine/hash.js +1 -1
- package/lib/cli-engine/index.js +1 -1
- package/lib/cli-engine/lint-result-cache.js +144 -145
- package/lib/cli-engine/load-rules.js +16 -16
- package/lib/cli.js +638 -457
- package/lib/config/config-loader.js +726 -622
- package/lib/config/config.js +247 -221
- package/lib/config/default-config.js +54 -45
- package/lib/config/flat-config-array.js +167 -172
- package/lib/config/flat-config-helpers.js +72 -72
- package/lib/config/flat-config-schema.js +375 -368
- package/lib/config/rule-validator.js +139 -144
- package/lib/config-api.js +2 -2
- package/lib/eslint/eslint-helpers.js +756 -681
- package/lib/eslint/eslint.js +934 -912
- package/lib/eslint/index.js +2 -2
- package/lib/eslint/legacy-eslint.js +577 -533
- package/lib/languages/js/index.js +263 -264
- package/lib/languages/js/source-code/index.js +1 -1
- package/lib/languages/js/source-code/source-code.js +1128 -1057
- package/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +39 -35
- package/lib/languages/js/source-code/token-store/backward-token-cursor.js +35 -36
- package/lib/languages/js/source-code/token-store/cursor.js +36 -36
- package/lib/languages/js/source-code/token-store/cursors.js +80 -52
- package/lib/languages/js/source-code/token-store/decorative-cursor.js +17 -18
- package/lib/languages/js/source-code/token-store/filter-cursor.js +19 -20
- package/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +40 -32
- package/lib/languages/js/source-code/token-store/forward-token-cursor.js +40 -41
- package/lib/languages/js/source-code/token-store/index.js +592 -498
- package/lib/languages/js/source-code/token-store/limit-cursor.js +17 -18
- package/lib/languages/js/source-code/token-store/padded-token-cursor.js +23 -16
- package/lib/languages/js/source-code/token-store/skip-cursor.js +19 -20
- package/lib/languages/js/source-code/token-store/utils.js +63 -60
- package/lib/languages/js/validate-language-options.js +104 -89
- package/lib/linter/apply-disable-directives.js +467 -383
- package/lib/linter/code-path-analysis/code-path-analyzer.js +650 -672
- package/lib/linter/code-path-analysis/code-path-segment.js +215 -216
- package/lib/linter/code-path-analysis/code-path-state.js +2118 -2096
- package/lib/linter/code-path-analysis/code-path.js +307 -319
- package/lib/linter/code-path-analysis/debug-helpers.js +183 -163
- package/lib/linter/code-path-analysis/fork-context.js +296 -271
- package/lib/linter/code-path-analysis/id-generator.js +22 -23
- package/lib/linter/file-context.js +119 -120
- package/lib/linter/index.js +3 -3
- package/lib/linter/interpolate.js +16 -16
- package/lib/linter/linter.js +2403 -2045
- package/lib/linter/node-event-generator.js +284 -225
- package/lib/linter/report-translator.js +256 -219
- package/lib/linter/rule-fixer.js +122 -124
- package/lib/linter/rules.js +36 -36
- package/lib/linter/safe-emitter.js +18 -18
- package/lib/linter/source-code-fixer.js +94 -92
- package/lib/linter/timing.js +104 -101
- package/lib/linter/vfile.js +70 -73
- package/lib/options.js +404 -361
- package/lib/rule-tester/index.js +1 -1
- package/lib/rule-tester/rule-tester.js +1308 -1046
- package/lib/rules/accessor-pairs.js +298 -263
- package/lib/rules/array-bracket-newline.js +250 -238
- package/lib/rules/array-bracket-spacing.js +263 -224
- package/lib/rules/array-callback-return.js +402 -356
- package/lib/rules/array-element-newline.js +358 -313
- package/lib/rules/arrow-body-style.js +400 -281
- package/lib/rules/arrow-parens.js +206 -173
- package/lib/rules/arrow-spacing.js +169 -163
- package/lib/rules/block-scoped-var.js +125 -123
- package/lib/rules/block-spacing.js +186 -176
- package/lib/rules/brace-style.js +262 -199
- package/lib/rules/callback-return.js +203 -190
- package/lib/rules/camelcase.js +403 -392
- package/lib/rules/capitalized-comments.js +253 -232
- package/lib/rules/class-methods-use-this.js +224 -172
- package/lib/rules/comma-dangle.js +379 -346
- package/lib/rules/comma-spacing.js +193 -195
- package/lib/rules/comma-style.js +375 -316
- package/lib/rules/complexity.js +173 -169
- package/lib/rules/computed-property-spacing.js +236 -211
- package/lib/rules/consistent-return.js +181 -170
- package/lib/rules/consistent-this.js +167 -147
- package/lib/rules/constructor-super.js +412 -404
- package/lib/rules/curly.js +407 -332
- package/lib/rules/default-case-last.js +38 -31
- package/lib/rules/default-case.js +89 -85
- package/lib/rules/default-param-last.js +69 -54
- package/lib/rules/dot-location.js +122 -110
- package/lib/rules/dot-notation.js +192 -156
- package/lib/rules/eol-last.js +122 -120
- package/lib/rules/eqeqeq.js +168 -155
- package/lib/rules/for-direction.js +146 -121
- package/lib/rules/func-call-spacing.js +261 -231
- package/lib/rules/func-name-matching.js +293 -209
- package/lib/rules/func-names.js +165 -164
- package/lib/rules/func-style.js +159 -127
- package/lib/rules/function-call-argument-newline.js +152 -129
- package/lib/rules/function-paren-newline.js +349 -291
- package/lib/rules/generator-star-spacing.js +229 -210
- package/lib/rules/getter-return.js +208 -172
- package/lib/rules/global-require.js +85 -74
- package/lib/rules/grouped-accessor-pairs.js +170 -150
- package/lib/rules/guard-for-in.js +72 -63
- package/lib/rules/handle-callback-err.js +108 -103
- package/lib/rules/id-blacklist.js +182 -199
- package/lib/rules/id-denylist.js +168 -187
- package/lib/rules/id-length.js +197 -171
- package/lib/rules/id-match.js +344 -289
- package/lib/rules/implicit-arrow-linebreak.js +102 -79
- package/lib/rules/indent-legacy.js +1344 -1118
- package/lib/rules/indent.js +2272 -1759
- package/lib/rules/index.js +317 -292
- package/lib/rules/init-declarations.js +137 -107
- package/lib/rules/jsx-quotes.js +94 -82
- package/lib/rules/key-spacing.js +750 -633
- package/lib/rules/keyword-spacing.js +648 -605
- package/lib/rules/line-comment-position.js +142 -128
- package/lib/rules/linebreak-style.js +107 -106
- package/lib/rules/lines-around-comment.js +540 -448
- package/lib/rules/lines-around-directive.js +233 -203
- package/lib/rules/lines-between-class-members.js +305 -234
- package/lib/rules/logical-assignment-operators.js +582 -399
- package/lib/rules/max-classes-per-file.js +69 -68
- package/lib/rules/max-depth.js +146 -143
- package/lib/rules/max-len.js +473 -434
- package/lib/rules/max-lines-per-function.js +201 -176
- package/lib/rules/max-lines.js +158 -162
- package/lib/rules/max-nested-callbacks.js +102 -104
- package/lib/rules/max-params.js +78 -76
- package/lib/rules/max-statements-per-line.js +205 -198
- package/lib/rules/max-statements.js +168 -164
- package/lib/rules/multiline-comment-style.js +637 -479
- package/lib/rules/multiline-ternary.js +241 -176
- package/lib/rules/new-cap.js +233 -213
- package/lib/rules/new-parens.js +88 -79
- package/lib/rules/newline-after-var.js +287 -250
- package/lib/rules/newline-before-return.js +229 -222
- package/lib/rules/newline-per-chained-call.js +142 -127
- package/lib/rules/no-alert.js +90 -79
- package/lib/rules/no-array-constructor.js +125 -113
- package/lib/rules/no-async-promise-executor.js +30 -24
- package/lib/rules/no-await-in-loop.js +69 -71
- package/lib/rules/no-bitwise.js +124 -100
- package/lib/rules/no-buffer-constructor.js +55 -47
- package/lib/rules/no-caller.js +39 -33
- package/lib/rules/no-case-declarations.js +61 -57
- package/lib/rules/no-catch-shadow.js +76 -73
- package/lib/rules/no-class-assign.js +51 -48
- package/lib/rules/no-compare-neg-zero.js +62 -48
- package/lib/rules/no-cond-assign.js +148 -132
- package/lib/rules/no-confusing-arrow.js +98 -81
- package/lib/rules/no-console.js +202 -199
- package/lib/rules/no-const-assign.js +47 -41
- package/lib/rules/no-constant-binary-expression.js +500 -405
- package/lib/rules/no-constant-condition.js +158 -143
- package/lib/rules/no-constructor-return.js +49 -49
- package/lib/rules/no-continue.js +25 -27
- package/lib/rules/no-control-regex.js +125 -121
- package/lib/rules/no-debugger.js +28 -30
- package/lib/rules/no-delete-var.js +29 -29
- package/lib/rules/no-div-regex.js +47 -41
- package/lib/rules/no-dupe-args.js +68 -69
- package/lib/rules/no-dupe-class-members.js +102 -89
- package/lib/rules/no-dupe-else-if.js +100 -77
- package/lib/rules/no-dupe-keys.js +133 -110
- package/lib/rules/no-duplicate-case.js +50 -43
- package/lib/rules/no-duplicate-imports.js +179 -176
- package/lib/rules/no-else-return.js +430 -385
- package/lib/rules/no-empty-character-class.js +57 -50
- package/lib/rules/no-empty-function.js +127 -128
- package/lib/rules/no-empty-pattern.js +63 -58
- package/lib/rules/no-empty-static-block.js +37 -35
- package/lib/rules/no-empty.js +98 -86
- package/lib/rules/no-eq-null.js +37 -32
- package/lib/rules/no-eval.js +256 -250
- package/lib/rules/no-ex-assign.js +42 -39
- package/lib/rules/no-extend-native.js +161 -159
- package/lib/rules/no-extra-bind.js +201 -190
- package/lib/rules/no-extra-boolean-cast.js +398 -348
- package/lib/rules/no-extra-label.js +150 -131
- package/lib/rules/no-extra-parens.js +1654 -1325
- package/lib/rules/no-extra-semi.js +146 -144
- package/lib/rules/no-fallthrough.js +199 -157
- package/lib/rules/no-floating-decimal.js +74 -66
- package/lib/rules/no-func-assign.js +54 -55
- package/lib/rules/no-global-assign.js +78 -73
- package/lib/rules/no-implicit-coercion.js +349 -293
- package/lib/rules/no-implicit-globals.js +158 -135
- package/lib/rules/no-implied-eval.js +140 -112
- package/lib/rules/no-import-assign.js +145 -159
- package/lib/rules/no-inline-comments.js +101 -95
- package/lib/rules/no-inner-declarations.js +115 -101
- package/lib/rules/no-invalid-regexp.js +222 -190
- package/lib/rules/no-invalid-this.js +123 -117
- package/lib/rules/no-irregular-whitespace.js +266 -252
- package/lib/rules/no-iterator.js +29 -33
- package/lib/rules/no-label-var.js +59 -62
- package/lib/rules/no-labels.js +138 -133
- package/lib/rules/no-lone-blocks.js +127 -123
- package/lib/rules/no-lonely-if.js +108 -77
- package/lib/rules/no-loop-func.js +238 -213
- package/lib/rules/no-loss-of-precision.js +218 -201
- package/lib/rules/no-magic-numbers.js +246 -218
- package/lib/rules/no-misleading-character-class.js +499 -446
- package/lib/rules/no-mixed-operators.js +188 -182
- package/lib/rules/no-mixed-requires.js +253 -240
- package/lib/rules/no-mixed-spaces-and-tabs.js +134 -121
- package/lib/rules/no-multi-assign.js +46 -44
- package/lib/rules/no-multi-spaces.js +163 -143
- package/lib/rules/no-multi-str.js +42 -41
- package/lib/rules/no-multiple-empty-lines.js +196 -158
- package/lib/rules/no-native-reassign.js +90 -85
- package/lib/rules/no-negated-condition.js +79 -75
- package/lib/rules/no-negated-in-lhs.js +45 -43
- package/lib/rules/no-nested-ternary.js +33 -32
- package/lib/rules/no-new-func.js +71 -62
- package/lib/rules/no-new-native-nonconstructor.js +43 -39
- package/lib/rules/no-new-object.js +48 -48
- package/lib/rules/no-new-require.js +48 -47
- package/lib/rules/no-new-symbol.js +52 -50
- package/lib/rules/no-new-wrappers.js +43 -41
- package/lib/rules/no-new.js +28 -29
- package/lib/rules/no-nonoctal-decimal-escape.js +141 -121
- package/lib/rules/no-obj-calls.js +66 -53
- package/lib/rules/no-object-constructor.js +104 -97
- package/lib/rules/no-octal-escape.js +40 -43
- package/lib/rules/no-octal.js +32 -32
- package/lib/rules/no-param-reassign.js +235 -217
- package/lib/rules/no-path-concat.js +66 -67
- package/lib/rules/no-plusplus.js +60 -61
- package/lib/rules/no-process-env.js +49 -48
- package/lib/rules/no-process-exit.js +54 -50
- package/lib/rules/no-promise-executor-return.js +214 -182
- package/lib/rules/no-proto.js +26 -29
- package/lib/rules/no-prototype-builtins.js +146 -124
- package/lib/rules/no-redeclare.js +154 -152
- package/lib/rules/no-regex-spaces.js +183 -161
- package/lib/rules/no-restricted-exports.js +208 -185
- package/lib/rules/no-restricted-globals.js +111 -112
- package/lib/rules/no-restricted-imports.js +657 -537
- package/lib/rules/no-restricted-modules.js +222 -202
- package/lib/rules/no-restricted-properties.js +181 -153
- package/lib/rules/no-restricted-syntax.js +56 -52
- package/lib/rules/no-return-assign.js +55 -50
- package/lib/rules/no-return-await.js +148 -124
- package/lib/rules/no-script-url.js +52 -45
- package/lib/rules/no-self-assign.js +148 -146
- package/lib/rules/no-self-compare.js +63 -46
- package/lib/rules/no-sequences.js +135 -116
- package/lib/rules/no-setter-return.js +185 -152
- package/lib/rules/no-shadow-restricted-names.js +61 -46
- package/lib/rules/no-shadow.js +342 -316
- package/lib/rules/no-spaced-func.js +82 -77
- package/lib/rules/no-sparse-arrays.js +54 -59
- package/lib/rules/no-sync.js +61 -60
- package/lib/rules/no-tabs.js +83 -72
- package/lib/rules/no-template-curly-in-string.js +33 -32
- package/lib/rules/no-ternary.js +25 -29
- package/lib/rules/no-this-before-super.js +321 -319
- package/lib/rules/no-throw-literal.js +31 -36
- package/lib/rules/no-trailing-spaces.js +199 -191
- package/lib/rules/no-undef-init.js +76 -61
- package/lib/rules/no-undef.js +51 -48
- package/lib/rules/no-undefined.js +73 -75
- package/lib/rules/no-underscore-dangle.js +370 -327
- package/lib/rules/no-unexpected-multiline.js +112 -102
- package/lib/rules/no-unmodified-loop-condition.js +254 -254
- package/lib/rules/no-unneeded-ternary.js +212 -147
- package/lib/rules/no-unreachable-loop.js +145 -142
- package/lib/rules/no-unreachable.js +255 -248
- package/lib/rules/no-unsafe-finally.js +93 -85
- package/lib/rules/no-unsafe-negation.js +105 -83
- package/lib/rules/no-unsafe-optional-chaining.js +192 -178
- package/lib/rules/no-unused-expressions.js +178 -162
- package/lib/rules/no-unused-labels.js +139 -124
- package/lib/rules/no-unused-private-class-members.js +206 -182
- package/lib/rules/no-unused-vars.js +1669 -1449
- package/lib/rules/no-use-before-define.js +229 -231
- package/lib/rules/no-useless-assignment.js +590 -511
- package/lib/rules/no-useless-backreference.js +212 -193
- package/lib/rules/no-useless-call.js +58 -53
- package/lib/rules/no-useless-catch.js +40 -40
- package/lib/rules/no-useless-computed-key.js +144 -115
- package/lib/rules/no-useless-concat.js +65 -60
- package/lib/rules/no-useless-constructor.js +158 -111
- package/lib/rules/no-useless-escape.js +342 -291
- package/lib/rules/no-useless-rename.js +183 -156
- package/lib/rules/no-useless-return.js +344 -312
- package/lib/rules/no-var.js +233 -212
- package/lib/rules/no-void.js +50 -48
- package/lib/rules/no-warning-comments.js +191 -186
- package/lib/rules/no-whitespace-before-property.js +131 -115
- package/lib/rules/no-with.js +24 -26
- package/lib/rules/nonblock-statement-body-position.js +149 -130
- package/lib/rules/object-curly-newline.js +306 -265
- package/lib/rules/object-curly-spacing.js +360 -314
- package/lib/rules/object-property-newline.js +137 -106
- package/lib/rules/object-shorthand.js +607 -502
- package/lib/rules/one-var-declaration-per-line.js +104 -100
- package/lib/rules/one-var.js +653 -537
- package/lib/rules/operator-assignment.js +219 -161
- package/lib/rules/operator-linebreak.js +295 -251
- package/lib/rules/padded-blocks.js +346 -308
- package/lib/rules/padding-line-between-statements.js +443 -439
- package/lib/rules/prefer-arrow-callback.js +362 -313
- package/lib/rules/prefer-const.js +418 -377
- package/lib/rules/prefer-destructuring.js +301 -279
- package/lib/rules/prefer-exponentiation-operator.js +176 -133
- package/lib/rules/prefer-named-capture-group.js +153 -140
- package/lib/rules/prefer-numeric-literals.js +121 -113
- package/lib/rules/prefer-object-has-own.js +116 -82
- package/lib/rules/prefer-object-spread.js +213 -193
- package/lib/rules/prefer-promise-reject-errors.js +140 -122
- package/lib/rules/prefer-reflect.js +127 -107
- package/lib/rules/prefer-regex-literals.js +578 -466
- package/lib/rules/prefer-rest-params.js +79 -80
- package/lib/rules/prefer-spread.js +47 -44
- package/lib/rules/prefer-template.js +266 -195
- package/lib/rules/quote-props.js +373 -307
- package/lib/rules/quotes.js +374 -326
- package/lib/rules/radix.js +152 -136
- package/lib/rules/require-atomic-updates.js +316 -285
- package/lib/rules/require-await.js +144 -116
- package/lib/rules/require-unicode-regexp.js +282 -177
- package/lib/rules/require-yield.js +53 -54
- package/lib/rules/rest-spread-spacing.js +128 -116
- package/lib/rules/semi-spacing.js +281 -250
- package/lib/rules/semi-style.js +176 -134
- package/lib/rules/semi.js +456 -436
- package/lib/rules/sort-imports.js +306 -233
- package/lib/rules/sort-keys.js +219 -188
- package/lib/rules/sort-vars.js +127 -93
- package/lib/rules/space-before-blocks.js +199 -189
- package/lib/rules/space-before-function-paren.js +186 -166
- package/lib/rules/space-in-parens.js +359 -288
- package/lib/rules/space-infix-ops.js +237 -201
- package/lib/rules/space-unary-ops.js +356 -298
- package/lib/rules/spaced-comment.js +363 -319
- package/lib/rules/strict.js +265 -230
- package/lib/rules/switch-colon-spacing.js +130 -122
- package/lib/rules/symbol-description.js +45 -48
- package/lib/rules/template-curly-spacing.js +148 -142
- package/lib/rules/template-tag-spacing.js +98 -88
- package/lib/rules/unicode-bom.js +54 -56
- package/lib/rules/use-isnan.js +237 -206
- package/lib/rules/utils/ast-utils.js +2039 -1860
- package/lib/rules/utils/char-source.js +162 -155
- package/lib/rules/utils/fix-tracker.js +83 -80
- package/lib/rules/utils/keywords.js +59 -59
- package/lib/rules/utils/lazy-loading-rule-map.js +79 -76
- package/lib/rules/utils/regular-expressions.js +32 -24
- package/lib/rules/utils/unicode/index.js +4 -4
- package/lib/rules/utils/unicode/is-combining-character.js +1 -1
- package/lib/rules/utils/unicode/is-emoji-modifier.js +1 -1
- package/lib/rules/utils/unicode/is-regional-indicator-symbol.js +1 -1
- package/lib/rules/utils/unicode/is-surrogate-pair.js +1 -1
- package/lib/rules/valid-typeof.js +153 -111
- package/lib/rules/vars-on-top.js +152 -145
- package/lib/rules/wrap-iife.js +204 -191
- package/lib/rules/wrap-regex.js +70 -58
- package/lib/rules/yield-star-spacing.js +145 -134
- package/lib/rules/yoda.js +283 -272
- package/lib/services/parser-service.js +35 -35
- package/lib/services/processor-service.js +66 -73
- package/lib/services/suppressions-service.js +289 -0
- package/lib/shared/ajv.js +14 -14
- package/lib/shared/assert.js +3 -4
- package/lib/shared/ast-utils.js +7 -6
- package/lib/shared/deep-merge-arrays.js +24 -22
- package/lib/shared/directives.js +3 -2
- package/lib/shared/flags.js +50 -17
- package/lib/shared/logging.js +24 -25
- package/lib/shared/option-utils.js +43 -36
- package/lib/shared/runtime-info.js +136 -127
- package/lib/shared/serialization.js +27 -27
- package/lib/shared/severity.js +22 -22
- package/lib/shared/stats.js +5 -5
- package/lib/shared/string-utils.js +16 -16
- package/lib/shared/text-table.js +28 -27
- package/lib/shared/traverser.js +153 -146
- package/lib/shared/types.js +4 -27
- package/lib/types/index.d.ts +2010 -1559
- package/lib/types/rules.d.ts +5253 -5140
- package/lib/types/use-at-your-own-risk.d.ts +32 -30
- package/lib/unsupported-api.js +5 -5
- package/messages/all-files-ignored.js +3 -3
- package/messages/all-matched-files-ignored.js +3 -3
- package/messages/config-file-missing.js +2 -2
- package/messages/config-plugin-missing.js +3 -3
- package/messages/config-serialize-function.js +9 -7
- package/messages/eslintrc-incompat.js +13 -15
- package/messages/eslintrc-plugins.js +3 -4
- package/messages/extend-config-missing.js +3 -3
- package/messages/failed-to-read-json.js +3 -3
- package/messages/file-not-found.js +3 -3
- package/messages/invalid-rule-options.js +2 -2
- package/messages/invalid-rule-severity.js +2 -2
- package/messages/no-config-found.js +3 -3
- package/messages/plugin-conflict.js +8 -8
- package/messages/plugin-invalid.js +3 -3
- package/messages/plugin-missing.js +3 -3
- package/messages/print-config-with-directory-path.js +2 -2
- package/messages/shared.js +6 -1
- package/messages/whitespace-found.js +3 -3
- package/package.json +14 -20
@@ -8,21 +8,21 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
const { isCommentToken } = require("@eslint-community/eslint-utils"),
|
12
|
+
TokenStore = require("./token-store"),
|
13
|
+
astUtils = require("../../../shared/ast-utils"),
|
14
|
+
Traverser = require("../../../shared/traverser"),
|
15
|
+
globals = require("../../../../conf/globals"),
|
16
|
+
{ directivesPattern } = require("../../../shared/directives"),
|
17
|
+
CodePathAnalyzer = require("../../../linter/code-path-analysis/code-path-analyzer"),
|
18
|
+
createEmitter = require("../../../linter/safe-emitter"),
|
19
|
+
{
|
20
|
+
ConfigCommentParser,
|
21
|
+
VisitNodeStep,
|
22
|
+
CallMethodStep,
|
23
|
+
Directive,
|
24
|
+
} = require("@eslint/plugin-kit"),
|
25
|
+
eslintScope = require("eslint-scope");
|
26
26
|
|
27
27
|
//------------------------------------------------------------------------------
|
28
28
|
// Type Definitions
|
@@ -41,13 +41,13 @@ const
|
|
41
41
|
const commentParser = new ConfigCommentParser();
|
42
42
|
|
43
43
|
const CODE_PATH_EVENTS = [
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
"onCodePathStart",
|
45
|
+
"onCodePathEnd",
|
46
|
+
"onCodePathSegmentStart",
|
47
|
+
"onCodePathSegmentEnd",
|
48
|
+
"onCodePathSegmentLoop",
|
49
|
+
"onUnreachableCodePathSegmentStart",
|
50
|
+
"onUnreachableCodePathSegmentEnd",
|
51
51
|
];
|
52
52
|
|
53
53
|
/**
|
@@ -58,25 +58,25 @@ const CODE_PATH_EVENTS = [
|
|
58
58
|
* @private
|
59
59
|
*/
|
60
60
|
function validate(ast) {
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
if (!ast) {
|
62
|
+
throw new TypeError(`Unexpected empty AST. (${ast})`);
|
63
|
+
}
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
if (!ast.tokens) {
|
66
|
+
throw new TypeError("AST is missing the tokens array.");
|
67
|
+
}
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
if (!ast.comments) {
|
70
|
+
throw new TypeError("AST is missing the comments array.");
|
71
|
+
}
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
if (!ast.loc) {
|
74
|
+
throw new TypeError("AST is missing location information.");
|
75
|
+
}
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
if (!ast.range) {
|
78
|
+
throw new TypeError("AST is missing range information");
|
79
|
+
}
|
80
80
|
}
|
81
81
|
|
82
82
|
/**
|
@@ -85,21 +85,20 @@ function validate(ast) {
|
|
85
85
|
* @returns {Object} The globals for the given ecmaVersion.
|
86
86
|
*/
|
87
87
|
function getGlobalsForEcmaVersion(ecmaVersion) {
|
88
|
+
switch (ecmaVersion) {
|
89
|
+
case 3:
|
90
|
+
return globals.es3;
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
return globals.es3;
|
92
|
+
case 5:
|
93
|
+
return globals.es5;
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
+
default:
|
96
|
+
if (ecmaVersion < 2015) {
|
97
|
+
return globals[`es${ecmaVersion + 2009}`];
|
98
|
+
}
|
95
99
|
|
96
|
-
|
97
|
-
|
98
|
-
return globals[`es${ecmaVersion + 2009}`];
|
99
|
-
}
|
100
|
-
|
101
|
-
return globals[`es${ecmaVersion}`];
|
102
|
-
}
|
100
|
+
return globals[`es${ecmaVersion}`];
|
101
|
+
}
|
103
102
|
}
|
104
103
|
|
105
104
|
/**
|
@@ -109,8 +108,12 @@ function getGlobalsForEcmaVersion(ecmaVersion) {
|
|
109
108
|
* @private
|
110
109
|
*/
|
111
110
|
function looksLikeExport(astNode) {
|
112
|
-
|
113
|
-
|
111
|
+
return (
|
112
|
+
astNode.type === "ExportDefaultDeclaration" ||
|
113
|
+
astNode.type === "ExportNamedDeclaration" ||
|
114
|
+
astNode.type === "ExportAllDeclaration" ||
|
115
|
+
astNode.type === "ExportSpecifier"
|
116
|
+
);
|
114
117
|
}
|
115
118
|
|
116
119
|
/**
|
@@ -121,19 +124,23 @@ function looksLikeExport(astNode) {
|
|
121
124
|
* @private
|
122
125
|
*/
|
123
126
|
function sortedMerge(tokens, comments) {
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
127
|
+
const result = [];
|
128
|
+
let tokenIndex = 0;
|
129
|
+
let commentIndex = 0;
|
130
|
+
|
131
|
+
while (tokenIndex < tokens.length || commentIndex < comments.length) {
|
132
|
+
if (
|
133
|
+
commentIndex >= comments.length ||
|
134
|
+
(tokenIndex < tokens.length &&
|
135
|
+
tokens[tokenIndex].range[0] < comments[commentIndex].range[0])
|
136
|
+
) {
|
137
|
+
result.push(tokens[tokenIndex++]);
|
138
|
+
} else {
|
139
|
+
result.push(comments[commentIndex++]);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
return result;
|
137
144
|
}
|
138
145
|
|
139
146
|
/**
|
@@ -144,26 +151,28 @@ function sortedMerge(tokens, comments) {
|
|
144
151
|
* @throws Error if global value is invalid
|
145
152
|
*/
|
146
153
|
function normalizeConfigGlobal(configuredValue) {
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
154
|
+
switch (configuredValue) {
|
155
|
+
case "off":
|
156
|
+
return "off";
|
157
|
+
|
158
|
+
case true:
|
159
|
+
case "true":
|
160
|
+
case "writeable":
|
161
|
+
case "writable":
|
162
|
+
return "writable";
|
163
|
+
|
164
|
+
case null:
|
165
|
+
case false:
|
166
|
+
case "false":
|
167
|
+
case "readable":
|
168
|
+
case "readonly":
|
169
|
+
return "readonly";
|
170
|
+
|
171
|
+
default:
|
172
|
+
throw new Error(
|
173
|
+
`'${configuredValue}' is not a valid configuration for a global (use 'readonly', 'writable', or 'off')`,
|
174
|
+
);
|
175
|
+
}
|
167
176
|
}
|
168
177
|
|
169
178
|
/**
|
@@ -174,8 +183,11 @@ function normalizeConfigGlobal(configuredValue) {
|
|
174
183
|
* @private
|
175
184
|
*/
|
176
185
|
function nodesOrTokensOverlap(first, second) {
|
177
|
-
|
178
|
-
|
186
|
+
return (
|
187
|
+
(first.range[0] <= second.range[0] &&
|
188
|
+
first.range[1] >= second.range[0]) ||
|
189
|
+
(second.range[0] <= first.range[0] && second.range[1] >= first.range[0])
|
190
|
+
);
|
179
191
|
}
|
180
192
|
|
181
193
|
/**
|
@@ -191,41 +203,41 @@ function nodesOrTokensOverlap(first, second) {
|
|
191
203
|
* @public
|
192
204
|
*/
|
193
205
|
function isSpaceBetween(sourceCode, first, second, checkInsideOfJSXText) {
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
206
|
+
if (nodesOrTokensOverlap(first, second)) {
|
207
|
+
return false;
|
208
|
+
}
|
209
|
+
|
210
|
+
const [startingNodeOrToken, endingNodeOrToken] =
|
211
|
+
first.range[1] <= second.range[0] ? [first, second] : [second, first];
|
212
|
+
const firstToken =
|
213
|
+
sourceCode.getLastToken(startingNodeOrToken) || startingNodeOrToken;
|
214
|
+
const finalToken =
|
215
|
+
sourceCode.getFirstToken(endingNodeOrToken) || endingNodeOrToken;
|
216
|
+
let currentToken = firstToken;
|
217
|
+
|
218
|
+
while (currentToken !== finalToken) {
|
219
|
+
const nextToken = sourceCode.getTokenAfter(currentToken, {
|
220
|
+
includeComments: true,
|
221
|
+
});
|
222
|
+
|
223
|
+
if (
|
224
|
+
currentToken.range[1] !== nextToken.range[0] ||
|
225
|
+
/*
|
226
|
+
* For backward compatibility, check spaces in JSXText.
|
227
|
+
* https://github.com/eslint/eslint/issues/12614
|
228
|
+
*/
|
229
|
+
(checkInsideOfJSXText &&
|
230
|
+
nextToken !== finalToken &&
|
231
|
+
nextToken.type === "JSXText" &&
|
232
|
+
/\s/u.test(nextToken.value))
|
233
|
+
) {
|
234
|
+
return true;
|
235
|
+
}
|
236
|
+
|
237
|
+
currentToken = nextToken;
|
238
|
+
}
|
239
|
+
|
240
|
+
return false;
|
229
241
|
}
|
230
242
|
|
231
243
|
//-----------------------------------------------------------------------------
|
@@ -241,62 +253,69 @@ function isSpaceBetween(sourceCode, first, second, checkInsideOfJSXText) {
|
|
241
253
|
* @param {Object|undefined} inlineGlobals The globals declared in the source code
|
242
254
|
* @returns {void}
|
243
255
|
*/
|
244
|
-
function addDeclaredGlobals(
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
256
|
+
function addDeclaredGlobals(
|
257
|
+
globalScope,
|
258
|
+
configGlobals = {},
|
259
|
+
inlineGlobals = {},
|
260
|
+
) {
|
261
|
+
// Define configured global variables.
|
262
|
+
for (const id of new Set([
|
263
|
+
...Object.keys(configGlobals),
|
264
|
+
...Object.keys(inlineGlobals),
|
265
|
+
])) {
|
266
|
+
/*
|
267
|
+
* `normalizeConfigGlobal` will throw an error if a configured global value is invalid. However, these errors would
|
268
|
+
* typically be caught when validating a config anyway (validity for inline global comments is checked separately).
|
269
|
+
*/
|
270
|
+
const configValue =
|
271
|
+
configGlobals[id] === void 0
|
272
|
+
? void 0
|
273
|
+
: normalizeConfigGlobal(configGlobals[id]);
|
274
|
+
const commentValue = inlineGlobals[id] && inlineGlobals[id].value;
|
275
|
+
const value = commentValue || configValue;
|
276
|
+
const sourceComments = inlineGlobals[id] && inlineGlobals[id].comments;
|
277
|
+
|
278
|
+
if (value === "off") {
|
279
|
+
continue;
|
280
|
+
}
|
281
|
+
|
282
|
+
let variable = globalScope.set.get(id);
|
283
|
+
|
284
|
+
if (!variable) {
|
285
|
+
variable = new eslintScope.Variable(id, globalScope);
|
286
|
+
|
287
|
+
globalScope.variables.push(variable);
|
288
|
+
globalScope.set.set(id, variable);
|
289
|
+
}
|
290
|
+
|
291
|
+
variable.eslintImplicitGlobalSetting = configValue;
|
292
|
+
variable.eslintExplicitGlobal = sourceComments !== void 0;
|
293
|
+
variable.eslintExplicitGlobalComments = sourceComments;
|
294
|
+
variable.writeable = value === "writable";
|
295
|
+
}
|
296
|
+
|
297
|
+
/*
|
298
|
+
* "through" contains all references which definitions cannot be found.
|
299
|
+
* Since we augment the global scope using configuration, we need to update
|
300
|
+
* references and remove the ones that were added by configuration.
|
301
|
+
*/
|
302
|
+
globalScope.through = globalScope.through.filter(reference => {
|
303
|
+
const name = reference.identifier.name;
|
304
|
+
const variable = globalScope.set.get(name);
|
305
|
+
|
306
|
+
if (variable) {
|
307
|
+
/*
|
308
|
+
* Links the variable and the reference.
|
309
|
+
* And this reference is removed from `Scope#through`.
|
310
|
+
*/
|
311
|
+
reference.resolved = variable;
|
312
|
+
variable.references.push(reference);
|
313
|
+
|
314
|
+
return false;
|
315
|
+
}
|
316
|
+
|
317
|
+
return true;
|
318
|
+
});
|
300
319
|
}
|
301
320
|
|
302
321
|
/**
|
@@ -308,16 +327,14 @@ function addDeclaredGlobals(globalScope, configGlobals = {}, inlineGlobals = {})
|
|
308
327
|
* @returns {void}
|
309
328
|
*/
|
310
329
|
function markExportedVariables(globalScope, variables) {
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
});
|
320
|
-
|
330
|
+
Object.keys(variables).forEach(name => {
|
331
|
+
const variable = globalScope.set.get(name);
|
332
|
+
|
333
|
+
if (variable) {
|
334
|
+
variable.eslintUsed = true;
|
335
|
+
variable.eslintExported = true;
|
336
|
+
}
|
337
|
+
});
|
321
338
|
}
|
322
339
|
|
323
340
|
//------------------------------------------------------------------------------
|
@@ -331,876 +348,930 @@ const caches = Symbol("caches");
|
|
331
348
|
* @implements {ISourceCode}
|
332
349
|
*/
|
333
350
|
class SourceCode extends TokenStore {
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
351
|
+
/**
|
352
|
+
* The cache of steps that were taken while traversing the source code.
|
353
|
+
* @type {Array<ITraversalStep>}
|
354
|
+
*/
|
355
|
+
#steps;
|
356
|
+
|
357
|
+
/**
|
358
|
+
* Creates a new instance.
|
359
|
+
* @param {string|Object} textOrConfig The source code text or config object.
|
360
|
+
* @param {string} textOrConfig.text The source code text.
|
361
|
+
* @param {ASTNode} textOrConfig.ast The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
|
362
|
+
* @param {boolean} textOrConfig.hasBOM Indicates if the text has a Unicode BOM.
|
363
|
+
* @param {Object|null} textOrConfig.parserServices The parser services.
|
364
|
+
* @param {ScopeManager|null} textOrConfig.scopeManager The scope of this source code.
|
365
|
+
* @param {Object|null} textOrConfig.visitorKeys The visitor keys to traverse AST.
|
366
|
+
* @param {ASTNode} [astIfNoConfig] The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
|
367
|
+
*/
|
368
|
+
constructor(textOrConfig, astIfNoConfig) {
|
369
|
+
let text, hasBOM, ast, parserServices, scopeManager, visitorKeys;
|
370
|
+
|
371
|
+
// Process overloading of arguments
|
372
|
+
if (typeof textOrConfig === "string") {
|
373
|
+
text = textOrConfig;
|
374
|
+
ast = astIfNoConfig;
|
375
|
+
hasBOM = false;
|
376
|
+
} else if (typeof textOrConfig === "object" && textOrConfig !== null) {
|
377
|
+
text = textOrConfig.text;
|
378
|
+
ast = textOrConfig.ast;
|
379
|
+
hasBOM = textOrConfig.hasBOM;
|
380
|
+
parserServices = textOrConfig.parserServices;
|
381
|
+
scopeManager = textOrConfig.scopeManager;
|
382
|
+
visitorKeys = textOrConfig.visitorKeys;
|
383
|
+
}
|
384
|
+
|
385
|
+
validate(ast);
|
386
|
+
super(ast.tokens, ast.comments);
|
387
|
+
|
388
|
+
/**
|
389
|
+
* General purpose caching for the class.
|
390
|
+
*/
|
391
|
+
this[caches] = new Map([
|
392
|
+
["scopes", new WeakMap()],
|
393
|
+
["vars", new Map()],
|
394
|
+
["configNodes", void 0],
|
395
|
+
]);
|
396
|
+
|
397
|
+
/**
|
398
|
+
* Indicates if the AST is ESTree compatible.
|
399
|
+
* @type {boolean}
|
400
|
+
*/
|
401
|
+
this.isESTree = ast.type === "Program";
|
402
|
+
|
403
|
+
/*
|
404
|
+
* Backwards compatibility for BOM handling.
|
405
|
+
*
|
406
|
+
* The `hasBOM` property has been available on the `SourceCode` object
|
407
|
+
* for a long time and is used to indicate if the source contains a BOM.
|
408
|
+
* The linter strips the BOM and just passes the `hasBOM` property to the
|
409
|
+
* `SourceCode` constructor to make it easier for languages to not deal with
|
410
|
+
* the BOM.
|
411
|
+
*
|
412
|
+
* However, the text passed in to the `SourceCode` constructor might still
|
413
|
+
* have a BOM if the constructor is called outside of the linter, so we still
|
414
|
+
* need to check for the BOM in the text.
|
415
|
+
*/
|
416
|
+
const textHasBOM = text.charCodeAt(0) === 0xfeff;
|
417
|
+
|
418
|
+
/**
|
419
|
+
* The flag to indicate that the source code has Unicode BOM.
|
420
|
+
* @type {boolean}
|
421
|
+
*/
|
422
|
+
this.hasBOM = textHasBOM || !!hasBOM;
|
423
|
+
|
424
|
+
/**
|
425
|
+
* The original text source code.
|
426
|
+
* BOM was stripped from this text.
|
427
|
+
* @type {string}
|
428
|
+
*/
|
429
|
+
this.text = textHasBOM ? text.slice(1) : text;
|
430
|
+
|
431
|
+
/**
|
432
|
+
* The parsed AST for the source code.
|
433
|
+
* @type {ASTNode}
|
434
|
+
*/
|
435
|
+
this.ast = ast;
|
436
|
+
|
437
|
+
/**
|
438
|
+
* The parser services of this source code.
|
439
|
+
* @type {Object}
|
440
|
+
*/
|
441
|
+
this.parserServices = parserServices || {};
|
442
|
+
|
443
|
+
/**
|
444
|
+
* The scope of this source code.
|
445
|
+
* @type {ScopeManager|null}
|
446
|
+
*/
|
447
|
+
this.scopeManager = scopeManager || null;
|
448
|
+
|
449
|
+
/**
|
450
|
+
* The visitor keys to traverse AST.
|
451
|
+
* @type {Object}
|
452
|
+
*/
|
453
|
+
this.visitorKeys = visitorKeys || Traverser.DEFAULT_VISITOR_KEYS;
|
454
|
+
|
455
|
+
// Check the source text for the presence of a shebang since it is parsed as a standard line comment.
|
456
|
+
const shebangMatched = this.text.match(astUtils.shebangPattern);
|
457
|
+
const hasShebang =
|
458
|
+
shebangMatched &&
|
459
|
+
ast.comments.length &&
|
460
|
+
ast.comments[0].value === shebangMatched[1];
|
461
|
+
|
462
|
+
if (hasShebang) {
|
463
|
+
ast.comments[0].type = "Shebang";
|
464
|
+
}
|
465
|
+
|
466
|
+
this.tokensAndComments = sortedMerge(ast.tokens, ast.comments);
|
467
|
+
|
468
|
+
/**
|
469
|
+
* The source code split into lines according to ECMA-262 specification.
|
470
|
+
* This is done to avoid each rule needing to do so separately.
|
471
|
+
* @type {string[]}
|
472
|
+
*/
|
473
|
+
this.lines = [];
|
474
|
+
this.lineStartIndices = [0];
|
475
|
+
|
476
|
+
const lineEndingPattern = astUtils.createGlobalLinebreakMatcher();
|
477
|
+
let match;
|
478
|
+
|
479
|
+
/*
|
480
|
+
* Previously, this was implemented using a regex that
|
481
|
+
* matched a sequence of non-linebreak characters followed by a
|
482
|
+
* linebreak, then adding the lengths of the matches. However,
|
483
|
+
* this caused a catastrophic backtracking issue when the end
|
484
|
+
* of a file contained a large number of non-newline characters.
|
485
|
+
* To avoid this, the current implementation just matches newlines
|
486
|
+
* and uses match.index to get the correct line start indices.
|
487
|
+
*/
|
488
|
+
while ((match = lineEndingPattern.exec(this.text))) {
|
489
|
+
this.lines.push(
|
490
|
+
this.text.slice(this.lineStartIndices.at(-1), match.index),
|
491
|
+
);
|
492
|
+
this.lineStartIndices.push(match.index + match[0].length);
|
493
|
+
}
|
494
|
+
this.lines.push(this.text.slice(this.lineStartIndices.at(-1)));
|
495
|
+
|
496
|
+
// don't allow further modification of this object
|
497
|
+
Object.freeze(this);
|
498
|
+
Object.freeze(this.lines);
|
499
|
+
}
|
500
|
+
|
501
|
+
/**
|
502
|
+
* Split the source code into multiple lines based on the line delimiters.
|
503
|
+
* @param {string} text Source code as a string.
|
504
|
+
* @returns {string[]} Array of source code lines.
|
505
|
+
* @public
|
506
|
+
*/
|
507
|
+
static splitLines(text) {
|
508
|
+
return text.split(astUtils.createGlobalLinebreakMatcher());
|
509
|
+
}
|
510
|
+
|
511
|
+
/**
|
512
|
+
* Gets the source code for the given node.
|
513
|
+
* @param {ASTNode} [node] The AST node to get the text for.
|
514
|
+
* @param {int} [beforeCount] The number of characters before the node to retrieve.
|
515
|
+
* @param {int} [afterCount] The number of characters after the node to retrieve.
|
516
|
+
* @returns {string} The text representing the AST node.
|
517
|
+
* @public
|
518
|
+
*/
|
519
|
+
getText(node, beforeCount, afterCount) {
|
520
|
+
if (node) {
|
521
|
+
return this.text.slice(
|
522
|
+
Math.max(node.range[0] - (beforeCount || 0), 0),
|
523
|
+
node.range[1] + (afterCount || 0),
|
524
|
+
);
|
525
|
+
}
|
526
|
+
return this.text;
|
527
|
+
}
|
528
|
+
|
529
|
+
/**
|
530
|
+
* Gets the entire source text split into an array of lines.
|
531
|
+
* @returns {Array} The source text as an array of lines.
|
532
|
+
* @public
|
533
|
+
*/
|
534
|
+
getLines() {
|
535
|
+
return this.lines;
|
536
|
+
}
|
537
|
+
|
538
|
+
/**
|
539
|
+
* Retrieves an array containing all comments in the source code.
|
540
|
+
* @returns {ASTNode[]} An array of comment nodes.
|
541
|
+
* @public
|
542
|
+
*/
|
543
|
+
getAllComments() {
|
544
|
+
return this.ast.comments;
|
545
|
+
}
|
546
|
+
|
547
|
+
/**
|
548
|
+
* Retrieves the JSDoc comment for a given node.
|
549
|
+
* @param {ASTNode} node The AST node to get the comment for.
|
550
|
+
* @returns {Token|null} The Block comment token containing the JSDoc comment
|
551
|
+
* for the given node or null if not found.
|
552
|
+
* @public
|
553
|
+
* @deprecated
|
554
|
+
*/
|
555
|
+
getJSDocComment(node) {
|
556
|
+
/**
|
557
|
+
* Checks for the presence of a JSDoc comment for the given node and returns it.
|
558
|
+
* @param {ASTNode} astNode The AST node to get the comment for.
|
559
|
+
* @returns {Token|null} The Block comment token containing the JSDoc comment
|
560
|
+
* for the given node or null if not found.
|
561
|
+
* @private
|
562
|
+
*/
|
563
|
+
const findJSDocComment = astNode => {
|
564
|
+
const tokenBefore = this.getTokenBefore(astNode, {
|
565
|
+
includeComments: true,
|
566
|
+
});
|
567
|
+
|
568
|
+
if (
|
569
|
+
tokenBefore &&
|
570
|
+
isCommentToken(tokenBefore) &&
|
571
|
+
tokenBefore.type === "Block" &&
|
572
|
+
tokenBefore.value.charAt(0) === "*" &&
|
573
|
+
astNode.loc.start.line - tokenBefore.loc.end.line <= 1
|
574
|
+
) {
|
575
|
+
return tokenBefore;
|
576
|
+
}
|
577
|
+
|
578
|
+
return null;
|
579
|
+
};
|
580
|
+
let parent = node.parent;
|
581
|
+
|
582
|
+
switch (node.type) {
|
583
|
+
case "ClassDeclaration":
|
584
|
+
case "FunctionDeclaration":
|
585
|
+
return findJSDocComment(
|
586
|
+
looksLikeExport(parent) ? parent : node,
|
587
|
+
);
|
588
|
+
|
589
|
+
case "ClassExpression":
|
590
|
+
return findJSDocComment(parent.parent);
|
591
|
+
|
592
|
+
case "ArrowFunctionExpression":
|
593
|
+
case "FunctionExpression":
|
594
|
+
if (
|
595
|
+
parent.type !== "CallExpression" &&
|
596
|
+
parent.type !== "NewExpression"
|
597
|
+
) {
|
598
|
+
while (
|
599
|
+
!this.getCommentsBefore(parent).length &&
|
600
|
+
!/Function/u.test(parent.type) &&
|
601
|
+
parent.type !== "MethodDefinition" &&
|
602
|
+
parent.type !== "Property"
|
603
|
+
) {
|
604
|
+
parent = parent.parent;
|
605
|
+
|
606
|
+
if (!parent) {
|
607
|
+
break;
|
608
|
+
}
|
609
|
+
}
|
610
|
+
|
611
|
+
if (
|
612
|
+
parent &&
|
613
|
+
parent.type !== "FunctionDeclaration" &&
|
614
|
+
parent.type !== "Program"
|
615
|
+
) {
|
616
|
+
return findJSDocComment(parent);
|
617
|
+
}
|
618
|
+
}
|
619
|
+
|
620
|
+
return findJSDocComment(node);
|
621
|
+
|
622
|
+
// falls through
|
623
|
+
default:
|
624
|
+
return null;
|
625
|
+
}
|
626
|
+
}
|
627
|
+
|
628
|
+
/**
|
629
|
+
* Gets the deepest node containing a range index.
|
630
|
+
* @param {int} index Range index of the desired node.
|
631
|
+
* @returns {ASTNode} The node if found or null if not found.
|
632
|
+
* @public
|
633
|
+
*/
|
634
|
+
getNodeByRangeIndex(index) {
|
635
|
+
let result = null;
|
636
|
+
|
637
|
+
Traverser.traverse(this.ast, {
|
638
|
+
visitorKeys: this.visitorKeys,
|
639
|
+
enter(node) {
|
640
|
+
if (node.range[0] <= index && index < node.range[1]) {
|
641
|
+
result = node;
|
642
|
+
} else {
|
643
|
+
this.skip();
|
644
|
+
}
|
645
|
+
},
|
646
|
+
leave(node) {
|
647
|
+
if (node === result) {
|
648
|
+
this.break();
|
649
|
+
}
|
650
|
+
},
|
651
|
+
});
|
652
|
+
|
653
|
+
return result;
|
654
|
+
}
|
655
|
+
|
656
|
+
/**
|
657
|
+
* Determines if two nodes or tokens have at least one whitespace character
|
658
|
+
* between them. Order does not matter. Returns false if the given nodes or
|
659
|
+
* tokens overlap.
|
660
|
+
* @param {ASTNode|Token} first The first node or token to check between.
|
661
|
+
* @param {ASTNode|Token} second The second node or token to check between.
|
662
|
+
* @returns {boolean} True if there is a whitespace character between
|
663
|
+
* any of the tokens found between the two given nodes or tokens.
|
664
|
+
* @public
|
665
|
+
*/
|
666
|
+
isSpaceBetween(first, second) {
|
667
|
+
return isSpaceBetween(this, first, second, false);
|
668
|
+
}
|
669
|
+
|
670
|
+
/**
|
671
|
+
* Determines if two nodes or tokens have at least one whitespace character
|
672
|
+
* between them. Order does not matter. Returns false if the given nodes or
|
673
|
+
* tokens overlap.
|
674
|
+
* For backward compatibility, this method returns true if there are
|
675
|
+
* `JSXText` tokens that contain whitespaces between the two.
|
676
|
+
* @param {ASTNode|Token} first The first node or token to check between.
|
677
|
+
* @param {ASTNode|Token} second The second node or token to check between.
|
678
|
+
* @returns {boolean} True if there is a whitespace character between
|
679
|
+
* any of the tokens found between the two given nodes or tokens.
|
680
|
+
* @deprecated in favor of isSpaceBetween().
|
681
|
+
* @public
|
682
|
+
*/
|
683
|
+
isSpaceBetweenTokens(first, second) {
|
684
|
+
return isSpaceBetween(this, first, second, true);
|
685
|
+
}
|
686
|
+
|
687
|
+
/**
|
688
|
+
* Converts a source text index into a (line, column) pair.
|
689
|
+
* @param {number} index The index of a character in a file
|
690
|
+
* @throws {TypeError} If non-numeric index or index out of range.
|
691
|
+
* @returns {Object} A {line, column} location object with a 0-indexed column
|
692
|
+
* @public
|
693
|
+
*/
|
694
|
+
getLocFromIndex(index) {
|
695
|
+
if (typeof index !== "number") {
|
696
|
+
throw new TypeError("Expected `index` to be a number.");
|
697
|
+
}
|
698
|
+
|
699
|
+
if (index < 0 || index > this.text.length) {
|
700
|
+
throw new RangeError(
|
701
|
+
`Index out of range (requested index ${index}, but source text has length ${this.text.length}).`,
|
702
|
+
);
|
703
|
+
}
|
704
|
+
|
705
|
+
/*
|
706
|
+
* For an argument of this.text.length, return the location one "spot" past the last character
|
707
|
+
* of the file. If the last character is a linebreak, the location will be column 0 of the next
|
708
|
+
* line; otherwise, the location will be in the next column on the same line.
|
709
|
+
*
|
710
|
+
* See getIndexFromLoc for the motivation for this special case.
|
711
|
+
*/
|
712
|
+
if (index === this.text.length) {
|
713
|
+
return {
|
714
|
+
line: this.lines.length,
|
715
|
+
column: this.lines.at(-1).length,
|
716
|
+
};
|
717
|
+
}
|
718
|
+
|
719
|
+
/*
|
720
|
+
* To figure out which line index is on, determine the last place at which index could
|
721
|
+
* be inserted into lineStartIndices to keep the list sorted.
|
722
|
+
*/
|
723
|
+
const lineNumber =
|
724
|
+
index >= this.lineStartIndices.at(-1)
|
725
|
+
? this.lineStartIndices.length
|
726
|
+
: this.lineStartIndices.findIndex(el => index < el);
|
727
|
+
|
728
|
+
return {
|
729
|
+
line: lineNumber,
|
730
|
+
column: index - this.lineStartIndices[lineNumber - 1],
|
731
|
+
};
|
732
|
+
}
|
733
|
+
|
734
|
+
/**
|
735
|
+
* Converts a (line, column) pair into a range index.
|
736
|
+
* @param {Object} loc A line/column location
|
737
|
+
* @param {number} loc.line The line number of the location (1-indexed)
|
738
|
+
* @param {number} loc.column The column number of the location (0-indexed)
|
739
|
+
* @throws {TypeError|RangeError} If `loc` is not an object with a numeric
|
740
|
+
* `line` and `column`, if the `line` is less than or equal to zero or
|
741
|
+
* the line or column is out of the expected range.
|
742
|
+
* @returns {number} The range index of the location in the file.
|
743
|
+
* @public
|
744
|
+
*/
|
745
|
+
getIndexFromLoc(loc) {
|
746
|
+
if (
|
747
|
+
typeof loc !== "object" ||
|
748
|
+
typeof loc.line !== "number" ||
|
749
|
+
typeof loc.column !== "number"
|
750
|
+
) {
|
751
|
+
throw new TypeError(
|
752
|
+
"Expected `loc` to be an object with numeric `line` and `column` properties.",
|
753
|
+
);
|
754
|
+
}
|
755
|
+
|
756
|
+
if (loc.line <= 0) {
|
757
|
+
throw new RangeError(
|
758
|
+
`Line number out of range (line ${loc.line} requested). Line numbers should be 1-based.`,
|
759
|
+
);
|
760
|
+
}
|
761
|
+
|
762
|
+
if (loc.line > this.lineStartIndices.length) {
|
763
|
+
throw new RangeError(
|
764
|
+
`Line number out of range (line ${loc.line} requested, but only ${this.lineStartIndices.length} lines present).`,
|
765
|
+
);
|
766
|
+
}
|
767
|
+
|
768
|
+
const lineStartIndex = this.lineStartIndices[loc.line - 1];
|
769
|
+
const lineEndIndex =
|
770
|
+
loc.line === this.lineStartIndices.length
|
771
|
+
? this.text.length
|
772
|
+
: this.lineStartIndices[loc.line];
|
773
|
+
const positionIndex = lineStartIndex + loc.column;
|
774
|
+
|
775
|
+
/*
|
776
|
+
* By design, getIndexFromLoc({ line: lineNum, column: 0 }) should return the start index of
|
777
|
+
* the given line, provided that the line number is valid element of this.lines. Since the
|
778
|
+
* last element of this.lines is an empty string for files with trailing newlines, add a
|
779
|
+
* special case where getting the index for the first location after the end of the file
|
780
|
+
* will return the length of the file, rather than throwing an error. This allows rules to
|
781
|
+
* use getIndexFromLoc consistently without worrying about edge cases at the end of a file.
|
782
|
+
*/
|
783
|
+
if (
|
784
|
+
(loc.line === this.lineStartIndices.length &&
|
785
|
+
positionIndex > lineEndIndex) ||
|
786
|
+
(loc.line < this.lineStartIndices.length &&
|
787
|
+
positionIndex >= lineEndIndex)
|
788
|
+
) {
|
789
|
+
throw new RangeError(
|
790
|
+
`Column number out of range (column ${loc.column} requested, but the length of line ${loc.line} is ${lineEndIndex - lineStartIndex}).`,
|
791
|
+
);
|
792
|
+
}
|
793
|
+
|
794
|
+
return positionIndex;
|
795
|
+
}
|
796
|
+
|
797
|
+
/**
|
798
|
+
* Gets the scope for the given node
|
799
|
+
* @param {ASTNode} currentNode The node to get the scope of
|
800
|
+
* @returns {Scope} The scope information for this node
|
801
|
+
* @throws {TypeError} If the `currentNode` argument is missing.
|
802
|
+
*/
|
803
|
+
getScope(currentNode) {
|
804
|
+
if (!currentNode) {
|
805
|
+
throw new TypeError("Missing required argument: node.");
|
806
|
+
}
|
807
|
+
|
808
|
+
// check cache first
|
809
|
+
const cache = this[caches].get("scopes");
|
810
|
+
const cachedScope = cache.get(currentNode);
|
811
|
+
|
812
|
+
if (cachedScope) {
|
813
|
+
return cachedScope;
|
814
|
+
}
|
815
|
+
|
816
|
+
// On Program node, get the outermost scope to avoid return Node.js special function scope or ES modules scope.
|
817
|
+
const inner = currentNode.type !== "Program";
|
818
|
+
|
819
|
+
for (let node = currentNode; node; node = node.parent) {
|
820
|
+
const scope = this.scopeManager.acquire(node, inner);
|
821
|
+
|
822
|
+
if (scope) {
|
823
|
+
if (scope.type === "function-expression-name") {
|
824
|
+
cache.set(currentNode, scope.childScopes[0]);
|
825
|
+
return scope.childScopes[0];
|
826
|
+
}
|
827
|
+
|
828
|
+
cache.set(currentNode, scope);
|
829
|
+
return scope;
|
830
|
+
}
|
831
|
+
}
|
832
|
+
|
833
|
+
cache.set(currentNode, this.scopeManager.scopes[0]);
|
834
|
+
return this.scopeManager.scopes[0];
|
835
|
+
}
|
836
|
+
|
837
|
+
/**
|
838
|
+
* Get the variables that `node` defines.
|
839
|
+
* This is a convenience method that passes through
|
840
|
+
* to the same method on the `scopeManager`.
|
841
|
+
* @param {ASTNode} node The node for which the variables are obtained.
|
842
|
+
* @returns {Array<Variable>} An array of variable nodes representing
|
843
|
+
* the variables that `node` defines.
|
844
|
+
*/
|
845
|
+
getDeclaredVariables(node) {
|
846
|
+
return this.scopeManager.getDeclaredVariables(node);
|
847
|
+
}
|
848
|
+
|
849
|
+
/* eslint-disable class-methods-use-this -- node is owned by SourceCode */
|
850
|
+
/**
|
851
|
+
* Gets all the ancestors of a given node
|
852
|
+
* @param {ASTNode} node The node
|
853
|
+
* @returns {Array<ASTNode>} All the ancestor nodes in the AST, not including the provided node, starting
|
854
|
+
* from the root node at index 0 and going inwards to the parent node.
|
855
|
+
* @throws {TypeError} When `node` is missing.
|
856
|
+
*/
|
857
|
+
getAncestors(node) {
|
858
|
+
if (!node) {
|
859
|
+
throw new TypeError("Missing required argument: node.");
|
860
|
+
}
|
861
|
+
|
862
|
+
const ancestorsStartingAtParent = [];
|
863
|
+
|
864
|
+
for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
|
865
|
+
ancestorsStartingAtParent.push(ancestor);
|
866
|
+
}
|
867
|
+
|
868
|
+
return ancestorsStartingAtParent.reverse();
|
869
|
+
}
|
870
|
+
|
871
|
+
/**
|
872
|
+
* Returns the location of the given node or token.
|
873
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to get the location of.
|
874
|
+
* @returns {SourceLocation} The location of the node or token.
|
875
|
+
*/
|
876
|
+
getLoc(nodeOrToken) {
|
877
|
+
return nodeOrToken.loc;
|
878
|
+
}
|
879
|
+
|
880
|
+
/**
|
881
|
+
* Returns the range of the given node or token.
|
882
|
+
* @param {ASTNode|Token} nodeOrToken The node or token to get the range of.
|
883
|
+
* @returns {[number, number]} The range of the node or token.
|
884
|
+
*/
|
885
|
+
getRange(nodeOrToken) {
|
886
|
+
return nodeOrToken.range;
|
887
|
+
}
|
888
|
+
|
889
|
+
/* eslint-enable class-methods-use-this -- node is owned by SourceCode */
|
890
|
+
|
891
|
+
/**
|
892
|
+
* Marks a variable as used in the current scope
|
893
|
+
* @param {string} name The name of the variable to mark as used.
|
894
|
+
* @param {ASTNode} [refNode] The closest node to the variable reference.
|
895
|
+
* @returns {boolean} True if the variable was found and marked as used, false if not.
|
896
|
+
*/
|
897
|
+
markVariableAsUsed(name, refNode = this.ast) {
|
898
|
+
const currentScope = this.getScope(refNode);
|
899
|
+
let initialScope = currentScope;
|
900
|
+
|
901
|
+
/*
|
902
|
+
* When we are in an ESM or CommonJS module, we need to start searching
|
903
|
+
* from the top-level scope, not the global scope. For ESM the top-level
|
904
|
+
* scope is the module scope; for CommonJS the top-level scope is the
|
905
|
+
* outer function scope.
|
906
|
+
*
|
907
|
+
* Without this check, we might miss a variable declared with `var` at
|
908
|
+
* the top-level because it won't exist in the global scope.
|
909
|
+
*/
|
910
|
+
if (
|
911
|
+
currentScope.type === "global" &&
|
912
|
+
currentScope.childScopes.length > 0 &&
|
913
|
+
// top-level scopes refer to a `Program` node
|
914
|
+
currentScope.childScopes[0].block === this.ast
|
915
|
+
) {
|
916
|
+
initialScope = currentScope.childScopes[0];
|
917
|
+
}
|
918
|
+
|
919
|
+
for (let scope = initialScope; scope; scope = scope.upper) {
|
920
|
+
const variable = scope.variables.find(
|
921
|
+
scopeVar => scopeVar.name === name,
|
922
|
+
);
|
923
|
+
|
924
|
+
if (variable) {
|
925
|
+
variable.eslintUsed = true;
|
926
|
+
return true;
|
927
|
+
}
|
928
|
+
}
|
929
|
+
|
930
|
+
return false;
|
931
|
+
}
|
932
|
+
|
933
|
+
/**
|
934
|
+
* Returns an array of all inline configuration nodes found in the
|
935
|
+
* source code.
|
936
|
+
* @returns {Array<Token>} An array of all inline configuration nodes.
|
937
|
+
*/
|
938
|
+
getInlineConfigNodes() {
|
939
|
+
// check the cache first
|
940
|
+
let configNodes = this[caches].get("configNodes");
|
941
|
+
|
942
|
+
if (configNodes) {
|
943
|
+
return configNodes;
|
944
|
+
}
|
945
|
+
|
946
|
+
// calculate fresh config nodes
|
947
|
+
configNodes = this.ast.comments.filter(comment => {
|
948
|
+
// shebang comments are never directives
|
949
|
+
if (comment.type === "Shebang") {
|
950
|
+
return false;
|
951
|
+
}
|
952
|
+
|
953
|
+
const directive = commentParser.parseDirective(comment.value);
|
954
|
+
|
955
|
+
if (!directive) {
|
956
|
+
return false;
|
957
|
+
}
|
958
|
+
|
959
|
+
if (!directivesPattern.test(directive.label)) {
|
960
|
+
return false;
|
961
|
+
}
|
962
|
+
|
963
|
+
// only certain comment types are supported as line comments
|
964
|
+
return (
|
965
|
+
comment.type !== "Line" ||
|
966
|
+
!!/^eslint-disable-(next-)?line$/u.test(directive.label)
|
967
|
+
);
|
968
|
+
});
|
969
|
+
|
970
|
+
this[caches].set("configNodes", configNodes);
|
971
|
+
|
972
|
+
return configNodes;
|
973
|
+
}
|
974
|
+
|
975
|
+
/**
|
976
|
+
* Returns an all directive nodes that enable or disable rules along with any problems
|
977
|
+
* encountered while parsing the directives.
|
978
|
+
* @returns {{problems:Array<Problem>,directives:Array<Directive>}} Information
|
979
|
+
* that ESLint needs to further process the directives.
|
980
|
+
*/
|
981
|
+
getDisableDirectives() {
|
982
|
+
// check the cache first
|
983
|
+
const cachedDirectives = this[caches].get("disableDirectives");
|
984
|
+
|
985
|
+
if (cachedDirectives) {
|
986
|
+
return cachedDirectives;
|
987
|
+
}
|
988
|
+
|
989
|
+
const problems = [];
|
990
|
+
const directives = [];
|
991
|
+
|
992
|
+
this.getInlineConfigNodes().forEach(comment => {
|
993
|
+
// Step 1: Parse the directive
|
994
|
+
const {
|
995
|
+
label,
|
996
|
+
value,
|
997
|
+
justification: justificationPart,
|
998
|
+
} = commentParser.parseDirective(comment.value);
|
999
|
+
|
1000
|
+
// Step 2: Extract the directive value
|
1001
|
+
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(
|
1002
|
+
label,
|
1003
|
+
);
|
1004
|
+
|
1005
|
+
if (comment.type === "Line" && !lineCommentSupported) {
|
1006
|
+
return;
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
// Step 3: Validate the directive does not span multiple lines
|
1010
|
+
if (
|
1011
|
+
label === "eslint-disable-line" &&
|
1012
|
+
comment.loc.start.line !== comment.loc.end.line
|
1013
|
+
) {
|
1014
|
+
const message = `${label} comment should not span multiple lines.`;
|
1015
|
+
|
1016
|
+
problems.push({
|
1017
|
+
ruleId: null,
|
1018
|
+
message,
|
1019
|
+
loc: comment.loc,
|
1020
|
+
});
|
1021
|
+
return;
|
1022
|
+
}
|
1023
|
+
|
1024
|
+
// Step 4: Extract the directive value and create the Directive object
|
1025
|
+
switch (label) {
|
1026
|
+
case "eslint-disable":
|
1027
|
+
case "eslint-enable":
|
1028
|
+
case "eslint-disable-next-line":
|
1029
|
+
case "eslint-disable-line": {
|
1030
|
+
const directiveType = label.slice("eslint-".length);
|
1031
|
+
|
1032
|
+
directives.push(
|
1033
|
+
new Directive({
|
1034
|
+
type: directiveType,
|
1035
|
+
node: comment,
|
1036
|
+
value,
|
1037
|
+
justification: justificationPart,
|
1038
|
+
}),
|
1039
|
+
);
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
// no default
|
1043
|
+
}
|
1044
|
+
});
|
1045
|
+
|
1046
|
+
const result = { problems, directives };
|
1047
|
+
|
1048
|
+
this[caches].set("disableDirectives", result);
|
1049
|
+
|
1050
|
+
return result;
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
/**
|
1054
|
+
* Applies language options sent in from the core.
|
1055
|
+
* @param {Object} languageOptions The language options for this run.
|
1056
|
+
* @returns {void}
|
1057
|
+
*/
|
1058
|
+
applyLanguageOptions(languageOptions) {
|
1059
|
+
/*
|
1060
|
+
* Add configured globals and language globals
|
1061
|
+
*
|
1062
|
+
* Using Object.assign instead of object spread for performance reasons
|
1063
|
+
* https://github.com/eslint/eslint/issues/16302
|
1064
|
+
*/
|
1065
|
+
const configGlobals = Object.assign(
|
1066
|
+
Object.create(null), // https://github.com/eslint/eslint/issues/18363
|
1067
|
+
getGlobalsForEcmaVersion(languageOptions.ecmaVersion),
|
1068
|
+
languageOptions.sourceType === "commonjs"
|
1069
|
+
? globals.commonjs
|
1070
|
+
: void 0,
|
1071
|
+
languageOptions.globals,
|
1072
|
+
);
|
1073
|
+
const varsCache = this[caches].get("vars");
|
1074
|
+
|
1075
|
+
varsCache.set("configGlobals", configGlobals);
|
1076
|
+
}
|
1077
|
+
|
1078
|
+
/**
|
1079
|
+
* Applies configuration found inside of the source code. This method is only
|
1080
|
+
* called when ESLint is running with inline configuration allowed.
|
1081
|
+
* @returns {{problems:Array<Problem>,configs:{config:FlatConfigArray,loc:Location}}} Information
|
1082
|
+
* that ESLint needs to further process the inline configuration.
|
1083
|
+
*/
|
1084
|
+
applyInlineConfig() {
|
1085
|
+
const problems = [];
|
1086
|
+
const configs = [];
|
1087
|
+
const exportedVariables = {};
|
1088
|
+
const inlineGlobals = Object.create(null);
|
1089
|
+
|
1090
|
+
this.getInlineConfigNodes().forEach(comment => {
|
1091
|
+
const { label, value } = commentParser.parseDirective(
|
1092
|
+
comment.value,
|
1093
|
+
);
|
1094
|
+
|
1095
|
+
switch (label) {
|
1096
|
+
case "exported":
|
1097
|
+
Object.assign(
|
1098
|
+
exportedVariables,
|
1099
|
+
commentParser.parseListConfig(value),
|
1100
|
+
);
|
1101
|
+
break;
|
1102
|
+
|
1103
|
+
case "globals":
|
1104
|
+
case "global":
|
1105
|
+
for (const [id, idSetting] of Object.entries(
|
1106
|
+
commentParser.parseStringConfig(value),
|
1107
|
+
)) {
|
1108
|
+
let normalizedValue;
|
1109
|
+
|
1110
|
+
try {
|
1111
|
+
normalizedValue = normalizeConfigGlobal(idSetting);
|
1112
|
+
} catch (err) {
|
1113
|
+
problems.push({
|
1114
|
+
ruleId: null,
|
1115
|
+
loc: comment.loc,
|
1116
|
+
message: err.message,
|
1117
|
+
});
|
1118
|
+
continue;
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
if (inlineGlobals[id]) {
|
1122
|
+
inlineGlobals[id].comments.push(comment);
|
1123
|
+
inlineGlobals[id].value = normalizedValue;
|
1124
|
+
} else {
|
1125
|
+
inlineGlobals[id] = {
|
1126
|
+
comments: [comment],
|
1127
|
+
value: normalizedValue,
|
1128
|
+
};
|
1129
|
+
}
|
1130
|
+
}
|
1131
|
+
break;
|
1132
|
+
|
1133
|
+
case "eslint": {
|
1134
|
+
const parseResult =
|
1135
|
+
commentParser.parseJSONLikeConfig(value);
|
1136
|
+
|
1137
|
+
if (parseResult.ok) {
|
1138
|
+
configs.push({
|
1139
|
+
config: {
|
1140
|
+
rules: parseResult.config,
|
1141
|
+
},
|
1142
|
+
loc: comment.loc,
|
1143
|
+
});
|
1144
|
+
} else {
|
1145
|
+
problems.push({
|
1146
|
+
ruleId: null,
|
1147
|
+
loc: comment.loc,
|
1148
|
+
message: parseResult.error.message,
|
1149
|
+
});
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
break;
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
// no default
|
1156
|
+
}
|
1157
|
+
});
|
1158
|
+
|
1159
|
+
// save all the new variables for later
|
1160
|
+
const varsCache = this[caches].get("vars");
|
1161
|
+
|
1162
|
+
varsCache.set("inlineGlobals", inlineGlobals);
|
1163
|
+
varsCache.set("exportedVariables", exportedVariables);
|
1164
|
+
|
1165
|
+
return {
|
1166
|
+
configs,
|
1167
|
+
problems,
|
1168
|
+
};
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
/**
|
1172
|
+
* Called by ESLint core to indicate that it has finished providing
|
1173
|
+
* information. We now add in all the missing variables and ensure that
|
1174
|
+
* state-changing methods cannot be called by rules.
|
1175
|
+
* @returns {void}
|
1176
|
+
*/
|
1177
|
+
finalize() {
|
1178
|
+
const varsCache = this[caches].get("vars");
|
1179
|
+
const configGlobals = varsCache.get("configGlobals");
|
1180
|
+
const inlineGlobals = varsCache.get("inlineGlobals");
|
1181
|
+
const exportedVariables = varsCache.get("exportedVariables");
|
1182
|
+
const globalScope = this.scopeManager.scopes[0];
|
1183
|
+
|
1184
|
+
addDeclaredGlobals(globalScope, configGlobals, inlineGlobals);
|
1185
|
+
|
1186
|
+
if (exportedVariables) {
|
1187
|
+
markExportedVariables(globalScope, exportedVariables);
|
1188
|
+
}
|
1189
|
+
}
|
1190
|
+
|
1191
|
+
/**
|
1192
|
+
* Traverse the source code and return the steps that were taken.
|
1193
|
+
* @returns {Array<TraversalStep>} The steps that were taken while traversing the source code.
|
1194
|
+
*/
|
1195
|
+
traverse() {
|
1196
|
+
// Because the AST doesn't mutate, we can cache the steps
|
1197
|
+
if (this.#steps) {
|
1198
|
+
return this.#steps;
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
const steps = (this.#steps = []);
|
1202
|
+
|
1203
|
+
/*
|
1204
|
+
* This logic works for any AST, not just ESTree. Because ESLint has allowed
|
1205
|
+
* custom parsers to return any AST, we need to ensure that the traversal
|
1206
|
+
* logic works for any AST.
|
1207
|
+
*/
|
1208
|
+
const emitter = createEmitter();
|
1209
|
+
let analyzer = {
|
1210
|
+
enterNode(node) {
|
1211
|
+
steps.push(
|
1212
|
+
new VisitNodeStep({
|
1213
|
+
target: node,
|
1214
|
+
phase: 1,
|
1215
|
+
args: [node, node.parent],
|
1216
|
+
}),
|
1217
|
+
);
|
1218
|
+
},
|
1219
|
+
leaveNode(node) {
|
1220
|
+
steps.push(
|
1221
|
+
new VisitNodeStep({
|
1222
|
+
target: node,
|
1223
|
+
phase: 2,
|
1224
|
+
args: [node, node.parent],
|
1225
|
+
}),
|
1226
|
+
);
|
1227
|
+
},
|
1228
|
+
emitter,
|
1229
|
+
};
|
1230
|
+
|
1231
|
+
/*
|
1232
|
+
* We do code path analysis for ESTree only. Code path analysis is not
|
1233
|
+
* necessary for other ASTs, and it's also not possible to do for other
|
1234
|
+
* ASTs because the necessary information is not available.
|
1235
|
+
*
|
1236
|
+
* Generally speaking, we can tell that the AST is an ESTree if it has a
|
1237
|
+
* Program node at the top level. This is not a perfect heuristic, but it
|
1238
|
+
* is good enough for now.
|
1239
|
+
*/
|
1240
|
+
if (this.isESTree) {
|
1241
|
+
analyzer = new CodePathAnalyzer(analyzer);
|
1242
|
+
|
1243
|
+
CODE_PATH_EVENTS.forEach(eventName => {
|
1244
|
+
emitter.on(eventName, (...args) => {
|
1245
|
+
steps.push(
|
1246
|
+
new CallMethodStep({
|
1247
|
+
target: eventName,
|
1248
|
+
args,
|
1249
|
+
}),
|
1250
|
+
);
|
1251
|
+
});
|
1252
|
+
});
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
/*
|
1256
|
+
* The actual AST traversal is done by the `Traverser` class. This class
|
1257
|
+
* is responsible for walking the AST and calling the appropriate methods
|
1258
|
+
* on the `analyzer` object, which is appropriate for the given AST.
|
1259
|
+
*/
|
1260
|
+
Traverser.traverse(this.ast, {
|
1261
|
+
enter(node, parent) {
|
1262
|
+
// save the parent node on a property for backwards compatibility
|
1263
|
+
node.parent = parent;
|
1264
|
+
|
1265
|
+
analyzer.enterNode(node);
|
1266
|
+
},
|
1267
|
+
leave(node) {
|
1268
|
+
analyzer.leaveNode(node);
|
1269
|
+
},
|
1270
|
+
visitorKeys: this.visitorKeys,
|
1271
|
+
});
|
1272
|
+
|
1273
|
+
return steps;
|
1274
|
+
}
|
1204
1275
|
}
|
1205
1276
|
|
1206
1277
|
module.exports = SourceCode;
|