From 1cf3b51b69165b37daaa8a18305451c78bb690e9 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 29 Nov 2023 11:25:48 -0500 Subject: [PATCH 1/4] chore: Convert rule tests to FlatRuleTester --- lib/rules/no-invalid-this.js | 2 +- tests/lib/rules/accessor-pairs.js | 684 +++---- tests/lib/rules/array-bracket-newline.js | 130 +- tests/lib/rules/array-bracket-spacing.js | 126 +- tests/lib/rules/array-callback-return.js | 180 +- tests/lib/rules/array-element-newline.js | 58 +- tests/lib/rules/arrow-body-style.js | 4 +- tests/lib/rules/arrow-parens.js | 95 +- tests/lib/rules/arrow-spacing.js | 4 +- tests/lib/rules/block-scoped-var.js | 102 +- tests/lib/rules/block-spacing.js | 112 +- tests/lib/rules/brace-style.js | 96 +- tests/lib/rules/callback-return.js | 36 +- tests/lib/rules/camelcase.js | 450 +++-- tests/lib/rules/capitalized-comments.js | 2 +- tests/lib/rules/class-methods-use-this.js | 136 +- tests/lib/rules/comma-dangle.js | 678 +++---- tests/lib/rules/comma-spacing.js | 70 +- tests/lib/rules/comma-style.js | 96 +- tests/lib/rules/complexity.js | 256 +-- tests/lib/rules/computed-property-spacing.js | 246 +-- tests/lib/rules/consistent-return.js | 53 +- tests/lib/rules/consistent-this.js | 12 +- tests/lib/rules/constructor-super.js | 4 +- tests/lib/rules/curly.js | 119 +- tests/lib/rules/default-case-last.js | 2 +- tests/lib/rules/default-case.js | 2 +- tests/lib/rules/default-param-last.js | 4 +- tests/lib/rules/dot-location.js | 79 +- tests/lib/rules/dot-notation.js | 57 +- tests/lib/rules/eol-last.js | 2 +- tests/lib/rules/eqeqeq.js | 6 +- tests/lib/rules/for-direction.js | 4 +- tests/lib/rules/func-call-spacing.js | 74 +- tests/lib/rules/func-name-matching.js | 366 ++-- tests/lib/rules/func-names.js | 234 +-- tests/lib/rules/func-style.js | 20 +- .../rules/function-call-argument-newline.js | 50 +- tests/lib/rules/function-paren-newline.js | 180 +- tests/lib/rules/generator-star-spacing.js | 16 +- tests/lib/rules/getter-return.js | 24 +- tests/lib/rules/global-require.js | 15 +- tests/lib/rules/grouped-accessor-pairs.js | 8 +- tests/lib/rules/guard-for-in.js | 2 +- tests/lib/rules/handle-callback-err.js | 12 +- tests/lib/rules/id-blacklist.js | 291 +-- tests/lib/rules/id-denylist.js | 305 ++-- tests/lib/rules/id-length.js | 394 ++-- tests/lib/rules/id-match.js | 156 +- tests/lib/rules/implicit-arrow-linebreak.js | 20 +- tests/lib/rules/indent-legacy.js | 141 +- tests/lib/rules/indent.js | 358 ++-- tests/lib/rules/init-declarations.js | 88 +- tests/lib/rules/jsx-quotes.js | 11 +- tests/lib/rules/key-spacing.js | 140 +- tests/lib/rules/keyword-spacing.js | 1597 +++++++++-------- tests/lib/rules/line-comment-position.js | 2 +- tests/lib/rules/linebreak-style.js | 2 +- tests/lib/rules/lines-around-comment.js | 184 +- tests/lib/rules/lines-around-directive.js | 178 +- .../lib/rules/lines-between-class-members.js | 12 +- .../lib/rules/logical-assignment-operators.js | 41 +- tests/lib/rules/max-classes-per-file.js | 4 +- tests/lib/rules/max-depth.js | 36 +- tests/lib/rules/max-len.js | 134 +- tests/lib/rules/max-lines-per-function.js | 4 +- tests/lib/rules/max-lines.js | 2 +- tests/lib/rules/max-nested-callbacks.js | 12 +- tests/lib/rules/max-params.js | 8 +- tests/lib/rules/max-statements-per-line.js | 50 +- tests/lib/rules/max-statements.js | 54 +- tests/lib/rules/multiline-comment-style.js | 2 +- tests/lib/rules/multiline-ternary.js | 2 +- tests/lib/rules/new-cap.js | 40 +- tests/lib/rules/new-parens.js | 6 +- tests/lib/rules/newline-after-var.js | 68 +- tests/lib/rules/newline-before-return.js | 39 +- tests/lib/rules/newline-per-chained-call.js | 26 +- tests/lib/rules/no-alert.js | 37 +- tests/lib/rules/no-array-constructor.js | 28 +- tests/lib/rules/no-async-promise-executor.js | 4 +- tests/lib/rules/no-await-in-loop.js | 4 +- tests/lib/rules/no-bitwise.js | 8 +- tests/lib/rules/no-buffer-constructor.js | 2 +- tests/lib/rules/no-caller.js | 2 +- tests/lib/rules/no-case-declarations.js | 72 +- tests/lib/rules/no-catch-shadow.js | 11 +- tests/lib/rules/no-class-assign.js | 4 +- tests/lib/rules/no-compare-neg-zero.js | 2 +- tests/lib/rules/no-cond-assign.js | 6 +- tests/lib/rules/no-confusing-arrow.js | 4 +- tests/lib/rules/no-console.js | 34 +- tests/lib/rules/no-const-assign.js | 4 +- .../rules/no-constant-binary-expression.js | 18 +- tests/lib/rules/no-constant-condition.js | 32 +- tests/lib/rules/no-constructor-return.js | 6 +- tests/lib/rules/no-continue.js | 2 +- tests/lib/rules/no-control-regex.js | 38 +- tests/lib/rules/no-debugger.js | 2 +- tests/lib/rules/no-delete-var.js | 9 +- tests/lib/rules/no-div-regex.js | 2 +- tests/lib/rules/no-dupe-args.js | 15 +- tests/lib/rules/no-dupe-class-members.js | 8 +- tests/lib/rules/no-dupe-else-if.js | 2 +- tests/lib/rules/no-dupe-keys.js | 49 +- tests/lib/rules/no-duplicate-case.js | 2 +- tests/lib/rules/no-duplicate-imports.js | 4 +- tests/lib/rules/no-else-return.js | 219 +-- tests/lib/rules/no-empty-character-class.js | 44 +- tests/lib/rules/no-empty-function.js | 36 +- tests/lib/rules/no-empty-pattern.js | 102 +- tests/lib/rules/no-empty-static-block.js | 4 +- tests/lib/rules/no-empty.js | 4 +- tests/lib/rules/no-eq-null.js | 2 +- tests/lib/rules/no-eval.js | 150 +- tests/lib/rules/no-ex-assign.js | 10 +- tests/lib/rules/no-extend-native.js | 55 +- tests/lib/rules/no-extra-bind.js | 46 +- tests/lib/rules/no-extra-boolean-cast.js | 100 +- tests/lib/rules/no-extra-label.js | 8 +- tests/lib/rules/no-extra-parens.js | 162 +- tests/lib/rules/no-extra-semi.js | 83 +- tests/lib/rules/no-fallthrough.js | 4 +- tests/lib/rules/no-floating-decimal.js | 6 +- tests/lib/rules/no-func-assign.js | 22 +- tests/lib/rules/no-global-assign.js | 30 +- tests/lib/rules/no-implicit-coercion.js | 86 +- tests/lib/rules/no-implicit-globals.js | 444 ++--- tests/lib/rules/no-implied-eval.js | 196 +- tests/lib/rules/no-import-assign.js | 24 +- tests/lib/rules/no-inline-comments.js | 14 +- tests/lib/rules/no-inner-declarations.js | 59 +- tests/lib/rules/no-invalid-regexp.js | 2 +- tests/lib/rules/no-invalid-this.js | 225 +-- tests/lib/rules/no-irregular-whitespace.js | 436 +++-- tests/lib/rules/no-iterator.js | 14 +- tests/lib/rules/no-label-var.js | 2 +- tests/lib/rules/no-labels.js | 2 +- tests/lib/rules/no-lone-blocks.js | 107 +- tests/lib/rules/no-lonely-if.js | 6 +- tests/lib/rules/no-loop-func.js | 112 +- tests/lib/rules/no-loss-of-precision.js | 149 +- tests/lib/rules/no-magic-numbers.js | 231 +-- .../rules/no-misleading-character-class.js | 109 +- tests/lib/rules/no-mixed-operators.js | 6 +- tests/lib/rules/no-mixed-requires.js | 2 +- tests/lib/rules/no-mixed-spaces-and-tabs.js | 30 +- tests/lib/rules/no-multi-assign.js | 48 +- tests/lib/rules/no-multi-spaces.js | 8 +- tests/lib/rules/no-multi-str.js | 12 +- tests/lib/rules/no-multiple-empty-lines.js | 18 +- tests/lib/rules/no-native-reassign.js | 21 +- tests/lib/rules/no-negated-condition.js | 2 +- tests/lib/rules/no-negated-in-lhs.js | 2 +- tests/lib/rules/no-nested-ternary.js | 2 +- tests/lib/rules/no-new-func.js | 18 +- .../lib/rules/no-new-native-nonconstructor.js | 4 +- tests/lib/rules/no-new-object.js | 10 +- tests/lib/rules/no-new-require.js | 2 +- tests/lib/rules/no-new-symbol.js | 4 +- tests/lib/rules/no-new-wrappers.js | 14 +- tests/lib/rules/no-new.js | 2 +- tests/lib/rules/no-nonoctal-decimal-escape.js | 9 +- tests/lib/rules/no-obj-calls.js | 221 +-- tests/lib/rules/no-object-constructor.js | 22 +- tests/lib/rules/no-octal-escape.js | 9 +- tests/lib/rules/no-octal.js | 9 +- tests/lib/rules/no-param-reassign.js | 120 +- tests/lib/rules/no-path-concat.js | 2 +- tests/lib/rules/no-plusplus.js | 2 +- tests/lib/rules/no-process-env.js | 2 +- tests/lib/rules/no-process-exit.js | 2 +- tests/lib/rules/no-promise-executor-return.js | 30 +- tests/lib/rules/no-proto.js | 12 +- tests/lib/rules/no-prototype-builtins.js | 62 +- tests/lib/rules/no-redeclare.js | 139 +- tests/lib/rules/no-regex-spaces.js | 18 +- tests/lib/rules/no-restricted-exports.js | 4 +- tests/lib/rules/no-restricted-globals.js | 59 +- tests/lib/rules/no-restricted-imports.js | 4 +- tests/lib/rules/no-restricted-modules.js | 14 +- tests/lib/rules/no-restricted-properties.js | 92 +- tests/lib/rules/no-restricted-syntax.js | 24 +- tests/lib/rules/no-return-assign.js | 20 +- tests/lib/rules/no-return-await.js | 4 +- tests/lib/rules/no-script-url.js | 16 +- tests/lib/rules/no-self-assign.js | 120 +- tests/lib/rules/no-self-compare.js | 10 +- tests/lib/rules/no-sequences.js | 19 +- tests/lib/rules/no-setter-return.js | 71 +- tests/lib/rules/no-shadow-restricted-names.js | 27 +- tests/lib/rules/no-shadow.js | 375 ++-- tests/lib/rules/no-spaced-func.js | 2 +- tests/lib/rules/no-sparse-arrays.js | 2 +- tests/lib/rules/no-sync.js | 2 +- tests/lib/rules/no-tabs.js | 2 +- .../lib/rules/no-template-curly-in-string.js | 40 +- tests/lib/rules/no-ternary.js | 2 +- tests/lib/rules/no-this-before-super.js | 16 +- tests/lib/rules/no-throw-literal.js | 26 +- tests/lib/rules/no-trailing-spaces.js | 26 +- tests/lib/rules/no-undef-init.js | 74 +- tests/lib/rules/no-undef.js | 208 ++- tests/lib/rules/no-undefined.js | 30 +- tests/lib/rules/no-underscore-dangle.js | 202 +-- tests/lib/rules/no-unexpected-multiline.js | 70 +- .../lib/rules/no-unmodified-loop-condition.js | 10 +- tests/lib/rules/no-unneeded-ternary.js | 54 +- tests/lib/rules/no-unreachable-loop.js | 4 +- tests/lib/rules/no-unreachable.js | 87 +- tests/lib/rules/no-unsafe-finally.js | 8 +- tests/lib/rules/no-unsafe-negation.js | 2 +- .../lib/rules/no-unsafe-optional-chaining.js | 22 +- tests/lib/rules/no-unused-expressions.js | 84 +- tests/lib/rules/no-unused-labels.js | 6 +- .../rules/no-unused-private-class-members.js | 4 +- tests/lib/rules/no-unused-vars.js | 479 ++--- tests/lib/rules/no-use-before-define.js | 581 +++--- tests/lib/rules/no-useless-backreference.js | 8 +- tests/lib/rules/no-useless-call.js | 46 +- tests/lib/rules/no-useless-catch.js | 14 +- tests/lib/rules/no-useless-computed-key.js | 38 +- tests/lib/rules/no-useless-concat.js | 20 +- tests/lib/rules/no-useless-constructor.js | 8 +- tests/lib/rules/no-useless-escape.js | 401 +++-- tests/lib/rules/no-useless-rename.js | 70 +- tests/lib/rules/no-var.js | 165 +- tests/lib/rules/no-void.js | 8 +- tests/lib/rules/no-warning-comments.js | 2 +- .../rules/no-whitespace-before-property.js | 77 +- tests/lib/rules/no-with.js | 9 +- .../rules/nonblock-statement-body-position.js | 4 +- tests/lib/rules/object-curly-newline.js | 108 +- tests/lib/rules/object-curly-spacing.js | 336 ++-- tests/lib/rules/object-property-newline.js | 102 +- tests/lib/rules/object-shorthand.js | 86 +- .../lib/rules/one-var-declaration-per-line.js | 32 +- tests/lib/rules/one-var.js | 356 ++-- tests/lib/rules/operator-assignment.js | 4 +- tests/lib/rules/operator-linebreak.js | 88 +- tests/lib/rules/padded-blocks.js | 164 +- .../rules/padding-line-between-statements.js | 190 +- tests/lib/rules/prefer-arrow-callback.js | 4 +- tests/lib/rules/prefer-const.js | 173 +- tests/lib/rules/prefer-destructuring.js | 10 +- .../rules/prefer-exponentiation-operator.js | 42 +- tests/lib/rules/prefer-named-capture-group.js | 30 +- tests/lib/rules/prefer-numeric-literals.js | 40 +- tests/lib/rules/prefer-object-has-own.js | 6 +- tests/lib/rules/prefer-object-spread.js | 50 +- .../lib/rules/prefer-promise-reject-errors.js | 4 +- tests/lib/rules/prefer-reflect.js | 9 +- tests/lib/rules/prefer-regex-literals.js | 511 +++--- tests/lib/rules/prefer-rest-params.js | 4 +- tests/lib/rules/prefer-spread.js | 4 +- tests/lib/rules/prefer-template.js | 4 +- tests/lib/rules/quote-props.js | 92 +- tests/lib/rules/quotes.js | 287 +-- tests/lib/rules/radix.js | 36 +- tests/lib/rules/require-atomic-updates.js | 8 +- tests/lib/rules/require-await.js | 24 +- tests/lib/rules/require-jsdoc.js | 54 +- tests/lib/rules/require-unicode-regexp.js | 55 +- tests/lib/rules/require-yield.js | 4 +- tests/lib/rules/rest-spread-spacing.js | 100 +- tests/lib/rules/semi-spacing.js | 56 +- tests/lib/rules/semi-style.js | 68 +- tests/lib/rules/semi.js | 560 +++--- tests/lib/rules/sort-imports.js | 4 +- tests/lib/rules/sort-keys.js | 162 +- tests/lib/rules/sort-vars.js | 81 +- tests/lib/rules/space-before-blocks.js | 126 +- .../lib/rules/space-before-function-paren.js | 100 +- tests/lib/rules/space-in-parens.js | 22 +- tests/lib/rules/space-infix-ops.js | 86 +- tests/lib/rules/space-unary-ops.js | 74 +- tests/lib/rules/spaced-comment.js | 2 +- tests/lib/rules/strict.js | 297 ++- tests/lib/rules/switch-colon-spacing.js | 2 +- tests/lib/rules/symbol-description.js | 9 +- tests/lib/rules/template-curly-spacing.js | 4 +- tests/lib/rules/template-tag-spacing.js | 4 +- tests/lib/rules/unicode-bom.js | 2 +- tests/lib/rules/use-isnan.js | 34 +- tests/lib/rules/utils/ast-utils.js | 20 +- tests/lib/rules/valid-jsdoc.js | 106 +- tests/lib/rules/valid-typeof.js | 20 +- tests/lib/rules/vars-on-top.js | 102 +- tests/lib/rules/wrap-iife.js | 45 +- tests/lib/rules/wrap-regex.js | 2 +- tests/lib/rules/yield-star-spacing.js | 4 +- tests/lib/rules/yoda.js | 180 +- 292 files changed, 11694 insertions(+), 11162 deletions(-) diff --git a/lib/rules/no-invalid-this.js b/lib/rules/no-invalid-this.js index 49ecbe514c6..9e214035c33 100644 --- a/lib/rules/no-invalid-this.js +++ b/lib/rules/no-invalid-this.js @@ -96,7 +96,7 @@ module.exports = { if (codePath.origin === "program") { const scope = sourceCode.getScope(node); - const features = context.parserOptions.ecmaFeatures || {}; + const features = context.languageOptions.parserOptions.ecmaFeatures || {}; // `this` at the top level of scripts always refers to the global object stack.push({ diff --git a/tests/lib/rules/accessor-pairs.js b/tests/lib/rules/accessor-pairs.js index d74913f4e74..556dba7af2e 100644 --- a/tests/lib/rules/accessor-pairs.js +++ b/tests/lib/rules/accessor-pairs.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/accessor-pairs"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -29,12 +29,12 @@ ruleTester.run("accessor-pairs", rule, { { code: "var { get: foo } = bar; ({ set: foo } = bar);", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { set } = foo; ({ get } = foo);", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, //------------------------------------------------------------------------------ @@ -60,7 +60,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { a };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { a: get };", @@ -81,32 +81,32 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { [get]: function() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { [set]: function(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Disabled options @@ -161,69 +161,69 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get ['abc']() {}, set ['abc'](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [1e2]() {}, set 100(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get abc() {}, set [`abc`](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get ['123']() {}, set 123(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Valid pairs with expressions { code: "var o = { get [a]() {}, set [a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [a]() {}, set [(a)](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [(a)]() {}, set [a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [a]() {}, set [ a ](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [/*comment*/a/*comment*/]() {}, set [a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [f()]() {}, set [f()](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [f(a)]() {}, set [f(a)](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [a + b]() {}, set [a + b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [`${a}`]() {}, set [`${a}`](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Multiple valid pairs in the same literal @@ -244,59 +244,59 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get a() {}, b, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, ...b, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "var o = { get a() {}, set a(foo) {}, ...a };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // Duplicate keys. This is the responsibility of no-dupe-keys, but this rule still checks is there the other accessor kind. { code: "var o = { get a() {}, get a() {}, set a(foo) {}, };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, set a(foo) {}, get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, set a(foo) {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set a(bar) {}, get a() {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set a(foo) {}, set a(foo) {} };", options: [{ setWithoutGet: false, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, set a(foo) {}, a };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { a, get a() {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, /* @@ -308,7 +308,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get a() {}, a:1, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, //------------------------------------------------------------------------------ @@ -322,8 +322,8 @@ ruleTester.run("accessor-pairs", rule, { "Object.defineProperties(obj, {set: {value: function() {}}});", "Object.create(null, {set: {value: function() {}}});", { code: "var o = {get: function() {}}", options: [{ getWithoutSet: true }] }, - { code: "var o = {[set]: function() {}}", parserOptions: { ecmaVersion: 6 } }, - { code: "var set = 'value'; Object.defineProperty(obj, 'foo', {[set]: function(value) {}});", parserOptions: { ecmaVersion: 6 } }, + { code: "var o = {[set]: function() {}}", languageOptions: { ecmaVersion: 6 } }, + { code: "var set = 'value'; Object.defineProperty(obj, 'foo', {[set]: function(value) {}});", languageOptions: { ecmaVersion: 6 } }, //------------------------------------------------------------------------------ // Classes @@ -333,255 +333,255 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get #a() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 } }, // Explicitly disabled option { code: "class A { set a(foo) {} }", options: [{ enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set b(foo) {} static get c() {} static set d(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(class A { get a() {} set b(foo) {} static get c() {} static set d(bar) {} });", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Disabled accessor kind options { code: "class A { get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set a(foo) {} }", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} }", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set a(foo) {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set b(foo) {} static get c() {} static set d(bar) {} }", options: [{ setWithoutGet: false, getWithoutSet: false, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // No accessors { code: "class A {}", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(class {})", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { constructor () {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static a() {} 'b'() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [a]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { a() {} static a() {} b() {} static c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Valid pairs with identifiers { code: "class A { get a() {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set a(foo) {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} static set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} static get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(class { set a(foo) {} get a() {} });", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Valid pairs with statically computed names { code: "class A { get 'a'() {} set ['a'](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set [`a`](foo) {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get 'a'() {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static get 1e2() {} static set [100](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Valid pairs with expressions { code: "class A { get [a]() {} set [a](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set [(f())](foo) {} get [(f())]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set [f(a)](foo) {} static get [f(a)]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Multiple valid pairs in the same class { code: "class A { get a() {} set b(foo) {} set a(bar) {} get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set a(bar) {} b() {} set c(foo) {} get c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(class { get a() {} static set a(foo) {} set a(bar) {} static get a() {} });", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Valid pairs with other elements { code: "class A { get a() {} b() {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set a(foo) {} get a() {} b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} get b() {} c() {} set b(foo) {} d() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set a(foo) {} static a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static get a() {} static b() {} static set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static set a(foo) {} static get a() {} a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Duplicate keys. This is the responsibility of no-dupe-class-members, but this rule still checks if there is the other accessor kind. { code: "class A { get a() {} get a() {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [a]() {} set [a](foo) {} set [a](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set 'a'(foo) {} get [`a`]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { get a() {} set a(foo) {} a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { a() {} get a() {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} static set a(foo) {} static get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} static set a(foo) {} static get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} static get a() {} static a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, /* @@ -591,12 +591,12 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} a() {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} static a() {} static get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -668,38 +668,38 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get ['abc']() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }] + errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [`abc`]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }] + errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [123]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter '123'.", type: "Property" }] + errors: [{ message: "Setter is not present for getter '123'.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [abc]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter.", type: "Property" }] + errors: [{ message: "Setter is not present for getter.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [f(abc)]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter.", type: "Property" }] + errors: [{ message: "Setter is not present for getter.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [a + b]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter.", type: "Property" }] + errors: [{ message: "Setter is not present for getter.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, // Various kinds of the setter's key @@ -726,38 +726,38 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { set ['abc'](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }] + errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set [`abc`](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }] + errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set [123](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter '123'.", type: "Property" }] + errors: [{ message: "Getter is not present for setter '123'.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set [abc](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter.", type: "Property" }] + errors: [{ message: "Getter is not present for setter.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set [f(abc)](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter.", type: "Property" }] + errors: [{ message: "Getter is not present for setter.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set [a + b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter.", type: "Property" }] + errors: [{ message: "Getter is not present for setter.", type: "Property" }], + languageOptions: { ecmaVersion: 6 } }, // Different keys @@ -828,56 +828,56 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get [`a`]() {}, set b(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }, { message: "Getter is not present for setter 'b'.", type: "Property", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [a]() {}, set [b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 25 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [a]() {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter 'a'.", type: "Property", column: 25 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, set [a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 23 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [a + b]() {}, set [a - b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 29 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get [`${0} `]() {}, set [`${0}`](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 31 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Multiple invalid of same and different kinds @@ -970,79 +970,79 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get a() {}, get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }, { message: "Setter is not present for getter 'a'.", type: "Property", column: 23 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set a(foo) {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }, { message: "Getter is not present for setter 'a'.", type: "Property", column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Other elements or even value property duplicates in the same literal do not affect this rule { code: "var o = { a, get b() {}, c };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter 'b'.", type: "Property", column: 14 }] + errors: [{ message: "Setter is not present for getter 'b'.", type: "Property", column: 14 }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { a, get b() {}, c, set d(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'b'.", type: "Property", column: 14 }, { message: "Getter is not present for setter 'd'.", type: "Property", column: 29 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, a:1 };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }] + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { a, get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 14 }] + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 14 }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { set a(foo) {}, a:1 };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }] + errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { a, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 14 }] + errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 14 }], + languageOptions: { ecmaVersion: 6 } }, { code: "var o = { get a() {}, ...b };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 2018 }, - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }] + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }], + languageOptions: { ecmaVersion: 2018 } }, { code: "var o = { get a() {}, ...a };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 2018 }, - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }] + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }], + languageOptions: { ecmaVersion: 2018 } }, { code: "var o = { set a(foo) {}, ...a };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 2018 }, - errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }] + errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }], + languageOptions: { ecmaVersion: 2018 } }, // Full location tests @@ -1061,7 +1061,6 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = {\n set [\n a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ message: "Getter is not present for setter.", type: "Property", @@ -1069,7 +1068,8 @@ ruleTester.run("accessor-pairs", rule, { column: 3, endLine: 3, endColumn: 4 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, //------------------------------------------------------------------------------ @@ -1094,43 +1094,43 @@ ruleTester.run("accessor-pairs", rule, { }, { code: "var o = {d: 1};\n Object?.defineProperty(o, 'c', \n{set: function(value) {\n val = value; \n} \n});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "Reflect?.defineProperty(obj, 'foo', {set: function(value) {}});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.defineProperties(obj, {foo: {set: function(value) {}}});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.create(null, {foo: {set: function(value) {}}});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var o = {d: 1};\n (Object?.defineProperty)(o, 'c', \n{set: function(value) {\n val = value; \n} \n});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Reflect?.defineProperty)(obj, 'foo', {set: function(value) {}});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperties)(obj, {foo: {set: function(value) {}}});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.create)(null, {foo: {set: function(value) {}}});", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], + languageOptions: { ecmaVersion: 2020 } }, //------------------------------------------------------------------------------ @@ -1140,674 +1140,673 @@ ruleTester.run("accessor-pairs", rule, { // Test default settings { code: "class A { set a(foo) {} }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set b(foo) {} }", options: [{}], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'b'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter 'b'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { get a() {} set b(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set a(value) {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(value) {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set a(value) {} };", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "(class A { static set a(value) {} });", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set '#a'(foo) {} }", - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Getter is not present for class setter '#a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter '#a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, { code: "class A { set #a(foo) {} }", - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Getter is not present for class private setter #a.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class private setter #a.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, { code: "class A { static set '#a'(foo) {} }", - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Getter is not present for class static setter '#a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class static setter '#a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, { code: "class A { static set #a(foo) {} }", - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Getter is not present for class static private setter #a.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class static private setter #a.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, // Test that the accessor kind options do not affect each other { code: "class A { set a(value) {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static set a(value) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let foo = class A { get a() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "(class { get a() {} });", options: [{ getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get '#a'() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Setter is not present for class getter '#a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter '#a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, { code: "class A { get #a() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Setter is not present for class private getter #a.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class private getter #a.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, { code: "class A { static get '#a'() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Setter is not present for class static getter '#a'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class static getter '#a'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, { code: "class A { static get #a() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, - errors: [{ message: "Setter is not present for class static private getter #a.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class static private getter #a.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 13 } }, // Various kinds of keys { code: "class A { get abc() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static set 'abc'(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class static setter 'abc'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class static setter 'abc'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "(class { get 123() {} });", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter '123'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter '123'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get 1e2() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class static getter '100'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class static getter '100'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { get ['abc']() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set [`abc`](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'abc'.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter 'abc'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get [123]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class static getter '123'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class static getter '123'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [abc]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get [f(abc)]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class static getter.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class static getter.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set [a + b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter.", type: "MethodDefinition" }] + errors: [{ message: "Getter is not present for class setter.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get ['constructor']() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'constructor'.", type: "MethodDefinition" }] + errors: [{ message: "Setter is not present for class getter 'constructor'.", type: "MethodDefinition" }], + languageOptions: { ecmaVersion: 6 } }, // Different keys { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set a(foo) {} get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static get a() {} static set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class static setter 'b'.", type: "MethodDefinition", column: 31 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get 'a '() {} set 'a'(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a '.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 25 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get 'a'() {} set 1(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter '1'.", type: "MethodDefinition", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get 1() {} set 2(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter '1'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter '2'.", type: "MethodDefinition", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get ''() {} set null(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter ''.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'null'.", type: "MethodDefinition", column: 23 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get a() {} set [a](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [a]() {} set [b](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [a]() {} set [a++](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [a + b]() {} set [a - b](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 28 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get #a() {} set '#a'(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, errors: [ { message: "Setter is not present for class private getter #a.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter '#a'.", type: "MethodDefinition", column: 23 } - ] + ], + languageOptions: { ecmaVersion: 13 } }, { code: "class A { get '#a'() {} set #a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, errors: [ { message: "Setter is not present for class getter '#a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class private setter #a.", type: "MethodDefinition", column: 25 } - ] + ], + languageOptions: { ecmaVersion: 13 } }, // Prototype and static accessors with same keys { code: "class A { get a() {} static set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static get a() {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 31 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set [a](foo) {} static get [a]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class static getter.", type: "MethodDefinition", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set [a](foo) {} get [a]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 34 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Multiple invalid of same and different kinds { code: "class A { get a() {} get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { get a() {} get [b]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [a]() {} get [b]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set a(foo) {} set b(bar) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} static get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class static getter 'b'.", type: "MethodDefinition", column: 29 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static set a(foo) {} static set b(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class static setter 'b'.", type: "MethodDefinition", column: 34 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} set b(foo) {} static set c(bar) {} get d() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 29 }, { message: "Getter is not present for class static setter 'c'.", type: "MethodDefinition", column: 43 }, { message: "Setter is not present for class getter 'd'.", type: "MethodDefinition", column: 64 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Checks per class { code: "class A { get a() {} } class B { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 34 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set a(foo) {} }, class { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 38 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { get a() {} }, { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for setter 'a'.", type: "Property", column: 29 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = { get a() {} }, class { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 7 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 29 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Combinations or valid and invalid { code: "class A { get a() {} get b() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }] + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { get b() {} get a() {} set b(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 24 }] + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 24 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set b(foo) {} get b() {} set a(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 36 }] + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 36 }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static get b() {} set a(foo) {} static set b(bar) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 31 }] + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 31 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} get b() {} set b(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 11 }] + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 11 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get b() {} static get a() {} set b(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 22 }] + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 22 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set b(foo) {} static get a() {} static get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 32 }] + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 32 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [v1](){} static set i1(foo){} static set v2(bar){} get [i2](){} static get i3(){} set [v1](baz){} static get v2(){} set i4(quux){} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'i1'.", type: "MethodDefinition", column: 24 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 66 }, { message: "Setter is not present for class static getter 'i3'.", type: "MethodDefinition", column: 79 }, { message: "Getter is not present for class setter 'i4'.", type: "MethodDefinition", column: 131 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // In the case of duplicates which don't have the other kind, all nodes are reported { code: "class A { get a() {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { set a(foo) {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static get a() {} static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 31 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { set a(foo) {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 25 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Other elements or even method duplicates in the same class do not affect this rule { code: "class A { a() {} get b() {} c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { a() {} get b() {} c() {} set d(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 20 }, { message: "Getter is not present for class setter 'd'.", type: "MethodDefinition", column: 38 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static a() {} get b() {} static c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 25 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static a() {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} static get b() {} c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'b'.", type: "MethodDefinition", column: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { static a() {} static set b(foo) {} static c() {} d() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'b'.", type: "MethodDefinition", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} static get a() {} a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static set a(foo) {} static a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Full location tests { code: "class A { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", @@ -1815,12 +1814,12 @@ ruleTester.run("accessor-pairs", rule, { column: 11, endLine: 1, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class {\n set [\n a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Getter is not present for class setter.", type: "MethodDefinition", @@ -1828,12 +1827,12 @@ ruleTester.run("accessor-pairs", rule, { column: 3, endLine: 3, endColumn: 4 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", @@ -1841,7 +1840,8 @@ ruleTester.run("accessor-pairs", rule, { column: 11, endLine: 1, endColumn: 23 - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/array-bracket-newline.js b/tests/lib/rules/array-bracket-newline.js index 3f2b66f549f..7d02fbb354c 100644 --- a/tests/lib/rules/array-bracket-newline.js +++ b/tests/lib/rules/array-bracket-newline.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/array-bracket-newline"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ @@ -281,160 +281,160 @@ ruleTester.run("array-bracket-newline", rule, { * ArrayPattern * default { multiline: true } */ - { code: "var [] = foo", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a] = foo;", parserOptions: { ecmaVersion: 6 } }, + { code: "var [] = foo", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a] = foo;", languageOptions: { ecmaVersion: 6 } }, { code: "var /* any comment */[a] = foo;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var /* any comment */\n[a] = foo;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, - { code: "var [a, b] = foo;", parserOptions: { ecmaVersion: 6 } }, + { code: "var [a, b] = foo;", languageOptions: { ecmaVersion: 6 } }, { code: "var [ // any comment\na, b\n] = foo;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n// any comment\na, b\n] = foo;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na, b\n// any comment\n] = foo;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, - { code: "var [\na,\nb\n] = foo;", parserOptions: { ecmaVersion: 6 } }, + { code: "var [\na,\nb\n] = foo;", languageOptions: { ecmaVersion: 6 } }, // "always" { code: "var [\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n// any\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n/* any */\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na, b\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na, b // any comment\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na, b /* any comment */\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na,\nb\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // "consistent" { code: "var [] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [a] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [//\na\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [/**/\na\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [/*\n*/a\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [//\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // { multiline: true } { code: "var [] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [a] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var /* any comment */[a] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var /* any comment */\n[a] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [ // any comment\na, b\n] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n// any comment\na, b\n] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na, b\n// any comment\n] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na,\nb\n] = foo;", options: [{ multiline: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -1736,7 +1736,6 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [] = foo;", output: "var [\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1750,13 +1749,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a] = foo;", output: "var [\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1770,13 +1769,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 7 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [ // any comment\na] = foo;", output: "var [ // any comment\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1784,13 +1783,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [ /* any comment */\na] = foo;", output: "var [ /* any comment */\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1798,13 +1797,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b] = foo;", output: "var [\na, b\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1818,13 +1817,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b // any comment\n] = foo;", output: "var [\na, b // any comment\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1832,13 +1831,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 5 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b /* any comment */] = foo;", output: "var [\na, b /* any comment */\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1852,13 +1851,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 28 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a,\nb] = foo;", output: "var [\na,\nb\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1872,7 +1871,8 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // "consistent" @@ -1880,7 +1880,6 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [\na] = foo", output: "var [\na\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1890,13 +1889,13 @@ ruleTester.run("array-bracket-newline", rule, { endLine: 2, endColumn: 3 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a\n] = foo", output: "var [a] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedClosingLinebreak", @@ -1906,13 +1905,13 @@ ruleTester.run("array-bracket-newline", rule, { endLine: 2, endColumn: 2 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [//\na] = foo", output: "var [//\na\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1922,7 +1921,8 @@ ruleTester.run("array-bracket-newline", rule, { endLine: 2, endColumn: 3 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // { minItems: 2 } @@ -1930,7 +1930,6 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [\n] = foo;", output: "var [] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedOpeningLinebreak", @@ -1944,13 +1943,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [\na\n] = foo;", output: "var [a] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedOpeningLinebreak", @@ -1964,13 +1963,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 3, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b] = foo;", output: "var [\na, b\n] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1984,13 +1983,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a,\nb] = foo;", output: "var [\na,\nb\n] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -2004,7 +2003,8 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/array-bracket-spacing.js b/tests/lib/rules/array-bracket-spacing.js index 33caf088928..44027f1c80f 100644 --- a/tests/lib/rules/array-bracket-spacing.js +++ b/tests/lib/rules/array-bracket-spacing.js @@ -10,7 +10,7 @@ const path = require("path"), rule = require("../../../lib/rules/array-bracket-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -19,10 +19,10 @@ const path = require("path"), /** * Gets the path to the specified parser. * @param {string} name The parser name to get. - * @returns {string} The path to the specified parser. + * @returns {Object} The specified parser. */ function parser(name) { - return path.resolve(__dirname, `../../fixtures/parsers/array-bracket-spacing/${name}.js`); + return require(path.resolve(__dirname, `../../fixtures/parsers/array-bracket-spacing/${name}.js`)); } //------------------------------------------------------------------------------ @@ -85,19 +85,19 @@ ruleTester.run("array-bracket-spacing", rule, { { code: "this.db.mappings.insert([\n { alias: 'a', url: 'http://www.amazon.de' },\n { alias: 'g', url: 'http://www.google.de' }\n], function() {});", options: ["always", { singleValue: false, objectsInArrays: true, arraysInArrays: true }] }, // always - destructuring assignment - { code: "var [ x, y ] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [ x,y ] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [ x, y\n] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, y ] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, y\n] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx,,,\n] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [ ,x, ] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, ...y\n] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, ...y ] = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [[ x, y ], z ] = arr;", options: ["always", { arraysInArrays: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "var [ x, [ y, z ]] = arr;", options: ["always", { arraysInArrays: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "[{ x, y }, z ] = arr;", options: ["always", { objectsInArrays: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "[ x, { y, z }] = arr;", options: ["always", { objectsInArrays: false }], parserOptions: { ecmaVersion: 6 } }, + { code: "var [ x, y ] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [ x,y ] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [ x, y\n] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, y ] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, y\n] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx,,,\n] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [ ,x, ] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, ...y\n] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, ...y ] = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [[ x, y ], z ] = arr;", options: ["always", { arraysInArrays: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "var [ x, [ y, z ]] = arr;", options: ["always", { arraysInArrays: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "[{ x, y }, z ] = arr;", options: ["always", { objectsInArrays: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "[ x, { y, z }] = arr;", options: ["always", { objectsInArrays: false }], languageOptions: { ecmaVersion: 6 } }, // never { code: "obj[foo]", options: ["never"] }, @@ -117,19 +117,19 @@ ruleTester.run("array-bracket-spacing", rule, { { code: "var arr = [\n1,\n2,\n3,\n4];", options: ["never"] }, // never - destructuring assignment - { code: "var [x, y] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [x,y] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [x, y\n] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, y] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, y\n] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx,,,\n] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [,x,] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, ...y\n] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [\nx, ...y] = z", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [ [x, y], z] = arr;", options: ["never", { arraysInArrays: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var [x, [y, z] ] = arr;", options: ["never", { arraysInArrays: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "[ { x, y }, z] = arr;", options: ["never", { objectsInArrays: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "[x, { y, z } ] = arr;", options: ["never", { objectsInArrays: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "var [x, y] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [x,y] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [x, y\n] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, y] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, y\n] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx,,,\n] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [,x,] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, ...y\n] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [\nx, ...y] = z", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [ [x, y], z] = arr;", options: ["never", { arraysInArrays: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var [x, [y, z] ] = arr;", options: ["never", { arraysInArrays: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "[ { x, y }, z] = arr;", options: ["never", { objectsInArrays: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "[x, { y, z } ] = arr;", options: ["never", { objectsInArrays: true }], languageOptions: { ecmaVersion: 6 } }, // never - singleValue { code: "var foo = [ 'foo' ]", options: ["never", { singleValue: true }] }, @@ -173,8 +173,8 @@ ruleTester.run("array-bracket-spacing", rule, { { code: "var obj = {'foo': [1, 2]}", options: ["never"] }, // destructuring with type annotation - { code: "([ a, b ]: Array) => {}", options: ["always"], parser: parser("flow-destructuring-1"), parserOptions: { ecmaVersion: 6 } }, - { code: "([a, b]: Array< any >) => {}", options: ["never"], parser: parser("flow-destructuring-2"), parserOptions: { ecmaVersion: 6 } } + { code: "([ a, b ]: Array) => {}", options: ["always"], languageOptions: { ecmaVersion: 6, parser: parser("flow-destructuring-1") } }, + { code: "([a, b]: Array< any >) => {}", options: ["never"], languageOptions: { ecmaVersion: 6, parser: parser("flow-destructuring-2") } } ], invalid: [ @@ -472,7 +472,6 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [x,y] = y", output: "var [ x,y ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -494,13 +493,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 9, endLine: 1, endColumn: 10 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [x,y ] = y", output: "var [ x,y ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -511,13 +510,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 5, endLine: 1, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [,,,x,,] = y", output: "var [ ,,,x,, ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -539,13 +538,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 12, endLine: 1, endColumn: 13 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [ ,,,x,,] = y", output: "var [ ,,,x,, ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceBefore", data: { @@ -556,13 +555,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 13, endLine: 1, endColumn: 14 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [...horse] = y", output: "var [ ...horse ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -584,13 +583,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 14, endLine: 1, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [...horse ] = y", output: "var [ ...horse ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -601,13 +600,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 5, endLine: 1, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [ [ x, y ], z ] = arr;", output: "var [[ x, y ], z ] = arr;", options: ["always", { arraysInArrays: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceAfter", data: { @@ -618,13 +617,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 6, endLine: 1, endColumn: 7 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "[ { x, y }, z ] = arr;", output: "[{ x, y }, z ] = arr;", options: ["always", { objectsInArrays: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceAfter", data: { @@ -635,13 +634,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 2, endLine: 1, endColumn: 3 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "[ x, { y, z } ] = arr;", output: "[ x, { y, z }] = arr;", options: ["always", { objectsInArrays: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceBefore", data: { @@ -652,7 +651,8 @@ ruleTester.run("array-bracket-spacing", rule, { column: 14, endLine: 1, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, // never - arraysInArrays @@ -921,10 +921,6 @@ ruleTester.run("array-bracket-spacing", rule, { code: "([ a, b ]: Array) => {}", output: "([a, b]: Array) => {}", options: ["never"], - parser: parser("flow-destructuring-1"), - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -948,16 +944,16 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 9 } - ] + ], + languageOptions: { + ecmaVersion: 6, + parser: parser("flow-destructuring-1") + } }, { code: "([a, b]: Array< any >) => {}", output: "([ a, b ]: Array< any >) => {}", options: ["always"], - parser: parser("flow-destructuring-2"), - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "missingSpaceAfter", @@ -981,7 +977,11 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 8 } - ] + ], + languageOptions: { + parser: parser("flow-destructuring-2"), + ecmaVersion: 6 + } }, // multiple spaces @@ -1018,9 +1018,6 @@ ruleTester.run("array-bracket-spacing", rule, { code: "function f( [ a, b ] ) {}", output: "function f( [a, b] ) {}", options: ["never"], - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1044,7 +1041,10 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 23 } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var arr = [ 1,\n 2 ];", diff --git a/tests/lib/rules/array-callback-return.js b/tests/lib/rules/array-callback-return.js index 39114dbc582..1b649bc216e 100644 --- a/tests/lib/rules/array-callback-return.js +++ b/tests/lib/rules/array-callback-return.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/array-callback-return"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -43,14 +43,14 @@ ruleTester.run("array-callback-return", rule, { "foo.forEach(function(x) { if (a === b) { return x;} var a=0; })", "foo.bar().forEach(function(x) { return; })", "[\"foo\",\"bar\",\"baz\"].forEach(function(x) { return x; })", - { code: "foo.forEach(x => { var a=0; })", parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach(x => { if (a === b) { return;} var a=0; })", parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach(x => x)", parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach(val => y += val)", parserOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(x => { var a=0; })", languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(x => { if (a === b) { return;} var a=0; })", languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(x => x)", languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(val => y += val)", languageOptions: { ecmaVersion: 6 } }, - { code: "foo.map(async function(){})", parserOptions: { ecmaVersion: 8 } }, - { code: "foo.map(async () => {})", parserOptions: { ecmaVersion: 8 } }, - { code: "foo.map(function* () {})", parserOptions: { ecmaVersion: 6 } }, + { code: "foo.map(async function(){})", languageOptions: { ecmaVersion: 8 } }, + { code: "foo.map(async () => {})", languageOptions: { ecmaVersion: 8 } }, + { code: "foo.map(function* () {})", languageOptions: { ecmaVersion: 6 } }, // options: { allowImplicit: false } { code: "Array.from(x, function() { return true; })", options: [{ allowImplicit: false }] }, @@ -69,7 +69,7 @@ ruleTester.run("array-callback-return", rule, { "foo.some(function() { return true; })", "foo.sort(function() { return 0; })", "foo.toSorted(function() { return 0; })", - { code: "foo.every(() => { return true; })", parserOptions: { ecmaVersion: 6 } }, + { code: "foo.every(() => { return true; })", languageOptions: { ecmaVersion: 6 } }, "foo.every(function() { if (a) return true; else return false; })", "foo.every(function() { switch (a) { case 0: bar(); default: return true; } })", "foo.every(function() { try { bar(); return true; } catch (err) { return false; } })", @@ -92,7 +92,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.some(function() { return; })", options: allowImplicitOptions }, { code: "foo.sort(function() { return; })", options: allowImplicitOptions }, { code: "foo.toSorted(function() { return; })", options: allowImplicitOptions }, - { code: "foo.every(() => { return; })", options: allowImplicitOptions, parserOptions: { ecmaVersion: 6 } }, + { code: "foo.every(() => { return; })", options: allowImplicitOptions, languageOptions: { ecmaVersion: 6 } }, { code: "foo.every(function() { if (a) return; else return a; })", options: allowImplicitOptions }, { code: "foo.every(function() { switch (a) { case 0: bar(); default: return; } })", options: allowImplicitOptions }, { code: "foo.every(function() { try { bar(); return; } catch (err) { return; } })", options: allowImplicitOptions }, @@ -103,13 +103,13 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(function(x) { var a=0; })", options: checkForEachOptions }, { code: "foo.forEach(function(x) { if (a === b) { return;} var a=0; })", options: checkForEachOptions }, { code: "foo.forEach(function() {return function() { if (a == b) { return; }}}())", options: checkForEachOptions }, - { code: "foo.forEach(x => { var a=0; })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach(x => { if (a === b) { return;} var a=0; })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach(x => { x })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(x => { var a=0; })", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(x => { if (a === b) { return;} var a=0; })", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(x => { x })", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(bar || function(x) { return; })", options: checkForEachOptions }, { code: "Array.from(x, function() { return true; })", options: checkForEachOptions }, { code: "Int32Array.from(x, function() { return true; })", options: checkForEachOptions }, - { code: "foo.every(() => { return true; })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 } }, + { code: "foo.every(() => { return true; })", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 } }, { code: "foo.every(function() { if (a) return 1; else return a; })", options: checkForEachOptions }, { code: "foo.every(function() { switch (a) { case 0: return bar(); default: return a; } })", options: checkForEachOptions }, { code: "foo.every(function() { try { bar(); return 1; } catch (err) { return err; } })", options: checkForEachOptions }, @@ -117,19 +117,19 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.every(function() { return; })", options: allowImplicitCheckForEach }, // options: { checkForEach: true, allowVoid: true } - { code: "foo.forEach((x) => void x)", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach((x) => void bar(x))", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach(function (x) { return void bar(x); })", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach((x) => { return void bar(x); })", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach((x) => { if (a === b) { return void a; } bar(x) })", options: checkForEachAllowVoid, parserOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => void x)", options: checkForEachAllowVoid, languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => void bar(x))", options: checkForEachAllowVoid, languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(function (x) { return void bar(x); })", options: checkForEachAllowVoid, languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => { return void bar(x); })", options: checkForEachAllowVoid, languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => { if (a === b) { return void a; } bar(x) })", options: checkForEachAllowVoid, languageOptions: { ecmaVersion: 6 } }, "Arrow.from(x, function() {})", "foo.abc(function() {})", "every(function() {})", "foo[every](function() {})", "var every = function() {}", - { code: "foo[`${every}`](function() {})", parserOptions: { ecmaVersion: 6 } }, - { code: "foo.every(() => true)", parserOptions: { ecmaVersion: 6 } } + { code: "foo[`${every}`](function() {})", languageOptions: { ecmaVersion: 6 } }, + { code: "foo.every(() => true)", languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -168,9 +168,9 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.bar.baz.every(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }] }, { code: "foo[\"every\"](function() {})", errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, { code: "foo[\"every\"](function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }] }, - { code: "foo[`every`](function() {})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, - { code: "foo[`every`](function foo() {})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }] }, - { code: "foo.every(() => {})", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expects a return value from arrow function.", column: 14 }] }, + { code: "foo[`every`](function() {})", errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo[`every`](function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.every(() => {})", errors: [{ message: "Array.prototype.every() expects a return value from arrow function.", column: 14 }], languageOptions: { ecmaVersion: 6 } }, { code: "foo.every(function() { if (a) return true; })", errors: [{ message: "Array.prototype.every() expects a value to be returned at the end of function.", column: 11 }] }, { code: "foo.every(function cb() { if (a) return true; })", errors: [{ message: "Array.prototype.every() expects a value to be returned at the end of function 'cb'.", column: 11 }] }, { code: "foo.every(function() { switch (a) { case 0: break; default: return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, @@ -189,8 +189,8 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.every(a ? function foo() {} : function bar() {})", errors: ["Array.prototype.every() expects a return value from function 'foo'.", "Array.prototype.every() expects a return value from function 'bar'."] }, { code: "foo.every(function(){ return function() {}; }())", errors: [{ message: "Array.prototype.every() expects a return value from function.", column: 30 }] }, { code: "foo.every(function(){ return function foo() {}; }())", errors: [{ message: "Array.prototype.every() expects a return value from function 'foo'.", column: 30 }] }, - { code: "foo.every(() => {})", options: [{ allowImplicit: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }] }, - { code: "foo.every(() => {})", options: [{ allowImplicit: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }] }, + { code: "foo.every(() => {})", options: [{ allowImplicit: false }], errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.every(() => {})", options: [{ allowImplicit: true }], errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }], languageOptions: { ecmaVersion: 6 } }, // options: { allowImplicit: true } { code: "Array.from(x, function() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.from" } }] }, @@ -204,7 +204,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.every(cb || function() {})", options: allowImplicitOptions, errors: ["Array.prototype.every() expects a return value from function."] }, { code: "[\"foo\",\"bar\"].sort(function foo() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.sort" } }] }, { code: "[\"foo\",\"bar\"].toSorted(function foo() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.toSorted" } }] }, - { code: "foo.forEach(x => x)", options: allowImplicitCheckForEach, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { code: "foo.forEach(x => x)", options: allowImplicitCheckForEach, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(function(x) { if (a == b) {return x;}})", options: allowImplicitCheckForEach, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "foo.forEach(function bar(x) { return x;})", options: allowImplicitCheckForEach, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function 'bar'", arrayMethodName: "Array.prototype.forEach" } }] }, @@ -212,62 +212,62 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(x => x)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach(x => {x})", messageId: "wrapBraces" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(x => (x))", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach(x => {(x)})", messageId: "wrapBraces" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(val => y += val)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach(val => {y += val})", messageId: "wrapBraces" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "[\"foo\",\"bar\"].forEach(x => ++x)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "[\"foo\",\"bar\"].forEach(x => {++x})", messageId: "wrapBraces" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.bar().forEach(x => x === y)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.bar().forEach(x => {x === y})", messageId: "wrapBraces" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(function() {return function() { if (a == b) { return a; }}}())", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "foo.forEach(function(x) { if (a == b) {return x;}})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] }, @@ -276,23 +276,22 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(function bar(x) { return x;})", options: checkForEachOptions, errors: ["Array.prototype.forEach() expects no useless return value from function 'bar'."] }, { code: "foo.bar().forEach(function bar(x) { return x;})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function 'bar'", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "[\"foo\",\"bar\"].forEach(function bar(x) { return x;})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function 'bar'", arrayMethodName: "Array.prototype.forEach" } }] }, - { code: "foo.forEach((x) => { return x;})", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { code: "foo.forEach((x) => { return x;})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, { code: "Array.from(x, function() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.from" } }] }, { code: "foo.every(function() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, { code: "foo.filter(function foo() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.filter" } }] }, { code: "foo.filter(function foo() { return; })", options: checkForEachOptions, errors: [{ messageId: "expectedReturnValue", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.filter" } }] }, { code: "foo.every(cb || function() {})", options: checkForEachOptions, errors: ["Array.prototype.every() expects a return value from function."] }, - { code: "foo.forEach((x) => void x)", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, - { code: "foo.forEach((x) => void bar(x))", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, - { code: "foo.forEach((x) => { return void bar(x); })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, - { code: "foo.forEach((x) => { if (a === b) { return void a; } bar(x) })", options: checkForEachOptions, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { code: "foo.forEach((x) => void x)", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => void bar(x))", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => { return void bar(x); })", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => { if (a === b) { return void a; } bar(x) })", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, // options: { checkForEach: true, allowVoid: true } { code: "foo.forEach(x => x)", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -300,12 +299,12 @@ ruleTester.run("array-callback-return", rule, { { output: "foo.forEach(x => {x})", messageId: "wrapBraces" }, { output: "foo.forEach(x => void x)", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(x => !x)", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -313,12 +312,12 @@ ruleTester.run("array-callback-return", rule, { { output: "foo.forEach(x => {!x})", messageId: "wrapBraces" }, { output: "foo.forEach(x => void !x)", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(x => (x))", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -326,97 +325,97 @@ ruleTester.run("array-callback-return", rule, { { output: "foo.forEach(x => {(x)})", messageId: "wrapBraces" }, { output: "foo.forEach(x => void (x))", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((x) => { return x; })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void x; })", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((x) => { return !x; })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void !x; })", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((x) => { return(x); })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void (x); })", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((x) => { return (x + 1); })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void (x + 1); })", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((x) => { if (a === b) { return x; } })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { if (a === b) { return void x; } })", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((x) => { if (a === b) { return !x; } })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { if (a === b) { return void !x; } })", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((x) => { if (a === b) { return (x + a); } })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { if (a === b) { return void (x + a); } })", messageId: "prependVoid" } ] - }] + }], + languageOptions: { ecmaVersion: 6 } }, // full location tests { code: "foo.filter(bar => { baz(); } )", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -425,11 +424,11 @@ ruleTester.run("array-callback-return", rule, { column: 16, endLine: 1, endColumn: 18 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.filter(\n() => {} )", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -438,11 +437,11 @@ ruleTester.run("array-callback-return", rule, { column: 4, endLine: 2, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.filter(bar || ((baz) => {}) )", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -451,11 +450,11 @@ ruleTester.run("array-callback-return", rule, { column: 26, endLine: 1, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.filter(bar => { return; })", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -464,11 +463,11 @@ ruleTester.run("array-callback-return", rule, { column: 21, endLine: 1, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "Array.from(foo, bar => { bar })", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" }, @@ -477,12 +476,12 @@ ruleTester.run("array-callback-return", rule, { column: 21, endLine: 1, endColumn: 23 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach(bar => bar)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -491,12 +490,12 @@ ruleTester.run("array-callback-return", rule, { column: 17, endLine: 1, endColumn: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((function () { return (bar) => bar; })())", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -505,12 +504,12 @@ ruleTester.run("array-callback-return", rule, { column: 41, endLine: 1, endColumn: 43 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((() => {\n return bar => bar; })())", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -519,12 +518,12 @@ ruleTester.run("array-callback-return", rule, { column: 13, endLine: 2, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.forEach((bar) => { if (bar) { return; } else { return bar ; } })", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -533,7 +532,8 @@ ruleTester.run("array-callback-return", rule, { column: 52, endLine: 1, endColumn: 64 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.filter(function(){})", @@ -660,28 +660,28 @@ ruleTester.run("array-callback-return", rule, { // Optional chaining { code: "foo?.filter(() => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.filter)(() => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "Array?.from([], () => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }] + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Array?.from)([], () => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }] + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.filter((function() { return () => { console.log('hello') } })?.())", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/array-element-newline.js b/tests/lib/rules/array-element-newline.js index 195b5be45f5..01221907a57 100644 --- a/tests/lib/rules/array-element-newline.js +++ b/tests/lib/rules/array-element-newline.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/array-element-newline"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ @@ -135,29 +135,29 @@ ruleTester.run("array-element-newline", rule, { * ArrayPattern * "always" */ - { code: "var [] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a,\nb] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, // any comment\nb] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [// any comment \na,\nb] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a,\nb // any comment\n] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a,\nb,\nb] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [\na,\n[\nb,\nc]] = foo;", parserOptions: { ecmaVersion: 6 } }, + { code: "var [] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a,\nb] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, // any comment\nb] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [// any comment \na,\nb] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a,\nb // any comment\n] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a,\nb,\nb] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [\na,\n[\nb,\nc]] = foo;", languageOptions: { ecmaVersion: 6 } }, // "never" - { code: "var [a,[b,c]] = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "var [a,[b,c]] = foo;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, // { minItems: 3 } - { code: "var [] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } }, - { code: "var [a] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, b] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } }, - { code: "var [a,\nb,\nc] = foo;", options: [{ minItems: 3 }], parserOptions: { ecmaVersion: 6 } }, + { code: "var [] = foo;", options: [{ minItems: 3 }], languageOptions: { ecmaVersion: 6 } }, + { code: "var [a] = foo;", options: [{ minItems: 3 }], languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, b] = foo;", options: [{ minItems: 3 }], languageOptions: { ecmaVersion: 6 } }, + { code: "var [a,\nb,\nc] = foo;", options: [{ minItems: 3 }], languageOptions: { ecmaVersion: 6 } }, /* * ArrayExpression & ArrayPattern * { ArrayExpression: "always", ArrayPattern: "never" } */ - { code: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], parserOptions: { ecmaVersion: 6 } }], + { code: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], languageOptions: { ecmaVersion: 6 } }], invalid: [ { @@ -859,20 +859,19 @@ ruleTester.run("array-element-newline", rule, { code: "var [a, b] = foo;", output: "var [a,\nb] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", line: 1, column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b, c] = foo;", output: "var [a,\nb,\nc] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -884,7 +883,8 @@ ruleTester.run("array-element-newline", rule, { line: 1, column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // { minItems: 3 } @@ -892,20 +892,19 @@ ruleTester.run("array-element-newline", rule, { code: "var [a,\nb] = foo;", output: "var [a, b] = foo;", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", line: 1, column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b, c] = foo;", output: "var [a,\nb,\nc] = foo;", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -917,7 +916,8 @@ ruleTester.run("array-element-newline", rule, { line: 1, column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, /* @@ -928,7 +928,6 @@ ruleTester.run("array-element-newline", rule, { code: "var [a,\nb] = [1, 2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -940,33 +939,34 @@ ruleTester.run("array-element-newline", rule, { line: 2, column: 9 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a, b] = [1, 2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", line: 1, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a,\nb] = [1,\n2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", line: 1, column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] diff --git a/tests/lib/rules/arrow-body-style.js b/tests/lib/rules/arrow-body-style.js index 0ccb440d392..444d0074a46 100644 --- a/tests/lib/rules/arrow-body-style.js +++ b/tests/lib/rules/arrow-body-style.js @@ -9,13 +9,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/arrow-body-style"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("arrow-body-style", rule, { valid: [ diff --git a/tests/lib/rules/arrow-parens.js b/tests/lib/rules/arrow-parens.js index c7af7f6dea8..9aa8a293915 100644 --- a/tests/lib/rules/arrow-parens.js +++ b/tests/lib/rules/arrow-parens.js @@ -11,15 +11,22 @@ const baseParser = require("../../fixtures/fixture-parser"), rule = require("../../../lib/rules/arrow-parens"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); -const parser = baseParser.bind(null, "arrow-parens"); +/** + * Loads a parser. + * @param {string} name The name of the parser to load. + * @returns {Object} The parser object. + */ +function parser(name) { + return require(baseParser("arrow-parens", name)); +} //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); const valid = [ @@ -36,7 +43,7 @@ const valid = [ "const f = (//\na) => a + a;", "const f = (/*\n */a//\n) => a + a;", "const f = (/** @type {number} */a/**hello*/) => a + a;", - { code: "a.then(async (foo) => { if (true) {}; });", parserOptions: { ecmaVersion: 8 } }, + { code: "a.then(async (foo) => { if (true) {}; });", languageOptions: { ecmaVersion: 8 } }, // "always" (explicit) { code: "() => {}", options: ["always"] }, @@ -45,9 +52,9 @@ const valid = [ { code: "(a) => {\n}", options: ["always"] }, { code: "a.then((foo) => {});", options: ["always"] }, { code: "a.then((foo) => { if (true) {}; });", options: ["always"] }, - { code: "a.then(async (foo) => { if (true) {}; });", options: ["always"], parserOptions: { ecmaVersion: 8 } }, - { code: "(a: T) => a", options: ["always"], parser: parser("identifier-type") }, - { code: "(a): T => a", options: ["always"], parser: parser("return-type") }, + { code: "a.then(async (foo) => { if (true) {}; });", options: ["always"], languageOptions: { ecmaVersion: 8 } }, + { code: "(a: T) => a", options: ["always"], languageOptions: { parser: parser("identifier-type") } }, + { code: "(a): T => a", options: ["always"], languageOptions: { parser: parser("return-type") } }, // "as-needed" { code: "() => {}", options: ["as-needed"] }, @@ -61,11 +68,11 @@ const valid = [ { code: "(a = 10) => {}", options: ["as-needed"] }, { code: "(...a) => a[0]", options: ["as-needed"] }, { code: "(a, b) => {}", options: ["as-needed"] }, - { code: "async a => a", options: ["as-needed"], parserOptions: { ecmaVersion: 8 } }, - { code: "async ([a, b]) => {}", options: ["as-needed"], parserOptions: { ecmaVersion: 8 } }, - { code: "async (a, b) => {}", options: ["as-needed"], parserOptions: { ecmaVersion: 8 } }, - { code: "(a: T) => a", options: ["as-needed"], parser: parser("identifier-type") }, - { code: "(a): T => a", options: ["as-needed"], parser: parser("return-type") }, + { code: "async a => a", options: ["as-needed"], languageOptions: { ecmaVersion: 8 } }, + { code: "async ([a, b]) => {}", options: ["as-needed"], languageOptions: { ecmaVersion: 8 } }, + { code: "async (a, b) => {}", options: ["as-needed"], languageOptions: { ecmaVersion: 8 } }, + { code: "(a: T) => a", options: ["as-needed"], languageOptions: { parser: parser("identifier-type") } }, + { code: "(a): T => a", options: ["as-needed"], languageOptions: { parser: parser("return-type") } }, // "as-needed", { "requireForBlockBody": true } { code: "() => {}", options: ["as-needed", { requireForBlockBody: true }] }, @@ -81,10 +88,10 @@ const valid = [ { code: "(...a) => a[0]", options: ["as-needed", { requireForBlockBody: true }] }, { code: "(a, b) => {}", options: ["as-needed", { requireForBlockBody: true }] }, { code: "a => ({})", options: ["as-needed", { requireForBlockBody: true }] }, - { code: "async a => ({})", options: ["as-needed", { requireForBlockBody: true }], parserOptions: { ecmaVersion: 8 } }, - { code: "async a => a", options: ["as-needed", { requireForBlockBody: true }], parserOptions: { ecmaVersion: 8 } }, - { code: "(a: T) => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("identifier-type") }, - { code: "(a): T => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("return-type") }, + { code: "async a => ({})", options: ["as-needed", { requireForBlockBody: true }], languageOptions: { ecmaVersion: 8 } }, + { code: "async a => a", options: ["as-needed", { requireForBlockBody: true }], languageOptions: { ecmaVersion: 8 } }, + { code: "(a: T) => a", options: ["as-needed", { requireForBlockBody: true }], languageOptions: { parser: parser("identifier-type") } }, + { code: "(a): T => a", options: ["as-needed", { requireForBlockBody: true }], languageOptions: { parser: parser("return-type") } }, { code: "const f = (/** @type {number} */a/**hello*/) => a + a;", options: ["as-needed"] @@ -111,32 +118,32 @@ const valid = [ }, { code: "var foo = (a,/**/) => b;", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, options: ["as-needed"] }, { code: "var foo = (a , /**/) => b;", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, options: ["as-needed"] }, { code: "var foo = (a\n,\n/**/) => b;", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, options: ["as-needed"] }, { code: "var foo = (a,//\n) => b;", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, options: ["as-needed"] }, { code: "const i = (a/**/,) => a + a;", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, options: ["as-needed"] }, { code: "const i = (a \n /**/,) => a + a;", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, options: ["as-needed"] }, { @@ -152,77 +159,77 @@ const valid = [ { code: "(a) => b", options: ["always"], - parser: parser("generics-simple") + languageOptions: { parser: parser("generics-simple") } }, { code: "(a) => b", options: ["as-needed"], - parser: parser("generics-simple") + languageOptions: { parser: parser("generics-simple") } }, { code: "(a) => b", options: ["as-needed", { requireForBlockBody: true }], - parser: parser("generics-simple") + languageOptions: { parser: parser("generics-simple") } }, { code: "async (a) => b", options: ["always"], - parser: parser("generics-simple-async") + languageOptions: { parser: parser("generics-simple-async") } }, { code: "async (a) => b", options: ["as-needed"], - parser: parser("generics-simple-async") + languageOptions: { parser: parser("generics-simple-async") } }, { code: "async (a) => b", options: ["as-needed", { requireForBlockBody: true }], - parser: parser("generics-simple-async") + languageOptions: { parser: parser("generics-simple-async") } }, { code: "() => b", options: ["always"], - parser: parser("generics-simple-no-params") + languageOptions: { parser: parser("generics-simple-no-params") } }, { code: "() => b", options: ["as-needed"], - parser: parser("generics-simple-no-params") + languageOptions: { parser: parser("generics-simple-no-params") } }, { code: "() => b", options: ["as-needed", { requireForBlockBody: true }], - parser: parser("generics-simple-no-params") + languageOptions: { parser: parser("generics-simple-no-params") } }, { code: "(a) => b", options: ["always"], - parser: parser("generics-extends") + languageOptions: { parser: parser("generics-extends") } }, { code: "(a) => b", options: ["as-needed"], - parser: parser("generics-extends") + languageOptions: { parser: parser("generics-extends") } }, { code: "(a) => b", options: ["as-needed", { requireForBlockBody: true }], - parser: parser("generics-extends") + languageOptions: { parser: parser("generics-extends") } }, { code: "(a) => b", options: ["always"], - parser: parser("generics-extends-complex") + languageOptions: { parser: parser("generics-extends-complex") } }, { code: "(a) => b", options: ["as-needed"], - parser: parser("generics-extends-complex") + languageOptions: { parser: parser("generics-extends-complex") } }, { code: "(a) => b", options: ["as-needed", { requireForBlockBody: true }], - parser: parser("generics-extends-complex") + languageOptions: { parser: parser("generics-extends-complex") } } ]; @@ -300,7 +307,7 @@ const invalid = [ { code: "a(async foo => { if (true) {}; });", output: "a(async (foo) => { if (true) {}; });", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ line: 1, column: 9, @@ -351,7 +358,7 @@ const invalid = [ code: "(a,) => a", output: "a => a", options: ["as-needed"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ line: 1, column: 2, @@ -364,7 +371,7 @@ const invalid = [ code: "async (a) => a", output: "async a => a", options: ["as-needed"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ line: 1, column: 8, @@ -377,7 +384,7 @@ const invalid = [ code: "async(a) => a", output: "async a => a", options: ["as-needed"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ line: 1, column: 7, @@ -440,7 +447,7 @@ const invalid = [ code: "async a => {}", output: "async (a) => {}", options: ["as-needed", { requireForBlockBody: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ line: 1, column: 7, @@ -453,7 +460,7 @@ const invalid = [ code: "async (a) => a", output: "async a => a", options: ["as-needed", { requireForBlockBody: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ line: 1, column: 8, @@ -466,7 +473,7 @@ const invalid = [ code: "async(a) => a", output: "async a => a", options: ["as-needed", { requireForBlockBody: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ line: 1, column: 7, diff --git a/tests/lib/rules/arrow-spacing.js b/tests/lib/rules/arrow-spacing.js index fe87462f928..248c94d1ef8 100644 --- a/tests/lib/rules/arrow-spacing.js +++ b/tests/lib/rules/arrow-spacing.js @@ -10,13 +10,13 @@ // const rule = require("../../../lib/rules/arrow-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); const valid = [ { diff --git a/tests/lib/rules/block-scoped-var.js b/tests/lib/rules/block-scoped-var.js index 175676b3a58..5ebaebd3616 100644 --- a/tests/lib/rules/block-scoped-var.js +++ b/tests/lib/rules/block-scoped-var.js @@ -10,20 +10,22 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/block-scoped-var"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { ecmaVersion: 5, sourceType: "script" } +}); ruleTester.run("block-scoped-var", rule, { valid: [ // See issue https://github.com/eslint/eslint/issues/2242 - { code: "function f() { } f(); var exports = { f: f };", parserOptions: { ecmaVersion: 6 } }, - { code: "var f = () => {}; f(); var exports = { f: f };", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function f() { } f(); var exports = { f: f };", languageOptions: { ecmaVersion: 6 } }, + { code: "var f = () => {}; f(); var exports = { f: f };", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, "!function f(){ f; }", "function f() { } f(); var exports = { f: f };", "function f() { var a, b; { a = true; } b = a; }", @@ -42,16 +44,16 @@ ruleTester.run("block-scoped-var", rule, { "var a; if (true) { a; }", "for (var i = 0; i < 10; i++) { i; }", "var i; for(i; i; i) { i; }", - { code: "function myFunc(foo) { \"use strict\"; var { bar } = foo; bar.hello();}", parserOptions: { ecmaVersion: 6 } }, - { code: "function myFunc(foo) { \"use strict\"; var [ bar ] = foo; bar.hello();}", parserOptions: { ecmaVersion: 6 } }, - { code: "function myFunc(...foo) { return foo;}", parserOptions: { ecmaVersion: 6 } }, - { code: "var f = () => { var g = f; }", parserOptions: { ecmaVersion: 6 } }, - { code: "class Foo {}\nexport default Foo;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "new Date", globals: { Date: false } }, - { code: "new Date", globals: {} }, - { code: "var eslint = require('eslint');", globals: { require: false } }, - { code: "var fun = function({x}) {return x;};", parserOptions: { ecmaVersion: 6 } }, - { code: "var fun = function([,x]) {return x;};", parserOptions: { ecmaVersion: 6 } }, + { code: "function myFunc(foo) { \"use strict\"; var { bar } = foo; bar.hello();}", languageOptions: { ecmaVersion: 6 } }, + { code: "function myFunc(foo) { \"use strict\"; var [ bar ] = foo; bar.hello();}", languageOptions: { ecmaVersion: 6 } }, + { code: "function myFunc(...foo) { return foo;}", languageOptions: { ecmaVersion: 6 } }, + { code: "var f = () => { var g = f; }", languageOptions: { ecmaVersion: 6 } }, + { code: "class Foo {}\nexport default Foo;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "new Date", languageOptions: { globals: { Date: false } } }, + { code: "new Date", languageOptions: { globals: {} } }, + { code: "var eslint = require('eslint');", languageOptions: { globals: { require: false } } }, + { code: "var fun = function({x}) {return x;};", languageOptions: { ecmaVersion: 6 } }, + { code: "var fun = function([,x]) {return x;};", languageOptions: { ecmaVersion: 6 } }, "function f(a) { return a.b; }", "var a = { \"foo\": 3 };", "var a = { foo: 3 };", @@ -67,25 +69,25 @@ ruleTester.run("block-scoped-var", rule, { "a:;", "foo: while (true) { bar: for (var i = 0; i < 13; ++i) {if (i === 7) break foo; } }", "foo: while (true) { bar: for (var i = 0; i < 13; ++i) {if (i === 7) continue foo; } }", - { code: "const React = require(\"react/addons\");const cx = React.addons.classSet;", parserOptions: { ecmaVersion: 6, sourceType: "module" }, globals: { require: false } }, - { code: "var v = 1; function x() { return v; };", parserOptions: { parserOptions: { ecmaVersion: 6 } } }, - { code: "import * as y from \"./other.js\"; y();", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import y from \"./other.js\"; y();", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {x as y} from \"./other.js\"; y();", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var x; export {x};", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var x; export {x as v};", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {x} from \"./other.js\";", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {x as v} from \"./other.js\";", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "class Test { myFunction() { return true; }}", parserOptions: { ecmaVersion: 6 } }, - { code: "class Test { get flag() { return true; }}", parserOptions: { ecmaVersion: 6 } }, - { code: "var Test = class { myFunction() { return true; }}", parserOptions: { ecmaVersion: 6 } }, - { code: "var doStuff; let {x: y} = {x: 1}; doStuff(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo({x: y}) { return y; }", parserOptions: { ecmaVersion: 6 } }, + { code: "const React = require(\"react/addons\");const cx = React.addons.classSet;", languageOptions: { ecmaVersion: 6, sourceType: "module", globals: { require: false } } }, + { code: "var v = 1; function x() { return v; };", languageOptions: { ecmaVersion: 6 } }, + { code: "import * as y from \"./other.js\"; y();", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import y from \"./other.js\"; y();", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {x as y} from \"./other.js\"; y();", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var x; export {x};", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var x; export {x as v};", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {x} from \"./other.js\";", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {x as v} from \"./other.js\";", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "class Test { myFunction() { return true; }}", languageOptions: { ecmaVersion: 6 } }, + { code: "class Test { get flag() { return true; }}", languageOptions: { ecmaVersion: 6 } }, + { code: "var Test = class { myFunction() { return true; }}", languageOptions: { ecmaVersion: 6 } }, + { code: "var doStuff; let {x: y} = {x: 1}; doStuff(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo({x: y}) { return y; }", languageOptions: { ecmaVersion: 6 } }, // those are the same as `no-undef`. "!function f(){}; f", "var f = function foo() { }; foo(); var exports = { f: foo };", - { code: "var f = () => { x; }", parserOptions: { ecmaVersion: 6 } }, + { code: "var f = () => { x; }", languageOptions: { ecmaVersion: 6 } }, "function f(){ x; }", "var eslint = require('eslint');", "function f(a) { return a[b]; }", @@ -101,24 +103,24 @@ ruleTester.run("block-scoped-var", rule, { "a:b;", // https://github.com/eslint/eslint/issues/2253 - { code: "/*global React*/ let {PropTypes, addons: {PureRenderMixin}} = React; let Test = React.createClass({mixins: [PureRenderMixin]});", parserOptions: { ecmaVersion: 6 } }, - { code: "/*global prevState*/ const { virtualSize: prevVirtualSize = 0 } = prevState;", parserOptions: { ecmaVersion: 6 } }, - { code: "const { dummy: { data, isLoading }, auth: { isLoggedIn } } = this.props;", parserOptions: { ecmaVersion: 6 } }, + { code: "/*global React*/ let {PropTypes, addons: {PureRenderMixin}} = React; let Test = React.createClass({mixins: [PureRenderMixin]});", languageOptions: { ecmaVersion: 6 } }, + { code: "/*global prevState*/ const { virtualSize: prevVirtualSize = 0 } = prevState;", languageOptions: { ecmaVersion: 6 } }, + { code: "const { dummy: { data, isLoading }, auth: { isLoggedIn } } = this.props;", languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/2747 "function a(n) { return n > 0 ? b(n - 1) : \"a\"; } function b(n) { return n > 0 ? a(n - 1) : \"b\"; }", // https://github.com/eslint/eslint/issues/2967 "(function () { foo(); })(); function foo() {}", - { code: "(function () { foo(); })(); function foo() {}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "(function () { foo(); })(); function foo() {}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "class C { static { var foo; foo; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo; var foo; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { if (bar) { foo; } var foo; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "var foo; class C { static { foo; } } ", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo; } } var foo;", parserOptions: { ecmaVersion: 2022 } }, - { code: "var foo; class C { static {} [foo]; } ", parserOptions: { ecmaVersion: 2022 } }, - { code: "foo; class C { static {} } var foo; ", parserOptions: { ecmaVersion: 2022 } } + { code: "class C { static { var foo; foo; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo; var foo; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { if (bar) { foo; } var foo; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "var foo; class C { static { foo; } } ", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo; } } var foo;", languageOptions: { ecmaVersion: 2022 } }, + { code: "var foo; class C { static {} [foo]; } ", languageOptions: { ecmaVersion: 2022 } }, + { code: "foo; class C { static {} } var foo; ", languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { @@ -193,7 +195,6 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "function a() { for(var b of {}) { var c = b; } c; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -204,7 +205,8 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 48, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function f(){ switch(2) { case 1: var b = 2; b; break; default: b; break;} b; }", @@ -250,7 +252,6 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "for (var a of []) {} a;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -261,11 +262,11 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 22, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ var a = 0; } a;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "outOfScope", data: { @@ -276,7 +277,8 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 16, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "if (true) { var a; } a;", @@ -348,7 +350,6 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "class C { static { if (bar) { var foo; } foo; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "outOfScope", data: { @@ -359,7 +360,8 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 42, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "{ var foo,\n bar; } bar;", @@ -377,7 +379,6 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "{ var { foo,\n bar } = baz; } bar;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -388,7 +389,8 @@ ruleTester.run("block-scoped-var", rule, { line: 2, column: 18, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { var a = 1; } else if (bar) { var a = 2; } else { var a = 3; }", diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index 0dfef7ed652..b89a4e0e70f 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/block-spacing"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -35,16 +35,16 @@ ruleTester.run("block-spacing", rule, { "do { foo(); } while (a);", "for (;;) { foo(); }", "for (var a in b) { foo(); }", - { code: "for (var a of b) { foo(); }", parserOptions: { ecmaVersion: 6 } }, + { code: "for (var a of b) { foo(); }", languageOptions: { ecmaVersion: 6 } }, "try { foo(); } catch (e) { foo(); }", "function foo() { bar(); }", "(function() { bar(); });", - { code: "(() => { bar(); });", parserOptions: { ecmaVersion: 6 } }, + { code: "(() => { bar(); });", languageOptions: { ecmaVersion: 6 } }, "if (a) { /* comment */ foo(); /* comment */ }", "if (a) { //comment\n foo(); }", - { code: "class C { static {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { /* comment */foo;/* comment */ } }", parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { static {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { /* comment */foo;/* comment */ } }", languageOptions: { ecmaVersion: 2022 } }, // never { code: "{foo();}", options: ["never"] }, @@ -59,19 +59,19 @@ ruleTester.run("block-spacing", rule, { { code: "do {foo();} while (a);", options: ["never"] }, { code: "for (;;) {foo();}", options: ["never"] }, { code: "for (var a in b) {foo();}", options: ["never"] }, - { code: "for (var a of b) {foo();}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "for (var a of b) {foo();}", options: ["never"], languageOptions: { ecmaVersion: 6 } }, { code: "try {foo();} catch (e) {foo();}", options: ["never"] }, { code: "function foo() {bar();}", options: ["never"] }, { code: "(function() {bar();});", options: ["never"] }, - { code: "(() => {bar();});", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "(() => {bar();});", options: ["never"], languageOptions: { ecmaVersion: 6 } }, { code: "if (a) {/* comment */ foo(); /* comment */}", options: ["never"] }, { code: "if (a) { //comment\n foo();}", options: ["never"] }, - { code: "class C { static { } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static {foo;} }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static {/* comment */ foo; /* comment */} }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { // line comment is allowed\n foo;\n} }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static {\nfoo;\n} }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { \n foo; \n } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } } + { code: "class C { static { } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static {foo;} }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static {/* comment */ foo; /* comment */} }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { // line comment is allowed\n foo;\n} }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static {\nfoo;\n} }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { \n foo; \n } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -181,11 +181,11 @@ ruleTester.run("block-spacing", rule, { { code: "for (var a of b) {foo();}", output: "for (var a of b) { foo(); }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", line: 1, column: 18, messageId: "missing", data: { location: "after", token: "{" } }, { type: "BlockStatement", line: 1, column: 25, messageId: "missing", data: { location: "before", token: "}" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "try {foo();} catch (e) {foo();} finally {foo();}", @@ -266,25 +266,24 @@ ruleTester.run("block-spacing", rule, { { code: "(() => {bar();});", output: "(() => { bar(); });", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }, { type: "BlockStatement", line: 1, column: 15, messageId: "missing", data: { location: "before", token: "}" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (a) {/* comment */ foo(); /* comment */}", output: "if (a) { /* comment */ foo(); /* comment */ }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }, { type: "BlockStatement", line: 1, column: 43, messageId: "missing", data: { location: "before", token: "}" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (a) {//comment\n foo(); }", output: "if (a) { //comment\n foo(); }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -298,14 +297,14 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 9 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // class static blocks { code: "class C { static {foo; } }", output: "class C { static { foo; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -319,12 +318,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 19 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo;} }", output: "class C { static { foo; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -338,12 +337,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 25 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static {foo;} }", output: "class C { static { foo; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -369,12 +368,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 24 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static {/* comment */} }", output: "class C { static { /* comment */ } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -400,12 +399,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 33 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static {/* comment 1 */ foo; /* comment 2 */} }", output: "class C { static { /* comment 1 */ foo; /* comment 2 */ } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -431,12 +430,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 56 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {foo()\nbar()} }", output: "class C {\n static { foo()\nbar() } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -462,7 +461,8 @@ ruleTester.run("block-spacing", rule, { endLine: 3, endColumn: 7 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- @@ -747,7 +747,6 @@ ruleTester.run("block-spacing", rule, { code: "for (var a of b) { foo(); }", output: "for (var a of b) {foo();}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -767,7 +766,8 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "try { foo(); } catch (e) { foo(); } finally { foo(); }", @@ -884,7 +884,6 @@ ruleTester.run("block-spacing", rule, { code: "(() => { bar(); });", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -904,7 +903,8 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (a) { /* comment */ foo(); /* comment */ }", @@ -935,7 +935,6 @@ ruleTester.run("block-spacing", rule, { code: "(() => { bar();});", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -946,13 +945,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "(() => {bar(); });", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -963,13 +962,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "(() => { bar(); });", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -989,7 +988,8 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 21 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // class static blocks @@ -997,7 +997,6 @@ ruleTester.run("block-spacing", rule, { code: "class C { static { foo;} }", output: "class C { static {foo;} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1011,13 +1010,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 20 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static {foo; } }", output: "class C { static {foo;} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1031,13 +1030,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 24 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo; } }", output: "class C { static {foo;} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1063,13 +1062,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 25 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { /* comment */ } }", output: "class C { static {/* comment */} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1095,13 +1094,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 34 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { /* comment 1 */ foo; /* comment 2 */ } }", output: "class C { static {/* comment 1 */ foo; /* comment 2 */} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1127,13 +1126,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 57 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static\n{ foo()\nbar() } }", output: "class C { static\n{foo()\nbar()} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1159,7 +1158,8 @@ ruleTester.run("block-spacing", rule, { endLine: 3, endColumn: 8 } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/brace-style.js b/tests/lib/rules/brace-style.js index 9629f42fc58..f213820c3e9 100644 --- a/tests/lib/rules/brace-style.js +++ b/tests/lib/rules/brace-style.js @@ -10,14 +10,14 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/brace-style"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), { unIndent } = require("../../_utils"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "script" } }); ruleTester.run("brace-style", rule, { valid: [ @@ -79,10 +79,10 @@ ruleTester.run("brace-style", rule, { { code: "switch(0) {}", options: ["1tbs", { allowSingleLine: true }] }, { code: "if (foo) {}\nelse {}", options: ["stroustrup", { allowSingleLine: true }] }, { code: "try { bar(); }\ncatch (e) { baz(); }", options: ["stroustrup", { allowSingleLine: true }] }, - { code: "var foo = () => { return; }", options: ["stroustrup", { allowSingleLine: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => { return; }", options: ["stroustrup", { allowSingleLine: true }], languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) {}\nelse {}", options: ["allman", { allowSingleLine: true }] }, { code: "try { bar(); }\ncatch (e) { baz(); }", options: ["allman", { allowSingleLine: true }] }, - { code: "var foo = () => { return; }", options: ["allman", { allowSingleLine: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => { return; }", options: ["allman", { allowSingleLine: true }], languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { baz(); } else {\n boom();\n}", options: ["1tbs", { allowSingleLine: true }] @@ -217,7 +217,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -229,7 +229,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -238,7 +238,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs", { allowSingleLine: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -249,7 +249,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -261,7 +261,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -270,7 +270,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup", { allowSingleLine: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -283,7 +283,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -294,7 +294,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -309,7 +309,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman", { allowSingleLine: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -322,7 +322,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -335,8 +335,8 @@ ruleTester.run("brace-style", rule, { { code: "var foo = () => { return; }", output: "var foo = () => {\n return; \n}", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { return; }", @@ -411,8 +411,8 @@ ruleTester.run("brace-style", rule, { { code: "for (foo of bar) \n { \n baz(); \n }", output: "for (foo of bar) { \n baz(); \n }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "try { \n bar(); \n }\ncatch (e) {\n}", @@ -809,10 +809,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -829,10 +829,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -849,10 +849,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -869,12 +869,12 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -889,10 +889,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -911,10 +911,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -931,10 +931,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -951,10 +951,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -971,12 +971,12 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -991,10 +991,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1015,10 +1015,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1039,10 +1039,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1063,10 +1063,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1085,12 +1085,12 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1107,10 +1107,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/callback-return.js b/tests/lib/rules/callback-return.js index 1f17ef6cc24..34186a6ccd6 100644 --- a/tests/lib/rules/callback-return.js +++ b/tests/lib/rules/callback-return.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/callback-return"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -51,24 +51,24 @@ ruleTester.run("callback-return", rule, { // arrow functions { code: "var x = err => { if (err) { callback(); return; } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var x = err => callback(err)", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var x = err => { setTimeout( () => { callback(); }); }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // classes { code: "class x { horse() { callback(); } } ", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class x { horse() { if (err) { return callback(); } callback(); } } ", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // options (only warns with the correct callback name) @@ -191,23 +191,23 @@ ruleTester.run("callback-return", rule, { }, { code: "var x = (err) => { if (err) { callback (err); } }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 31, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = { x(err) { if (err) { callback (err); } } }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 31, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function x(err) { if (err) {\n log();\n callback(err); } }", @@ -220,13 +220,13 @@ ruleTester.run("callback-return", rule, { }, { code: "var x = { x(err) { if (err) { callback && callback (err); } } }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 43, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function a(err) { callback (err); callback(); }", @@ -257,13 +257,13 @@ ruleTester.run("callback-return", rule, { }, { code: "var a = (err) => { callback (err); callback(); }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 20, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function a(err) { if (err) { callback (err); } else if (x) { callback(err); return; } }", @@ -286,13 +286,13 @@ ruleTester.run("callback-return", rule, { }, { code: "class x { horse() { if (err) { callback(); } callback(); } } ", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 32, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, @@ -324,7 +324,6 @@ ruleTester.run("callback-return", rule, { }, { code: "() => { if (x) { callback(); } }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -332,7 +331,8 @@ ruleTester.run("callback-return", rule, { column: 18, type: "CallExpression" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function b() { switch(x) { case 'horse': callback(); } }", diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index f634c71b43d..2c56f09e43d 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/camelcase"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("camelcase", rule, { valid: [ @@ -93,236 +98,228 @@ ruleTester.run("camelcase", rule, { }, { code: "const { ['foo']: _foo } = obj;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const { [_foo_]: foo } = obj;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: category_id } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id = 1 } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { [{category_id} = query]: categoryId } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: category } = query;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { _leading } = query;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { trailing_ } = query;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "import { camelCased } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { _leading } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { trailing_ } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as camelCased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as _leading } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as trailing_ } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as camelCased, anotherCamelCased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { snake_cased } from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { snake_cased as snake_cased } from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import { 'snake_cased' as snake_cased } from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import { camelCased } from 'mod'", options: [{ ignoreImports: false }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // this rule doesn't apply to quoted module export names, as it doesn't apply to quoted property names. { code: "export { a as 'snake_cased' } from 'mod'", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export * as 'snake_cased' from 'mod'", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "var _camelCased = aGlobalVariable", options: [{ ignoreGlobals: false }], - globals: { aGlobalVariable: "readonly" } + languageOptions: { globals: { aGlobalVariable: "readonly" } } }, { code: "var camelCased = _aGlobalVariable", options: [{ ignoreGlobals: false }], - globals: { _aGlobalVariable: "readonly" } + languageOptions: { globals: { _aGlobalVariable: "readonly" } } }, { code: "var camelCased = a_global_variable", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable.foo()", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable[undefined]", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var foo = a_global_variable.bar", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable.foo = bar", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "( { foo: a_global_variable.bar } = baz )", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable = foo", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable = foo", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "({ a_global_variable } = foo)", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "({ snake_cased: a_global_variable } = foo)", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "({ snake_cased: a_global_variable = foo } = bar)", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "[a_global_variable] = bar", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "[a_global_variable = foo] = bar", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "foo[a_global_variable] = bar", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var foo = { [a_global_variable]: bar }", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var { [a_global_variable]: foo } = bar", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "readonly" } // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "function foo({ no_camelcased: camelCased }) {};", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ no_camelcased: _leading }) {};", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ no_camelcased: trailing_ }) {};", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ camelCased = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ _leading = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ trailing_ = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ camelCased }) {};", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ _leading }) {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ trailing_ }) {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "ignored_foo = 0;", @@ -343,70 +340,70 @@ ruleTester.run("camelcase", rule, { { code: "foo = { [computedBar]: 0 };", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.fo_o } = bar);", options: [{ allow: ["fo_o"] }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.foo } = bar);", options: [{ allow: ["fo_o"] }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.fo_o } = bar);", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.fo_o.b_ar } = bar);", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: { b: obj.fo_o } } = bar);", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "([obj.fo_o] = bar);", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ c: [ob.fo_o]} = bar);", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "([obj.fo_o.b_ar] = bar);", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({obj} = baz.fo_o);", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "([obj] = baz.fo_o);", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "([obj.foo = obj.fo_o] = bar);", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class C { camelCase; #camelCase; #camelCase2() {} }", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { snake_case; #snake_case; #snake_case2() {} }", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // Combinations of `properties` and `ignoreDestructuring` @@ -425,7 +422,7 @@ ruleTester.run("camelcase", rule, { }; `, options: [{ properties: "never", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/15572 @@ -435,7 +432,7 @@ ruleTester.run("camelcase", rule, { doSomething({ some_property }); `, options: [{ properties: "never", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -574,352 +571,351 @@ ruleTester.run("camelcase", rule, { }, { code: "var { category_id: category_alias } = query;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_alias" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: category_alias } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_alias" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { [category_id]: categoryId } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { [category_id]: categoryId } = query;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: categoryId, ...other_props } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "notCamelCase", data: { name: "other_props" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var { category_id } = query;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: category_id } = query;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id = 1 } = query;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "import no_camelcased from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as no_camelcased from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as no_camel_cased } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camel_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { camelCased as no_camel_cased } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camel_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { 'snake_cased' as snake_cased } from 'mod'", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import { 'snake_cased' as another_snake_cased } from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "another_snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import { camelCased, no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "another_no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import camelCased, { no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import snake_cased from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as snake_cased from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import snake_cased from 'mod'", options: [{ ignoreImports: false }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as snake_cased from 'mod'", options: [{ ignoreImports: false }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var camelCased = snake_cased", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable.foo()", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable[undefined]", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var camelCased = snake_cased", - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var camelCased = snake_cased", options: [{}], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "foo.a_global_variable = bar", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var foo = { a_global_variable: bar }", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var foo = { a_global_variable: a_global_variable }", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -927,51 +923,48 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 13 } - ] + ], + languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var foo = { a_global_variable() {} }", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "class Foo { a_global_variable() {} }", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "a_global_variable: for (;;);", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "if (foo) { let a_global_variable; a_global_variable = bar; }", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -985,13 +978,12 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 35 } - ] + ], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "function foo(a_global_variable) { foo = a_global_variable; }", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1005,37 +997,36 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 41 } - ] + ], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var a_global_variable", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function a_global_variable () {}", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const a_global_variable = foo; bar = a_global_variable", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1049,13 +1040,12 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 38 } - ] + ], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "bar = a_global_variable; var a_global_variable;", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1069,20 +1059,20 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 30 } - ] + ], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "var foo = { a_global_variable }", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase }, { code: "undefined_variable;", @@ -1108,40 +1098,39 @@ ruleTester.run("camelcase", rule, { }, { code: "export * as snake_cased from 'mod'", - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "function foo({ no_camelcased }) {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ no_camelcased = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1153,73 +1142,74 @@ ruleTester.run("camelcase", rule, { data: { name: "camelcased_value" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { bar: no_camelcased } = foo;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ value_1: my_default }) {}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "my_default" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ isCamelcased: no_camelcased }) {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { foo: bar_baz = 1 } = quz;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "bar_baz" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { no_camelcased = false } = bar;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { no_camelcased = foo_bar } = bar;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "not_ignored_foo = 0;", @@ -1246,205 +1236,205 @@ ruleTester.run("camelcase", rule, { { code: "foo = { [computed_bar]: 0 };", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "computed_bar" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.fo_o } = bar);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.fo_o } = bar);", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.fo_o.b_ar } = baz);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "b_ar" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: { b: { c: obj.fo_o } } } = bar);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "b_ar" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "([obj.fo_o] = bar);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "([obj.fo_o] = bar);", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "([obj.fo_o = 1] = bar);", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: [obj.fo_o] } = bar);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: { b: [obj.fo_o] } } = bar);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "([obj.fo_o.ba_r] = baz);", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "ba_r" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({...obj.fo_o} = baz);", - parserOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 9 } }, { code: "({...obj.fo_o.ba_r} = baz);", - parserOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", data: { name: "ba_r" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 9 } }, { code: "({c: {...obj.fo_o }} = baz);", - parserOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 9 } }, // Optional chaining. { code: "obj.o_k.non_camelcase = 0", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }] + errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.o_k).non_camelcase = 0", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }] + errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }], + languageOptions: { ecmaVersion: 2020 } }, // class public/private fields, private methods. { code: "class C { snake_case; }", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "notCamelCase", data: { name: "snake_case" } }] + errors: [{ messageId: "notCamelCase", data: { name: "snake_case" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #snake_case; foo() { this.#snake_case; } }", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" }, column: 11 }] + errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" }, column: 11 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #snake_case() {} }", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }] + errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }], + languageOptions: { ecmaVersion: 2022 } }, // Combinations of `properties` and `ignoreDestructuring` @@ -1454,7 +1444,6 @@ ruleTester.run("camelcase", rule, { doSomething({ some_property }); `, options: [{ properties: "always", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1462,7 +1451,8 @@ ruleTester.run("camelcase", rule, { line: 3, column: 27 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -1471,7 +1461,6 @@ ruleTester.run("camelcase", rule, { doSomething({ [some_property]: "bar" }); `, options: [{ properties: "never", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1479,7 +1468,8 @@ ruleTester.run("camelcase", rule, { line: 4, column: 28 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -1496,7 +1486,6 @@ ruleTester.run("camelcase", rule, { }; `, options: [{ properties: "always", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1516,7 +1505,8 @@ ruleTester.run("camelcase", rule, { line: 8, column: 27 } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/capitalized-comments.js b/tests/lib/rules/capitalized-comments.js index 043226055b4..ac7e7375483 100644 --- a/tests/lib/rules/capitalized-comments.js +++ b/tests/lib/rules/capitalized-comments.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/capitalized-comments"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/class-methods-use-this.js b/tests/lib/rules/class-methods-use-this.js index eeb122f75b0..8ae661bef62 100644 --- a/tests/lib/rules/class-methods-use-this.js +++ b/tests/lib/rules/class-methods-use-this.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/class-methods-use-this"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -20,116 +20,115 @@ const ruleTester = new RuleTester(); ruleTester.run("class-methods-use-this", rule, { valid: [ - { code: "class A { constructor() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo() {this} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo() {this.bar = 'bar';} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo() {bar(this);} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { foo() {super.foo();} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo() { if(true) { return this; } } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { static foo() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "({ a(){} });", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo() { () => this; } }", parserOptions: { ecmaVersion: 6 } }, - { code: "({ a: function () {} });", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo() {this} bar() {} }", options: [{ exceptMethods: ["bar"] }], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { \"foo\"() { } }", options: [{ exceptMethods: ["foo"] }], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { 42() { } }", options: [{ exceptMethods: ["42"] }], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo = function() {this} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { foo = () => {this} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { foo = () => {super.toString} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { static foo = function() {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { static foo = () => {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { #bar() {} }", options: [{ exceptMethods: ["#bar"] }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { foo = function () {} }", options: [{ enforceForClassFields: false }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { foo = () => {} }", options: [{ enforceForClassFields: false }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { foo() { return class { [this.foo] = 1 }; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { static {} }", parserOptions: { ecmaVersion: 2022 } } + { code: "class A { constructor() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo() {this} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo() {this.bar = 'bar';} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo() {bar(this);} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { foo() {super.foo();} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo() { if(true) { return this; } } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { static foo() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "({ a(){} });", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo() { () => this; } }", languageOptions: { ecmaVersion: 6 } }, + { code: "({ a: function () {} });", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo() {this} bar() {} }", options: [{ exceptMethods: ["bar"] }], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { \"foo\"() { } }", options: [{ exceptMethods: ["foo"] }], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { 42() { } }", options: [{ exceptMethods: ["42"] }], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo = function() {this} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { foo = () => {this} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { foo = () => {super.toString} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { static foo = function() {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { static foo = () => {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { #bar() {} }", options: [{ exceptMethods: ["#bar"] }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { foo = function () {} }", options: [{ enforceForClassFields: false }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { foo = () => {} }", options: [{ enforceForClassFields: false }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { foo() { return class { [this.foo] = 1 }; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { static {} }", languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { code: "class A { foo() {} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() {/**this**/} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() {var a = function () {this};} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() {var a = function () {var b = function(){this}};} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() {window.this} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() {that.this = 'this';} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() { () => undefined; } }", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() {} bar() {} }", options: [{ exceptMethods: ["bar"] }], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() {} hasOwnProperty() {} }", options: [{ exceptMethods: ["foo"] }], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 20, messageId: "missingThis", data: { name: "method 'hasOwnProperty'" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [foo]() {} }", options: [{ exceptMethods: ["foo"] }], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { #foo() { } foo() {} #bar() {} }", options: [{ exceptMethods: ["#foo"] }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { type: "FunctionExpression", line: 1, column: 22, messageId: "missingThis", data: { name: "method 'foo'" } }, { type: "FunctionExpression", line: 1, column: 31, messageId: "missingThis", data: { name: "private method #bar" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { foo(){} 'bar'(){} 123(){} [`baz`](){} [a](){} [f(a)](){} get quux(){} set[a](b){} *quuux(){} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, type: "FunctionExpression", column: 11 }, { messageId: "missingThis", data: { name: "method 'bar'" }, type: "FunctionExpression", column: 19 }, @@ -140,77 +139,78 @@ ruleTester.run("class-methods-use-this", rule, { { messageId: "missingThis", data: { name: "getter 'quux'" }, type: "FunctionExpression", column: 68 }, { messageId: "missingThis", data: { name: "setter" }, type: "FunctionExpression", column: 81 }, { messageId: "missingThis", data: { name: "generator method 'quuux'" }, type: "FunctionExpression", column: 93 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo = function() {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 25 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { foo = () => {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 17 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { #foo = function() {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 26 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { #foo = () => {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 18 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { #foo() {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { get #foo() {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private getter #foo" }, column: 11, endColumn: 19 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { set #foo(x) {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private setter #foo" }, column: 11, endColumn: 19 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { foo () { return class { foo = this }; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { foo () { return function () { foo = this }; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { foo () { return class { static { this; } } } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/comma-dangle.js b/tests/lib/rules/comma-dangle.js index 49cd6c2546b..e0ab1a60f6b 100644 --- a/tests/lib/rules/comma-dangle.js +++ b/tests/lib/rules/comma-dangle.js @@ -12,8 +12,7 @@ const path = require("path"), { unIndent } = require("../../_utils"), rule = require("../../../lib/rules/comma-dangle"), - { RuleTester } = require("../../../lib/rule-tester"), - FlatRuleTester = require("../../../lib/rule-tester/flat-rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -22,44 +21,55 @@ const path = require("path"), /** * Gets the path to the parser of the given name. * @param {string} name The name of a parser to get. - * @returns {string} The path to the specified parser. + * @returns {Object} The parser object. */ function parser(name) { - return path.resolve( + return require(path.resolve( __dirname, `../../fixtures/parsers/comma-dangle/${name}.js` - ); + )); } //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + plugins: { + custom: { + rules: { + "add-named-import": { + meta: { + fixable: "code" + }, + create(context) { + return { + ImportDeclaration(node) { + const sourceCode = context.sourceCode; + const closingBrace = sourceCode.getLastToken(node, token => token.value === "}"); + const addComma = sourceCode.getTokenBefore(closingBrace).value !== ","; -ruleTester.defineRule("add-named-import", { - meta: { - fixable: "code" - }, - create(context) { - return { - ImportDeclaration(node) { - const sourceCode = context.sourceCode; - const closingBrace = sourceCode.getLastToken(node, token => token.value === "}"); - const addComma = sourceCode.getTokenBefore(closingBrace).value !== ","; - - context.report({ - message: "Add I18nManager.", - node, - fix(fixer) { - return fixer.insertTextBefore(closingBrace, `${addComma ? "," : ""}I18nManager`); + context.report({ + message: "Add I18nManager.", + node, + fix(fixer) { + return fixer.insertTextBefore(closingBrace, `${addComma ? "," : ""}I18nManager`); + } + }); + } + }; } - }); + } } - }; + } + }, + languageOptions: { + ecmaVersion: 5, + sourceType: "script" } }); + ruleTester.run("comma-dangle", rule, { valid: [ "var foo = { bar: 'baz' }", @@ -76,10 +86,10 @@ ruleTester.run("comma-dangle", rule, { { code: "var foo = { bar: 'baz' }", options: ["never"] }, { code: "var foo = {\nbar: 'baz'\n}", options: ["never"] }, { code: "var foo = [ 'baz' ]", options: ["never"] }, - { code: "var { a, b } = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [ a, b ] = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { a,\n b, \n} = foo;", options: ["only-multiline"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [ a,\n b, \n] = foo;", options: ["only-multiline"], parserOptions: { ecmaVersion: 6 } }, + { code: "var { a, b } = foo;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [ a, b ] = foo;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { a,\n b, \n} = foo;", options: ["only-multiline"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [ a,\n b, \n] = foo;", options: ["only-multiline"], languageOptions: { ecmaVersion: 6 } }, { code: "[(1),]", options: ["always"] }, { code: "var x = { foo: (1),};", options: ["always"] }, @@ -119,146 +129,146 @@ ruleTester.run("comma-dangle", rule, { { code: "var [a, ...rest] = [];", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n a,\n ...rest\n] = [];", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n a,\n ...rest\n] = [];", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [\n a,\n ...rest\n] = [];", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "[a, ...rest] = [];", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "for ([a, ...rest] of []);", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = [b, ...spread,];", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7297 { code: "var {foo, ...bar} = baz", options: ["always"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/3794 { code: "import {foo,} from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo, {abc,} from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as foo from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo,} from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo, {abc} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as foo from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo} from 'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo} from 'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {\n foo,\n} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {\n foo,\n} from 'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {\n foo,\n} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {\n foo,\n} from 'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo} from \n'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo} from \n'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "function foo(a) {}", @@ -303,232 +313,273 @@ ruleTester.run("comma-dangle", rule, { { code: "function foo(a) {}", options: ["always"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "foo(a)", options: ["always"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "function foo(a) {}", options: ["never"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "foo(a)", options: ["never"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "function foo(a,\nb) {}", options: ["always-multiline"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "foo(a,\nb)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "function foo(a,\nb\n) {}", options: ["always-multiline"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "foo(a,\nb\n)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "function foo(a,\nb) {}", options: ["only-multiline"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "foo(a,\nb)", options: ["only-multiline"], - parserOptions: { ecmaVersion: 7 } + languageOptions: { ecmaVersion: 7 } }, { code: "function foo(a) {}", options: ["never"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a)", options: ["never"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,) {}", options: ["always"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", options: ["always"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(\na,\nb,\n) {}", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\na,b)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,b) {}", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,b)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,b) {}", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,b)", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, // trailing comma in functions { code: "function foo(a) {} ", options: [{}], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a)", options: [{}], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a) {} ", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a)", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,) {}", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function bar(a, ...b) {}", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 } }, { code: "bar(...a,)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a) {} ", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(\na,\nb,\n) {} ", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(\na,\n...b\n) {} ", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\na,\nb,\n)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\na,\n...b,\n)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a) {} ", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a)", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(\na,\nb,\n) {} ", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\na,\nb,\n)", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(\na,\nb\n) {} ", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\na,\nb\n)", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, // https://github.com/eslint/eslint/issues/7370 { code: "function foo({a}: {a: string,}) {}", options: ["never"], - parser: parser("object-pattern-1") + languageOptions: { + parser: parser("object-pattern-1") + } }, { code: "function foo({a,}: {a: string}) {}", options: ["always"], - parser: parser("object-pattern-2") + languageOptions: { + parser: parser("object-pattern-2") + } }, { code: "function foo(a): {b: boolean,} {}", options: [{ functions: "never" }], - parser: parser("return-type-1") + languageOptions: { + parser: parser("return-type-1") + } }, { code: "function foo(a,): {b: boolean} {}", options: [{ functions: "always" }], - parser: parser("return-type-2") + languageOptions: { + parser: parser("return-type-2") + } + }, + + // https://github.com/eslint/eslint/issues/16442 + { + code: "function f(\n a,\n b\n) {}", + options: ["always-multiline"], + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } + }, + { + code: "f(\n a,\n b\n);", + options: ["always-multiline"], + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } + }, + { + code: "function f(\n a,\n b\n) {}", + options: ["always-multiline"], + languageOptions: { + ecmaVersion: 2016 + } + }, + { + code: "f(\n a,\n b\n);", + options: ["always-multiline"], + languageOptions: { + ecmaVersion: 2016 + } } + ], invalid: [ { @@ -1039,7 +1090,6 @@ ruleTester.run("comma-dangle", rule, { code: "var { a, b, } = foo;", output: "var { a, b } = foo;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1047,13 +1097,13 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a, b, } = foo;", output: "var { a, b } = foo;", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1061,13 +1111,13 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [ a, b, ] = foo;", output: "var [ a, b ] = foo;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1075,13 +1125,13 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [ a, b, ] = foo;", output: "var [ a, b ] = foo;", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1089,7 +1139,8 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "[(1),]", @@ -1149,92 +1200,92 @@ ruleTester.run("comma-dangle", rule, { code: "import {foo} from 'foo';", output: "import {foo,} from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "missing", type: "ImportSpecifier" }] + errors: [{ messageId: "missing", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo, {abc} from 'foo';", output: "import foo, {abc,} from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "missing", type: "ImportSpecifier" }] + errors: [{ messageId: "missing", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo} from 'foo';", output: "export {foo,} from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "missing", type: "ExportSpecifier" }] + errors: [{ messageId: "missing", type: "ExportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo, {abc,} from 'foo';", output: "import foo, {abc} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo, {abc,} from 'foo';", output: "import foo, {abc} from 'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {\n foo\n} from 'foo';", output: "import {\n foo,\n} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "missing", type: "ImportSpecifier" }] + errors: [{ messageId: "missing", type: "ImportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {\n foo\n} from 'foo';", output: "export {\n foo,\n} from 'foo';", options: ["always-multiline"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "missing", type: "ExportSpecifier" }] + errors: [{ messageId: "missing", type: "ExportSpecifier" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // https://github.com/eslint/eslint/issues/6233 @@ -1262,395 +1313,395 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a,) => a", output: "(a) => a", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a,) => (a)", output: "(a) => (a)", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "({foo(a,) {}})", output: "({foo(a) {}})", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "class A {foo(a,) {}}", output: "class A {foo(a) {}}", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a) {}", output: "function foo(a,) {}", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a) {})", output: "(function foo(a,) {})", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a) => a", output: "(a,) => a", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a) => (a)", output: "(a,) => (a)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "({foo(a) {}})", output: "({foo(a,) {}})", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "class A {foo(a) {}}", output: "class A {foo(a,) {}}", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a)", output: "foo(a,)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a)", output: "foo(...a,)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "SpreadElement" }] + errors: [{ messageId: "missing", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(\na,\nb\n) {}", output: "function foo(\na,\nb,\n) {}", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\na,\nb\n)", output: "foo(\na,\nb,\n)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\n...a,\n...b\n)", output: "foo(\n...a,\n...b,\n)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "SpreadElement" }] + errors: [{ messageId: "missing", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a,) => a", output: "(a) => a", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a,) => (a)", output: "(a) => (a)", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "({foo(a,) {}})", output: "({foo(a) {}})", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "class A {foo(a,) {}}", output: "class A {foo(a) {}}", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", output: "foo(a)", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a,)", output: "foo(...a)", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a) {}", output: "function foo(a,) {}", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a) {})", output: "(function foo(a,) {})", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a) => a", output: "(a,) => a", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(a) => (a)", output: "(a,) => (a)", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "({foo(a) {}})", output: "({foo(a,) {},})", options: ["always"], - parserOptions: { ecmaVersion: 8 }, errors: [ { messageId: "missing", type: "Identifier" }, { messageId: "missing", type: "Property" } - ] + ], + languageOptions: { ecmaVersion: 8 } }, { code: "class A {foo(a) {}}", output: "class A {foo(a,) {}}", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a)", output: "foo(a,)", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a)", output: "foo(...a,)", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "SpreadElement" }] + errors: [{ messageId: "missing", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", output: "foo(a)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a,)", output: "foo(...a)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(\na,\nb\n) {}", output: "function foo(\na,\nb,\n) {}", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\na,\nb\n)", output: "foo(\na,\nb,\n)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(\n...a,\n...b\n)", output: "foo(\n...a,\n...b,\n)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missing", type: "SpreadElement" }] + errors: [{ messageId: "missing", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(a,)", output: "foo(a)", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }], + languageOptions: { ecmaVersion: 8 } }, { code: "foo(...a,)", output: "foo(...a)", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }], + languageOptions: { ecmaVersion: 8 } }, { code: "function foo(a) {}", output: "function foo(a,) {}", options: ["always"], - parserOptions: { ecmaVersion: 9 }, - errors: [{ messageId: "missing", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }], + languageOptions: { ecmaVersion: 9 } }, // separated options @@ -1672,11 +1723,11 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 1 }, { messageId: "unexpected", line: 1 } - ] + ], + languageOptions: { ecmaVersion: 8, sourceType: "module" } }, { code: `let {a,} = {a: 1,}; @@ -1696,11 +1747,11 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 2 }, { messageId: "unexpected", line: 2 } - ] + ], + languageOptions: { ecmaVersion: 8, sourceType: "module" } }, { code: `let {a,} = {a: 1,}; @@ -1720,10 +1771,10 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 8, sourceType: "module" } }, { code: `let {a,} = {a: 1,}; @@ -1743,10 +1794,10 @@ let d = 0;export {d}; exports: "never", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 4 } - ] + ], + languageOptions: { ecmaVersion: 8, sourceType: "module" } }, { code: `let {a,} = {a: 1,}; @@ -1766,11 +1817,11 @@ let d = 0;export {d,}; exports: "ignore", functions: "never" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 5 }, { messageId: "unexpected", line: 5 } - ] + ], + languageOptions: { ecmaVersion: 8, sourceType: "module" } }, // https://github.com/eslint/eslint/issues/7370 @@ -1778,43 +1829,51 @@ let d = 0;export {d,}; code: "function foo({a}: {a: string,}) {}", output: "function foo({a,}: {a: string,}) {}", options: ["always"], - parser: parser("object-pattern-1"), - errors: [{ messageId: "missing" }] + errors: [{ messageId: "missing" }], + languageOptions: { + parser: parser("object-pattern-1") + } }, { code: "function foo({a,}: {a: string}) {}", output: "function foo({a}: {a: string}) {}", options: ["never"], - parser: parser("object-pattern-2"), - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { + parser: parser("object-pattern-2") + } }, { code: "function foo(a): {b: boolean,} {}", output: "function foo(a,): {b: boolean,} {}", options: [{ functions: "always" }], - parser: parser("return-type-1"), - errors: [{ messageId: "missing" }] + errors: [{ messageId: "missing" }], + languageOptions: { + parser: parser("return-type-1") + } }, { code: "function foo(a,): {b: boolean} {}", output: "function foo(a): {b: boolean} {}", options: [{ functions: "never" }], - parser: parser("return-type-2"), - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { + parser: parser("return-type-2") + } }, // https://github.com/eslint/eslint/issues/11502 { code: "foo(a,)", output: "foo(a)", - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 8 } }, // https://github.com/eslint/eslint/issues/15660 { code: unIndent` - /*eslint add-named-import:1*/ + /*eslint custom/add-named-import:1*/ import { StyleSheet, View, @@ -1826,7 +1885,7 @@ let d = 0;export {d,}; } from 'react-native'; `, output: unIndent` - /*eslint add-named-import:1*/ + /*eslint custom/add-named-import:1*/ import { StyleSheet, View, @@ -1838,12 +1897,12 @@ let d = 0;export {d,}; } from 'react-native'; `, options: [{ imports: "always-multiline" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: 2 + errors: 2, + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` - /*eslint add-named-import:1*/ + /*eslint custom/add-named-import:1*/ import { StyleSheet, View, @@ -1855,7 +1914,7 @@ let d = 0;export {d,}; } from 'react-native'; `, output: unIndent` - /*eslint add-named-import:1*/ + /*eslint custom/add-named-import:1*/ import { StyleSheet, View, @@ -1867,105 +1926,66 @@ let d = 0;export {d,}; } from 'react-native'; `, options: [{ imports: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: 2 - } - ] -}); - -const flatRuleTester = new FlatRuleTester(); - -// https://github.com/eslint/eslint/issues/16442 -flatRuleTester.run("comma-dangle", rule, { - valid: [ - { - code: "function f(\n a,\n b\n) {}", - options: ["always-multiline"], - languageOptions: { - ecmaVersion: 5, - sourceType: "script" - } + errors: 2, + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { - code: "f(\n a,\n b\n);", - options: ["always-multiline"], - languageOptions: { - ecmaVersion: 5, - sourceType: "script" - } - }, - { - code: "function f(\n a,\n b\n) {}", - options: ["always-multiline"], - languageOptions: { - ecmaVersion: 2016 - } - }, - { - code: "f(\n a,\n b\n);", - options: ["always-multiline"], - languageOptions: { - ecmaVersion: 2016 - } - } - ], - invalid: [ + // https://github.com/eslint/eslint/issues/16442 { code: "function f(\n a,\n b\n) {}", output: "function f(\n a,\n b,\n) {}", options: ["always-multiline"], - languageOptions: { - ecmaVersion: 2017 - }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }] + }], + languageOptions: { + ecmaVersion: 2017 + } }, { code: "f(\n a,\n b\n);", output: "f(\n a,\n b,\n);", options: ["always-multiline"], - languageOptions: { - ecmaVersion: 2017 - }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }] + }], + languageOptions: { + ecmaVersion: 2017 + } }, { code: "function f(\n a,\n b\n) {}", output: "function f(\n a,\n b,\n) {}", options: ["always-multiline"], - languageOptions: { - ecmaVersion: "latest" - }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }] + }], + languageOptions: { + ecmaVersion: "latest" + } }, { code: "f(\n a,\n b\n);", output: "f(\n a,\n b,\n);", options: ["always-multiline"], - languageOptions: { - ecmaVersion: "latest" - }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }] + }], + languageOptions: { + ecmaVersion: "latest" + } } ] }); diff --git a/tests/lib/rules/comma-spacing.js b/tests/lib/rules/comma-spacing.js index a3b23b62d73..b4d17f08452 100644 --- a/tests/lib/rules/comma-spacing.js +++ b/tests/lib/rules/comma-spacing.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/comma-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -60,11 +60,11 @@ ruleTester.run("comma-spacing", rule, { "var obj = {'foo':'bar', 'baz':\n'qur'};", "var obj = {'foo':\n'bar', 'baz':\n'qur'};", "function foo(a, b){}", - { code: "function foo(a, b = 1){}", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(a = 1, b, c){}", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = (a, b) => {}", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = (a=1, b) => {}", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = a => a + 2", parserOptions: { ecmaVersion: 6 } }, + { code: "function foo(a, b = 1){}", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(a = 1, b, c){}", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = (a, b) => {}", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = (a=1, b) => {}", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = a => a + 2", languageOptions: { ecmaVersion: 6 } }, "a, b", "var a = (1 + 2, 2);", "a(b, c)", @@ -76,12 +76,12 @@ ruleTester.run("comma-spacing", rule, { "go.boom((a + b), 10, (4))", "var x = [ (a + c), (b + b) ]", "[' , ']", - { code: "[` , `]", parserOptions: { ecmaVersion: 6 } }, - { code: "`${[1, 2]}`", parserOptions: { ecmaVersion: 6 } }, - { code: "fn(a, b,)", parserOptions: { ecmaVersion: 2018 } }, // #11295 - { code: "const fn = (a, b,) => {}", parserOptions: { ecmaVersion: 2018 } }, // #11295 - { code: "const fn = function (a, b,) {}", parserOptions: { ecmaVersion: 2018 } }, // #11295 - { code: "function fn(a, b,) {}", parserOptions: { ecmaVersion: 2018 } }, // #11295 + { code: "[` , `]", languageOptions: { ecmaVersion: 6 } }, + { code: "`${[1, 2]}`", languageOptions: { ecmaVersion: 6 } }, + { code: "fn(a, b,)", languageOptions: { ecmaVersion: 2018 } }, // #11295 + { code: "const fn = (a, b,) => {}", languageOptions: { ecmaVersion: 2018 } }, // #11295 + { code: "const fn = function (a, b,) {}", languageOptions: { ecmaVersion: 2018 } }, // #11295 + { code: "function fn(a, b,) {}", languageOptions: { ecmaVersion: 2018 } }, // #11295 "foo(/,/, 'a')", "var x = ',,,,,';", "var code = 'var foo = 1, bar = 3;'", @@ -149,25 +149,25 @@ ruleTester.run("comma-spacing", rule, { { code: "var arr = [1,,3];", options: [{ before: false, after: false }] }, { code: "var arr = [1,2,3];", options: [{ before: false, after: false }] }, { code: "var a = (1 + 2,2)", options: [{ before: false, after: false }] }, - { code: "var a; console.log(`${a}`, \"a\");", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, b] = [1, 2];", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, b, ] = [1, 2];", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, b,] = [1, 2];", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, , b] = [1, 2, 3];", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a,, b] = [1, 2, 3];", parserOptions: { ecmaVersion: 6 } }, - { code: "var [ , b] = a;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [, b] = a;", parserOptions: { ecmaVersion: 6 } }, - { code: "var { a,} = a;", parserOptions: { ecmaVersion: 6 } }, - { code: "import { a,} from 'mod';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: ",", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: " , ", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "Hello, world", options: [{ before: true, after: false }], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { code: "var a; console.log(`${a}`, \"a\");", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, b] = [1, 2];", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, b, ] = [1, 2];", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, b,] = [1, 2];", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, , b] = [1, 2, 3];", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a,, b] = [1, 2, 3];", languageOptions: { ecmaVersion: 6 } }, + { code: "var [ , b] = a;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [, b] = a;", languageOptions: { ecmaVersion: 6 } }, + { code: "var { a,} = a;", languageOptions: { ecmaVersion: 6 } }, + { code: "import { a,} from 'mod';", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: ",", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: " , ", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "Hello, world", options: [{ before: true, after: false }], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, // For backwards compatibility. Ignoring spacing between a comment and comma of a null element was possibly unintentional. { code: "[a, /**/ , ]", options: [{ before: false, after: true }] }, { code: "[a , /**/, ]", options: [{ before: true, after: true }] }, - { code: "[a, /**/ , ] = foo", options: [{ before: false, after: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "[a , /**/, ] = foo", options: [{ before: true, after: true }], parserOptions: { ecmaVersion: 6 } } + { code: "[a, /**/ , ] = foo", options: [{ before: false, after: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "[a , /**/, ] = foo", options: [{ before: true, after: true }], languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -441,7 +441,6 @@ ruleTester.run("comma-spacing", rule, { code: "var foo = (a,b) => {}", output: "var foo = (a , b) => {}", options: [{ before: true, after: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missing", @@ -453,13 +452,13 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = (a = 1,b) => {}", output: "var foo = (a = 1 , b) => {}", options: [{ before: true, after: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missing", @@ -471,13 +470,13 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a = 1 ,b = 2) {}", output: "function foo(a = 1, b = 2) {}", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "There should be no space before ','.", @@ -488,12 +487,12 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "{foo(1 ,2)}", output: "{foo(1, 2)}", - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, errors: [ { message: "There should be no space before ','.", @@ -504,7 +503,8 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ] + ], + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "myfunc(404, true/* bla bla bla */ , 'hello');", diff --git a/tests/lib/rules/comma-style.js b/tests/lib/rules/comma-style.js index e0ac78d6813..e055ed88cbe 100644 --- a/tests/lib/rules/comma-style.js +++ b/tests/lib/rules/comma-style.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/comma-style"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -81,38 +81,38 @@ ruleTester.run("comma-style", rule, { }, { code: "const foo = (a\n, b) => { return a + b; }", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "function foo([a\n, b]) { return a + b; }", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "const foo = ([a\n, b]) => { return a + b; }", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "import { a\n, b } from './source';", - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "const foo = function (a\n, b) { return a + b; }", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "var {foo\n, bar} = {foo:'apples', bar:'oranges'};", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -123,7 +123,7 @@ ruleTester.run("comma-style", rule, { ObjectPattern: true } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -158,7 +158,7 @@ ruleTester.run("comma-style", rule, { FunctionExpression: true } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -169,7 +169,7 @@ ruleTester.run("comma-style", rule, { ArrayPattern: true } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -180,7 +180,7 @@ ruleTester.run("comma-style", rule, { ArrowFunctionExpression: true } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -191,7 +191,7 @@ ruleTester.run("comma-style", rule, { ArrayPattern: true } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -202,7 +202,7 @@ ruleTester.run("comma-style", rule, { ImportDeclaration: true } }], - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" } @@ -214,7 +214,7 @@ ruleTester.run("comma-style", rule, { ObjectPattern: true } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -242,7 +242,7 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -253,21 +253,21 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "const arr = [\n 1 \n , \n ,2 \n]", options: ["first"], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "const arr = [\n ,'fifi' \n]", options: ["first"], - parserOptions: { + languageOptions: { ecmaVersion: 6 } } @@ -375,13 +375,13 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { - ecmaVersion: 6 - }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }] + }], + languageOptions: { + ecmaVersion: 6 + } }, { code: "f(1\n, 2);", @@ -417,14 +417,14 @@ ruleTester.run("comma-style", rule, { FunctionExpression: false } }], - parserOptions: { - ecmaVersion: 6, - sourceType: "module" - }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }] + }], + languageOptions: { + ecmaVersion: 6, + sourceType: "module" + } }, { code: "function foo([a\n, b]) { return a + b; }", @@ -434,13 +434,13 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { - ecmaVersion: 6 - }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }] + }], + languageOptions: { + ecmaVersion: 6 + } }, { code: "const foo = (a\n, b) => { return a + b; }", @@ -450,13 +450,13 @@ ruleTester.run("comma-style", rule, { ArrowFunctionExpression: false } }], - parserOptions: { - ecmaVersion: 6 - }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }] + }], + languageOptions: { + ecmaVersion: 6 + } }, { code: "const foo = ([a\n, b]) => { return a + b; }", @@ -466,13 +466,13 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { - ecmaVersion: 6 - }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }] + }], + languageOptions: { + ecmaVersion: 6 + } }, { code: "import { a\n, b } from './source';", @@ -482,14 +482,14 @@ ruleTester.run("comma-style", rule, { ImportDeclaration: false } }], - parserOptions: { - ecmaVersion: 6, - sourceType: "module" - }, errors: [{ messageId: "expectedCommaLast", type: "ImportSpecifier" - }] + }], + languageOptions: { + ecmaVersion: 6, + sourceType: "module" + } }, { code: "var {foo\n, bar} = {foo:'apples', bar:'oranges'};", @@ -499,13 +499,13 @@ ruleTester.run("comma-style", rule, { ObjectPattern: false } }], - parserOptions: { - ecmaVersion: 6 - }, errors: [{ messageId: "expectedCommaLast", type: "Property" - }] + }], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var foo = 1,\nbar = 2;", diff --git a/tests/lib/rules/complexity.js b/tests/lib/rules/complexity.js index d6feb8a2f05..cb11eed566b 100644 --- a/tests/lib/rules/complexity.js +++ b/tests/lib/rules/complexity.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/complexity"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -52,7 +52,7 @@ function makeError(name, complexity, max) { // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2021 } }); ruleTester.run("complexity", rule, { valid: [ @@ -87,41 +87,41 @@ ruleTester.run("complexity", rule, { { code: "function a(x) {while(true) {'foo';}}", options: [2] }, { code: "function a(x) {do {'foo';} while (true)}", options: [2] }, { code: "if (foo) { bar(); }", options: [3] }, - { code: "var a = (x) => {do {'foo';} while (true)}", options: [2], parserOptions: { ecmaVersion: 6 } }, + { code: "var a = (x) => {do {'foo';} while (true)}", options: [2], languageOptions: { ecmaVersion: 6 } }, // class fields - { code: "function foo() { class C { x = a || b; y = c || d; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { class C { static x = a || b; static y = c || d; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { class C { x = a || b; y = c || d; } e || f; }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { a || b; class C { x = c || d; y = e || f; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { class C { [x || y] = a || b; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x = a || b; y() { c || d; } z = e || f; }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x() { a || b; } y = c || d; z() { e || f; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x = (() => { a || b }) || (() => { c || d }) }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x = () => { a || b }; y = () => { c || d } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x = a || (() => { b || c }); }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x = class { y = a || b; z = c || d; }; }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x = a || class { y = b || c; z = d || e; }; }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { x; y = a; static z; static q = b; }", options: [1], parserOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { x = a || b; y = c || d; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { static x = a || b; static y = c || d; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { x = a || b; y = c || d; } e || f; }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { a || b; class C { x = c || d; y = e || f; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { [x || y] = a || b; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x = a || b; y() { c || d; } z = e || f; }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x() { a || b; } y = c || d; z() { e || f; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x = (() => { a || b }) || (() => { c || d }) }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x = () => { a || b }; y = () => { c || d } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x = a || (() => { b || c }); }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x = class { y = a || b; z = c || d; }; }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x = a || class { y = b || c; z = d || e; }; }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { x; y = a; static z; static q = b; }", options: [1], languageOptions: { ecmaVersion: 2022 } }, // class static blocks - { code: "function foo() { class C { static { a || b; } static { c || d; } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { a || b; class C { static { c || d; } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { class C { static { a || b; } } c || d; }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { class C { static { a || b; } } class D { static { c || d; } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a || b; } static { c || d; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a || b; } static { c || d; } static { e || f; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { () => a || b; c || d; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a || b; () => c || d; } static { c || d; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a } }", options: [1], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a } static { b } }", options: [1], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a || b; } } class D { static { c || d; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a || b; } static c = d || e; }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static a = b || c; static { c || d; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a || b; } c = d || e; }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { a = b || c; static { d || e; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { a || b; c || d; } }", options: [3], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { if (a || b) c = d || e; } }", options: [4], parserOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { static { a || b; } static { c || d; } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { a || b; class C { static { c || d; } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { static { a || b; } } c || d; }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { static { a || b; } } class D { static { c || d; } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a || b; } static { c || d; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a || b; } static { c || d; } static { e || f; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { () => a || b; c || d; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a || b; () => c || d; } static { c || d; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a } }", options: [1], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a } static { b } }", options: [1], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a || b; } } class D { static { c || d; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a || b; } static c = d || e; }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static a = b || c; static { c || d; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a || b; } c = d || e; }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { a = b || c; static { d || e; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { a || b; c || d; } }", options: [3], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { if (a || b) c = d || e; } }", options: [4], languageOptions: { ecmaVersion: 2022 } }, // object property options { code: "function b(x) {}", options: [{ max: 1 }] } @@ -129,15 +129,15 @@ ruleTester.run("complexity", rule, { invalid: [ { code: "function a(x) {}", options: [0], errors: [makeError("Function 'a'", 1, 0)] }, { code: "var func = function () {}", options: [0], errors: [makeError("Function", 1, 0)] }, - { code: "var obj = { a(x) {} }", options: [0], parserOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 1, 0)] }, - { code: "class Test { a(x) {} }", options: [0], parserOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 1, 0)] }, - { code: "var a = (x) => {if (true) {return x;}}", options: [1], parserOptions: { ecmaVersion: 6 }, errors: 1 }, + { code: "var obj = { a(x) {} }", options: [0], errors: [makeError("Method 'a'", 1, 0)], languageOptions: { ecmaVersion: 6 } }, + { code: "class Test { a(x) {} }", options: [0], errors: [makeError("Method 'a'", 1, 0)], languageOptions: { ecmaVersion: 6 } }, + { code: "var a = (x) => {if (true) {return x;}}", options: [1], errors: 1, languageOptions: { ecmaVersion: 6 } }, { code: "function a(x) {if (true) {return x;}}", options: [1], errors: 1 }, { code: "function a(x) {if (true) {return x;} else {return x+1;}}", options: [1], errors: 1 }, { code: "function a(x) {if (true) {return x;} else if (false) {return x+1;} else {return 4;}}", options: [2], errors: 1 }, { code: "function a(x) {for(var i = 0; i < 5; i ++) {x ++;} return x;}", options: [1], errors: 1 }, { code: "function a(obj) {for(var i in obj) {obj[i] = 3;}}", options: [1], errors: 1 }, - { code: "function a(obj) {for(var i of obj) {obj[i] = 3;}}", options: [1], parserOptions: { ecmaVersion: 6 }, errors: 1 }, + { code: "function a(obj) {for(var i of obj) {obj[i] = 3;}}", options: [1], errors: 1, languageOptions: { ecmaVersion: 6 } }, { code: "function a(x) {for(var i = 0; i < 5; i ++) {if(i % 2 === 0) {x ++;}} return x;}", options: [2], errors: 1 }, { code: "function a(obj) {if(obj){ for(var x in obj) {try {x.getThis();} catch (e) {x.getThat();}}} else {return false;}}", options: [3], errors: 1 }, { code: "function a(x) {try {x.getThis();} catch (e) {x.getThat();}}", options: [1], errors: 1 }, @@ -155,7 +155,7 @@ ruleTester.run("complexity", rule, { { code: "function a(x) {do {'foo';} while (true)}", options: [1], errors: 1 }, { code: "function a(x) {(function() {while(true){'foo';}})(); (function() {while(true){'bar';}})();}", options: [1], errors: 2 }, { code: "function a(x) {(function() {while(true){'foo';}})(); (function() {'bar';})();}", options: [1], errors: 1 }, - { code: "var obj = { a(x) { return x ? 0 : 1; } };", options: [1], parserOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 2, 1)] }, + { code: "var obj = { a(x) { return x ? 0 : 1; } };", options: [1], errors: [makeError("Method 'a'", 2, 1)], languageOptions: { ecmaVersion: 6 } }, { code: "var obj = { a: function b(x) { return x ? 0 : 1; } };", options: [1], errors: [makeError("Method 'a'", 2, 1)] }, { code: createComplexity(21), @@ -171,121 +171,120 @@ ruleTester.run("complexity", rule, { { code: "function foo () { a || b; class C { x; } c || d; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { a || b; class C { x = c; } d || e; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { a || b; class C { [x || y]; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { a || b; class C { [x || y] = c; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { class C { [x || y]; } a || b; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { class C { [x || y] = a; } b || c; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { class C { [x || y]; [z || q]; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { class C { [x || y] = a; [z || q] = b; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { a || b; class C { x = c || d; } e || f; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x(){ a || b; } y = c || d || e; z() { f || g; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class field initializer", 3, 2)] + errors: [makeError("Class field initializer", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = a || b; y() { c || d || e; } z = f || g; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Method 'y'", 3, 2)] + errors: [makeError("Method 'y'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x; y() { c || d || e; } z; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Method 'y'", 3, 2)] + errors: [makeError("Method 'y'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = a || b; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class field initializer", 2, 1)] + errors: [makeError("Class field initializer", 2, 1)], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class { x = a || b; })", options: [1], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class field initializer", 2, 1)] + errors: [makeError("Class field initializer", 2, 1)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static x = a || b; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class field initializer", 2, 1)] + errors: [makeError("Class field initializer", 2, 1)], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class { x = a ? b : c; })", options: [1], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class field initializer", 2, 1)] + errors: [makeError("Class field initializer", 2, 1)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = a || b || c; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class field initializer", 3, 2)] + errors: [makeError("Class field initializer", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = a || b; y = b || c || d; z = e || f; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class field initializer", 3, 2), line: 1, column: 27, endLine: 1, endColumn: 38 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = a || b || c; y = d || e; z = f || g || h; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 3, 2), @@ -301,30 +300,30 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 55 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = () => a || b || c; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Method 'x'", 3, 2)] + errors: [makeError("Method 'x'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = (() => a || b || c) || d; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Arrow function", 3, 2)] + errors: [makeError("Arrow function", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = () => a || b || c; y = d || e; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Method 'x'", 3, 2)] + errors: [makeError("Method 'x'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = () => a || b || c; y = d || e || f; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [ makeError("Method 'x'", 3, 2), { @@ -334,21 +333,21 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 49 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = function () { a || b }; y = function () { c || d }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, errors: [ makeError("Method 'x'", 2, 1), makeError("Method 'y'", 2, 1) - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = class { [y || z]; }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -357,12 +356,12 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 34 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = class { [y || z] = a; }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -371,12 +370,12 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 38 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = class { y = a || b; }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -385,128 +384,128 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 33 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // class static blocks { code: "function foo () { a || b; class C { static {} } c || d; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo () { a || b; class C { static { c || d; } } e || f; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Function 'foo'", 3, 2)] + errors: [makeError("Function 'foo'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b; } }", options: [1], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 2, 1)] + errors: [makeError("Class static block", 2, 1)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b || c; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 3, 2)] + errors: [makeError("Class static block", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b; c || d; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 3, 2)] + errors: [makeError("Class static block", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b; c || d; e || f; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 4, 3)] + errors: [makeError("Class static block", 4, 3)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b; c || d; { e || f; } } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 4, 3)] + errors: [makeError("Class static block", 4, 3)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (a || b) c = d || e; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 4, 3)] + errors: [makeError("Class static block", 4, 3)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (a || b) c = (d => e || f)() || (g => h || i)(); } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 4, 3)] + errors: [makeError("Class static block", 4, 3)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x(){ a || b; } static { c || d || e; } z() { f || g; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 3, 2)] + errors: [makeError("Class static block", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = a || b; static { c || d || e; } y = f || g; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 3, 2)] + errors: [makeError("Class static block", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static x = a || b; static { c || d || e; } static y = f || g; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Class static block", 3, 2)] + errors: [makeError("Class static block", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b; } static(){ c || d || e; } static { f || g; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Method 'static'", 3, 2)] + errors: [makeError("Method 'static'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b; } static static(){ c || d || e; } static { f || g; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [makeError("Static method 'static'", 3, 2)] + errors: [makeError("Static method 'static'", 3, 2)], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b; } static x = c || d || e; static { f || g; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class field initializer", 3, 2), column: 41, endColumn: 52 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b || c || d; } static { e || f || g; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class static block", 4, 3), column: 11, endColumn: 39 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b || c; } static { d || e || f || g; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class static block", 4, 3), column: 35, endColumn: 63 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a || b || c || d; } static { e || f || g || h; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class static block", 4, 3), @@ -518,7 +517,8 @@ ruleTester.run("complexity", rule, { column: 40, endColumn: 68 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // object property options diff --git a/tests/lib/rules/computed-property-spacing.js b/tests/lib/rules/computed-property-spacing.js index 35533d9e686..89d26b222e3 100644 --- a/tests/lib/rules/computed-property-spacing.js +++ b/tests/lib/rules/computed-property-spacing.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/computed-property-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -24,7 +24,7 @@ ruleTester.run("computed-property-spacing", rule, { // default - never "obj[foo]", "obj['foo']", - { code: "var x = {[b]: a}", parserOptions: { ecmaVersion: 6 } }, + { code: "var x = {[b]: a}", languageOptions: { ecmaVersion: 6 } }, // always { code: "obj[ foo ]", options: ["always"] }, @@ -40,10 +40,10 @@ ruleTester.run("computed-property-spacing", rule, { { code: "var foo = obj[ [1, 1] ];", options: ["always"] }, // always - objectLiteralComputedProperties - { code: "var x = {[ \"a\" ]: a}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = {[ x ]: a}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var x = {[ \"a\" ]() {}}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = {[ x ]() {}}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "var x = {[ \"a\" ]: a}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = {[ x ]: a}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = {[ \"a\" ]() {}}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = {[ x ]() {}}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, // always - unrelated cases { code: "var foo = {};", options: ["always"] }, @@ -65,10 +65,10 @@ ruleTester.run("computed-property-spacing", rule, { { code: "var foo = obj[[ 1, 1 ]];", options: ["never"] }, // never - objectLiteralComputedProperties - { code: "var x = {[\"a\"]: a}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = {[x]: a}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var x = {[\"a\"]() {}}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = {[x]() {}}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "var x = {[\"a\"]: a}", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = {[x]: a}", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = {[\"a\"]() {}}", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = {[x]() {}}", options: ["never"], languageOptions: { ecmaVersion: 6 } }, // never - unrelated cases { code: "var foo = {};", options: ["never"] }, @@ -82,106 +82,106 @@ ruleTester.run("computed-property-spacing", rule, { { code: "class A { [ a ](){} }", options: ["never", { enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["never", { enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [a](){} }", options: ["always", { enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [a](){} get [b](){} set [b](foo){} static [c](){} static get [d](){} static set [d](bar){} }", options: ["always", { enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [ a ]; }", options: ["never", { enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { [a]; }", options: ["always", { enforceForClassMembers: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // valid spacing { code: "A = class { [a](){} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [a] ( ) { } }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [ \n a \n ](){} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [a](){} get [b](){} set [b](foo){} static [c](){} static get [d](){} static set [d](bar){} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [ a ](){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [ a ](){}[ b ](){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [\na\n](){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [a]; static [a]; [a] = 0; static [a] = 0; }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "A = class { [ a ]; static [ a ]; [ a ] = 0; static [ a ] = 0; }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // non-computed { code: "class A { a ( ) { } get b(){} set b ( foo ){} static c (){} static get d() {} static set d( bar ) {} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class {a(){}get b(){}set b(foo){}static c(){}static get d(){}static set d(bar){}}", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { foo; #a; static #b; #c = 0; static #d = 0; }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "A = class { foo; #a; static #b; #c = 0; static #d = 0; }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // handling of parens and comments @@ -192,7 +192,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -201,7 +201,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -210,7 +210,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -219,7 +219,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -228,7 +228,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -237,7 +237,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -246,7 +246,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -255,7 +255,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -264,29 +264,29 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // Destructuring Assignment { code: "const { [a]: someProp } = obj;", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ [a]: someProp } = obj);", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const { [ a ]: someProp } = obj;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ [ a ]: someProp } = obj);", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -554,7 +554,6 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[a]: b}", output: "var x = {[ a ]: b}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -574,13 +573,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 13 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = {[a ]: b}", output: "var x = {[ a ]: b}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -591,13 +590,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = {[ a]: b}", output: "var x = {[ a ]: b}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceBefore", @@ -608,7 +607,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // never - objectLiteralComputedProperties @@ -616,7 +616,6 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[ a ]: b}", output: "var x = {[a]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -636,13 +635,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = {[a ]: b}", output: "var x = {[a]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -653,13 +652,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 13 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = {[ a]: b}", output: "var x = {[a]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -670,13 +669,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = {[ a\n]: b}", output: "var x = {[a\n]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -687,14 +686,14 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // test default settings for classes { code: "class A { [ a ](){} }", output: "class A { [a](){} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -714,13 +713,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", output: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -830,13 +829,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 105 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", options: ["never", {}], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -946,13 +945,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 107 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [a](){} }", output: "A = class { [ a ](){} }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -972,13 +971,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1088,13 +1087,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 96 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", output: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["always", {}], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1204,7 +1203,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 94 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // never - classes @@ -1212,7 +1212,6 @@ ruleTester.run("computed-property-spacing", rule, { code: "class A { [ a](){} }", output: "class A { [a](){} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1223,13 +1222,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 13 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [a](){} b(){} static [c ](){} static [d](){}}", output: "A = class { [a](){} b(){} static [c](){} static [d](){}}", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1240,13 +1239,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 37 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }", output: "class A { get [a](){} set [a](foo){} get b(){} static set b(bar){} static get [a](){} static set [a](baz){} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1284,13 +1283,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 104 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1400,13 +1399,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 107 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [ a]; [b ]; [ c ]; [ a] = 0; [b ] = 0; [ c ] = 0; }", output: "class A { [a]; [b]; [c]; [a] = 0; [b] = 0; [c] = 0; }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1456,7 +1455,8 @@ ruleTester.run("computed-property-spacing", rule, { column: 53, endColumn: 54 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // always - classes @@ -1464,7 +1464,6 @@ ruleTester.run("computed-property-spacing", rule, { code: "class A { [ a](){} }", output: "class A { [ a ](){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceBefore", @@ -1475,13 +1474,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [ a ](){} b(){} static [c ](){} static [ d ](){}}", output: "A = class { [ a ](){} b(){} static [ c ](){} static [ d ](){}}", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1492,13 +1491,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 37 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }", output: "class A { get [ a ](){} set [ a ](foo){} get b(){} static set b(bar){} static get [ a ](){} static set [ a ](baz){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1536,13 +1535,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 102 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1652,13 +1651,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 96 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { [ a]; [b ]; [c]; [ a] = 0; [b ] = 0; [c] = 0; }", output: "class A { [ a ]; [ b ]; [ c ]; [ a ] = 0; [ b ] = 0; [ c ] = 0; }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceBefore", @@ -1700,7 +1699,8 @@ ruleTester.run("computed-property-spacing", rule, { column: 50, endColumn: 51 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // handling of parens and comments @@ -1716,7 +1716,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1736,7 +1735,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1750,7 +1750,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1770,7 +1769,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1784,7 +1784,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1804,7 +1803,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1818,7 +1818,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1838,7 +1837,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1852,7 +1852,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1872,7 +1871,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1886,7 +1886,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1924,7 +1923,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 9 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1938,7 +1938,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1976,7 +1975,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1990,7 +1990,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -2019,7 +2018,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 19 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -2033,7 +2033,6 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -2062,7 +2061,8 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 19 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Optional chaining @@ -2070,21 +2070,21 @@ ruleTester.run("computed-property-spacing", rule, { code: "obj?.[1];", output: "obj?.[ 1 ];", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.[ 1 ];", output: "obj?.[1];", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, // Destructuring Assignment @@ -2092,59 +2092,59 @@ ruleTester.run("computed-property-spacing", rule, { code: "const { [ a]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { [a ]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { [ a ]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "({ [ a ]: someProp } = obj);", output: "({ [a]: someProp } = obj);", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { [a]: someProp } = obj;", output: "const { [ a ]: someProp } = obj;", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "({ [a]: someProp } = obj);", output: "({ [ a ]: someProp } = obj);", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/consistent-return.js b/tests/lib/rules/consistent-return.js index 16a1ed97a19..6903b630d86 100644 --- a/tests/lib/rules/consistent-return.js +++ b/tests/lib/rules/consistent-return.js @@ -9,13 +9,18 @@ // Requirements //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/consistent-return"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("consistent-return", rule, { @@ -37,12 +42,12 @@ ruleTester.run("consistent-return", rule, { { code: "function foo() { if (true) return undefined; else return void 0; }", options: [{ treatUndefinedAsUnspecified: true }] }, { code: "function foo() { if (true) return void 0; else return; }", options: [{ treatUndefinedAsUnspecified: true }] }, { code: "function foo() { if (true) return void 0; else return undefined; }", options: [{ treatUndefinedAsUnspecified: true }] }, - { code: "var x = () => { return {}; };", parserOptions: { ecmaVersion: 6 } }, - { code: "if (true) { return 1; } return 0;", parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } } }, + { code: "var x = () => { return {}; };", languageOptions: { ecmaVersion: 6 } }, + { code: "if (true) { return 1; } return 0;", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // https://github.com/eslint/eslint/issues/7790 - { code: "class Foo { constructor() { if (true) return foo; } }", parserOptions: { ecmaVersion: 6 } }, - { code: "var Foo = class { constructor() { if (true) return foo; } }", parserOptions: { ecmaVersion: 6 } } + { code: "class Foo { constructor() { if (true) return foo; } }", languageOptions: { ecmaVersion: 6 } }, + { code: "var Foo = class { constructor() { if (true) return foo; } }", languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -62,7 +67,6 @@ ruleTester.run("consistent-return", rule, { }, { code: "var foo = () => { if (true) return true; else return; }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturnValue", @@ -73,7 +77,8 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 54 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (true) return; else return false; }", @@ -119,7 +124,6 @@ ruleTester.run("consistent-return", rule, { }, { code: "f(a => { if (true) return; else return false; })", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedReturnValue", @@ -130,7 +134,8 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 46 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (true) return true; return undefined; }", @@ -194,7 +199,6 @@ ruleTester.run("consistent-return", rule, { }, { code: "if (true) { return 1; } return;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "missingReturnValue", @@ -205,7 +209,8 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 32 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "function foo() { if (a) return true; }", @@ -265,7 +270,6 @@ ruleTester.run("consistent-return", rule, { }, { code: "f(() => { if (a) return true; });", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -276,11 +280,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {foo() { if (a) return true; }};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -291,11 +295,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A {foo() { if (a) return true; }};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -306,11 +310,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 13 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (a) return true;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "missingReturn", @@ -321,11 +325,11 @@ ruleTester.run("consistent-return", rule, { endLine: void 0, endColumn: void 0 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "class A { CapitalizedFunction() { if (a) return true; } }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -336,11 +340,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 30 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ constructor() { if (a) return true; } });", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -351,7 +355,8 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/consistent-this.js b/tests/lib/rules/consistent-this.js index 1ddb0aa1ec6..c78b70be09e 100644 --- a/tests/lib/rules/consistent-this.js +++ b/tests/lib/rules/consistent-this.js @@ -9,7 +9,7 @@ // Requirements //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/consistent-this"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -25,8 +25,7 @@ function destructuringTest(code) { return { code, options: ["self"], - env: { es6: true }, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }; } @@ -34,7 +33,12 @@ function destructuringTest(code) { // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("consistent-this", rule, { valid: [ diff --git a/tests/lib/rules/constructor-super.js b/tests/lib/rules/constructor-super.js index 85e4471acc8..1e0db711020 100644 --- a/tests/lib/rules/constructor-super.js +++ b/tests/lib/rules/constructor-super.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/constructor-super"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2021 } }); ruleTester.run("constructor-super", rule, { valid: [ diff --git a/tests/lib/rules/curly.js b/tests/lib/rules/curly.js index e5fe88273ec..6c0867d3e88 100644 --- a/tests/lib/rules/curly.js +++ b/tests/lib/rules/curly.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/curly"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("curly", rule, { valid: [ @@ -28,7 +33,7 @@ ruleTester.run("curly", rule, { "for (var foo in bar) { console.log(foo) }", { code: "for (var foo of bar) { console.log(foo) }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "for (;foo;) bar()", @@ -53,12 +58,12 @@ ruleTester.run("curly", rule, { { code: "for (var foo of bar) console.log(foo)", options: ["multi"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "for (var foo of bar) { console.log(1); console.log(2) }", options: ["multi"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) bar()", @@ -99,12 +104,12 @@ ruleTester.run("curly", rule, { { code: "for (var foo of bar) console.log(foo)", options: ["multi-line"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "for (var foo of bar) { \n console.log(1); \n console.log(2); \n }", options: ["multi-line"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { \n bar(); \n baz(); \n }", @@ -157,22 +162,22 @@ ruleTester.run("curly", rule, { { code: "for (var foo of bar) \n console.log(foo)", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "for (var foo of bar) { \n if (foo) console.log(1); \n else console.log(2) \n }", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { const bar = 'baz'; }", options: ["multi"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "while (foo) { let bar = 'baz'; }", options: ["multi"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "for(;;) { function foo() {} }", @@ -181,37 +186,37 @@ ruleTester.run("curly", rule, { { code: "for (foo in bar) { class Baz {} }", options: ["multi"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { let bar; } else { baz(); }", options: ["multi", "consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { bar(); } else { const baz = 'quux'; }", options: ["multi", "consistent"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { \n const bar = 'baz'; \n }", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { \n let bar = 'baz'; \n }", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { \n function bar() {} \n }", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { \n class bar {} \n }", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/12370 @@ -242,7 +247,7 @@ ruleTester.run("curly", rule, { { code: "for (var foo of bar) console.log(foo) \n ;", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "while (foo) doSomething() \n ;", @@ -279,7 +284,7 @@ ruleTester.run("curly", rule, { { code: "for (var foo of bar)\n;", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "while (foo)\n;", @@ -394,7 +399,7 @@ ruleTester.run("curly", rule, { { code: "if (a) { for (elem of arr) if (b) foo(); } else bar();", options: ["multi"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (a) { with (obj) if (b) foo(); } else bar();", @@ -559,7 +564,6 @@ ruleTester.run("curly", rule, { { code: "for (var foo of bar) console.log(foo)", output: "for (var foo of bar) {console.log(foo)}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -570,12 +574,12 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 38 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var foo of bar) \n console.log(foo)", output: "for (var foo of bar) \n {console.log(foo)}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -586,12 +590,12 @@ ruleTester.run("curly", rule, { endLine: 2, endColumn: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for (a;;) console.log(foo)", output: "for (a;;) {console.log(foo)}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", @@ -602,12 +606,12 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for (a;;) \n console.log(foo)", output: "for (a;;) \n {console.log(foo)}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", @@ -618,13 +622,13 @@ ruleTester.run("curly", rule, { endLine: 2, endColumn: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var foo of bar) {console.log(foo)}", output: "for (var foo of bar) console.log(foo)", options: ["multi"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -635,13 +639,13 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 40 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "do{foo();} while(bar);", output: "do foo(); while(bar);", options: ["multi"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -652,7 +656,8 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for (;foo;) { bar() }", @@ -849,14 +854,14 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) { console.log(foo) }", output: "for (var foo of bar) console.log(foo) ", options: ["multi"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) \n baz()", @@ -1013,7 +1018,6 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) \n console.log(foo)", output: "for (var foo of bar) \n {console.log(foo)}", options: ["multi-line"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -1024,20 +1028,21 @@ ruleTester.run("curly", rule, { endLine: 2, endColumn: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var foo of bar) \n console.log(1); \n console.log(2)", output: "for (var foo of bar) \n {console.log(1);} \n console.log(2)", options: ["multi-line"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) \n quz = { \n bar: baz, \n qux: foo \n };", @@ -1091,27 +1096,27 @@ ruleTester.run("curly", rule, { code: "if (foo) { let bar; } else baz();", output: "if (foo) { let bar; } else {baz();}", options: ["multi", "consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", data: { name: "else" }, type: "IfStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) bar(); else { const baz = 'quux' }", output: "if (foo) {bar();} else { const baz = 'quux' }", options: ["multi", "consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { \n var bar = 'baz'; \n }", @@ -1219,27 +1224,27 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) \n if (foo) console.log(1); \n else console.log(2);", output: "for (var foo of bar) \n {if (foo) console.log(1); \n else console.log(2);}", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var foo of bar) { if (foo) console.log(1) }", output: "for (var foo of bar) if (foo) console.log(1) ", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if (true) foo(); \n else { \n bar(); \n baz(); \n }", @@ -1458,8 +1463,8 @@ ruleTester.run("curly", rule, { code: "if (foo) { bar }\n/regex/.test('foo');", output: null, options: ["multi"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { bar }\nBaz();", @@ -1495,8 +1500,8 @@ ruleTester.run("curly", rule, { code: "if (foo) { var foo = () => {} } else {}", output: null, options: ["multi"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { var foo = function() {} } else {}", @@ -1508,8 +1513,8 @@ ruleTester.run("curly", rule, { code: "if (foo) { var foo = function*() {} } else {}", output: null, options: ["multi"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "if (true)\nfoo()\n;[1, 2, 3].bar()", @@ -1553,8 +1558,8 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) {\ndoSomething()\n;\n}", output: "for (var foo of bar) \ndoSomething()\n;\n", options: ["multi-or-nest"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "while (foo) {\ndoSomething()\n;\n}", @@ -1830,7 +1835,6 @@ ruleTester.run("curly", rule, { { code: "for(var i of \n z)\nfoo()\n", output: "for(var i of \n z)\n{foo()}\n", - parserOptions: { ecmaVersion: 6 }, errors: [{ data: { name: "for-of" }, type: "ForOfStatement", @@ -1839,7 +1843,8 @@ ruleTester.run("curly", rule, { column: 1, endLine: 3, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/default-case-last.js b/tests/lib/rules/default-case-last.js index 9f75329abd6..b0628c2e665 100644 --- a/tests/lib/rules/default-case-last.js +++ b/tests/lib/rules/default-case-last.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/default-case-last"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers diff --git a/tests/lib/rules/default-case.js b/tests/lib/rules/default-case.js index 8c5e3f97f12..d8b37506aad 100644 --- a/tests/lib/rules/default-case.js +++ b/tests/lib/rules/default-case.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/default-case"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/default-param-last.js b/tests/lib/rules/default-param-last.js index e628db39e8e..8ff141f1036 100644 --- a/tests/lib/rules/default-param-last.js +++ b/tests/lib/rules/default-param-last.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/default-param-last"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -18,7 +18,7 @@ const { RuleTester } = require("../../../lib/rule-tester"); const SHOULD_BE_LAST = "shouldBeLast"; const ruleTester = new RuleTester({ - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }); const cannedError = { diff --git a/tests/lib/rules/dot-location.js b/tests/lib/rules/dot-location.js index d1206575e4c..67d55ce4671 100644 --- a/tests/lib/rules/dot-location.js +++ b/tests/lib/rules/dot-location.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/dot-location"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("dot-location", rule, { valid: [ @@ -69,7 +74,7 @@ ruleTester.run("dot-location", rule, { { code: "`\n`.prop", options: ["object"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "obj[prop]", @@ -142,74 +147,74 @@ ruleTester.run("dot-location", rule, { { code: "obj?.prop", options: ["object"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.[key]", options: ["object"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.\nprop", options: ["object"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj\n?.[key]", options: ["object"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.\n[key]", options: ["object"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.[\nkey]", options: ["object"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.prop", options: ["property"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.[key]", options: ["property"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj\n?.prop", options: ["property"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj\n?.[key]", options: ["property"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.\n[key]", options: ["property"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.[\nkey]", options: ["property"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // Private properties { code: "class C { #a; foo() { this.\n#a; } }", options: ["object"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #a; foo() { this\n.#a; } }", options: ["property"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -265,29 +270,29 @@ ruleTester.run("dot-location", rule, { code: "5_000\n.toExponential()", output: "5_000 .\ntoExponential()", options: ["object"], - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], + languageOptions: { ecmaVersion: 2021 } }, { code: "5_000_00\n.toExponential()", output: "5_000_00 .\ntoExponential()", options: ["object"], - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], + languageOptions: { ecmaVersion: 2021 } }, { code: "5.000_000\n.toExponential()", output: "5.000_000.\ntoExponential()", options: ["object"], - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], + languageOptions: { ecmaVersion: 2021 } }, { code: "0b1010_1010\n.toExponential()", output: "0b1010_1010.\ntoExponential()", options: ["object"], - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], + languageOptions: { ecmaVersion: 2021 } }, { code: "foo /* a */ . /* b */ \n /* c */ bar", @@ -311,8 +316,8 @@ ruleTester.run("dot-location", rule, { code: "`\n`\n.prop", output: "`\n`.\nprop", options: ["object"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/11868 (also in valid) @@ -382,22 +387,22 @@ ruleTester.run("dot-location", rule, { code: "obj\n?.prop", output: "obj?.\nprop", options: ["object"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedDotAfterObject" }] + errors: [{ messageId: "expectedDotAfterObject" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "10\n?.prop", output: "10?.\nprop", options: ["object"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedDotAfterObject" }] + errors: [{ messageId: "expectedDotAfterObject" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.\nprop", output: "obj\n?.prop", options: ["property"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedDotBeforeProperty" }] + errors: [{ messageId: "expectedDotBeforeProperty" }], + languageOptions: { ecmaVersion: 2020 } }, // Private properties @@ -405,15 +410,15 @@ ruleTester.run("dot-location", rule, { code: "class C { #a; foo() { this\n.#a; } }", output: "class C { #a; foo() { this.\n#a; } }", options: ["object"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedDotAfterObject" }] + errors: [{ messageId: "expectedDotAfterObject" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #a; foo() { this.\n#a; } }", output: "class C { #a; foo() { this\n.#a; } }", options: ["property"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedDotBeforeProperty" }] + errors: [{ messageId: "expectedDotBeforeProperty" }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/dot-notation.js b/tests/lib/rules/dot-notation.js index c2ced102b9c..0ee0925b64c 100644 --- a/tests/lib/rules/dot-notation.js +++ b/tests/lib/rules/dot-notation.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/dot-notation"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); /** * Quote a string in "double quotes" because it’s painful @@ -54,20 +59,20 @@ ruleTester.run("dot-notation", rule, { { code: "a.null;", options: [{ allowKeywords: true }] }, { code: "a['snake_case'];", options: [{ allowPattern: "^[a-z]+(_[a-z]+)+$" }] }, { code: "a['lots_of_snake_case'];", options: [{ allowPattern: "^[a-z]+(_[a-z]+)+$" }] }, - { code: "a[`time${range}`];", parserOptions: { ecmaVersion: 6 } }, - { code: "a[`while`];", options: [{ allowKeywords: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "a[`time range`];", parserOptions: { ecmaVersion: 6 } }, + { code: "a[`time${range}`];", languageOptions: { ecmaVersion: 6 } }, + { code: "a[`while`];", options: [{ allowKeywords: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "a[`time range`];", languageOptions: { ecmaVersion: 6 } }, "a.true;", "a.null;", "a[undefined];", "a[void 0];", "a[b()];", - { code: "a[/(?0)/];", parserOptions: { ecmaVersion: 2018 } }, - { code: "class C { foo() { this['#a'] } }", parserOptions: { ecmaVersion: 2022 } }, + { code: "a[/(?0)/];", languageOptions: { ecmaVersion: 2018 } }, + { code: "class C { foo() { this['#a'] } }", languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #in; foo() { this.#in; } }", options: [{ allowKeywords: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -85,8 +90,8 @@ ruleTester.run("dot-notation", rule, { { code: "a[`time`];", output: "a.time;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "useDot", data: { key: "`time`" } }] + errors: [{ messageId: "useDot", data: { key: "`time`" } }], + languageOptions: { ecmaVersion: 6 } }, { code: "a[null];", @@ -267,54 +272,54 @@ ruleTester.run("dot-notation", rule, { { code: "5_000['prop']", output: "5_000 .prop", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "useDot", data: { key: q("prop") } }] + errors: [{ messageId: "useDot", data: { key: q("prop") } }], + languageOptions: { ecmaVersion: 2021 } }, { code: "5_000_00['prop']", output: "5_000_00 .prop", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "useDot", data: { key: q("prop") } }] + errors: [{ messageId: "useDot", data: { key: q("prop") } }], + languageOptions: { ecmaVersion: 2021 } }, { code: "5.000_000['prop']", output: "5.000_000.prop", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "useDot", data: { key: q("prop") } }] + errors: [{ messageId: "useDot", data: { key: q("prop") } }], + languageOptions: { ecmaVersion: 2021 } }, { code: "0b1010_1010['prop']", output: "0b1010_1010.prop", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "useDot", data: { key: q("prop") } }] + errors: [{ messageId: "useDot", data: { key: q("prop") } }], + languageOptions: { ecmaVersion: 2021 } }, // Optional chaining { code: "obj?.['prop']", output: "obj?.prop", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "useDot", data: { key: q("prop") } }] + errors: [{ messageId: "useDot", data: { key: q("prop") } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "0?.['prop']", output: "0?.prop", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "useDot", data: { key: q("prop") } }] + errors: [{ messageId: "useDot", data: { key: q("prop") } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.true", output: "obj?.[\"true\"]", options: [{ allowKeywords: false }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "useBrackets", data: { key: "true" } }] + errors: [{ messageId: "useBrackets", data: { key: "true" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "let?.true", output: "let?.[\"true\"]", options: [{ allowKeywords: false }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "useBrackets", data: { key: "true" } }] + errors: [{ messageId: "useBrackets", data: { key: "true" } }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/eol-last.js b/tests/lib/rules/eol-last.js index 7474b019e02..84999344236 100644 --- a/tests/lib/rules/eol-last.js +++ b/tests/lib/rules/eol-last.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/eol-last"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/eqeqeq.js b/tests/lib/rules/eqeqeq.js index 05e33bbcfa9..c2628bf4616 100644 --- a/tests/lib/rules/eqeqeq.js +++ b/tests/lib/rules/eqeqeq.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/eqeqeq"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -50,10 +50,10 @@ ruleTester.run("eqeqeq", rule, { { code: "null != null", options: ["always", { null: "never" }] }, // https://github.com/eslint/eslint/issues/8020 - { code: "foo === /abc/u", options: ["always", { null: "never" }], parserOptions: { ecmaVersion: 2015 } }, + { code: "foo === /abc/u", options: ["always", { null: "never" }], languageOptions: { ecmaVersion: 2015 } }, // bigint - { code: "foo === 1n", options: ["always", { null: "never" }], parserOptions: { ecmaVersion: 2020 } } + { code: "foo === 1n", options: ["always", { null: "never" }], languageOptions: { ecmaVersion: 2020 } } ], invalid: [ { code: "a == b", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, diff --git a/tests/lib/rules/for-direction.js b/tests/lib/rules/for-direction.js index 630f89df54d..e23142305ad 100644 --- a/tests/lib/rules/for-direction.js +++ b/tests/lib/rules/for-direction.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/for-direction"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2020 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2020 } }); const incorrectDirection = { messageId: "incorrectDirection" }; ruleTester.run("for-direction", rule, { diff --git a/tests/lib/rules/func-call-spacing.js b/tests/lib/rules/func-call-spacing.js index 3520882b019..8455ec380a4 100644 --- a/tests/lib/rules/func-call-spacing.js +++ b/tests/lib/rules/func-call-spacing.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/func-call-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -40,7 +40,7 @@ ruleTester.run("func-call-spacing", rule, { "new (foo())", { code: "import(source)", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // "never" @@ -111,7 +111,7 @@ ruleTester.run("func-call-spacing", rule, { { code: "import(source)", options: ["never"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // "always" @@ -166,7 +166,7 @@ ruleTester.run("func-call-spacing", rule, { { code: "import (source)", options: ["always"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // "always", "allowNewlines": true @@ -217,29 +217,29 @@ ruleTester.run("func-call-spacing", rule, { { code: "import\n(source)", options: ["always", { allowNewlines: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // Optional chaining { code: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "func ?.()", options: ["always"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "func?. ()", options: ["always"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "func ?. ()", options: ["always"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } } ], invalid: [ @@ -324,8 +324,8 @@ ruleTester.run("func-call-spacing", rule, { { code: "import (source);", output: "import(source);", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] + errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/7787 @@ -357,8 +357,8 @@ ruleTester.run("func-call-spacing", rule, { { code: "import\n(source);", output: null, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] + errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }], + languageOptions: { ecmaVersion: 2020 } }, // "never" @@ -453,8 +453,8 @@ ruleTester.run("func-call-spacing", rule, { code: "import (source);", output: "import(source);", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] + errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/7787 @@ -704,8 +704,8 @@ ruleTester.run("func-call-spacing", rule, { code: "import(source);", output: "import (source);", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "missing", type: "ImportExpression" }] + errors: [{ messageId: "missing", type: "ImportExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "f();\n t();", @@ -900,71 +900,71 @@ ruleTester.run("func-call-spacing", rule, { code: "func ?.()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace" }] + errors: [{ messageId: "unexpectedWhitespace" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func?. ()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace" }] + errors: [{ messageId: "unexpectedWhitespace" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func ?. ()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace" }] + errors: [{ messageId: "unexpectedWhitespace" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func\n?.()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace" }] + errors: [{ messageId: "unexpectedWhitespace" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func\n//comment\n?.()", output: null, // Don't remove comments options: ["never"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace" }] + errors: [{ messageId: "unexpectedWhitespace" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func?.()", output: null, // Not sure inserting a space into either before/after `?.`. options: ["always"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "missing" }] + errors: [{ messageId: "missing" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func\n ?.()", output: "func ?.()", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedNewline" }] + errors: [{ messageId: "unexpectedNewline" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func?.\n ()", output: "func?. ()", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedNewline" }] + errors: [{ messageId: "unexpectedNewline" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func ?.\n ()", output: "func ?. ()", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedNewline" }] + errors: [{ messageId: "unexpectedNewline" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "func\n /*comment*/ ?.()", output: null, // Don't remove comments options: ["always"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedNewline" }] + errors: [{ messageId: "unexpectedNewline" }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/func-name-matching.js b/tests/lib/rules/func-name-matching.js index c020066e752..d7ec8be3d58 100644 --- a/tests/lib/rules/func-name-matching.js +++ b/tests/lib/rules/func-name-matching.js @@ -10,8 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/func-name-matching"), - { RuleTester } = require("../../../lib/rule-tester"), - FlatRuleTester = require("../../../lib/rule-tester/flat-rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -26,13 +25,13 @@ ruleTester.run("func-name-matching", rule, { { code: "var foo = function foo() {};", options: ["always"] }, { code: "var foo = function bar() {};", options: ["never"] }, "var foo = function() {}", - { code: "var foo = () => {}", parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => {}", languageOptions: { ecmaVersion: 6 } }, "foo = function foo() {};", { code: "foo = function foo() {};", options: ["always"] }, { code: "foo = function bar() {};", options: ["never"] }, - { code: "foo &&= function foo() {};", parserOptions: { ecmaVersion: 2021 } }, - { code: "obj.foo ||= function foo() {};", parserOptions: { ecmaVersion: 2021 } }, - { code: "obj['foo'] ??= function foo() {};", parserOptions: { ecmaVersion: 2021 } }, + { code: "foo &&= function foo() {};", languageOptions: { ecmaVersion: 2021 } }, + { code: "obj.foo ||= function foo() {};", languageOptions: { ecmaVersion: 2021 } }, + { code: "obj['foo'] ??= function foo() {};", languageOptions: { ecmaVersion: 2021 } }, "obj.foo = function foo() {};", { code: "obj.foo = function foo() {};", options: ["always"] }, { code: "obj.foo = function bar() {};", options: ["never"] }, @@ -63,124 +62,124 @@ ruleTester.run("func-name-matching", rule, { "var obj = {foo: function() {}};", { code: "var obj = {foo: function() {}};", options: ["always"] }, { code: "var obj = {foo: function() {}};", options: ["never"] }, - { code: "var obj = {[foo]: function bar() {}} ", parserOptions: { ecmaVersion: 6 } }, - { code: "var obj = {['x' + 2]: function bar(){}};", parserOptions: { ecmaVersion: 6 } }, + { code: "var obj = {[foo]: function bar() {}} ", languageOptions: { ecmaVersion: 6 } }, + { code: "var obj = {['x' + 2]: function bar(){}};", languageOptions: { ecmaVersion: 6 } }, "obj['x' + 2] = function bar(){};", - { code: "var [ bar ] = [ function bar(){} ];", parserOptions: { ecmaVersion: 6 } }, - { code: "function a(foo = function bar() {}) {}", parserOptions: { ecmaVersion: 6 } }, + { code: "var [ bar ] = [ function bar(){} ];", languageOptions: { ecmaVersion: 6 } }, + { code: "function a(foo = function bar() {}) {}", languageOptions: { ecmaVersion: 6 } }, "module.exports = function foo(name) {};", "module['exports'] = function foo(name) {};", { code: "module.exports = function foo(name) {};", options: [{ includeCommonJSModuleExports: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "module.exports = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "module.exports = function foo(name) {};", options: ["never", { includeCommonJSModuleExports: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "module['exports'] = function foo(name) {};", options: [{ includeCommonJSModuleExports: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "module['exports'] = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "module['exports'] = function foo(name) {};", options: ["never", { includeCommonJSModuleExports: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({['foo']: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({['foo']: function foo() {}})", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({['foo']: function bar() {}})", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({['❤']: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[foo]: function bar() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[null]: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[1]: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[true]: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[`x`]: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[/abc/]: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[[1, 2, 3]]: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[{x: 1}]: function foo() {}})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "[] = function foo() {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({} = function foo() {})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "[a] = function foo() {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({a} = function foo() {})", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [] = function foo() {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var {} = function foo() {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [a] = function foo() {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var {a} = function foo() {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ value: function value() {} })", @@ -225,27 +224,27 @@ ruleTester.run("func-name-matching", rule, { { code: "Object.defineProperties(foo, { ['bar']: { value: function bar() {} } })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "Object.create(proto, { ['bar']: { value: function bar() {} } })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "Object.defineProperty(foo, 'bar', { value() {} })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "Object.defineProperties(foo, { bar: { value() {} } })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "Object.create(proto, { bar: { value() {} } })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "Reflect.defineProperty(foo, 'bar', { value: function bar() {} })", @@ -258,7 +257,7 @@ ruleTester.run("func-name-matching", rule, { { code: "Reflect.defineProperty(foo, 'bar', { value() {} })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "foo({ value: function value() {} })", @@ -269,378 +268,385 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { x = function () {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = function () {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'x' = function () {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'x' = function () {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x = function () {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x = function () {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [x] = function () {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [x] = function () {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['x'] = function () {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['x'] = function () {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = function x() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = function y() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'x' = function x() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'x' = function y() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x = function x() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x = function y() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [x] = function x() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [x] = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [x] = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [x] = function y() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['x'] = function x() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['x'] = function y() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'xy ' = function foo() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'xy ' = function xy() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['xy '] = function foo() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['xy '] = function xy() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 1 = function x0() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 1 = function x1() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [1] = function x0() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [1] = function x1() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [f()] = function g() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [f()] = function f() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static x = function x() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static x = function y() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = (function y() {})(); }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = (function x() {})(); }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "(class { x = function x() {}; })", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "(class { x = function y() {}; })", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { this.#x = function x() {}; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { this.#x = function x() {}; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { this.#x = function y() {}; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { this.#x = function y() {}; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { a.b.#x = function x() {}; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { a.b.#x = function x() {}; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { a.b.#x = function y() {}; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #x; foo() { a.b.#x = function y() {}; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, - "var obj = { '\\u1885': function foo() {} };" // not a valid identifier in es5 + { + code: "var obj = { '\\u1885': function foo() {} };", // not a valid identifier in es5 + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } + } + ], invalid: [ { code: "let foo = function bar() {};", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo &&= function bar() {};", - parserOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 2021 } }, { code: "obj.foo ||= function bar() {};", - parserOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 2021 } }, { code: "obj['foo'] ??= function bar() {};", - parserOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 2021 } }, { code: "obj.foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "obj.bar.foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "obj['foo'] = function bar() {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let obj = {foo: function bar() {}};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let obj = {'foo': function bar() {}};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({['foo']: function bar() {}})", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "module.exports = function foo(name) {};", options: [{ includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "module.exports = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "module.exports = function exports(name) {};", options: ["never", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "exports", name: "exports" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "module['exports'] = function foo(name) {};", options: [{ includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "module['exports'] = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "module['exports'] = function exports(name) {};", options: ["never", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "exports", name: "exports" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function foo(name) {};", @@ -730,189 +736,163 @@ ruleTester.run("func-name-matching", rule, { // Optional chaining { code: "(obj?.aaa).foo = function bar() {};", - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.defineProperty(foo, 'bar', { value: function baz() {} })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperty)(foo, 'bar', { value: function baz() {} })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.defineProperty(foo, 'bar', { value: function bar() {} })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperty)(foo, 'bar', { value: function bar() {} })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.defineProperties(foo, { bar: { value: function baz() {} } })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperties)(foo, { bar: { value: function baz() {} } })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.defineProperties(foo, { bar: { value: function bar() {} } })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperties)(foo, { bar: { value: function bar() {} } })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, // class fields { code: "class C { x = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { x = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'x' = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'x' = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['x'] = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { ['x'] = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static x = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static x = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class { x = function y() {}; })", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class { x = function x() {}; })", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "var obj = { '\\u1885': function foo() {} };", // valid identifier in es2015 - parserOptions: { ecmaVersion: 6 }, - errors: [ - { messageId: "matchProperty", data: { funcName: "foo", name: "\u1885" } } - ] - } - ] -}); - -const flatRuleTester = new FlatRuleTester(); - -flatRuleTester.run("func-name-matching", rule, { - valid: [ - { - code: "var obj = { '\\u1885': function foo() {} };", // not a valid identifier in es5 - languageOptions: { - ecmaVersion: 5, - sourceType: "script" - } - } - ], - - invalid: [ - { - code: "var obj = { '\\u1885': function foo() {} };", // valid identifier in es2015 - languageOptions: { - ecmaVersion: 2015 - }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "\u1885" } } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/func-names.js b/tests/lib/rules/func-names.js index 3341df7f016..e03f454de29 100644 --- a/tests/lib/rules/func-names.js +++ b/tests/lib/rules/func-names.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/func-names"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,18 +21,18 @@ const ruleTester = new RuleTester(); ruleTester.run("func-names", rule, { valid: [ "Foo.prototype.bar = function bar(){};", - { code: "Foo.prototype.bar = () => {}", parserOptions: { ecmaVersion: 6 } }, + { code: "Foo.prototype.bar = () => {}", languageOptions: { ecmaVersion: 6 } }, "function foo(){}", "function test(d, e, f) {}", "new function bar(){}", "exports = { get foo() { return 1; }, set bar(val) { return val; } };", { code: "({ foo() { return 1; } });", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { constructor(){} foo(){} get bar(){} set baz(value){} static qux(){}}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() {}", @@ -45,12 +45,12 @@ ruleTester.run("func-names", rule, { { code: "class A { constructor(){} foo(){} get bar(){} set baz(value){} static qux(){}}", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ foo() {} });", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function(){};", @@ -67,22 +67,22 @@ ruleTester.run("func-names", rule, { { code: "({foo = function(){}} = {});", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({key: foo = function(){}} = {});", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "[foo = function(){}] = [];", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function fn(foo = function(){}) {}", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() {}", @@ -111,174 +111,174 @@ ruleTester.run("func-names", rule, { { code: "class A { constructor(){} foo(){} get bar(){} set baz(value){} static qux(){}}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({ foo() {} });", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // export default { code: "export default function foo() {}", options: ["always"], - parserOptions: { sourceType: "module", ecmaVersion: 6 } + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "export default function foo() {}", options: ["as-needed"], - parserOptions: { sourceType: "module", ecmaVersion: 6 } + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "export default function foo() {}", options: ["never"], - parserOptions: { sourceType: "module", ecmaVersion: 6 } + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "export default function() {}", options: ["never"], - parserOptions: { sourceType: "module", ecmaVersion: 6 } + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, // generators { code: "var foo = bar(function *baz() {});", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["always", { generators: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["always", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["always", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["as-needed", { generators: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["as-needed", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["as-needed", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["never", { generators: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["never", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["never", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["never", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["never", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["never", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["always", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["always", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["always", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["as-needed", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["as-needed", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["as-needed", { generators: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // class fields { code: "class C { foo = function() {}; }", options: ["as-needed"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo] = function() {}; }", options: ["as-needed"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #foo = function() {}; }", options: ["as-needed"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -400,62 +400,62 @@ ruleTester.run("func-names", rule, { { code: "var {foo} = function(){};", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 13, endColumn: 21 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "({ a: obj.prop = function(){} } = foo);", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 18, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "[obj.prop = function(){}] = foo;", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 13, endColumn: 21 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a: [b] = function(){} } = foo;", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 16, endColumn: 24 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ a } = function(){}) {};", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 22, endColumn: 30 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = function foo() {};", @@ -498,283 +498,282 @@ ruleTester.run("func-names", rule, { { code: "export default function() {}", options: ["always"], - parserOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionDeclaration", column: 16, endColumn: 24 - }] + }], + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "export default function() {}", options: ["as-needed"], - parserOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionDeclaration", column: 16, endColumn: 24 - }] + }], + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "export default (function(){});", options: ["as-needed"], - parserOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", column: 17, endColumn: 25 - }] + }], + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, // generators { code: "var foo = bar(function *() {});", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["always", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["always", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["always", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["always", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["always", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["as-needed", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["as-needed", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["as-needed", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["as-needed", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["as-needed", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["never", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["never", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["never", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *() {});", options: ["never", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function*() {}())", options: ["never", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -782,12 +781,12 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["never", { generators: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -795,12 +794,12 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["always", { generators: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -808,12 +807,12 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar(function *baz() {});", options: ["as-needed", { generators: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -821,64 +820,65 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, // class fields { code: "class C { foo = function() {} }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "method 'foo'" }, column: 11, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo] = function() {} }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "method" }, column: 11, endColumn: 27 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #foo = function() {} }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "private method #foo" }, column: 11, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = bar(function() {}) }", options: ["as-needed"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "function" }, column: 21, endColumn: 29 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = function bar() {} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "named", data: { name: "method 'foo'" }, column: 11, endColumn: 29 - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/func-style.js b/tests/lib/rules/func-style.js index 0017c8627be..1e5823f5c63 100644 --- a/tests/lib/rules/func-style.js +++ b/tests/lib/rules/func-style.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/func-style"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -55,7 +55,7 @@ ruleTester.run("func-style", rule, { { code: "var foo = () => {};\n var bar = () => {}", options: ["expression"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/3819 @@ -66,21 +66,21 @@ ruleTester.run("func-style", rule, { { code: "var foo = () => { this; };", options: ["declaration"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "export default function () {};", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = () => {};", options: ["declaration", { allowArrowFunctions: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = () => { function foo() { this; } };", options: ["declaration", { allowArrowFunctions: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -98,24 +98,24 @@ ruleTester.run("func-style", rule, { { code: "var foo = () => {};", options: ["declaration"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "declaration", type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = () => { function foo() { this; } };", options: ["declaration"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "declaration", type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(){}", diff --git a/tests/lib/rules/function-call-argument-newline.js b/tests/lib/rules/function-call-argument-newline.js index 85c908a135d..f67d97a1e23 100644 --- a/tests/lib/rules/function-call-argument-newline.js +++ b/tests/lib/rules/function-call-argument-newline.js @@ -5,7 +5,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/function-call-argument-newline"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -44,10 +44,10 @@ ruleTester.run("function-call-argument-newline", rule, { { code: "fn(\n\ta,\n\tb,\n\tx => {\n\t\tx()\n\t}\n)", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "fn({\n\ta: 1\n},\n\tb,\n\tc)", options: ["always"] }, - { code: "fn(`\n`,\n\ta)", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "fn(`\n`,\n\ta)", options: ["always"], languageOptions: { ecmaVersion: 6 } }, /* "never" */ { code: "fn(a, b)", options: ["never"] }, @@ -59,18 +59,18 @@ ruleTester.run("function-call-argument-newline", rule, { { code: "fn(a, b, x => {\n\tx()\n})", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "fn({\n\ta: 1\n}, b)", options: ["never"] }, - { code: "fn(`\n`, a)", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "fn(`\n`, a)", options: ["never"], languageOptions: { ecmaVersion: 6 } }, /* "consistent" */ { code: "fn(a, b, c)", options: ["consistent"] }, { code: "fn(a,\n\tb,\n\tc)", options: ["consistent"] }, { code: "fn({\n\ta: 1\n}, b, c)", options: ["consistent"] }, { code: "fn({\n\ta: 1\n},\n\tb,\n\tc)", options: ["consistent"] }, - { code: "fn(`\n`, b, c)", options: ["consistent"], parserOptions: { ecmaVersion: 6 } }, - { code: "fn(`\n`,\n\tb,\n\tc)", options: ["consistent"], parserOptions: { ecmaVersion: 6 } } + { code: "fn(`\n`, b, c)", options: ["consistent"], languageOptions: { ecmaVersion: 6 } }, + { code: "fn(`\n`,\n\tb,\n\tc)", options: ["consistent"], languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -192,7 +192,6 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(a, b, x => {\n\tx()\n})", output: "fn(a,\nb,\nx => {\n\tx()\n})", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -208,7 +207,8 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 1, endColumn: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "fn({\n\ta: 1\n}, b)", @@ -228,7 +228,6 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`, b)", output: "fn(`\n`,\nb)", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -237,7 +236,8 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 2, endColumn: 4 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, /* "never" */ @@ -343,7 +343,6 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(a,\n\tb,\n\tx => {\n\t\tx()\n})", output: "fn(a, b, x => {\n\t\tx()\n})", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -359,7 +358,8 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 2 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "fn({\n\ta: 1\n},\nb)", @@ -379,7 +379,6 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`,\nb)", output: "fn(`\n`, b)", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -388,13 +387,13 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "fn(a,/* comment */\nb)", output: "fn(a,/* comment */ b)", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -403,7 +402,8 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 2, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, /* "consistent" */ @@ -495,7 +495,6 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`,\nb, c)", output: "fn(`\n`,\nb,\nc)", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -504,13 +503,13 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 4 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "fn(`\n`, b,\nc)", output: "fn(`\n`, b, c)", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -519,13 +518,13 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "fn(a,// comment\n{b, c})", output: null, options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -534,7 +533,8 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 2, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "fn(a, // comment\nb)", @@ -554,7 +554,6 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`, b, // comment\nc)", output: null, options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -563,7 +562,8 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/function-paren-newline.js b/tests/lib/rules/function-paren-newline.js index a8c7cc85827..16ea5f2e929 100644 --- a/tests/lib/rules/function-paren-newline.js +++ b/tests/lib/rules/function-paren-newline.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/function-paren-newline"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const { unIndent } = require("../../_utils"); const fixtureParser = require("../../fixtures/fixture-parser"); @@ -25,7 +25,7 @@ const RIGHT_MISSING_ERROR = { messageId: "expectedBefore", type: "Punctuator" }; const RIGHT_UNEXPECTED_ERROR = { messageId: "unexpectedBefore", type: "Punctuator" }; const EXPECTED_BETWEEN = { messageId: "expectedBetween", type: "Identifier" }; -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "script" } }); ruleTester.run("function-paren-newline", rule, { @@ -93,7 +93,7 @@ ruleTester.run("function-paren-newline", rule, { }, { code: "async (foo, bar) => {};", - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -102,19 +102,19 @@ ruleTester.run("function-paren-newline", rule, { bar ) => {}; `, - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "async foo => {};", - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source)", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "import(source\n + ext)", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // multiline-arguments @@ -273,12 +273,12 @@ ruleTester.run("function-paren-newline", rule, { { code: "async (foo, bar) => {};", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "async (foo) => {};", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -287,7 +287,7 @@ ruleTester.run("function-paren-newline", rule, { ) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -297,22 +297,22 @@ ruleTester.run("function-paren-newline", rule, { ) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "async foo => {};", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source)", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "import(source\n + ext)", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { @@ -391,7 +391,7 @@ ruleTester.run("function-paren-newline", rule, { ) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -401,17 +401,17 @@ ruleTester.run("function-paren-newline", rule, { ) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "async foo => {};", options: ["always"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "import(\n source\n)", options: ["always"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // never option @@ -442,17 +442,17 @@ ruleTester.run("function-paren-newline", rule, { { code: "async (foo, bar) => {};", options: ["never"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "async foo => {};", options: ["never"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source)", options: ["never"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // minItems option @@ -483,7 +483,7 @@ ruleTester.run("function-paren-newline", rule, { { code: "async (foo, bar) => {};", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -494,22 +494,22 @@ ruleTester.run("function-paren-newline", rule, { ) => {}; `, options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "async foo => {};", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source)", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "import(\n source\n)", options: [{ minItems: 1 }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // consistent option @@ -544,12 +544,12 @@ ruleTester.run("function-paren-newline", rule, { { code: "async (foo, bar) => {};", options: ["consistent"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "async foo => {};", options: ["consistent"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -557,7 +557,7 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["consistent"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -566,7 +566,7 @@ ruleTester.run("function-paren-newline", rule, { ) => {}; `, options: ["consistent"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -576,17 +576,17 @@ ruleTester.run("function-paren-newline", rule, { ) => {}; `, options: ["consistent"], - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source)", options: ["consistent"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "import(\n source\n)", options: ["consistent"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/15091#issuecomment-975605821 @@ -602,7 +602,9 @@ ruleTester.run("function-paren-newline", rule, { method6(3, () => {}); `, options: ["multiline"], - parser: fixtureParser("function-paren-newline", "arrow-function-return-type") + languageOptions: { + parser: require(fixtureParser("function-paren-newline", "arrow-function-return-type")) + } } ], @@ -736,8 +738,8 @@ ruleTester.run("function-paren-newline", rule, { output: ` async (foo, bar) => {}; `, - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -747,8 +749,8 @@ ruleTester.run("function-paren-newline", rule, { output: ` async (foo, bar) => {}; `, - parserOptions: { ecmaVersion: 2017 }, - errors: [RIGHT_UNEXPECTED_ERROR] + errors: [RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -759,8 +761,8 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar\n) => {}; `, - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -773,14 +775,14 @@ ruleTester.run("function-paren-newline", rule, { foo, bar\n) => {}; `, - parserOptions: { ecmaVersion: 2017 }, - errors: [RIGHT_MISSING_ERROR] + errors: [RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: "import(\n source\n)", output: "import(source)", - parserOptions: { ecmaVersion: 2020 }, - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2020 } }, // multiline-arguments @@ -978,8 +980,8 @@ ruleTester.run("function-paren-newline", rule, { async (foo, bar) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 }, - errors: [RIGHT_UNEXPECTED_ERROR] + errors: [RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -991,8 +993,8 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -1006,22 +1008,22 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 }, - errors: [RIGHT_MISSING_ERROR] + errors: [RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source\n)", output: "import(source)", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2020 }, - errors: [RIGHT_UNEXPECTED_ERROR] + errors: [RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2020 } }, { code: "import(\n source)", output: "import(\n source\n)", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2020 }, - errors: [RIGHT_MISSING_ERROR] + errors: [RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2020 } }, // always option @@ -1109,8 +1111,8 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar\n) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -1122,8 +1124,8 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -1137,15 +1139,15 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 }, - errors: [RIGHT_MISSING_ERROR] + errors: [RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source)", output: "import(\nsource\n)", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2020 } }, // never option @@ -1280,8 +1282,8 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["never"], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -1294,15 +1296,15 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["never"], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: "import(\n source\n)", output: "import(source)", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2020 } }, // minItems option @@ -1356,8 +1358,8 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -1370,8 +1372,8 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -1381,22 +1383,22 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar, baz\n) => {}; `, options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 }, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: "import(\n source\n)", output: "import(source)", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2020 }, - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2020 } }, { code: "import(source)", output: "import(\nsource\n)", options: [{ minItems: 1 }], - parserOptions: { ecmaVersion: 2020 }, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2020 } }, // consistent option @@ -1439,8 +1441,8 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["consistent"], - parserOptions: { ecmaVersion: 2017 }, - errors: [RIGHT_MISSING_ERROR] + errors: [RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: ` @@ -1453,22 +1455,22 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["consistent"], - parserOptions: { ecmaVersion: 2017 }, - errors: [RIGHT_UNEXPECTED_ERROR] + errors: [RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2017 } }, { code: "import(source\n)", output: "import(source)", options: ["consistent"], - parserOptions: { ecmaVersion: 2020 }, - errors: [RIGHT_UNEXPECTED_ERROR] + errors: [RIGHT_UNEXPECTED_ERROR], + languageOptions: { ecmaVersion: 2020 } }, { code: "import(\n source)", output: "import(\n source\n)", options: ["consistent"], - parserOptions: { ecmaVersion: 2020 }, - errors: [RIGHT_MISSING_ERROR] + errors: [RIGHT_MISSING_ERROR], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/15091#issuecomment-975605821 @@ -1492,8 +1494,10 @@ ruleTester.run("function-paren-newline", rule, { method6(3, () => {}); `, options: ["never"], - parser: fixtureParser("function-paren-newline", "arrow-function-return-type"), - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], + languageOptions: { + parser: require(fixtureParser("function-paren-newline", "arrow-function-return-type")) + } } ] }); diff --git a/tests/lib/rules/generator-star-spacing.js b/tests/lib/rules/generator-star-spacing.js index 7dcfbfbe04f..f89ff6eb636 100644 --- a/tests/lib/rules/generator-star-spacing.js +++ b/tests/lib/rules/generator-star-spacing.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/generator-star-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2018 } }); const missingBeforeError = { messageId: "missingBefore", type: "Punctuator" }; const missingAfterError = { messageId: "missingAfter", type: "Punctuator" }; @@ -462,27 +462,27 @@ ruleTester.run("generator-star-spacing", rule, { // https://github.com/eslint/eslint/issues/7101#issuecomment-246080531 { code: "async function foo() { }", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "(async function() { })", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async () => { }", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "({async foo() { }})", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "class A {async foo() { }}", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "(class {async foo() { }})", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } } ], diff --git a/tests/lib/rules/getter-return.js b/tests/lib/rules/getter-return.js index 3fb755caca5..474d3d81056 100644 --- a/tests/lib/rules/getter-return.js +++ b/tests/lib/rules/getter-return.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/getter-return"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); const expectedError = { messageId: "expected", data: { name: "getter 'bar'" } }; const expectedAlwaysError = { messageId: "expectedAlways", data: { name: "getter 'bar'" } }; const options = [{ allowImplicit: true }]; @@ -304,31 +304,31 @@ ruleTester.run("getter-return", rule, { // Optional chaining { code: "Object?.defineProperty(foo, 'bar', { get: function (){} });", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }] + errors: [{ messageId: "expected", data: { name: "method 'get'" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperty)(foo, 'bar', { get: function (){} });", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }] + errors: [{ messageId: "expected", data: { name: "method 'get'" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.defineProperty(foo, 'bar', { get: function (){} });", options, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }] + errors: [{ messageId: "expected", data: { name: "method 'get'" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperty)(foo, 'bar', { get: function (){} });", options, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }] + errors: [{ messageId: "expected", data: { name: "method 'get'" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.create)(foo, { bar: { get: function (){} } });", options, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }] + errors: [{ messageId: "expected", data: { name: "method 'get'" } }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/global-require.js b/tests/lib/rules/global-require.js index df8337d41ec..7a97cbbbe1e 100644 --- a/tests/lib/rules/global-require.js +++ b/tests/lib/rules/global-require.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/global-require"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); const valid = [ { code: "var x = require('y');" }, @@ -36,7 +41,7 @@ const valid = [ // Optional chaining { code: "var x = require('y')?.foo;", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } } ]; @@ -69,12 +74,12 @@ const invalid = [ // non-block statements { code: "var getModule = x => require(x);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [error] }, { code: "var x = (x => require(x))('weird')", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [error] }, { diff --git a/tests/lib/rules/grouped-accessor-pairs.js b/tests/lib/rules/grouped-accessor-pairs.js index 75aa3a04ff6..24db32842f9 100644 --- a/tests/lib/rules/grouped-accessor-pairs.js +++ b/tests/lib/rules/grouped-accessor-pairs.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/grouped-accessor-pairs"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("grouped-accessor-pairs", rule, { valid: [ @@ -438,8 +438,8 @@ ruleTester.run("grouped-accessor-pairs", rule, { }, { code: "class A { get a(){} a; set a(foo){} }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "notGrouped", data: { formerName: "getter 'a'", latterName: "setter 'a'" }, type: "MethodDefinition", column: 24 }] + errors: [{ messageId: "notGrouped", data: { formerName: "getter 'a'", latterName: "setter 'a'" }, type: "MethodDefinition", column: 24 }], + languageOptions: { ecmaVersion: 2022 } }, // full location tests diff --git a/tests/lib/rules/guard-for-in.js b/tests/lib/rules/guard-for-in.js index 578c60165ec..7cde0aa0f1e 100644 --- a/tests/lib/rules/guard-for-in.js +++ b/tests/lib/rules/guard-for-in.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/guard-for-in"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/handle-callback-err.js b/tests/lib/rules/handle-callback-err.js index 73ce75da0d2..c073cd3c8ee 100644 --- a/tests/lib/rules/handle-callback-err.js +++ b/tests/lib/rules/handle-callback-err.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/handle-callback-err"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -39,11 +39,11 @@ ruleTester.run("handle-callback-err", rule, { "function userHandler(err) {process.nextTick(function() {if (err) {}})}", "function help() { function userHandler(err) {function tester() { err; process.nextTick(function() { err; }); } } }", "function help(done) { var err = new Error('error'); done(); }", - { code: "var test = err => err;", parserOptions: { ecmaVersion: 6 } }, - { code: "var test = err => !err;", parserOptions: { ecmaVersion: 6 } }, - { code: "var test = err => err.message;", parserOptions: { ecmaVersion: 6 } }, + { code: "var test = err => err;", languageOptions: { ecmaVersion: 6 } }, + { code: "var test = err => !err;", languageOptions: { ecmaVersion: 6 } }, + { code: "var test = err => err.message;", languageOptions: { ecmaVersion: 6 } }, { code: "var test = function(error) {if(error){/* do nothing */}};", options: ["error"] }, - { code: "var test = (error) => {if(error){/* do nothing */}};", options: ["error"], parserOptions: { ecmaVersion: 6 } }, + { code: "var test = (error) => {if(error){/* do nothing */}};", options: ["error"], languageOptions: { ecmaVersion: 6 } }, { code: "var test = function(error) {if(! error){doSomethingHere();}};", options: ["error"] }, { code: "var test = function(err) { console.log(err); };", options: ["^(err|error)$"] }, { code: "var test = function(error) { console.log(error); };", options: ["^(err|error)$"] }, @@ -57,7 +57,7 @@ ruleTester.run("handle-callback-err", rule, { { code: "function test(err) {errorLookingWord();}", errors: [expectedFunctionDeclarationError] }, { code: "function test(err) {try{} catch(err) {}}", errors: [expectedFunctionDeclarationError] }, { code: "function test(err, callback) { foo(function(err, callback) {}); }", errors: [expectedFunctionDeclarationError, expectedFunctionExpressionError] }, - { code: "var test = (err) => {};", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expected" }] }, + { code: "var test = (err) => {};", errors: [{ messageId: "expected" }], languageOptions: { ecmaVersion: 6 } }, { code: "var test = function(err) {};", errors: [expectedFunctionExpressionError] }, { code: "var test = function test(err, data) {};", errors: [expectedFunctionExpressionError] }, { code: "var test = function test(err) {/* if(err){} */};", errors: [expectedFunctionExpressionError] }, diff --git a/tests/lib/rules/id-blacklist.js b/tests/lib/rules/id-blacklist.js index 4d13459acf6..ce61242313b 100644 --- a/tests/lib/rules/id-blacklist.js +++ b/tests/lib/rules/id-blacklist.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/id-blacklist"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); const error = { messageId: "restricted", type: "Identifier" }; ruleTester.run("id-blacklist", rule, { @@ -44,12 +49,12 @@ ruleTester.run("id-blacklist", rule, { { code: "import { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "foo.bar()", @@ -78,42 +83,42 @@ ruleTester.run("id-blacklist", rule, { { code: "const {foo: bar} = baz", options: ["foo"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: baz }) {}", options: ["bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({baz} = obj.qux) {}", options: ["qux"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ foo: {baz} = obj.qux }) {}", options: ["qux"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({a: bar = obj.baz});", options: ["baz"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: {a: bar = obj.baz}} = qux);", options: ["baz"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var arr = [foo.bar];", @@ -150,12 +155,12 @@ ruleTester.run("id-blacklist", rule, { { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[obj.bar]: a = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // references to global variables @@ -182,14 +187,18 @@ ruleTester.run("id-blacklist", rule, { { code: "foo = { [myGlobal]: 1 };", options: ["myGlobal"], - parserOptions: { ecmaVersion: 6 }, - globals: { myGlobal: "readonly" } + languageOptions: { + ecmaVersion: 6, + globals: { myGlobal: "readonly" } + } }, { code: "({ myGlobal } = foo);", // writability doesn't affect the logic, it's always assumed that user doesn't have control over the names of globals. options: ["myGlobal"], - parserOptions: { ecmaVersion: 6 }, - globals: { myGlobal: "writable" } + languageOptions: { + ecmaVersion: 6, + globals: { myGlobal: "writable" } + } }, { code: "/* global myGlobal: readonly */ myGlobal = 5;", @@ -198,12 +207,16 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = [Map];", options: ["Map"], - env: { es6: true } + languageOptions: { ecmaVersion: 6, sourceType: "script" } }, { code: "var foo = { bar: window.baz };", options: ["window"], - env: { browser: true } + languageOptions: { + globals: { + window: "readonly" + } + } } ], invalid: [ @@ -238,116 +251,115 @@ ruleTester.run("id-blacklist", rule, { { code: "import foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "import { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo, { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 8 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as bar };", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 26 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -361,12 +373,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as bar };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -382,12 +394,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -407,12 +419,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as bar };", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -432,70 +444,71 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "foo.bar()", @@ -630,7 +643,6 @@ ruleTester.run("id-blacklist", rule, { { code: "const {foo} = baz", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -638,12 +650,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -651,12 +663,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 13 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {[foo]: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -670,12 +682,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 15 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -683,12 +695,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -702,12 +714,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 21 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {[foo]: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -727,12 +739,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 23 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: baz }) {}", options: ["bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -740,12 +752,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 21 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -753,12 +765,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -766,12 +778,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -779,12 +791,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({[foo]: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -798,12 +810,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: { a: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -811,12 +823,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: obj.bar = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -824,12 +836,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: obj.bar.bar.baz = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -837,12 +849,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: obj[bar] = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -850,12 +862,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: [obj.bar] = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -863,12 +875,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: { a: obj.bar = baz}} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -876,12 +888,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: { [a]: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -889,12 +901,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({...obj.bar} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 9 }, errors: [ { messageId: "restricted", @@ -902,12 +914,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 9 } }, { code: "([obj.bar] = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -915,12 +927,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 7 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const [bar] = baz;", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -928,7 +940,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // not a reference to a global variable, because it isn't a reference to a variable @@ -969,31 +982,30 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = { Number() {} };", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { Number() {} }", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1007,14 +1019,16 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 30 } - ] + ], + languageOptions: { + globals: { myGlobal: "readonly" } + } }, // globals declared in the given source code are not excluded from consideration { code: "const foo = 1; bar = foo;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1028,12 +1042,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let foo; foo = bar;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1047,7 +1061,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "bar = foo; var foo;", @@ -1088,7 +1103,6 @@ ruleTester.run("id-blacklist", rule, { { code: "class Foo {} var bar = Foo;", options: ["Foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1102,14 +1116,14 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // redeclared globals are not excluded from consideration { code: "let undefined; undefined = 1;", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1123,7 +1137,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo = undefined; var undefined;", @@ -1164,7 +1179,6 @@ ruleTester.run("id-blacklist", rule, { { code: "class Number {} x = Number.NaN;", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1178,7 +1192,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 21 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, /* @@ -1188,7 +1203,6 @@ ruleTester.run("id-blacklist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], - env: { browser: true }, errors: [ { messageId: "restricted", @@ -1196,21 +1210,28 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 31 } - ] + ], + languageOptions: { + globals: { + window: "readonly" + } + } }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], - globals: { undefined: "off" }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ] + ], + languageOptions: { + globals: { undefined: "off" } + } }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1239,7 +1260,6 @@ ruleTester.run("id-blacklist", rule, { { code: "if (foo) { let undefined; bar = undefined; }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1253,7 +1273,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 33 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(Number) { var x = Number.NaN; }", @@ -1276,7 +1297,6 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1290,12 +1310,14 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 36 } - ] + ], + languageOptions: { + globals: { myGlobal: "readonly" } + } }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1309,12 +1331,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 58 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import Number from 'myNumber'; const foo = Number.parseInt(bar);", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1328,7 +1350,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 44 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = function undefined() {};", @@ -1346,14 +1369,14 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = { undefined }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/id-denylist.js b/tests/lib/rules/id-denylist.js index 4e8248399e4..04c5602ee85 100644 --- a/tests/lib/rules/id-denylist.js +++ b/tests/lib/rules/id-denylist.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/id-denylist"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); const error = { messageId: "restricted", type: "Identifier" }; ruleTester.run("id-denylist", rule, { @@ -44,12 +49,12 @@ ruleTester.run("id-denylist", rule, { { code: "import { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "foo.bar()", @@ -78,42 +83,42 @@ ruleTester.run("id-denylist", rule, { { code: "const {foo: bar} = baz", options: ["foo"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: baz }) {}", options: ["bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({baz} = obj.qux) {}", options: ["qux"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ foo: {baz} = obj.qux }) {}", options: ["qux"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({a: bar = obj.baz});", options: ["baz"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: {a: bar = obj.baz}} = qux);", options: ["baz"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var arr = [foo.bar];", @@ -150,12 +155,12 @@ ruleTester.run("id-denylist", rule, { { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "({[obj.bar]: a = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // references to global variables @@ -182,14 +187,18 @@ ruleTester.run("id-denylist", rule, { { code: "foo = { [myGlobal]: 1 };", options: ["myGlobal"], - parserOptions: { ecmaVersion: 6 }, - globals: { myGlobal: "readonly" } + languageOptions: { + ecmaVersion: 6, + globals: { myGlobal: "readonly" } + } }, { code: "({ myGlobal } = foo);", // writability doesn't affect the logic, it's always assumed that user doesn't have control over the names of globals. options: ["myGlobal"], - parserOptions: { ecmaVersion: 6 }, - globals: { myGlobal: "writable" } + languageOptions: { + ecmaVersion: 6, + globals: { myGlobal: "writable" } + } }, { code: "/* global myGlobal: readonly */ myGlobal = 5;", @@ -198,24 +207,30 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = [Map];", options: ["Map"], - env: { es6: true } + languageOptions: { + ecmaVersion: 6 + } }, { code: "var foo = { bar: window.baz };", options: ["window"], - env: { browser: true } + languageOptions: { + globals: { + window: "readonly" + } + } }, // Class fields { code: "class C { camelCase; #camelCase; #camelCase2() {} }", options: ["foo"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { snake_case; #snake_case; #snake_case2() {} }", options: ["foo"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -250,116 +265,115 @@ ruleTester.run("id-denylist", rule, { { code: "import foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "import { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import foo, { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 8 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as bar };", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 26 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -373,12 +387,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as bar };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -394,12 +408,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -419,12 +433,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo; export { foo as bar };", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -444,70 +458,71 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "foo.bar()", @@ -642,7 +657,6 @@ ruleTester.run("id-denylist", rule, { { code: "const {foo} = baz", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -650,12 +664,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -663,12 +677,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 13 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {[foo]: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -682,12 +696,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 15 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -695,12 +709,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {foo: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -714,12 +728,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 21 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const {[foo]: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -739,12 +753,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 23 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: baz }) {}", options: ["bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -752,12 +766,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 21 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -765,12 +779,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -778,12 +792,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -791,12 +805,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({[foo]: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -810,12 +824,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: { a: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -823,12 +837,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: obj.bar = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -836,12 +850,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: obj.bar.bar.baz = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -849,12 +863,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: obj[bar] = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -862,12 +876,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({a: [obj.bar] = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -875,12 +889,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: { a: obj.bar = baz}} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -888,12 +902,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({foo: { [a]: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -901,12 +915,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({...obj.bar} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 9 }, errors: [ { messageId: "restricted", @@ -914,12 +928,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 9 } }, { code: "([obj.bar] = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -927,12 +941,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 7 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const [bar] = baz;", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -940,7 +954,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // not a reference to a global variable, because it isn't a reference to a variable @@ -981,31 +996,30 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = { Number() {} };", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { Number() {} }", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1019,14 +1033,16 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 30 } - ] + ], + languageOptions: { + globals: { myGlobal: "readonly" } + } }, // globals declared in the given source code are not excluded from consideration { code: "const foo = 1; bar = foo;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1040,12 +1056,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let foo; foo = bar;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1059,7 +1075,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "bar = foo; var foo;", @@ -1100,7 +1117,6 @@ ruleTester.run("id-denylist", rule, { { code: "class Foo {} var bar = Foo;", options: ["Foo"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1114,14 +1130,14 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // redeclared globals are not excluded from consideration { code: "let undefined; undefined = 1;", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1135,7 +1151,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo = undefined; var undefined;", @@ -1176,7 +1193,6 @@ ruleTester.run("id-denylist", rule, { { code: "class Number {} x = Number.NaN;", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1190,7 +1206,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 21 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, /* @@ -1200,7 +1217,6 @@ ruleTester.run("id-denylist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], - env: { browser: true }, errors: [ { messageId: "restricted", @@ -1208,21 +1224,28 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 31 } - ] + ], + languageOptions: { + globals: { + window: "readonly" + } + } }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], - globals: { undefined: "off" }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ] + ], + languageOptions: { + globals: { undefined: "off" } + } }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1251,7 +1274,6 @@ ruleTester.run("id-denylist", rule, { { code: "if (foo) { let undefined; bar = undefined; }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1265,7 +1287,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 33 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(Number) { var x = Number.NaN; }", @@ -1288,7 +1311,6 @@ ruleTester.run("id-denylist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1302,12 +1324,14 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 36 } - ] + ], + languageOptions: { + globals: { myGlobal: "readonly" } + } }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1321,12 +1345,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 58 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import Number from 'myNumber'; const foo = Number.parseInt(bar);", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1340,7 +1364,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 44 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = function undefined() {};", @@ -1358,21 +1383,20 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = { undefined }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Class fields { code: "class C { camelCase; #camelCase; #camelCase2() {} }", options: ["camelCase"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "restricted", @@ -1384,13 +1408,13 @@ ruleTester.run("id-denylist", rule, { data: { name: "camelCase" }, type: "PrivateIdentifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { snake_case; #snake_case() {}; #snake_case2() {} }", options: ["snake_case"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "restricted", @@ -1402,7 +1426,8 @@ ruleTester.run("id-denylist", rule, { data: { name: "snake_case" }, type: "PrivateIdentifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] diff --git a/tests/lib/rules/id-length.js b/tests/lib/rules/id-length.js index 871db908f92..a38e84862fa 100644 --- a/tests/lib/rules/id-length.js +++ b/tests/lib/rules/id-length.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/id-length"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -41,45 +41,45 @@ ruleTester.run("id-length", rule, { "var obj = { 'a': 1, bc: 2 }; obj.tk = obj.a;", "var query = location.query.q || '';", "var query = location.query.q ? location.query.q : ''", - { code: "let {a: foo} = bar;", parserOptions: { ecmaVersion: 6 } }, - { code: "let foo = { [a]: 1 };", parserOptions: { ecmaVersion: 6 } }, - { code: "let foo = { [a + b]: 1 };", parserOptions: { ecmaVersion: 6 } }, + { code: "let {a: foo} = bar;", languageOptions: { ecmaVersion: 6 } }, + { code: "let foo = { [a]: 1 };", languageOptions: { ecmaVersion: 6 } }, + { code: "let foo = { [a + b]: 1 };", languageOptions: { ecmaVersion: 6 } }, { code: "var x = Foo(42)", options: [{ min: 1 }] }, { code: "var x = Foo(42)", options: [{ min: 0 }] }, { code: "foo.$x = Foo(42)", options: [{ min: 1 }] }, { code: "var lalala = Foo(42)", options: [{ max: 6 }] }, { code: "for (var q, h=0; h < 10; h++) { console.log(h); q++; }", options: [{ exceptions: ["h", "q"] }] }, - { code: "(num) => { num * num };", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(num = 0) { }", parserOptions: { ecmaVersion: 6 } }, - { code: "class MyClass { }", parserOptions: { ecmaVersion: 6 } }, - { code: "class Foo { method() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(...args) { }", parserOptions: { ecmaVersion: 6 } }, - { code: "var { prop } = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var { [a]: prop } = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var { a: foo } = {};", options: [{ min: 3 }], parserOptions: { ecmaVersion: 6 } }, - { code: "var { prop: foo } = {};", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } }, - { code: "var { longName: foo } = {};", options: [{ min: 3, max: 5 }], parserOptions: { ecmaVersion: 6 } }, - { code: "var { foo: a } = {};", options: [{ exceptions: ["a"] }], parserOptions: { ecmaVersion: 6 } }, - { code: "var { a: { b: { c: longName } } } = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "({ a: obj.x.y.z } = {});", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "import something from 'y';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export var num = 0;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "({ prop: obj.x.y.something } = {});", parserOptions: { ecmaVersion: 6 } }, - { code: "({ prop: obj.longName } = {});", parserOptions: { ecmaVersion: 6 } }, + { code: "(num) => { num * num };", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(num = 0) { }", languageOptions: { ecmaVersion: 6 } }, + { code: "class MyClass { }", languageOptions: { ecmaVersion: 6 } }, + { code: "class Foo { method() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(...args) { }", languageOptions: { ecmaVersion: 6 } }, + { code: "var { prop } = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var { [a]: prop } = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var { a: foo } = {};", options: [{ min: 3 }], languageOptions: { ecmaVersion: 6 } }, + { code: "var { prop: foo } = {};", options: [{ max: 3 }], languageOptions: { ecmaVersion: 6 } }, + { code: "var { longName: foo } = {};", options: [{ min: 3, max: 5 }], languageOptions: { ecmaVersion: 6 } }, + { code: "var { foo: a } = {};", options: [{ exceptions: ["a"] }], languageOptions: { ecmaVersion: 6 } }, + { code: "var { a: { b: { c: longName } } } = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "({ a: obj.x.y.z } = {});", options: [{ properties: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "import something from 'y';", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export var num = 0;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "({ prop: obj.x.y.something } = {});", languageOptions: { ecmaVersion: 6 } }, + { code: "({ prop: obj.longName } = {});", languageOptions: { ecmaVersion: 6 } }, { code: "var obj = { a: 1, bc: 2 };", options: [{ properties: "never" }] }, - { code: "var obj = { [a]: 2 };", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, + { code: "var obj = { [a]: 2 };", options: [{ properties: "never" }], languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {}; obj.a = 1; obj.bc = 2;", options: [{ properties: "never" }] }, - { code: "({ prop: obj.x } = {});", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, + { code: "({ prop: obj.x } = {});", options: [{ properties: "never" }], languageOptions: { ecmaVersion: 6 } }, { code: "var obj = { aaaaa: 1 };", options: [{ max: 4, properties: "never" }] }, { code: "var obj = {}; obj.aaaaa = 1;", options: [{ max: 4, properties: "never" }] }, - { code: "({ a: obj.x.y.z } = {});", options: [{ max: 4, properties: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "({ prop: obj.xxxxx } = {});", options: [{ max: 4, properties: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "var arr = [i,j,f,b]", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo([arr]) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "var {x} = foo;", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "var {x, y: {z}} = foo;", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "let foo = { [a]: 1 };", options: [{ properties: "always" }], parserOptions: { ecmaVersion: 6 } }, - { code: "let foo = { [a + b]: 1 };", options: [{ properties: "always" }], parserOptions: { ecmaVersion: 6 } }, + { code: "({ a: obj.x.y.z } = {});", options: [{ max: 4, properties: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "({ prop: obj.xxxxx } = {});", options: [{ max: 4, properties: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var arr = [i,j,f,b]", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo([arr]) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "var {x} = foo;", options: [{ properties: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var {x, y: {z}} = foo;", options: [{ properties: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "let foo = { [a]: 1 };", options: [{ properties: "always" }], languageOptions: { ecmaVersion: 6 } }, + { code: "let foo = { [a + b]: 1 };", options: [{ properties: "always" }], languageOptions: { ecmaVersion: 6 } }, { code: "function BEFORE_send() {};", options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_"] }] }, { code: "function BEFORE_send() {};", options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_", "send$"] }] }, { code: "function BEFORE_send() {};", options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_", "^A", "^Z"] }] }, @@ -89,145 +89,145 @@ ruleTester.run("id-length", rule, { // Class Fields { code: "class Foo { #xyz() {} }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { xyz = 1 }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { #xyz = 1 }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { #abc() {} }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { abc = 1 }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { #abc = 1 }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // Identifier consisting of two code units { code: "var 𠮟 = 2", options: [{ min: 1, max: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var 葛󠄀 = 2", // 2 code points but only 1 grapheme options: [{ min: 1, max: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = { 𐌘: 1 };", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "(𐌘) => { 𐌘 * 𐌘 };", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "class 𠮟 { }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "class F { 𐌘() {} }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "class F { #𐌘() {} }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class F { 𐌘 = 1 }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class F { #𐌘 = 1 }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "function f(...𐌘) { }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "function f([𐌘]) { }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "var [ 𐌘 ] = a;", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "var { p: [𐌘]} = {};", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "function f({𐌘}) { }", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "var { 𐌘 } = {};", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "var { p: 𐌘} = {};", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "({ prop: o.𐌘 } = {});", options: [{ min: 1, max: 1 }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } } @@ -243,9 +243,9 @@ ruleTester.run("id-length", rule, { { code: "var handler = function (e) {};", errors: [tooShortError] }, { code: "for (var i=0; i < 10; i++) { console.log(i); }", errors: [tooShortError] }, { code: "var j=0; while (j > -10) { console.log(--j); }", errors: [tooShortError] }, - { code: "var [i] = arr;", parserOptions: { ecmaVersion: 6 }, errors: [tooShortError] }, - { code: "var [,i,a] = arr;", parserOptions: { ecmaVersion: 6 }, errors: [tooShortError, tooShortError] }, - { code: "function foo([a]) {}", parserOptions: { ecmaVersion: 6 }, errors: [tooShortError] }, + { code: "var [i] = arr;", errors: [tooShortError], languageOptions: { ecmaVersion: 6 } }, + { code: "var [,i,a] = arr;", errors: [tooShortError, tooShortError], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo([a]) {}", errors: [tooShortError], languageOptions: { ecmaVersion: 6 } }, { code: "var _$xt_$ = Foo(42)", options: [{ min: 2, max: 4 }], @@ -269,84 +269,83 @@ ruleTester.run("id-length", rule, { }, { code: "(a) => { a * a };", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(x = 0) { }", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class x { }", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { x() {} }", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(...x) { }", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({x}) { }", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({x: a}) { }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", data: { name: "a", min: 2 }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({x: a, longName}) { }", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ longName: a }) {}", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ prop: longName }) {};", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, errors: [ tooLongError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ a: b }) {};", options: [{ exceptions: ["a"] }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -355,7 +354,8 @@ ruleTester.run("id-length", rule, { column: 19, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var hasOwnProperty;", @@ -372,7 +372,6 @@ ruleTester.run("id-length", rule, { }, { code: "function foo({ a: { b: { c: d, e } } }) { }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -388,66 +387,66 @@ ruleTester.run("id-length", rule, { column: 32, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { x} = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { x: a} = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", data: { name: "a", min: 2 }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a: a} = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { prop: a } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { longName: a } = {};", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { prop: [x] } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { prop: [[x]] } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { prop: longName } = {};", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooLong", @@ -456,12 +455,12 @@ ruleTester.run("id-length", rule, { column: 13, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { x: a} = {};", options: [{ exceptions: ["x"] }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -470,11 +469,11 @@ ruleTester.run("id-length", rule, { column: 10, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a: { b: { c: d } } } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -483,11 +482,11 @@ ruleTester.run("id-length", rule, { column: 20, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a: { b: { c: d, e } } } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -503,11 +502,11 @@ ruleTester.run("id-length", rule, { column: 23, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a: { b: { c, e: longName } } } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -516,11 +515,11 @@ ruleTester.run("id-length", rule, { column: 17, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a: { b: { c: d, e: longName } } } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -529,11 +528,11 @@ ruleTester.run("id-length", rule, { column: 20, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a, b: { c: d, e: longName } } = {};", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -549,25 +548,25 @@ ruleTester.run("id-length", rule, { column: 18, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "import x from 'y';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export var x = 0;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "({ a: obj.x.y.z } = {});", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -576,11 +575,11 @@ ruleTester.run("id-length", rule, { column: 15, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ prop: obj.x } = {});", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -589,13 +588,13 @@ ruleTester.run("id-length", rule, { column: 14, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = 1;", options: [{ properties: "never" }], errors: [tooShortError] }, { code: "var {prop: x} = foo;", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -604,15 +603,16 @@ ruleTester.run("id-length", rule, { column: 12, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = {x: prop};", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function BEFORE_send() {};", @@ -639,199 +639,199 @@ ruleTester.run("id-length", rule, { // Class Fields { code: "class Foo { #x() {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ tooShortErrorPrivate - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { x = 1 }", - parserOptions: { ecmaVersion: 2022 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { #x = 1 }", - parserOptions: { ecmaVersion: 2022 }, errors: [ tooShortErrorPrivate - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { #abcdefg() {} }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 }, errors: [ tooLongErrorPrivate - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { abcdefg = 1 }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 }, errors: [ tooLongError - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class Foo { #abcdefg = 1 }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 }, errors: [ tooLongErrorPrivate - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // Identifier consisting of two code units { code: "var 𠮟 = 2", - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var 葛󠄀 = 2", // 2 code points but only 1 grapheme - parserOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var myObj = { 𐌘: 1 };", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "(𐌘) => { 𐌘 * 𐌘 };", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "class 𠮟 { }", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "class Foo { 𐌘() {} }", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "class Foo1 { #𐌘() {} }", - parserOptions: { - ecmaVersion: 2022 - }, errors: [ tooShortErrorPrivate - ] + ], + languageOptions: { + ecmaVersion: 2022 + } }, { code: "class Foo2 { 𐌘 = 1 }", - parserOptions: { - ecmaVersion: 2022 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 2022 + } }, { code: "class Foo3 { #𐌘 = 1 }", - parserOptions: { - ecmaVersion: 2022 - }, errors: [ tooShortErrorPrivate - ] + ], + languageOptions: { + ecmaVersion: 2022 + } }, { code: "function foo1(...𐌘) { }", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "function foo([𐌘]) { }", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var [ 𐌘 ] = arr;", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var { prop: [𐌘]} = {};", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "function foo({𐌘}) { }", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var { 𐌘 } = {};", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var { prop: 𐌘} = {};", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "({ prop: obj.𐌘 } = {});", - parserOptions: { - ecmaVersion: 6 - }, errors: [ tooShortError - ] + ], + languageOptions: { + ecmaVersion: 6 + } } ] }); diff --git a/tests/lib/rules/id-match.js b/tests/lib/rules/id-match.js index 7e469bd4d5b..036b24c03c7 100644 --- a/tests/lib/rules/id-match.js +++ b/tests/lib/rules/id-match.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/id-match"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -122,7 +122,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id } = query;", @@ -130,7 +130,7 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: category_id } = query;", @@ -138,7 +138,7 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id = 1 } = query;", @@ -146,7 +146,7 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var o = {key: 1}", @@ -195,7 +195,7 @@ ruleTester.run("id-match", rule, { options: ["^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$", { properties: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -208,7 +208,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -221,7 +221,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { onlyDeclarations: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -235,7 +235,7 @@ ruleTester.run("id-match", rule, { properties: false, onlyDeclarations: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -247,19 +247,19 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // Class Methods { code: "class x { foo() {} }", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class x { #foo() {} }", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // Class Fields @@ -268,14 +268,14 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { classFields: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class x { #_foo = 1; }", options: ["^[^_]+$", { classFields: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -407,13 +407,13 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_alias' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: category_alias } = query;", @@ -421,13 +421,13 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_alias' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id: categoryId, ...other_props } = query;", @@ -435,200 +435,199 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { message: "Identifier 'other_props' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var { category_id } = query;", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_id' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { category_id = 1 } = query;", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_id' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "import no_camelcased from \"external-module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as no_camelcased from \"external-module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export * as no_camelcased from \"external-module\";", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "import { no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as no_camel_cased } from \"external module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camel_cased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { camelCased as no_camel_cased } from \"external module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camel_cased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { camelCased, no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'another_no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import camelCased, { no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "function foo({ no_camelcased }) {};", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ no_camelcased = 'default value' }) {};", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased }) {}", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -638,72 +637,73 @@ ruleTester.run("id-match", rule, { message: "Identifier 'camelcased_value' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { bar: no_camelcased } = foo;", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ value_1: my_default }) {}", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'my_default' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({ isCamelcased: no_camelcased }) {};", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { foo: bar_baz = 1 } = quz;", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'bar_baz' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { no_camelcased = false } = bar;", options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/15395 @@ -723,7 +723,6 @@ ruleTester.run("id-match", rule, { options: ["^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'foo_variable' does not match the pattern '^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$'.", @@ -773,31 +772,32 @@ ruleTester.run("id-match", rule, { line: 11, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Class Methods { code: "class x { _foo() {} }", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '_foo' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class x { #_foo() {} }", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '#_foo' does not match the pattern '^[^_]+$'.", type: "PrivateIdentifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // Class Fields @@ -806,26 +806,26 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { classFields: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '_foo' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class x { #_foo = 1; }", options: ["^[^_]+$", { classFields: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '#_foo' does not match the pattern '^[^_]+$'.", type: "PrivateIdentifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/15123 @@ -841,7 +841,6 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.", @@ -851,7 +850,8 @@ ruleTester.run("id-match", rule, { message: "Identifier 'bar_one' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -865,7 +865,6 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.", @@ -875,7 +874,8 @@ ruleTester.run("id-match", rule, { message: "Identifier 'bar_one' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -887,13 +887,13 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'a' does not match the pattern '^[^a]'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/15443 @@ -907,13 +907,13 @@ ruleTester.run("id-match", rule, { properties: false, onlyDeclarations: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'a' does not match the pattern '^[^a]'.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/implicit-arrow-linebreak.js b/tests/lib/rules/implicit-arrow-linebreak.js index c65d4750a7d..e92000dc873 100644 --- a/tests/lib/rules/implicit-arrow-linebreak.js +++ b/tests/lib/rules/implicit-arrow-linebreak.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/implicit-arrow-linebreak"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const { unIndent } = require("../../_utils"); const EXPECTED_LINEBREAK = { messageId: "expected" }; @@ -19,7 +19,7 @@ const UNEXPECTED_LINEBREAK = { messageId: "unexpected" }; // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("implicit-arrow-linebreak", rule, { @@ -100,14 +100,14 @@ ruleTester.run("implicit-arrow-linebreak", rule, { code: ` async foo => () => bar; `, - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: ` // comment async foo => 'string' `, - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, // 'below' option @@ -399,8 +399,8 @@ ruleTester.run("implicit-arrow-linebreak", rule, { 'string' `, output: null, - parserOptions: { ecmaVersion: 8 }, - errors: [UNEXPECTED_LINEBREAK] + errors: [UNEXPECTED_LINEBREAK], + languageOptions: { ecmaVersion: 8 } }, { code: unIndent` async foo => @@ -409,8 +409,8 @@ ruleTester.run("implicit-arrow-linebreak", rule, { bar; `, output: null, - parserOptions: { ecmaVersion: 8 }, - errors: [UNEXPECTED_LINEBREAK] + errors: [UNEXPECTED_LINEBREAK], + languageOptions: { ecmaVersion: 8 } }, { code: unIndent` async (foo) => @@ -418,8 +418,8 @@ ruleTester.run("implicit-arrow-linebreak", rule, { 'string' `, output: null, - parserOptions: { ecmaVersion: 8 }, - errors: [UNEXPECTED_LINEBREAK] + errors: [UNEXPECTED_LINEBREAK], + languageOptions: { ecmaVersion: 8 } }, { code: unIndent` const foo = 1, diff --git a/tests/lib/rules/indent-legacy.js b/tests/lib/rules/indent-legacy.js index e3295e1f3da..d60ad53e5f7 100644 --- a/tests/lib/rules/indent-legacy.js +++ b/tests/lib/rules/indent-legacy.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/indent-legacy"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const fs = require("fs"); const path = require("path"); @@ -53,7 +53,12 @@ function expectedErrors(providedIndentType, providedErrors) { })); } -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("indent-legacy", rule, { valid: [ @@ -116,7 +121,7 @@ ruleTester.run("indent-legacy", rule, { " );\n" + "}\n", options: [4], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -137,7 +142,7 @@ ruleTester.run("indent-legacy", rule, { " return 100 * x;\n" + " });\n", options: [4], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -236,7 +241,7 @@ ruleTester.run("indent-legacy", rule, { " expect(true).toBe(true);\n" + "});\n", options: [2], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -302,7 +307,7 @@ ruleTester.run("indent-legacy", rule, { " console.log('hi');\n" + " return true;};", options: [2, { VariableDeclarator: 1, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -601,14 +606,14 @@ ruleTester.run("indent-legacy", rule, { "let geometry,\n" + " rotate;", options: [2, { VariableDeclarator: 2 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const geometry = 2,\n" + " rotate = 3;", options: [2, { VariableDeclarator: 2 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -648,7 +653,7 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + " });\n", options: [4], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -656,7 +661,7 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -664,7 +669,7 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -793,7 +798,7 @@ ruleTester.run("indent-legacy", rule, { { code: "import {addons} from 'react/addons'\nimport React from 'react'", options: [2], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: @@ -847,7 +852,7 @@ ruleTester.run("indent-legacy", rule, { " }\n" + ");\n", options: [2, { VariableDeclarator: 3 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { @@ -859,7 +864,7 @@ ruleTester.run("indent-legacy", rule, { "let light = true,\n" + " shadow = false;", options: [2, { VariableDeclarator: { const: 3, let: 2 } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -885,7 +890,7 @@ ruleTester.run("indent-legacy", rule, { " b: 2\n" + " };\n", options: [2, { VariableDeclarator: { var: 2, const: 3 }, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -928,7 +933,7 @@ ruleTester.run("indent-legacy", rule, { " });\n" + "};", options: [2], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: @@ -939,7 +944,7 @@ ruleTester.run("indent-legacy", rule, { " // ... function body, indented two spaces\n" + "}\n", options: [2], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: @@ -972,7 +977,7 @@ ruleTester.run("indent-legacy", rule, { " a = 5,\n" + " b = 4\n", options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -985,7 +990,7 @@ ruleTester.run("indent-legacy", rule, { "\n" + "if (YO) console.log(TE)", options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1038,7 +1043,7 @@ ruleTester.run("indent-legacy", rule, { " console.log(argument);\n" + " },\n" + " someOtherValue = 'someOtherValue';\n", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1060,7 +1065,7 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + " };", options: [2, { VariableDeclarator: 2, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1073,7 +1078,7 @@ ruleTester.run("indent-legacy", rule, { " },\n" + " c = 3;", options: [2, { VariableDeclarator: 2, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1083,7 +1088,7 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "}", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1093,7 +1098,7 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "}", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1150,7 +1155,7 @@ ruleTester.run("indent-legacy", rule, { " });\n" + "};", options: [4, { MemberExpression: 0 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1163,7 +1168,7 @@ ruleTester.run("indent-legacy", rule, { " });\n" + "};", options: [4], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1207,7 +1212,7 @@ ruleTester.run("indent-legacy", rule, { " }\n" + "};", options: [2], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1216,7 +1221,7 @@ ruleTester.run("indent-legacy", rule, { " baz() {}\n" + "}", options: [2], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1225,7 +1230,7 @@ ruleTester.run("indent-legacy", rule, { " baz() {}\n" + "}", options: [2], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1233,7 +1238,7 @@ ruleTester.run("indent-legacy", rule, { " files[name] = foo;\n" + "});", options: [2, { outerIIFEBody: 0 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1362,7 +1367,7 @@ ruleTester.run("indent-legacy", rule, { "}\n" + "})();", options: [2, { outerIIFEBody: 0 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1378,7 +1383,7 @@ ruleTester.run("indent-legacy", rule, { "}\n" + "})();", options: [2, { outerIIFEBody: 0 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1695,14 +1700,14 @@ ruleTester.run("indent-legacy", rule, { "return (\n" + " foo\n" + ");", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { sourceType: "script", parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "return (\n" + " foo\n" + ")", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, "var foo = [\n" + " bar,\n" + @@ -1848,7 +1853,7 @@ ruleTester.run("indent-legacy", rule, { " );" + "}", options: [2, { ObjectExpression: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1861,7 +1866,7 @@ ruleTester.run("indent-legacy", rule, { " );" + "}", options: [2, { ObjectExpression: "first" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7733 @@ -2276,10 +2281,10 @@ ruleTester.run("indent-legacy", rule, { " .bar\n" + "}", options: [4, { MemberExpression: 2 }], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors( [3, 12, 13, "Punctuator"] - ) + ), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2297,12 +2302,12 @@ ruleTester.run("indent-legacy", rule, { " });\n" + "};", options: [2, { MemberExpression: 1 }], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors( [ [3, 4, 6, "Punctuator"] ] - ) + ), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2432,11 +2437,11 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 2, "ExpressionStatement"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2449,11 +2454,11 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 2, "ReturnStatement"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2466,8 +2471,8 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, - errors: expectedErrors([[2, 4, 0, "Identifier"]]) + errors: expectedErrors([[2, 4, 0, "Identifier"]]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2479,10 +2484,10 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "ExpressionStatement"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2494,10 +2499,10 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "ReturnStatement"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2571,13 +2576,13 @@ ruleTester.run("indent-legacy", rule, { " 'c'\n" + "];", options: [4], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 9, "Literal"], [3, 4, 9, "Literal"], [4, 4, 9, "Literal"], [5, 0, 2, "ArrayExpression"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: "while (1 < 2)\nconsole.log('foo')\n console.log('bar')", @@ -2693,10 +2698,10 @@ ruleTester.run("indent-legacy", rule, { "let geometry,\n" + " rotate;", options: [2, { VariableDeclarator: 2 }], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "VariableDeclarator"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2760,11 +2765,11 @@ ruleTester.run("indent-legacy", rule, { " b\n" + "]", options: [2, { VariableDeclarator: { let: 2 }, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 2, 4, "Identifier"], [3, 2, 4, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2803,12 +2808,12 @@ ruleTester.run("indent-legacy", rule, { " }),\n" + " d = 4;\n", options: [2, { VariableDeclarator: { var: 2 } }], - parserOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [6, 4, 6, "Property"], [7, 2, 4, "ObjectExpression"], [8, 2, 4, "VariableDeclarator"] - ]) + ]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2897,8 +2902,8 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "}", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, - errors: expectedErrors([[2, 4, 2, "MethodDefinition"]]) + errors: expectedErrors([[2, 4, 2, "MethodDefinition"]]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2914,8 +2919,8 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "};", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, - errors: expectedErrors([[2, 4, 2, "MethodDefinition"], [4, 4, 2, "MethodDefinition"]]) + errors: expectedErrors([[2, 4, 2, "MethodDefinition"], [4, 4, 2, "MethodDefinition"]]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2933,8 +2938,8 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + " };", options: [2, { VariableDeclarator: 2, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, - errors: expectedErrors([[3, 6, 4, "MethodDefinition"]]) + errors: expectedErrors([[3, 6, 4, "MethodDefinition"]]), + languageOptions: { ecmaVersion: 6 } }, { code: @@ -3681,8 +3686,8 @@ ruleTester.run("indent-legacy", rule, { "return (\n" + " foo\n" + ");", - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: expectedErrors([3, 0, 4, "ReturnStatement"]) + errors: expectedErrors([3, 0, 4, "ReturnStatement"]), + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: @@ -3693,8 +3698,8 @@ ruleTester.run("indent-legacy", rule, { "return (\n" + " foo\n" + ")", - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: expectedErrors([3, 0, 4, "ReturnStatement"]) + errors: expectedErrors([3, 0, 4, "ReturnStatement"]), + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // https://github.com/eslint/eslint/issues/7604 diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 4880fa5ec02..c9a05485197 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/indent"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const fs = require("fs"); const path = require("path"); @@ -60,7 +60,15 @@ function expectedErrors(providedIndentType, providedErrors) { // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 8, + sourceType: "script", + parserOptions: { + ecmaFeatures: { jsx: true } + } + } +}); ruleTester.run("indent", rule, { valid: [ @@ -271,7 +279,7 @@ ruleTester.run("indent", rule, { ;(() => {})() `, options: [4], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -1102,7 +1110,7 @@ ruleTester.run("indent", rule, { import React from 'react' `, options: [2], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -1112,7 +1120,7 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -1123,7 +1131,7 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -1281,7 +1289,7 @@ ruleTester.run("indent", rule, { }; `, options: [2, { FunctionDeclaration: { parameters: "first" } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -1293,7 +1301,7 @@ ruleTester.run("indent", rule, { } `, options: [2, { FunctionDeclaration: { parameters: "first" } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -2724,7 +2732,7 @@ ruleTester.run("indent", rule, { foo ); `, - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: unIndent` @@ -2732,7 +2740,7 @@ ruleTester.run("indent", rule, { foo ) `, - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, unIndent` var foo = [ @@ -3258,7 +3266,7 @@ ruleTester.run("indent", rule, { baz } `, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -3582,11 +3590,11 @@ ruleTester.run("indent", rule, { import {foo} from 'bar'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import 'foo'", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -3596,7 +3604,7 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [4, { ImportDeclaration: 1 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -3607,7 +3615,7 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [4, { ImportDeclaration: 1 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -3616,7 +3624,7 @@ ruleTester.run("indent", rule, { import { cat } from 'animals'; `, options: [4, { ImportDeclaration: "first" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -3626,7 +3634,7 @@ ruleTester.run("indent", rule, { turned } from 'off'; `, options: [4, { ImportDeclaration: "off" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // https://github.com/eslint/eslint/issues/8455 @@ -4006,7 +4014,7 @@ ruleTester.run("indent", rule, { baz: number; } `, - parser: parser("unknown-nodes/interface") + languageOptions: { parser: require(parser("unknown-nodes/interface")) } }, { code: unIndent` @@ -4019,7 +4027,7 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-valid") + languageOptions: { parser: require(parser("unknown-nodes/namespace-valid")) } }, { code: unIndent` @@ -4036,7 +4044,7 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/abstract-class-valid") + languageOptions: { parser: require(parser("unknown-nodes/abstract-class-valid")) } }, { code: unIndent` @@ -4052,7 +4060,7 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/functions-with-abstract-class-valid") + languageOptions: { parser: require(parser("unknown-nodes/functions-with-abstract-class-valid")) } }, { code: unIndent` @@ -4070,7 +4078,7 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-valid") + languageOptions: { parser: require(parser("unknown-nodes/namespace-with-functions-with-abstract-class-valid")) } }, { code: unIndent` @@ -4079,7 +4087,7 @@ ruleTester.run("indent", rule, { | 'PUT'; `, options: [2, { VariableDeclarator: 0 }], - parser: parser("unknown-nodes/variable-declarator-type-indent-two-spaces") + languageOptions: { parser: require(parser("unknown-nodes/variable-declarator-type-indent-two-spaces")) } }, { code: unIndent` @@ -4088,7 +4096,7 @@ ruleTester.run("indent", rule, { | 'PUT'; `, options: [2, { VariableDeclarator: 1 }], - parser: parser("unknown-nodes/variable-declarator-type-no-indent") + languageOptions: { parser: require(parser("unknown-nodes/variable-declarator-type-no-indent")) } }, unIndent` foo(\`foo @@ -5190,7 +5198,7 @@ ruleTester.run("indent", rule, { ) `, options: [4, { ignoredNodes: ["ExportDefaultDeclaration > CallExpression > ObjectExpression"] }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -5544,7 +5552,7 @@ ruleTester.run("indent", rule, { // after ) `, - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/12122 @@ -5560,7 +5568,7 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5575,7 +5583,7 @@ ruleTester.run("indent", rule, { }); } `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5598,7 +5606,7 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5621,7 +5629,7 @@ ruleTester.run("indent", rule, { }); }; `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5641,7 +5649,7 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5658,7 +5666,7 @@ ruleTester.run("indent", rule, { }) }); `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5666,7 +5674,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5674,7 +5682,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5684,7 +5692,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5695,7 +5703,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5705,7 +5713,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5715,7 +5723,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5727,7 +5735,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5738,7 +5746,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5750,7 +5758,7 @@ ruleTester.run("indent", rule, { }) `, options: [4, { MemberExpression: 0 }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5762,7 +5770,7 @@ ruleTester.run("indent", rule, { }) `, options: [4, { MemberExpression: 2 }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -5873,7 +5881,7 @@ ruleTester.run("indent", rule, { } `, options: [2], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5885,7 +5893,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5897,7 +5905,7 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5909,7 +5917,7 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 0 } }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5921,7 +5929,7 @@ ruleTester.run("indent", rule, { } `, options: ["tab"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5933,7 +5941,7 @@ ruleTester.run("indent", rule, { } `, options: ["tab", { StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5946,7 +5954,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5958,7 +5966,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5971,7 +5979,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5984,7 +5992,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -5997,7 +6005,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -6013,7 +6021,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -6030,7 +6038,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -6047,7 +6055,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -6068,7 +6076,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -6082,7 +6090,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -6096,7 +6104,7 @@ ruleTester.run("indent", rule, { } `, options: [4, { FunctionExpression: { body: 2 }, StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/15930 @@ -8808,8 +8816,8 @@ ruleTester.run("indent", rule, { foo ); `, - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: unIndent` @@ -8822,8 +8830,8 @@ ruleTester.run("indent", rule, { foo ) `, - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // https://github.com/eslint/eslint/issues/7604 @@ -9301,8 +9309,8 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 2, "Identifier"]]) + errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 2, "Identifier"]]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -9318,8 +9326,8 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [4, { ImportDeclaration: "first" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([[3, 9, 10, "Identifier"]]) + errors: expectedErrors([[3, 9, 10, "Identifier"]]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -9335,8 +9343,8 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [2, { ImportDeclaration: 2 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([[3, 4, 5, "Identifier"]]) + errors: expectedErrors([[3, 4, 5, "Identifier"]]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -9355,8 +9363,8 @@ ruleTester.run("indent", rule, { baz }; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]) + errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -9375,8 +9383,8 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]) + errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { @@ -9813,8 +9821,8 @@ ruleTester.run("indent", rule, { baz } `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 8, "Identifier"], [5, 4, 2, "Identifier"]]) + errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 8, "Identifier"], [5, 4, 2, "Identifier"]]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -10185,8 +10193,8 @@ ruleTester.run("indent", rule, { import {foo} from 'bar'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([2, 4, 0, "Identifier"]) + errors: expectedErrors([2, 4, 0, "Identifier"]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -10197,8 +10205,8 @@ ruleTester.run("indent", rule, { export {foo} from 'bar'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedErrors([2, 4, 0, "Identifier"]) + errors: expectedErrors([2, 4, 0, "Identifier"]), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: unIndent` @@ -10415,8 +10423,8 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-invalid"), - errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]) + errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]), + languageOptions: { parser: require(parser("unknown-nodes/namespace-invalid")) } }, { code: unIndent` @@ -10447,8 +10455,8 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/abstract-class-invalid"), - errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]) + errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]), + languageOptions: { parser: require(parser("unknown-nodes/abstract-class-invalid")) } }, { code: unIndent` @@ -10477,14 +10485,14 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/functions-with-abstract-class-invalid"), errors: expectedErrors([ [4, 12, 8, "Keyword"], [5, 16, 8, "Keyword"], [6, 20, 8, "Identifier"], [7, 16, 8, "Punctuator"], [8, 12, 8, "Punctuator"] - ]) + ]), + languageOptions: { parser: require(parser("unknown-nodes/functions-with-abstract-class-invalid")) } }, { code: unIndent` @@ -10517,11 +10525,11 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid"), errors: expectedErrors([ [3, 8, 4, "Keyword"], [7, 24, 20, "Identifier"] - ]) + ]), + languageOptions: { parser: require(parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid")) } }, //---------------------------------------------------------------------- @@ -11322,8 +11330,8 @@ ruleTester.run("indent", rule, { foo }: bar) => baz `, - parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation"), - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation") } }, { code: unIndent` @@ -11336,8 +11344,8 @@ ruleTester.run("indent", rule, { foo ]: bar) => baz `, - parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation"), - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation") } }, { code: unIndent` @@ -11350,8 +11358,8 @@ ruleTester.run("indent", rule, { foo }: {}) => baz `, - parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation"), - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation") } }, { code: unIndent` @@ -11844,11 +11852,11 @@ ruleTester.run("indent", rule, { source ) `, - parserOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 0, 4, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/12122 @@ -11875,10 +11883,10 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 4, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -11903,12 +11911,12 @@ ruleTester.run("indent", rule, { }); } `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 8, "Identifier"], [7, 8, 12, "Identifier"], [8, 4, 8, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -11949,12 +11957,12 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 12, "Identifier"], [15, 8, 12, "Identifier"], [16, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -11995,12 +12003,12 @@ ruleTester.run("indent", rule, { }); } `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 12, "Identifier"], [15, 8, 12, "Identifier"], [16, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -12035,11 +12043,11 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 4, 0, "Identifier"], [11, 8, 4, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -12068,12 +12076,12 @@ ruleTester.run("indent", rule, { }) }); `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [4, 4, 8, "Identifier"], [5, 4, 0, "Identifier"], [9, 8, 0, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -12086,10 +12094,10 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 8, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -12102,11 +12110,11 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 0, 4, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -12123,10 +12131,10 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -12145,10 +12153,10 @@ ruleTester.run("indent", rule, { bar(); }) `, - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 8, 0, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, { code: unIndent` @@ -12168,12 +12176,12 @@ ruleTester.run("indent", rule, { }) `, options: [4, { MemberExpression: 0 }], - parserOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 0, 4, "Punctuator"], [5, 4, 0, "Identifier"], [6, 0, 4, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2015 } }, // Optional chaining @@ -12193,13 +12201,13 @@ ruleTester.run("indent", rule, { [key] `, options: [4], - parserOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 4, 0, "Punctuator"], [4, 4, 0, "Punctuator"], [5, 8, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2020 } }, { code: unIndent` @@ -12221,11 +12229,11 @@ ruleTester.run("indent", rule, { ?.[key] `, options: [4], - parserOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [6, 4, 0, "Punctuator"], [7, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2020 } }, { code: unIndent` @@ -12241,12 +12249,12 @@ ruleTester.run("indent", rule, { (arg) `, options: [4], - parserOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 4, 0, "Punctuator"], [4, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2020 } }, { code: unIndent` @@ -12268,11 +12276,11 @@ ruleTester.run("indent", rule, { ?.(arg) `, options: [4], - parserOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [6, 4, 0, "Punctuator"], [7, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2020 } }, { code: unIndent` @@ -12290,10 +12298,10 @@ ruleTester.run("indent", rule, { } `, options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }], - parserOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 19, 20, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 2020 } }, { code: unIndent` @@ -12323,11 +12331,11 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 0, "Keyword"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12357,7 +12365,6 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 8, 0, "Punctuator"], @@ -12368,7 +12375,8 @@ ruleTester.run("indent", rule, { [8, 12, 0, "Punctuator"], [9, 16, 0, "Numeric"], [10, 16, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12418,7 +12426,6 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 8, 0, "Identifier"], @@ -12439,7 +12446,8 @@ ruleTester.run("indent", rule, { [18, 8, 0, "Numeric"], [19, 4, 0, "Punctuator"], [20, 8, 0, "Numeric"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12459,12 +12467,12 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 8, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12484,13 +12492,13 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "PrivateIdentifier"], [3, 4, 0, "Identifier"], [4, 8, 0, "Keyword"], [5, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12510,13 +12518,13 @@ ruleTester.run("indent", rule, { } `, options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 2, 0, "Keyword"], [3, 4, 0, "Identifier"], [4, 4, 0, "Identifier"], [5, 2, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12536,13 +12544,13 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Identifier"], [4, 8, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12562,13 +12570,13 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 8, "Keyword"], [3, 8, 4, "Identifier"], [4, 8, 0, "Identifier"], [5, 4, 8, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12588,13 +12596,13 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 12, 0, "Identifier"], [4, 12, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12614,13 +12622,13 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 0 } }], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Identifier"], [4, 4, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12640,13 +12648,13 @@ ruleTester.run("indent", rule, { } `, options: ["tab"], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors("tab", [ [2, 1, 0, "Keyword"], [3, 2, 0, "Identifier"], [4, 2, 0, "Identifier"], [5, 1, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12666,13 +12674,13 @@ ruleTester.run("indent", rule, { } `, options: ["tab", { StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors("tab", [ [2, 1, 0, "Keyword"], [3, 3, 0, "Identifier"], [4, 3, 0, "Identifier"], [5, 1, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12694,14 +12702,14 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Punctuator"], [4, 8, 0, "Identifier"], [5, 8, 0, "Identifier"], [6, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12723,11 +12731,11 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 8, "Punctuator"], [6, 4, 8, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12747,13 +12755,13 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], [4, 12, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12775,14 +12783,14 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Punctuator"], [4, 8, 0, "Keyword"], [5, 12, 0, "Identifier"], [6, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12804,14 +12812,14 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], [4, 12, 0, "Identifier"], [5, 8, 0, "Punctuator"], [6, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12833,14 +12841,14 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Punctuator"], [4, 12, 0, "Identifier"], [5, 8, 0, "Punctuator"], [6, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12868,7 +12876,6 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [4, 4, 0, "Keyword"], @@ -12876,7 +12883,8 @@ ruleTester.run("indent", rule, { [7, 4, 0, "Keyword"], [8, 4, 0, "Punctuator"], [9, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12906,7 +12914,6 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Keyword"], [4, 8, 4, "Identifier"], @@ -12914,7 +12921,8 @@ ruleTester.run("indent", rule, { [7, 4, 0, "Keyword"], [8, 8, 4, "Identifier"], [9, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12944,14 +12952,14 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Identifier"], [5, 4, 0, "Keyword"], [6, 8, 4, "Identifier"], [7, 4, 0, "Punctuator"], [9, 4, 0, "Identifier"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -12989,7 +12997,6 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Identifier"], [4, 8, 4, "Identifier"], @@ -13000,7 +13007,8 @@ ruleTester.run("indent", rule, { [11, 4, 0, "Identifier"], [12, 8, 4, "Identifier"], [13, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -13024,7 +13032,6 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], @@ -13032,7 +13039,8 @@ ruleTester.run("indent", rule, { [5, 12, 0, "Identifier"], [6, 8, 0, "Punctuator"], [7, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -13056,7 +13064,6 @@ ruleTester.run("indent", rule, { } `, options: [4, { FunctionExpression: { body: 2 }, StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 12, 0, "Identifier"], @@ -13064,7 +13071,8 @@ ruleTester.run("indent", rule, { [5, 4, 0, "Keyword"], [6, 12, 0, "Identifier"], [7, 4, 0, "Punctuator"] - ]) + ]), + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/15930 diff --git a/tests/lib/rules/init-declarations.js b/tests/lib/rules/init-declarations.js index 556086abac7..2c860ddb9a2 100644 --- a/tests/lib/rules/init-declarations.js +++ b/tests/lib/rules/init-declarations.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/init-declarations"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -28,71 +28,71 @@ ruleTester.run("init-declarations", rule, { "var foo = bar = 2;", "for (var i = 0; i < 1; i++) {}", "for (var foo in []) {}", - { code: "for (var foo of []) {}", parserOptions: { ecmaVersion: 6 } }, + { code: "for (var foo of []) {}", languageOptions: { ecmaVersion: 6 } }, { code: "let a = true;", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = {};", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a = 1, b = false; if (a) { let c = 3, d = null; } }", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { const a = 1, b = true; if (a) { const c = 3, d = null; } }", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a = 1; const b = false; var c = true; }", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo;", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo, bar, baz;", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var foo; var bar; }", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a;", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 1;", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a, b; if (a) { let c, d; } }", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { const a = 1, b = true; if (a) { const c = 3, d = null; } }", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; const b = false; var c; }", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "for(var i = 0; i < 1; i++){}", @@ -105,7 +105,7 @@ ruleTester.run("init-declarations", rule, { { code: "for (var foo of []) {}", options: ["never", { ignoreForLoopInit: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -134,7 +134,6 @@ ruleTester.run("init-declarations", rule, { { code: "var foo, bar = false, baz;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -146,60 +145,60 @@ ruleTester.run("init-declarations", rule, { data: { idName: "baz" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var foo = 0; var bar; }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "bar" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var foo; var bar = foo; }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let a;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "a" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a = 1, b; if (a) { let c = 3, d = null; } }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "b" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; const b = false; var c; }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -211,36 +210,36 @@ ruleTester.run("init-declarations", rule, { data: { idName: "c" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = bar = 2;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = true;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo, bar = 5, baz = 3;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -252,12 +251,12 @@ ruleTester.run("init-declarations", rule, { data: { idName: "baz" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var foo; var bar = foo; }", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -265,43 +264,44 @@ ruleTester.run("init-declarations", rule, { type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 1;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "a" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a = 'foo', b; if (a) { let c, d; } }", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "a" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; const b = false; var c = 1; }", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "c" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for(var i = 0; i < 1; i++){}", @@ -328,14 +328,14 @@ ruleTester.run("init-declarations", rule, { { code: "for (var foo of []) {}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/jsx-quotes.js b/tests/lib/rules/jsx-quotes.js index cdc1b043286..919a633f80b 100644 --- a/tests/lib/rules/jsx-quotes.js +++ b/tests/lib/rules/jsx-quotes.js @@ -10,13 +10,20 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/jsx-quotes"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 6, + parserOptions: { + ecmaFeatures: { jsx: true } + } + } +}); ruleTester.run("jsx-quotes", rule, { valid: [ diff --git a/tests/lib/rules/key-spacing.js b/tests/lib/rules/key-spacing.js index 96103129e9f..e25064842ab 100644 --- a/tests/lib/rules/key-spacing.js +++ b/tests/lib/rules/key-spacing.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/key-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -32,7 +32,7 @@ ruleTester.run("key-spacing", rule, { }, { code: "var obj = { [(a + b)]: value };", options: [{}], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = { a:bar };", options: [{ @@ -80,7 +80,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "callExpr(arg, {", @@ -94,7 +94,7 @@ ruleTester.run("key-spacing", rule, { beforeColon: true, afterColon: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -213,7 +213,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: [ "var test = {", @@ -222,7 +222,7 @@ ruleTester.run("key-spacing", rule, { " b", "};" ].join("\n"), - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var test = {", @@ -232,7 +232,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -242,7 +242,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var test = {", @@ -250,7 +250,7 @@ ruleTester.run("key-spacing", rule, { " a() { }", "};" ].join("\n"), - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var test = {", @@ -260,7 +260,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -270,7 +270,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -284,7 +284,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -323,7 +323,7 @@ ruleTester.run("key-spacing", rule, { beforeColon: true, afterColon: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: [ "var obj = {", @@ -336,7 +336,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: [ "callExpr(arg, {", @@ -352,7 +352,7 @@ ruleTester.run("key-spacing", rule, { beforeColon: true, afterColon: false }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: [ "var obj = {", @@ -372,7 +372,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: [ "({", @@ -392,7 +392,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/4792 @@ -512,7 +512,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/5613 @@ -534,7 +534,7 @@ ruleTester.run("key-spacing", rule, { beforeColon: true, afterColon: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -553,7 +553,7 @@ ruleTester.run("key-spacing", rule, { beforeColon: true, afterColon: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -571,7 +571,7 @@ ruleTester.run("key-spacing", rule, { } } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -587,8 +587,8 @@ ruleTester.run("key-spacing", rule, { afterColon: false } }], - parserOptions: { ecmaVersion: 6 }, - errors: [] + errors: [], + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -605,7 +605,7 @@ ruleTester.run("key-spacing", rule, { mode: "minimum" } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -623,7 +623,7 @@ ruleTester.run("key-spacing", rule, { } } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -661,7 +661,7 @@ ruleTester.run("key-spacing", rule, { afterColon: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -692,7 +692,7 @@ ruleTester.run("key-spacing", rule, { afterColon: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -720,7 +720,7 @@ ruleTester.run("key-spacing", rule, { afterColon: false } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -745,7 +745,7 @@ ruleTester.run("key-spacing", rule, { } } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -770,7 +770,7 @@ ruleTester.run("key-spacing", rule, { mode: "minimum" } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -966,7 +966,7 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -980,7 +980,7 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/16490 @@ -998,7 +998,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -1054,7 +1054,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/16674 @@ -1191,8 +1191,8 @@ ruleTester.run("key-spacing", rule, { code: "var obj = { [ (a + b) ]:value };", output: "var obj = { [ (a + b) ]: value };", options: [{}], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "missingValue", data: { computed: "computed ", key: "a + b" }, type: "Identifier", line: 1, column: 25 }] + errors: [{ messageId: "missingValue", data: { computed: "computed ", key: "a + b" }, type: "Identifier", line: 1, column: 25 }], + languageOptions: { ecmaVersion: 6 } }, { code: "fn({ foo:bar, 'key' :value });", output: "fn({ foo:bar, 'key':value });", @@ -1310,13 +1310,13 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "a" }, type: "CallExpression", line: 2, column: 6 }, { messageId: "extraKey", data: { computed: "", key: "b" }, type: "Literal", line: 3, column: 8 }, { messageId: "missingValue", data: { computed: "", key: "foo" }, type: "Identifier", line: 4, column: 9 }, { messageId: "extraKey", data: { computed: "computed ", key: "a" }, type: "Identifier", line: 6, column: 8 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "foo = {", @@ -1506,10 +1506,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -1526,10 +1526,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 11, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -1546,10 +1546,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -1566,10 +1566,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 11, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -1594,10 +1594,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "baz" }, line: 6, column: 8, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -1742,11 +1742,11 @@ ruleTester.run("key-spacing", rule, { "})" ].join("\n"), options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 5, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "f" }, line: 12, column: 6, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/4792 @@ -1960,11 +1960,11 @@ ruleTester.run("key-spacing", rule, { code: "({ a:b, ...object, c : d })", output: "({ a: b, ...object, c: d })", options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "a" }, line: 1, column: 6, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "c" }, line: 1, column: 21, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/5613 @@ -1991,13 +1991,13 @@ ruleTester.run("key-spacing", rule, { mode: "strict" } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingKey", data: { computed: "", key: "longName" }, line: 2, column: 5, type: "Identifier" }, { messageId: "missingValue", data: { computed: "", key: "longName" }, line: 2, column: 14, type: "Literal" }, { messageId: "missingValue", data: { computed: "", key: "small" }, line: 3, column: 15, type: "Literal" }, { messageId: "missingKey", data: { computed: "", key: "xs" }, line: 4, column: 5, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -2039,14 +2039,14 @@ ruleTester.run("key-spacing", rule, { mode: "strict" } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "func" }, line: 2, column: 10, type: "FunctionExpression" }, { messageId: "missingKey", data: { computed: "", key: "longName" }, line: 5, column: 5, type: "Identifier" }, { messageId: "missingKey", data: { computed: "", key: "small" }, line: 6, column: 5, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "xs" }, line: 7, column: 7, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "singleLine" }, line: 11, column: 15, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "({", @@ -2088,7 +2088,6 @@ ruleTester.run("key-spacing", rule, { } } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "func" }, line: 2, column: 10, type: "FunctionExpression" }, { messageId: "missingKey", data: { computed: "", key: "small" }, line: 6, column: 5, type: "Identifier" }, @@ -2096,7 +2095,8 @@ ruleTester.run("key-spacing", rule, { { messageId: "extraValue", data: { computed: "", key: "xs" }, line: 7, column: 19, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "func2" }, line: 8, column: 14, type: "FunctionExpression" }, { messageId: "extraKey", data: { computed: "", key: "singleLine" }, line: 11, column: 15, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -2130,11 +2130,11 @@ ruleTester.run("key-spacing", rule, { } } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "key2" }, line: 4, column: 9, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "key3" }, line: 5, column: 9, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ "var obj = {", @@ -2168,11 +2168,11 @@ ruleTester.run("key-spacing", rule, { on: "colon" } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "key2" }, line: 4, column: 9, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "key3" }, line: 5, column: 9, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { // https://github.com/eslint/eslint/issues/7603 @@ -2413,10 +2413,10 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "a" }, line: 3, column: 22, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2436,10 +2436,10 @@ ruleTester.run("key-spacing", rule, { on: "colon" } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 17, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2459,10 +2459,10 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "a" }, line: 3, column: 20, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2518,12 +2518,12 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "id" }, line: 4, column: 19, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "code" }, line: 5, column: 21, type: "Literal" }, { messageId: "extraValue", data: { computed: "computed ", key: "n" }, line: 6, column: 20, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js index 97d198f56fc..df33ef87dee 100644 --- a/tests/lib/rules/keyword-spacing.js +++ b/tests/lib/rules/keyword-spacing.js @@ -11,7 +11,7 @@ const parser = require("../../fixtures/fixture-parser"), rule = require("../../../lib/rules/keyword-spacing"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), fixtureParser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -117,7 +117,12 @@ function unexpectedBeforeAndAfter(keyword) { // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("keyword-spacing", rule, { valid: [ @@ -127,196 +132,196 @@ ruleTester.run("keyword-spacing", rule, { //---------------------------------------------------------------------- // import { a as b } - { code: "import { a } from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { a as b } from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { \"a\" as b } from \"foo\"", parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "import{ a }from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import{ a as b }from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import{ \"a\"as b }from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "import{ \"a\" as b }from\"foo\"", options: [override("as", BOTH)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "import { a as b } from \"foo\"", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "import { \"a\"as b } from \"foo\"", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import { a } from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { a as b } from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { \"a\" as b } from \"foo\"", languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import{ a }from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import{ a as b }from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import{ \"a\"as b }from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import{ \"a\" as b }from\"foo\"", options: [override("as", BOTH)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import { a as b } from \"foo\"", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import { \"a\"as b } from \"foo\"", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, // export { a as b } - { code: "let a; export { a };", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { \"a\" } from \"foo\";", parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "let a; export { a as b };", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "let a; export { a as \"b\" };", parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { \"a\" as b } from \"foo\";", parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { \"a\" as \"b\" } from \"foo\";", parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "let a; export{ a };", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export{ \"a\" }from\"foo\";", options: [NEITHER], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "let a; export{ a as b };", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "let a; export{ a as\"b\" };", options: [NEITHER], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export{ \"a\"as b }from\"foo\";", options: [NEITHER], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export{ \"a\"as\"b\" }from\"foo\";", options: [NEITHER], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "let a; export{ a as \"b\" };", options: [override("as", BOTH)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export{ \"a\" as b }from\"foo\";", options: [override("as", BOTH)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export{ \"a\" as \"b\" }from\"foo\";", options: [override("as", BOTH)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "let a; export { a as b };", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "let a; export { a as\"b\" };", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { \"a\"as b } from \"foo\";", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { \"a\"as\"b\" } from \"foo\";", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "let a; export { a };", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { \"a\" } from \"foo\";", languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "let a; export { a as b };", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "let a; export { a as \"b\" };", languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { \"a\" as b } from \"foo\";", languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { \"a\" as \"b\" } from \"foo\";", languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "let a; export{ a };", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export{ \"a\" }from\"foo\";", options: [NEITHER], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "let a; export{ a as b };", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "let a; export{ a as\"b\" };", options: [NEITHER], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export{ \"a\"as b }from\"foo\";", options: [NEITHER], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export{ \"a\"as\"b\" }from\"foo\";", options: [NEITHER], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "let a; export{ a as \"b\" };", options: [override("as", BOTH)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export{ \"a\" as b }from\"foo\";", options: [override("as", BOTH)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export{ \"a\" as \"b\" }from\"foo\";", options: [override("as", BOTH)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "let a; export { a as b };", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "let a; export { a as\"b\" };", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { \"a\"as b } from \"foo\";", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { \"a\"as\"b\" } from \"foo\";", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, // import * as a - { code: "import * as a from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import*as a from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import* as a from\"foo\"", options: [override("as", BOTH)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import *as a from \"foo\"", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import * as a from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import*as a from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import* as a from\"foo\"", options: [override("as", BOTH)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import *as a from \"foo\"", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // export * as a - { code: "export * as a from \"foo\"", parserOptions: { ecmaVersion: 2020, sourceType: "module" } }, - { code: "export * as \"a\" from \"foo\"", parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export*as a from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 2020, sourceType: "module" } }, - { code: "export*as\"a\"from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export* as a from\"foo\"", options: [override("as", BOTH)], parserOptions: { ecmaVersion: 2020, sourceType: "module" } }, - { code: "export* as \"a\"from\"foo\"", options: [override("as", BOTH)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export *as a from \"foo\"", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 2020, sourceType: "module" } }, - { code: "export *as\"a\" from \"foo\"", options: [override("as", NEITHER)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export * as a from \"foo\"", languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, + { code: "export * as \"a\" from \"foo\"", languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export*as a from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, + { code: "export*as\"a\"from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export* as a from\"foo\"", options: [override("as", BOTH)], languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, + { code: "export* as \"a\"from\"foo\"", options: [override("as", BOTH)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export *as a from \"foo\"", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, + { code: "export *as\"a\" from \"foo\"", options: [override("as", NEITHER)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, //---------------------------------------------------------------------- // async //---------------------------------------------------------------------- - { code: "{} async function foo() {}", parserOptions: { ecmaVersion: 8 } }, - { code: "{}async function foo() {}", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "{} async function foo() {}", options: [override("async", BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: "{}async function foo() {}", options: [override("async", NEITHER)], parserOptions: { ecmaVersion: 8 } }, - { code: "{} async () => {}", parserOptions: { ecmaVersion: 8 } }, - { code: "{}async () => {}", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "{} async () => {}", options: [override("async", BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: "{}async () => {}", options: [override("async", NEITHER)], parserOptions: { ecmaVersion: 8 } }, - { code: "({async [b]() {}})", parserOptions: { ecmaVersion: 8 } }, - { code: "({async[b]() {}})", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "({async [b]() {}})", options: [override("async", BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: "({async[b]() {}})", options: [override("async", NEITHER)], parserOptions: { ecmaVersion: 8 } }, - { code: "class A {a(){} async [b]() {}}", parserOptions: { ecmaVersion: 8 } }, - { code: "class A {a(){}async[b]() {}}", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "class A {a(){} async [b]() {}}", options: [override("async", BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: "class A {a(){}async[b]() {}}", options: [override("async", NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { code: "{} async function foo() {}", languageOptions: { ecmaVersion: 8 } }, + { code: "{}async function foo() {}", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "{} async function foo() {}", options: [override("async", BOTH)], languageOptions: { ecmaVersion: 8 } }, + { code: "{}async function foo() {}", options: [override("async", NEITHER)], languageOptions: { ecmaVersion: 8 } }, + { code: "{} async () => {}", languageOptions: { ecmaVersion: 8 } }, + { code: "{}async () => {}", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "{} async () => {}", options: [override("async", BOTH)], languageOptions: { ecmaVersion: 8 } }, + { code: "{}async () => {}", options: [override("async", NEITHER)], languageOptions: { ecmaVersion: 8 } }, + { code: "({async [b]() {}})", languageOptions: { ecmaVersion: 8 } }, + { code: "({async[b]() {}})", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "({async [b]() {}})", options: [override("async", BOTH)], languageOptions: { ecmaVersion: 8 } }, + { code: "({async[b]() {}})", options: [override("async", NEITHER)], languageOptions: { ecmaVersion: 8 } }, + { code: "class A {a(){} async [b]() {}}", languageOptions: { ecmaVersion: 8 } }, + { code: "class A {a(){}async[b]() {}}", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "class A {a(){} async [b]() {}}", options: [override("async", BOTH)], languageOptions: { ecmaVersion: 8 } }, + { code: "class A {a(){}async[b]() {}}", options: [override("async", NEITHER)], languageOptions: { ecmaVersion: 8 } }, // not conflict with `array-bracket-spacing` - { code: "[async function foo() {}]", parserOptions: { ecmaVersion: 8 } }, - { code: "[ async function foo() {}]", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "[async function foo() {}]", languageOptions: { ecmaVersion: 8 } }, + { code: "[ async function foo() {}]", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `arrow-spacing` - { code: "() =>async function foo() {}", parserOptions: { ecmaVersion: 8 } }, - { code: "() => async function foo() {}", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "() =>async function foo() {}", languageOptions: { ecmaVersion: 8 } }, + { code: "() => async function foo() {}", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `block-spacing` - { code: "{async function foo() {} }", parserOptions: { ecmaVersion: 8 } }, - { code: "{ async function foo() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "{async function foo() {} }", languageOptions: { ecmaVersion: 8 } }, + { code: "{ async function foo() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `comma-spacing` - { code: "(0,async function foo() {})", parserOptions: { ecmaVersion: 8 } }, - { code: "(0, async function foo() {})", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "(0,async function foo() {})", languageOptions: { ecmaVersion: 8 } }, + { code: "(0, async function foo() {})", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `computed-property-spacing` - { code: "a[async function foo() {}]", parserOptions: { ecmaVersion: 8 } }, - { code: "({[async function foo() {}]: 0})", parserOptions: { ecmaVersion: 8 } }, - { code: "a[ async function foo() {}]", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "({[ async function foo() {}]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "a[async function foo() {}]", languageOptions: { ecmaVersion: 8 } }, + { code: "({[async function foo() {}]: 0})", languageOptions: { ecmaVersion: 8 } }, + { code: "a[ async function foo() {}]", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "({[ async function foo() {}]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `generator-star-spacing` - { code: "({ async* foo() {} })", parserOptions: { ecmaVersion: 2018 } }, - { code: "({ async *foo() {} })", options: [NEITHER], parserOptions: { ecmaVersion: 2018 } }, + { code: "({ async* foo() {} })", languageOptions: { ecmaVersion: 2018 } }, + { code: "({ async *foo() {} })", options: [NEITHER], languageOptions: { ecmaVersion: 2018 } }, // not conflict with `key-spacing` - { code: "({a:async function foo() {} })", parserOptions: { ecmaVersion: 8 } }, - { code: "({a: async function foo() {} })", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "({a:async function foo() {} })", languageOptions: { ecmaVersion: 8 } }, + { code: "({a: async function foo() {} })", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `semi-spacing` - { code: ";async function foo() {};", parserOptions: { ecmaVersion: 8 } }, - { code: "; async function foo() {} ;", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: ";async function foo() {};", languageOptions: { ecmaVersion: 8 } }, + { code: "; async function foo() {} ;", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `space-before-function-paren` - { code: "async() => {}", parserOptions: { ecmaVersion: 8 } }, - { code: "async () => {}", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async() => {}", languageOptions: { ecmaVersion: 8 } }, + { code: "async () => {}", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `space-in-parens` - { code: "(async function foo() {})", parserOptions: { ecmaVersion: 8 } }, - { code: "( async function foo() {})", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "(async function foo() {})", languageOptions: { ecmaVersion: 8 } }, + { code: "( async function foo() {})", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `space-infix-ops` - { code: "a =async function foo() {}", parserOptions: { ecmaVersion: 8 } }, - { code: "a = async function foo() {}", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "a =async function foo() {}", languageOptions: { ecmaVersion: 8 } }, + { code: "a = async function foo() {}", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `space-unary-ops` - { code: "!async function foo() {}", parserOptions: { ecmaVersion: 8 } }, - { code: "! async function foo() {}", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "!async function foo() {}", languageOptions: { ecmaVersion: 8 } }, + { code: "! async function foo() {}", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `template-curly-spacing` - { code: "`${async function foo() {}}`", parserOptions: { ecmaVersion: 8 } }, - { code: "`${ async function foo() {}}`", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "`${async function foo() {}}`", languageOptions: { ecmaVersion: 8 } }, + { code: "`${ async function foo() {}}`", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { ecmaVersion: 8, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { ecmaVersion: 8, parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // await //---------------------------------------------------------------------- - { code: "async function wrap() { {} await +1 }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { {}await +1 }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { {} await +1 }", options: [override("await", BOTH)], parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { {}await +1 }", options: [override("await", NEITHER)], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { {} await +1 }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { {}await +1 }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { {} await +1 }", options: [override("await", BOTH)], languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { {}await +1 }", options: [override("await", NEITHER)], languageOptions: { ecmaVersion: 8 } }, // not conflict with `array-bracket-spacing` - { code: "async function wrap() { [await a] }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { [ await a] }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { [await a] }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { [ await a] }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `arrow-spacing` - { code: "async () =>await a", parserOptions: { ecmaVersion: 8 } }, - { code: "async () => await a", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async () =>await a", languageOptions: { ecmaVersion: 8 } }, + { code: "async () => await a", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `block-spacing` - { code: "async function wrap() { {await a } }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { { await a } }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { {await a } }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { { await a } }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `comma-spacing` - { code: "async function wrap() { (0,await a) }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { (0, await a) }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { (0,await a) }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { (0, await a) }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `computed-property-spacing` - { code: "async function wrap() { a[await a] }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { ({[await a]: 0}) }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { a[ await a] }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { ({[ await a]: 0}) }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { a[await a] }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ({[await a]: 0}) }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { a[ await a] }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ({[ await a]: 0}) }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `key-spacing` - { code: "async function wrap() { ({a:await a }) }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { ({a: await a }) }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ({a:await a }) }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ({a: await a }) }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `semi-spacing` - { code: "async function wrap() { ;await a; }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { ; await a ; }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ;await a; }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ; await a ; }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `space-in-parens` - { code: "async function wrap() { (await a) }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { ( await a) }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { (await a) }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ( await a) }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `space-infix-ops` - { code: "async function wrap() { a =await a }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { a = await a }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { a+await a }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { a + await a }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { aawait a }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { a > await a }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { a =await a }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { a = await a }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { a+await a }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { a + await a }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { aawait a }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { a > await a }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `space-unary-ops` - { code: "async function wrap() { !await'a' }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { ! await 'a' }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { !await'a' }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { ! await 'a' }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `template-curly-spacing` - { code: "async function wrap() { `${await a}` }", parserOptions: { ecmaVersion: 8 } }, - { code: "async function wrap() { `${ await a}` }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { `${await a}` }", languageOptions: { ecmaVersion: 8 } }, + { code: "async function wrap() { `${ await a}` }", options: [NEITHER], languageOptions: { ecmaVersion: 8 } }, // not conflict with `jsx-curly-spacing` - { code: "async function wrap() { }", parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, - { code: "async function wrap() { }", options: [NEITHER], parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } }, + { code: "async function wrap() { }", languageOptions: { ecmaVersion: 8, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "async function wrap() { }", options: [NEITHER], languageOptions: { ecmaVersion: 8, parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // break @@ -369,92 +374,92 @@ ruleTester.run("keyword-spacing", rule, { // class //---------------------------------------------------------------------- - { code: "{} class Bar {}", parserOptions: { ecmaVersion: 6 } }, - { code: "(class {})", parserOptions: { ecmaVersion: 6 } }, - { code: "{}class Bar {}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "(class{})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "{} class Bar {}", options: [override("class", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "{}class Bar {}", options: [override("class", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "{} class Bar {}", languageOptions: { ecmaVersion: 6 } }, + { code: "(class {})", languageOptions: { ecmaVersion: 6 } }, + { code: "{}class Bar {}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "(class{})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "{} class Bar {}", options: [override("class", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "{}class Bar {}", options: [override("class", NEITHER)], languageOptions: { ecmaVersion: 6 } }, // not conflict with `array-bracket-spacing` - { code: "[class {}]", parserOptions: { ecmaVersion: 6 } }, - { code: "[ class{}]", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "[class {}]", languageOptions: { ecmaVersion: 6 } }, + { code: "[ class{}]", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `arrow-spacing` - { code: "() =>class {}", parserOptions: { ecmaVersion: 6 } }, - { code: "() => class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "() =>class {}", languageOptions: { ecmaVersion: 6 } }, + { code: "() => class{}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` - { code: "{class Bar {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "{ class Bar {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "{class Bar {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "{ class Bar {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `comma-spacing` - { code: "(0,class {})", parserOptions: { ecmaVersion: 6 } }, - { code: "(0, class{})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "(0,class {})", languageOptions: { ecmaVersion: 6 } }, + { code: "(0, class{})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `computed-property-spacing` - { code: "a[class {}]", parserOptions: { ecmaVersion: 6 } }, - { code: "({[class {}]: 0})", parserOptions: { ecmaVersion: 6 } }, - { code: "a[ class{}]", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "({[ class{}]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "a[class {}]", languageOptions: { ecmaVersion: 6 } }, + { code: "({[class {}]: 0})", languageOptions: { ecmaVersion: 6 } }, + { code: "a[ class{}]", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "({[ class{}]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` - { code: "({a:class {} })", parserOptions: { ecmaVersion: 6 } }, - { code: "({a: class{} })", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({a:class {} })", languageOptions: { ecmaVersion: 6 } }, + { code: "({a: class{} })", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: ";class Bar {};", parserOptions: { ecmaVersion: 6 } }, - { code: "; class Bar {} ;", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: ";class Bar {};", languageOptions: { ecmaVersion: 6 } }, + { code: "; class Bar {} ;", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-in-parens` - { code: "( class{})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "( class{})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-infix-ops` - { code: "a =class {}", parserOptions: { ecmaVersion: 6 } }, - { code: "a = class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "a+class {}", parserOptions: { ecmaVersion: 6 } }, - { code: "a + class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "aclass {}", parserOptions: { ecmaVersion: 6 } }, - { code: "a > class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "a =class {}", languageOptions: { ecmaVersion: 6 } }, + { code: "a = class{}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "a+class {}", languageOptions: { ecmaVersion: 6 } }, + { code: "a + class{}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "aclass {}", languageOptions: { ecmaVersion: 6 } }, + { code: "a > class{}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-unary-ops` - { code: "!class {}", parserOptions: { ecmaVersion: 6 } }, - { code: "! class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "!class {}", languageOptions: { ecmaVersion: 6 } }, + { code: "! class{}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `template-curly-spacing` - { code: "`${class {}}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ class{}}`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${class {}}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ class{}}`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, // private names - { code: "class C {\n#x;\nfoo() {\nfor (this.#x of bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C {\n#x;\nfoo() {\nfor (this.#x in bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } }, + { code: "class C {\n#x;\nfoo() {\nfor (this.#x of bar){}}}", options: [{ before: false }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C {\n#x;\nfoo() {\nfor (this.#x in bar){}}}", options: [{ before: false }], languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- // const //---------------------------------------------------------------------- - { code: "{} const [a] = b", parserOptions: { ecmaVersion: 6 } }, - { code: "{} const {a} = b", parserOptions: { ecmaVersion: 6 } }, - { code: "{}const[a] = b", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "{}const{a} = b", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "{} const [a] = b", options: [override("const", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "{} const {a} = b", options: [override("const", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "{}const[a] = b", options: [override("const", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "{}const{a} = b", options: [override("const", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "{} const [a] = b", languageOptions: { ecmaVersion: 6 } }, + { code: "{} const {a} = b", languageOptions: { ecmaVersion: 6 } }, + { code: "{}const[a] = b", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "{}const{a} = b", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "{} const [a] = b", options: [override("const", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "{} const {a} = b", options: [override("const", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "{}const[a] = b", options: [override("const", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "{}const{a} = b", options: [override("const", NEITHER)], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` - { code: "{const a = b}", parserOptions: { ecmaVersion: 6 } }, - { code: "{ const a = b}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "{const a = b}", languageOptions: { ecmaVersion: 6 } }, + { code: "{ const a = b}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: ";const a = b;", parserOptions: { ecmaVersion: 6 } }, - { code: "; const a = b ;", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: ";const a = b;", languageOptions: { ecmaVersion: 6 } }, + { code: "; const a = b ;", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- // continue @@ -521,8 +526,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "[ delete foo.a]", options: [NEITHER] }, // not conflict with `arrow-spacing` - { code: "(() =>delete foo.a)", parserOptions: { ecmaVersion: 6 } }, - { code: "(() => delete foo.a)", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "(() =>delete foo.a)", languageOptions: { ecmaVersion: 6 } }, + { code: "(() => delete foo.a)", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` "{delete foo.a }", @@ -534,9 +539,9 @@ ruleTester.run("keyword-spacing", rule, { // not conflict with `computed-property-spacing` "a[delete foo.a]", - { code: "({[delete foo.a]: 0})", parserOptions: { ecmaVersion: 6 } }, + { code: "({[delete foo.a]: 0})", languageOptions: { ecmaVersion: 6 } }, { code: "a[ delete foo.a]", options: [NEITHER] }, - { code: "({[ delete foo.a]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({[ delete foo.a]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` "({a:delete foo.a })", @@ -565,12 +570,12 @@ ruleTester.run("keyword-spacing", rule, { { code: "! delete (foo.a)", options: [NEITHER] }, // not conflict with `template-curly-spacing` - { code: "`${delete foo.a}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ delete foo.a}`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${delete foo.a}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ delete foo.a}`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // do @@ -622,25 +627,25 @@ ruleTester.run("keyword-spacing", rule, { // export //---------------------------------------------------------------------- - { code: "var a = 0; {} export {a}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{} export default a", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{} export * from \"a\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var a = 0; {}export{a}", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var a = 0; {} export {a}", options: [override("export", BOTH)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var a = 0; {}export{a}", options: [override("export", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a = 0; {} export {a}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{} export default a", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{} export * from \"a\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a = 0; {}export{a}", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a = 0; {} export {a}", options: [override("export", BOTH)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a = 0; {}export{a}", options: [override("export", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // not conflict with `semi-spacing` - { code: "var a = 0;\n;export {a}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var a = 0;\n; export{a}", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a = 0;\n;export {a}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a = 0;\n; export{a}", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- // extends //---------------------------------------------------------------------- - { code: "class Bar extends [] {}", parserOptions: { ecmaVersion: 6 } }, - { code: "class Bar extends[] {}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class Bar extends [] {}", options: [override("extends", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "class Bar extends[] {}", options: [override("extends", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "class Bar extends [] {}", languageOptions: { ecmaVersion: 6 } }, + { code: "class Bar extends[] {}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class Bar extends [] {}", options: [override("extends", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "class Bar extends[] {}", options: [override("extends", NEITHER)], languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- // finally @@ -659,55 +664,55 @@ ruleTester.run("keyword-spacing", rule, { "{} for (;;) {}", "{} for (var foo in obj) {}", - { code: "{} for (var foo of list) {}", parserOptions: { ecmaVersion: 6 } }, + { code: "{} for (var foo of list) {}", languageOptions: { ecmaVersion: 6 } }, { code: "{}for(;;) {}", options: [NEITHER] }, { code: "{}for(var foo in obj) {}", options: [NEITHER] }, - { code: "{}for(var foo of list) {}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "{}for(var foo of list) {}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, { code: "{} for (;;) {}", options: [override("for", BOTH)] }, { code: "{} for (var foo in obj) {}", options: [override("for", BOTH)] }, - { code: "{} for (var foo of list) {}", options: [override("for", BOTH)], parserOptions: { ecmaVersion: 6 } }, + { code: "{} for (var foo of list) {}", options: [override("for", BOTH)], languageOptions: { ecmaVersion: 6 } }, { code: "{}for(;;) {}", options: [override("for", NEITHER)] }, { code: "{}for(var foo in obj) {}", options: [override("for", NEITHER)] }, - { code: "{}for(var foo of list) {}", options: [override("for", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "{}for(var foo of list) {}", options: [override("for", NEITHER)], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` "{for (;;) {} }", "{for (var foo in obj) {} }", - { code: "{for (var foo of list) {} }", parserOptions: { ecmaVersion: 6 } }, + { code: "{for (var foo of list) {} }", languageOptions: { ecmaVersion: 6 } }, { code: "{ for(;;) {} }", options: [NEITHER] }, { code: "{ for(var foo in obj) {} }", options: [NEITHER] }, - { code: "{ for(var foo of list) {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "{ for(var foo of list) {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` ";for (;;) {}", ";for (var foo in obj) {}", - { code: ";for (var foo of list) {}", parserOptions: { ecmaVersion: 6 } }, + { code: ";for (var foo of list) {}", languageOptions: { ecmaVersion: 6 } }, { code: "; for(;;) {}", options: [NEITHER] }, { code: "; for(var foo in obj) {}", options: [NEITHER] }, - { code: "; for(var foo of list) {}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "; for(var foo of list) {}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- // from //---------------------------------------------------------------------- - { code: "import {foo} from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {foo} from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export * from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export * as \"x\" from \"foo\"", parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "import{foo}from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export{foo}from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export*from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export*as x from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 2020, sourceType: "module" } }, - { code: "export*as\"x\"from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "import{foo} from \"foo\"", options: [override("from", BOTH)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export{foo} from \"foo\"", options: [override("from", BOTH)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export* from \"foo\"", options: [override("from", BOTH)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export*as\"x\" from \"foo\"", options: [override("from", BOTH)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "import {foo}from\"foo\"", options: [override("from", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {foo}from\"foo\"", options: [override("from", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export *from\"foo\"", options: [override("from", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export * as x from\"foo\"", options: [override("from", NEITHER)], parserOptions: { ecmaVersion: 2020, sourceType: "module" } }, - { code: "export * as \"x\"from\"foo\"", options: [override("from", NEITHER)], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import {foo} from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {foo} from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export * from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export * as \"x\" from \"foo\"", languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import{foo}from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export{foo}from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export*from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export*as x from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, + { code: "export*as\"x\"from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import{foo} from \"foo\"", options: [override("from", BOTH)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export{foo} from \"foo\"", options: [override("from", BOTH)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export* from \"foo\"", options: [override("from", BOTH)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export*as\"x\" from \"foo\"", options: [override("from", BOTH)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import {foo}from\"foo\"", options: [override("from", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {foo}from\"foo\"", options: [override("from", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export *from\"foo\"", options: [override("from", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export * as x from\"foo\"", options: [override("from", NEITHER)], languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, + { code: "export * as \"x\"from\"foo\"", options: [override("from", NEITHER)], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, //---------------------------------------------------------------------- // function @@ -723,8 +728,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "[ function() {}]", options: [NEITHER] }, // not conflict with `arrow-spacing` - { code: "(() =>function() {})", parserOptions: { ecmaVersion: 6 } }, - { code: "(() => function() {})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "(() =>function() {})", languageOptions: { ecmaVersion: 6 } }, + { code: "(() => function() {})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` "{function foo() {} }", @@ -736,13 +741,13 @@ ruleTester.run("keyword-spacing", rule, { // not conflict with `computed-property-spacing` "a[function() {}]", - { code: "({[function() {}]: 0})", parserOptions: { ecmaVersion: 6 } }, + { code: "({[function() {}]: 0})", languageOptions: { ecmaVersion: 6 } }, { code: "a[ function() {}]", options: [NEITHER] }, - { code: "({[ function(){}]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({[ function(){}]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `generator-star-spacing` - { code: "function* foo() {}", parserOptions: { ecmaVersion: 6 } }, - { code: "function *foo() {}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() {}", languageOptions: { ecmaVersion: 6 } }, + { code: "function *foo() {}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` "({a:function() {} })", @@ -774,37 +779,37 @@ ruleTester.run("keyword-spacing", rule, { { code: "! function() {}", options: [NEITHER] }, // not conflict with `template-curly-spacing` - { code: "`${function() {}}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ function() {}}`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${function() {}}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ function() {}}`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // get //---------------------------------------------------------------------- - { code: "({ get [b]() {} })", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {} get [b]() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {} static get [b]() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "({ get[b]() {} })", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {}get[b]() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {}static get[b]() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "({ get [b]() {} })", options: [override("get", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {} get [b]() {} }", options: [override("get", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "({ get[b]() {} })", options: [override("get", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {}get[b]() {} }", options: [override("get", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a; get #b() {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a;get#b() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, + { code: "({ get [b]() {} })", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {} get [b]() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {} static get [b]() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "({ get[b]() {} })", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {}get[b]() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {}static get[b]() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "({ get [b]() {} })", options: [override("get", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {} get [b]() {} }", options: [override("get", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "({ get[b]() {} })", options: [override("get", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {}get[b]() {} }", options: [override("get", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a; get #b() {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a;get#b() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, // not conflict with `comma-spacing` - { code: "({ a,get [b]() {} })", parserOptions: { ecmaVersion: 6 } }, - { code: "({ a, get[b]() {} })", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({ a,get [b]() {} })", languageOptions: { ecmaVersion: 6 } }, + { code: "({ a, get[b]() {} })", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: "class A { ;get #b() {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { ; get#b() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, + { code: "class A { ;get #b() {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { ; get#b() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- // if @@ -831,29 +836,29 @@ ruleTester.run("keyword-spacing", rule, { // import //---------------------------------------------------------------------- - { code: "{} import {a} from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{} import a from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{} import * as a from \"a\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{}import{a}from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{}import*as a from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{} import {a}from\"foo\"", options: [override("import", BOTH)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{} import *as a from\"foo\"", options: [override("import", BOTH)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{}import{a} from \"foo\"", options: [override("import", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "{}import* as a from \"foo\"", options: [override("import", NEITHER)], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{} import {a} from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{} import a from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{} import * as a from \"a\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{}import{a}from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{}import*as a from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{} import {a}from\"foo\"", options: [override("import", BOTH)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{} import *as a from\"foo\"", options: [override("import", BOTH)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{}import{a} from \"foo\"", options: [override("import", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "{}import* as a from \"foo\"", options: [override("import", NEITHER)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // not conflict with `semi-spacing` - { code: ";import {a} from \"foo\"", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "; import{a}from\"foo\"", options: [NEITHER], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: ";import {a} from \"foo\"", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "; import{a}from\"foo\"", options: [NEITHER], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- // in //---------------------------------------------------------------------- - { code: "for ([foo] in {foo: 0}) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "for([foo]in{foo: 0}) {}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "for([foo] in {foo: 0}) {}", options: [override("in", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "for ([foo]in{foo: 0}) {}", options: [override("in", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "for ([foo] in ({foo: 0})) {}", parserOptions: { ecmaVersion: 6 } }, + { code: "for ([foo] in {foo: 0}) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "for([foo]in{foo: 0}) {}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "for([foo] in {foo: 0}) {}", options: [override("in", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "for ([foo]in{foo: 0}) {}", options: [override("in", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "for ([foo] in ({foo: 0})) {}", languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-infix-ops` "if (\"foo\"in{foo: 0}) {}", @@ -871,18 +876,18 @@ ruleTester.run("keyword-spacing", rule, { // let //---------------------------------------------------------------------- - { code: "{} let [a] = b", parserOptions: { ecmaVersion: 6 } }, - { code: "{}let[a] = b", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "{} let [a] = b", options: [override("let", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "{}let[a] = b", options: [override("let", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "{} let [a] = b", languageOptions: { ecmaVersion: 6 } }, + { code: "{}let[a] = b", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "{} let [a] = b", options: [override("let", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "{}let[a] = b", options: [override("let", NEITHER)], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` - { code: "{let [a] = b }", parserOptions: { ecmaVersion: 6 } }, - { code: "{ let[a] = b }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "{let [a] = b }", languageOptions: { ecmaVersion: 6 } }, + { code: "{ let[a] = b }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: ";let [a] = b", parserOptions: { ecmaVersion: 6 } }, - { code: "; let[a] = b", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: ";let [a] = b", languageOptions: { ecmaVersion: 6 } }, + { code: "; let[a] = b", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- // new @@ -898,8 +903,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "[ new foo()]", options: [NEITHER] }, // not conflict with `arrow-spacing` - { code: "(() =>new foo())", parserOptions: { ecmaVersion: 6 } }, - { code: "(() => new foo())", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "(() =>new foo())", languageOptions: { ecmaVersion: 6 } }, + { code: "(() => new foo())", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` "{new foo() }", @@ -911,9 +916,9 @@ ruleTester.run("keyword-spacing", rule, { // not conflict with `computed-property-spacing` "a[new foo()]", - { code: "({[new foo()]: 0})", parserOptions: { ecmaVersion: 6 } }, + { code: "({[new foo()]: 0})", languageOptions: { ecmaVersion: 6 } }, { code: "a[ new foo()]", options: [NEITHER] }, - { code: "({[ new foo()]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({[ new foo()]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` "({a:new foo() })", @@ -942,22 +947,22 @@ ruleTester.run("keyword-spacing", rule, { { code: "! new (foo)()", options: [NEITHER] }, // not conflict with `template-curly-spacing` - { code: "`${new foo()}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ new foo()}`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${new foo()}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ new foo()}`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // of //---------------------------------------------------------------------- - { code: "for ([foo] of {foo: 0}) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "for([foo]of{foo: 0}) {}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "for([foo] of {foo: 0}) {}", options: [override("of", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "for ([foo]of{foo: 0}) {}", options: [override("of", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "for ([foo] of ({foo: 0})) {}", parserOptions: { ecmaVersion: 6 } }, + { code: "for ([foo] of {foo: 0}) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "for([foo]of{foo: 0}) {}", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "for([foo] of {foo: 0}) {}", options: [override("of", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "for ([foo]of{foo: 0}) {}", options: [override("of", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "for ([foo] of ({foo: 0})) {}", languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- // return @@ -966,13 +971,13 @@ ruleTester.run("keyword-spacing", rule, { "function foo() { {} return +a }", { code: "function foo() { return

; }", - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "function foo() { {}return+a }", options: [NEITHER] }, { code: "function foo() { return

; }", options: [{ after: false }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "function foo() { {} return +a }", options: [override("return", BOTH)] }, { code: "function foo() { {}return+a }", options: [override("return", NEITHER)] }, @@ -991,122 +996,122 @@ ruleTester.run("keyword-spacing", rule, { // set //---------------------------------------------------------------------- - { code: "({ set [b](value) {} })", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {} set [b](value) {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {} static set [b](value) {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "({ set[b](value) {} })", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {}set[b](value) {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "({ set [b](value) {} })", options: [override("set", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {} set [b](value) {} }", options: [override("set", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "({ set[b](value) {} })", options: [override("set", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {}set[b](value) {} }", options: [override("set", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a; set #b(value) {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a;set#b(value) {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, + { code: "({ set [b](value) {} })", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {} set [b](value) {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {} static set [b](value) {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "({ set[b](value) {} })", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {}set[b](value) {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "({ set [b](value) {} })", options: [override("set", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {} set [b](value) {} }", options: [override("set", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "({ set[b](value) {} })", options: [override("set", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {}set[b](value) {} }", options: [override("set", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a; set #b(value) {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a;set#b(value) {} }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, // not conflict with `comma-spacing` - { code: "({ a,set [b](value) {} })", parserOptions: { ecmaVersion: 6 } }, - { code: "({ a, set[b](value) {} })", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({ a,set [b](value) {} })", languageOptions: { ecmaVersion: 6 } }, + { code: "({ a, set[b](value) {} })", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: "class A { ;set #b(value) {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { ; set#b(value) {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, + { code: "class A { ;set #b(value) {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { ; set#b(value) {} }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- // static //---------------------------------------------------------------------- - { code: "class A { a() {} static [b]() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {}static[b]() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {} static [b]() {} }", options: [override("static", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() {}static[b]() {} }", options: [override("static", NEITHER)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a; static [b]; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a;static[b]; }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a; static #b; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a;static#b; }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a() {} static {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a() {}static{} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a() {} static {} }", options: [override("static", BOTH)], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a() {}static{} }", options: [override("static", NEITHER)], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { a() {}\nstatic\n{} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, + { code: "class A { a() {} static [b]() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {}static[b]() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {} static [b]() {} }", options: [override("static", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() {}static[b]() {} }", options: [override("static", NEITHER)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a; static [b]; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a;static[b]; }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a; static #b; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a;static#b; }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a() {} static {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a() {}static{} }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a() {} static {} }", options: [override("static", BOTH)], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a() {}static{} }", options: [override("static", NEITHER)], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { a() {}\nstatic\n{} }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, // not conflict with `generator-star-spacing` - { code: "class A { static* [a]() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { static *[a]() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A { static* [a]() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { static *[a]() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: "class A { ;static a() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { ; static a() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A { ;static a; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { ; static a ; }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { ;static {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { ; static{} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } }, + { code: "class A { ;static a() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { ; static a() {} }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A { ;static a; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { ; static a ; }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { ;static {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { ; static{} }", options: [NEITHER], languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- // super //---------------------------------------------------------------------- - { code: "class A extends B { a() { {} super[b](); } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { a() { {}super[b](); } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { a() { {} super[b](); } }", options: [override("super", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { a() { {}super[b](); } }", options: [override("super", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { a() { {} super[b](); } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { a() { {}super[b](); } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { a() { {} super[b](); } }", options: [override("super", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { a() { {}super[b](); } }", options: [override("super", NEITHER)], languageOptions: { ecmaVersion: 6 } }, // not conflict with `array-bracket-spacing` - { code: "class A extends B { constructor() { [super()]; } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { [ super() ]; } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { [super()]; } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { [ super() ]; } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `arrow-spacing` - { code: "class A extends B { constructor() { () =>super(); } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { () => super(); } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { () =>super(); } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { () => super(); } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` - { code: "class A extends B { constructor() {super()} }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() {super()} }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { super() } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `comma-spacing` - { code: "class A extends B { constructor() { (0,super()) } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { (0, super()) } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { (0,super()) } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { (0, super()) } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `computed-property-spacing` - { code: "class A extends B { constructor() { ({[super()]: 0}) } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { ({[ super() ]: 0}) } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ({[super()]: 0}) } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ({[ super() ]: 0}) } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` - { code: "class A extends B { constructor() { ({a:super() }) } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { ({a: super() }) } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ({a:super() }) } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ({a: super() }) } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `func-call-spacing` - { code: "class A extends B { constructor() { super(); } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { super (); } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { super(); } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { super (); } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: "class A extends B { constructor() { ;super(); } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { ; super() ; } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ;super(); } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ; super() ; } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-in-parens` - { code: "class A extends B { constructor() { (super()) } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { ( super() ) } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { (super()) } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ( super() ) } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-infix-ops` - { code: "class A extends B { constructor() { b =super() } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { b = super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { b+super() } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { b + super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { bsuper() } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { b > super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { b =super() } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { b = super() } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { b+super() } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { b + super() } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { bsuper() } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { b > super() } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-unary-ops` - { code: "class A extends B { constructor() { !super() } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { ! super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { !super() } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { ! super() } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `template-curly-spacing` - { code: "class A extends B { constructor() { `${super()}` } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A extends B { constructor() { `${ super() }` } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { `${super()}` } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A extends B { constructor() { `${ super() }` } }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "class A extends B { constructor() { } }", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "class A extends B { constructor() { } }", options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { code: "class A extends B { constructor() { } }", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "class A extends B { constructor() { } }", options: [NEITHER], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // switch @@ -1136,12 +1141,16 @@ ruleTester.run("keyword-spacing", rule, { { code: " this.blah", - parser: fixtureParser("keyword-spacing", "prefix-cast-operator-space") + languageOptions: { + parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-space")) + } }, { code: "this.blah", options: [override("this", { before: false })], - parser: fixtureParser("keyword-spacing", "prefix-cast-operator-no-space") + languageOptions: { + parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-no-space")) + } }, // not conflict with `array-bracket-spacing` @@ -1149,8 +1158,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "[ this ]", options: [NEITHER] }, // not conflict with `arrow-spacing` - { code: "(() =>this)", parserOptions: { ecmaVersion: 6 } }, - { code: "(() => this)", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "(() =>this)", languageOptions: { ecmaVersion: 6 } }, + { code: "(() => this)", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` "{this}", @@ -1162,9 +1171,9 @@ ruleTester.run("keyword-spacing", rule, { // not conflict with `computed-property-spacing` "a[this]", - { code: "({[this]: 0})", parserOptions: { ecmaVersion: 6 } }, + { code: "({[this]: 0})", languageOptions: { ecmaVersion: 6 } }, { code: "a[ this ]", options: [NEITHER] }, - { code: "({[ this ]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({[ this ]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` "({a:this })", @@ -1199,12 +1208,12 @@ ruleTester.run("keyword-spacing", rule, { { code: "! this", options: [NEITHER] }, // not conflict with `template-curly-spacing` - { code: "`${this}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ this }`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${this}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ this }`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // throw @@ -1256,8 +1265,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "[ typeof foo]", options: [NEITHER] }, // not conflict with `arrow-spacing` - { code: "(() =>typeof foo)", parserOptions: { ecmaVersion: 6 } }, - { code: "(() => typeof foo)", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "(() =>typeof foo)", languageOptions: { ecmaVersion: 6 } }, + { code: "(() => typeof foo)", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` "{typeof foo }", @@ -1269,9 +1278,9 @@ ruleTester.run("keyword-spacing", rule, { // not conflict with `computed-property-spacing` "a[typeof foo]", - { code: "({[typeof foo]: 0})", parserOptions: { ecmaVersion: 6 } }, + { code: "({[typeof foo]: 0})", languageOptions: { ecmaVersion: 6 } }, { code: "a[ typeof foo]", options: [NEITHER] }, - { code: "({[ typeof foo]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({[ typeof foo]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` "({a:typeof foo })", @@ -1300,21 +1309,21 @@ ruleTester.run("keyword-spacing", rule, { { code: "! typeof +foo", options: [NEITHER] }, // not conflict with `template-curly-spacing` - { code: "`${typeof foo}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ typeof foo}`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${typeof foo}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ typeof foo}`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // var //---------------------------------------------------------------------- - { code: "{} var [a] = b", parserOptions: { ecmaVersion: 6 } }, - { code: "{}var[a] = b", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "{} var [a] = b", options: [override("var", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "{}var[a] = b", options: [override("var", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "{} var [a] = b", languageOptions: { ecmaVersion: 6 } }, + { code: "{}var[a] = b", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "{} var [a] = b", options: [override("var", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "{}var[a] = b", options: [override("var", NEITHER)], languageOptions: { ecmaVersion: 6 } }, "for (var foo in [1, 2, 3]) {}", // not conflict with `block-spacing` @@ -1339,8 +1348,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "[ void foo]", options: [NEITHER] }, // not conflict with `arrow-spacing` - { code: "(() =>void foo)", parserOptions: { ecmaVersion: 6 } }, - { code: "(() => void foo)", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "(() =>void foo)", languageOptions: { ecmaVersion: 6 } }, + { code: "(() => void foo)", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `block-spacing` "{void foo }", @@ -1352,9 +1361,9 @@ ruleTester.run("keyword-spacing", rule, { // not conflict with `computed-property-spacing` "a[void foo]", - { code: "({[void foo]: 0})", parserOptions: { ecmaVersion: 6 } }, + { code: "({[void foo]: 0})", languageOptions: { ecmaVersion: 6 } }, { code: "a[ void foo]", options: [NEITHER] }, - { code: "({[ void foo]: 0})", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "({[ void foo]: 0})", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` "({a:void foo })", @@ -1383,12 +1392,12 @@ ruleTester.run("keyword-spacing", rule, { { code: "! void +foo", options: [NEITHER] }, // not conflict with `template-curly-spacing` - { code: "`${void foo}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ void foo}`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${void foo}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ void foo}`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "", options: [NEITHER], parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", options: [NEITHER], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // while @@ -1436,76 +1445,76 @@ ruleTester.run("keyword-spacing", rule, { // yield //---------------------------------------------------------------------- - { code: "function* foo() { {} yield foo }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { {}yield foo }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { {} yield foo }", options: [override("yield", BOTH)], parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { {}yield foo }", options: [override("yield", NEITHER)], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { {} yield foo }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { {}yield foo }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { {} yield foo }", options: [override("yield", BOTH)], languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { {}yield foo }", options: [override("yield", NEITHER)], languageOptions: { ecmaVersion: 6 } }, // not conflict with `array-bracket-spacing` - { code: "function* foo() { [yield] }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { [ yield ] }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { [yield] }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { [ yield ] }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, /* * This is invalid syntax: https://github.com/eslint/eslint/issues/5405 * not conflict with `arrow-spacing` - * {code: "function* foo() { (() =>yield foo) }", parserOptions: {ecmaVersion: 6}}, - * {code: "function* foo() { (() => yield foo) }", options: [NEITHER], parserOptions: {ecmaVersion: 6}}, + * {code: "function* foo() { (() =>yield foo) }", languageOptions: {ecmaVersion: 6}}, + * {code: "function* foo() { (() => yield foo) }", options: [NEITHER], languageOptions: {ecmaVersion: 6}}, * not conflict with `block-spacing` */ - { code: "function* foo() {yield}", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { yield }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() {yield}", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { yield }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `comma-spacing` - { code: "function* foo() { (0,yield foo) }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { (0, yield foo) }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { (0,yield foo) }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { (0, yield foo) }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `computed-property-spacing` - { code: "function* foo() { a[yield] }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { ({[yield]: 0}) }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { a[ yield ] }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { ({[ yield ]: 0}) }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { a[yield] }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { ({[yield]: 0}) }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { a[ yield ] }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { ({[ yield ]: 0}) }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `key-spacing` - { code: "function* foo() { ({a:yield foo }) }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { ({a: yield foo }) }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { ({a:yield foo }) }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { ({a: yield foo }) }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `semi-spacing` - { code: "function* foo() { ;yield; }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { ; yield ; }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { ;yield; }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { ; yield ; }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-in-parens` - { code: "function* foo() { (yield) }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { ( yield ) }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { (yield) }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { ( yield ) }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-infix-ops` - { code: "function* foo() { a =yield foo }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { a = yield foo }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { a =yield foo }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { a = yield foo }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `space-unary-ops` - { code: "function* foo() { yield+foo }", parserOptions: { ecmaVersion: 6 } }, - { code: "function* foo() { yield +foo }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { yield+foo }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { yield +foo }", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `template-curly-spacing` - { code: "`${yield}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${ yield}`", options: [NEITHER], parserOptions: { ecmaVersion: 6 } }, + { code: "`${yield}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${ yield}`", options: [NEITHER], languageOptions: { ecmaVersion: 6 } }, // not conflict with `jsx-curly-spacing` - { code: "function* foo() { }", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "function* foo() { }", options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, + { code: "function* foo() { }", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "function* foo() { }", options: [NEITHER], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, //---------------------------------------------------------------------- // typescript parser //---------------------------------------------------------------------- // class declaration don't error with decorator - { code: "@dec class Foo {}", parser: parser("typescript-parsers/decorator-with-class") }, + { code: "@dec class Foo {}", languageOptions: { parser: require(parser("typescript-parsers/decorator-with-class")) } }, // get, set, async methods don't error with decorator - { code: "class Foo { @dec get bar() {} @dec set baz() {} @dec async baw() {} }", parser: parser("typescript-parsers/decorator-with-class-methods") }, - { code: "class Foo { @dec static qux() {} @dec static get bar() {} @dec static set baz() {} @dec static async baw() {} }", parser: parser("typescript-parsers/decorator-with-static-class-methods") }, + { code: "class Foo { @dec get bar() {} @dec set baz() {} @dec async baw() {} }", languageOptions: { parser: require(parser("typescript-parsers/decorator-with-class-methods")) } }, + { code: "class Foo { @dec static qux() {} @dec static get bar() {} @dec static set baz() {} @dec static async baw() {} }", languageOptions: { parser: require(parser("typescript-parsers/decorator-with-static-class-methods")) } }, // type keywords can be used as parameters in arrow functions - { code: "symbol => 4;", parser: parser("typescript-parsers/keyword-with-arrow-function") } + { code: "symbol => 4;", languageOptions: { parser: require(parser("typescript-parsers/keyword-with-arrow-function")) } } ], invalid: [ @@ -1518,119 +1527,118 @@ ruleTester.run("keyword-spacing", rule, { { code: "import { \"a\"as b } from \"foo\"", output: "import { \"a\" as b } from \"foo\"", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBefore("as") + errors: expectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import{ \"a\" as b }from\"foo\"", output: "import{ \"a\"as b }from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBefore("as") + errors: unexpectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import{ \"a\"as b }from\"foo\"", output: "import{ \"a\" as b }from\"foo\"", options: [override("as", BOTH)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBefore("as") + errors: expectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import { \"a\" as b } from \"foo\"", output: "import { \"a\"as b } from \"foo\"", options: [override("as", NEITHER)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBefore("as") + errors: unexpectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, // export { a as b } { code: "let a; export { a as\"b\" };", output: "let a; export { a as \"b\" };", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedAfter("as") + errors: expectedAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export { \"a\"as b } from \"foo\";", output: "export { \"a\" as b } from \"foo\";", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBefore("as") + errors: expectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export { \"a\"as\"b\" } from \"foo\";", output: "export { \"a\" as \"b\" } from \"foo\";", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBeforeAndAfter("as") + errors: expectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "let a; export{ a as \"b\" };", output: "let a; export{ a as\"b\" };", options: [NEITHER], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedAfter("as") + errors: unexpectedAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export{ \"a\" as b }from\"foo\";", output: "export{ \"a\"as b }from\"foo\";", options: [NEITHER], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBefore("as") + errors: unexpectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export{ \"a\" as \"b\" }from\"foo\";", output: "export{ \"a\"as\"b\" }from\"foo\";", options: [NEITHER], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("as") + errors: unexpectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "let a; export{ a as\"b\" };", output: "let a; export{ a as \"b\" };", options: [override("as", BOTH)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedAfter("as") + errors: expectedAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export{ \"a\"as b }from\"foo\";", output: "export{ \"a\" as b }from\"foo\";", options: [override("as", BOTH)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBefore("as") + errors: expectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export{ \"a\"as\"b\" }from\"foo\";", output: "export{ \"a\" as \"b\" }from\"foo\";", options: [override("as", BOTH)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBeforeAndAfter("as") + errors: expectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "let a; export { a as \"b\" };", output: "let a; export { a as\"b\" };", options: [override("as", NEITHER)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedAfter("as") + errors: unexpectedAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export { \"a\" as b } from \"foo\";", output: "export { \"a\"as b } from \"foo\";", options: [override("as", NEITHER)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBefore("as") + errors: unexpectedBefore("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export { \"a\" as \"b\" } from \"foo\";", output: "export { \"a\"as\"b\" } from \"foo\";", options: [override("as", NEITHER)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("as") + errors: unexpectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, // import * as a { code: "import *as a from \"foo\"", output: "import * as a from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBefore", data: { value: "as" }, @@ -1638,13 +1646,13 @@ ruleTester.run("keyword-spacing", rule, { column: 9, endLine: 1, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import* as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBefore", data: { value: "as" }, @@ -1652,13 +1660,13 @@ ruleTester.run("keyword-spacing", rule, { column: 8, endLine: 1, endColumn: 9 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import* as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBefore", data: { value: "as" }, @@ -1666,77 +1674,78 @@ ruleTester.run("keyword-spacing", rule, { column: 8, endLine: 1, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import*as a from\"foo\"", output: "import* as a from\"foo\"", options: [override("as", BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBefore("as") + errors: expectedBefore("as"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as a from \"foo\"", output: "import *as a from \"foo\"", options: [override("as", NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBefore("as") + errors: unexpectedBefore("as"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // export * as a { code: "export *as a from \"foo\"", output: "export * as a from \"foo\"", - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, - errors: expectedBefore("as") + errors: expectedBefore("as"), + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "export *as\"a\" from \"foo\"", output: "export * as \"a\" from \"foo\"", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBeforeAndAfter("as") + errors: expectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export* as a from\"foo\"", output: "export*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, - errors: unexpectedBefore("as") + errors: unexpectedBefore("as"), + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "export* as \"a\"from\"foo\"", output: "export*as\"a\"from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("as") + errors: unexpectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export*as a from\"foo\"", output: "export* as a from\"foo\"", options: [override("as", BOTH)], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, - errors: expectedBefore("as") + errors: expectedBefore("as"), + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "export*as\"a\"from\"foo\"", output: "export* as \"a\"from\"foo\"", options: [override("as", BOTH)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBeforeAndAfter("as") + errors: expectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "export * as a from \"foo\"", output: "export *as a from \"foo\"", options: [override("as", NEITHER)], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, - errors: unexpectedBefore("as") + errors: unexpectedBefore("as"), + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "export * as \"a\" from \"foo\"", output: "export *as\"a\" from \"foo\"", options: [override("as", NEITHER)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("as") + errors: unexpectedBeforeAndAfter("as"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -1746,110 +1755,110 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}async function foo() {}", output: "{} async function foo() {}", - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore("async") + errors: expectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "{} async function foo() {}", output: "{}async function foo() {}", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore("async") + errors: unexpectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "{}async function foo() {}", output: "{} async function foo() {}", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore("async") + errors: expectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "{} async function foo() {}", output: "{}async function foo() {}", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore("async") + errors: unexpectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "{}async () => {}", output: "{} async () => {}", - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore("async") + errors: expectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "{} async () => {}", output: "{}async () => {}", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore("async") + errors: unexpectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "{}async () => {}", output: "{} async () => {}", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore("async") + errors: expectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "{} async () => {}", output: "{}async () => {}", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore("async") + errors: unexpectedBefore("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "({async[b]() {}})", output: "({async [b]() {}})", - parserOptions: { ecmaVersion: 8 }, - errors: expectedAfter("async") + errors: expectedAfter("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "({async [b]() {}})", output: "({async[b]() {}})", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedAfter("async") + errors: unexpectedAfter("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "({async[b]() {}})", output: "({async [b]() {}})", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedAfter("async") + errors: expectedAfter("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "({async [b]() {}})", output: "({async[b]() {}})", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedAfter("async") + errors: unexpectedAfter("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "class A {a(){}async[b]() {}}", output: "class A {a(){} async [b]() {}}", - parserOptions: { ecmaVersion: 8 }, - errors: expectedBeforeAndAfter("async") + errors: expectedBeforeAndAfter("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "class A {a(){} async [b]() {}}", output: "class A {a(){}async[b]() {}}", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBeforeAndAfter("async") + errors: unexpectedBeforeAndAfter("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "class A {a(){}async[b]() {}}", output: "class A {a(){} async [b]() {}}", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBeforeAndAfter("async") + errors: expectedBeforeAndAfter("async"), + languageOptions: { ecmaVersion: 8 } }, { code: "class A {a(){} async [b]() {}}", output: "class A {a(){}async[b]() {}}", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBeforeAndAfter("async") + errors: unexpectedBeforeAndAfter("async"), + languageOptions: { ecmaVersion: 8 } }, //---------------------------------------------------------------------- @@ -1859,57 +1868,57 @@ ruleTester.run("keyword-spacing", rule, { { code: "async function wrap() { {}await a }", output: "async function wrap() { {} await a }", - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore("await") + errors: expectedBefore("await"), + languageOptions: { ecmaVersion: 8 } }, { code: "async function wrap() { {} await a }", output: "async function wrap() { {}await a }", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore("await") + errors: unexpectedBefore("await"), + languageOptions: { ecmaVersion: 8 } }, { code: "async function wrap() { {}await a }", output: "async function wrap() { {} await a }", options: [override("await", BOTH)], - parserOptions: { ecmaVersion: 8 }, - errors: expectedBefore("await") + errors: expectedBefore("await"), + languageOptions: { ecmaVersion: 8 } }, { code: "async function wrap() { {} await a }", output: "async function wrap() { {}await a }", options: [override("await", NEITHER)], - parserOptions: { ecmaVersion: 8 }, - errors: unexpectedBefore("await") + errors: unexpectedBefore("await"), + languageOptions: { ecmaVersion: 8 } }, { code: "async function wrap() { for await(x of xs); }", output: "async function wrap() { for await (x of xs); }", - parserOptions: { ecmaVersion: 2018 }, - errors: expectedAfter("await") + errors: expectedAfter("await"), + languageOptions: { ecmaVersion: 2018 } }, { code: "async function wrap() { for await (x of xs); }", output: "async function wrap() { for await(x of xs); }", options: [NEITHER], - parserOptions: { ecmaVersion: 2018 }, - errors: unexpectedAfter("await") + errors: unexpectedAfter("await"), + languageOptions: { ecmaVersion: 2018 } }, { code: "async function wrap() { for await(x of xs); }", output: "async function wrap() { for await (x of xs); }", options: [override("await", BOTH)], - parserOptions: { ecmaVersion: 2018 }, - errors: expectedAfter("await") + errors: expectedAfter("await"), + languageOptions: { ecmaVersion: 2018 } }, { code: "async function wrap() { for await (x of xs); }", output: "async function wrap() { for await(x of xs); }", options: [override("await", NEITHER)], - parserOptions: { ecmaVersion: 2018 }, - errors: unexpectedAfter("await") + errors: unexpectedAfter("await"), + languageOptions: { ecmaVersion: 2018 } }, //---------------------------------------------------------------------- @@ -2014,42 +2023,42 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}class Bar {}", output: "{} class Bar {}", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore("class") + errors: expectedBefore("class"), + languageOptions: { ecmaVersion: 6 } }, { code: "(class{})", output: "(class {})", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("class") + errors: expectedAfter("class"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} class Bar {}", output: "{}class Bar {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore("class") + errors: unexpectedBefore("class"), + languageOptions: { ecmaVersion: 6 } }, { code: "(class {})", output: "(class{})", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("class") + errors: unexpectedAfter("class"), + languageOptions: { ecmaVersion: 6 } }, { code: "{}class Bar {}", output: "{} class Bar {}", options: [override("class", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore("class") + errors: expectedBefore("class"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} class Bar {}", output: "{}class Bar {}", options: [override("class", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore("class") + errors: unexpectedBefore("class"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -2059,56 +2068,56 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}const[a] = b", output: "{} const [a] = b", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("const") + errors: expectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, { code: "{}const{a} = b", output: "{} const {a} = b", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("const") + errors: expectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} const [a] = b", output: "{}const[a] = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("const") + errors: unexpectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} const {a} = b", output: "{}const{a} = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("const") + errors: unexpectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, { code: "{}const[a] = b", output: "{} const [a] = b", options: [override("const", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("const") + errors: expectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, { code: "{}const{a} = b", output: "{} const {a} = b", options: [override("const", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("const") + errors: expectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} const [a] = b", output: "{}const[a] = b", options: [override("const", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("const") + errors: unexpectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} const {a} = b", output: "{}const{a} = b", options: [override("const", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("const") + errors: unexpectedBeforeAndAfter("const"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -2364,47 +2373,47 @@ ruleTester.run("keyword-spacing", rule, { { code: "var a = 0; {}export{a}", output: "var a = 0; {} export {a}", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("export") + errors: expectedBeforeAndAfter("export"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0; {}export default a", output: "var a = 0; {} export default a", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBefore("export") + errors: expectedBefore("export"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0; export default{a}", output: "var a = 0; export default {a}", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedAfter("default") + errors: expectedAfter("default"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{}export* from \"a\"", output: "{} export * from \"a\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("export") + errors: expectedBeforeAndAfter("export"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0; {} export {a}", output: "var a = 0; {}export{a}", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("export") + errors: unexpectedBeforeAndAfter("export"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0; {}export{a}", output: "var a = 0; {} export {a}", options: [override("export", BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("export") + errors: expectedBeforeAndAfter("export"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0; {} export {a}", output: "var a = 0; {}export{a}", options: [override("export", NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("export") + errors: unexpectedBeforeAndAfter("export"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -2414,48 +2423,48 @@ ruleTester.run("keyword-spacing", rule, { { code: "class Bar extends[] {}", output: "class Bar extends [] {}", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("extends") + errors: expectedAfter("extends"), + languageOptions: { ecmaVersion: 6 } }, { code: "(class extends[] {})", output: "(class extends [] {})", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("extends") + errors: expectedAfter("extends"), + languageOptions: { ecmaVersion: 6 } }, { code: "class Bar extends [] {}", output: "class Bar extends[] {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("extends") + errors: unexpectedAfter("extends"), + languageOptions: { ecmaVersion: 6 } }, { code: "(class extends [] {})", output: "(class extends[] {})", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("extends") + errors: unexpectedAfter("extends"), + languageOptions: { ecmaVersion: 6 } }, { code: "class Bar extends[] {}", output: "class Bar extends [] {}", options: [override("extends", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("extends") + errors: expectedAfter("extends"), + languageOptions: { ecmaVersion: 6 } }, { code: "class Bar extends [] {}", output: "class Bar extends[] {}", options: [override("extends", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("extends") + errors: unexpectedAfter("extends"), + languageOptions: { ecmaVersion: 6 } }, { code: "class Bar extends`}` {}", output: "class Bar extends `}` {}", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("extends") + errors: expectedAfter("extends"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -2503,8 +2512,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}for(var foo of list) {}", output: "{} for (var foo of list) {}", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("for") + errors: expectedBeforeAndAfter("for"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} for (;;) {}", @@ -2522,8 +2531,8 @@ ruleTester.run("keyword-spacing", rule, { code: "{} for (var foo of list) {}", output: "{}for(var foo of list) {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("for") + errors: unexpectedBeforeAndAfter("for"), + languageOptions: { ecmaVersion: 6 } }, { code: "{}for(;;) {}", @@ -2541,8 +2550,8 @@ ruleTester.run("keyword-spacing", rule, { code: "{}for(var foo of list) {}", output: "{} for (var foo of list) {}", options: [override("for", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("for") + errors: expectedBeforeAndAfter("for"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} for (;;) {}", @@ -2560,8 +2569,8 @@ ruleTester.run("keyword-spacing", rule, { code: "{} for (var foo of list) {}", output: "{}for(var foo of list) {}", options: [override("for", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("for") + errors: unexpectedBeforeAndAfter("for"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -2571,124 +2580,124 @@ ruleTester.run("keyword-spacing", rule, { { code: "import {foo}from\"foo\"", output: "import {foo} from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo}from\"foo\"", output: "export {foo} from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export *from\"foo\"", output: "export * from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export * as \"a\"from\"foo\"", output: "export * as \"a\" from \"foo\"", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import{foo} from \"foo\"", output: "import{foo}from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export{foo} from \"foo\"", output: "export{foo}from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export* from \"foo\"", output: "export*from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export*as x from \"foo\"", output: "export*as x from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, - errors: unexpectedAfter("from") + errors: unexpectedAfter("from"), + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "export*as\"x\" from \"foo\"", output: "export*as\"x\"from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import{foo}from\"foo\"", output: "import{foo} from \"foo\"", options: [override("from", BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export{foo}from\"foo\"", output: "export{foo} from \"foo\"", options: [override("from", BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export*from\"foo\"", output: "export* from \"foo\"", options: [override("from", BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export*as\"x\"from\"foo\"", output: "export*as\"x\" from \"foo\"", options: [override("from", BOTH)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: expectedBeforeAndAfter("from") + errors: expectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "import {foo} from \"foo\"", output: "import {foo}from\"foo\"", options: [override("from", NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export {foo} from \"foo\"", output: "export {foo}from\"foo\"", options: [override("from", NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export * from \"foo\"", output: "export *from\"foo\"", options: [override("from", NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export * as x from \"foo\"", output: "export * as x from\"foo\"", options: [override("from", NEITHER)], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, - errors: unexpectedAfter("from") + errors: unexpectedAfter("from"), + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, { code: "export * as \"x\" from \"foo\"", output: "export * as \"x\"from\"foo\"", options: [override("from", NEITHER)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("from") + errors: unexpectedBeforeAndAfter("from"), + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -2726,82 +2735,82 @@ ruleTester.run("keyword-spacing", rule, { { code: "({ get[b]() {} })", output: "({ get [b]() {} })", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("get") + errors: expectedAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}get[b]() {} }", output: "class A { a() {} get [b]() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("get") + errors: expectedBeforeAndAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} static get[b]() {} }", output: "class A { a() {} static get [b]() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("get") + errors: expectedAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "({ get [b]() {} })", output: "({ get[b]() {} })", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("get") + errors: unexpectedAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} get [b]() {} }", output: "class A { a() {}get[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("get") + errors: unexpectedBeforeAndAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}static get [b]() {} }", output: "class A { a() {}static get[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("get") + errors: unexpectedAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "({ get[b]() {} })", output: "({ get [b]() {} })", options: [override("get", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("get") + errors: expectedAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}get[b]() {} }", output: "class A { a() {} get [b]() {} }", options: [override("get", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("get") + errors: expectedBeforeAndAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "({ get [b]() {} })", output: "({ get[b]() {} })", options: [override("get", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("get") + errors: unexpectedAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} get [b]() {} }", output: "class A { a() {}get[b]() {} }", options: [override("get", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("get") + errors: unexpectedBeforeAndAfter("get"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a;get#b() {} }", output: "class A { a;get #b() {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: expectedAfter("get") + errors: expectedAfter("get"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a; get #b() {} }", output: "class A { a; get#b() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedAfter("get") + errors: unexpectedAfter("get"), + languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- @@ -2862,7 +2871,6 @@ ruleTester.run("keyword-spacing", rule, { { code: "import* as a from \"foo\"", output: "import * as a from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedAfter", data: { value: "import" }, @@ -2870,13 +2878,13 @@ ruleTester.run("keyword-spacing", rule, { column: 1, endLine: 1, endColumn: 7 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import *as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedAfter", data: { value: "import" }, @@ -2884,13 +2892,13 @@ ruleTester.run("keyword-spacing", rule, { column: 7, endLine: 1, endColumn: 8 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import *as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedAfter", data: { value: "import" }, @@ -2898,67 +2906,68 @@ ruleTester.run("keyword-spacing", rule, { column: 7, endLine: 1, endColumn: 10 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{}import{a} from \"foo\"", output: "{} import {a} from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("import") + errors: expectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{}import a from \"foo\"", output: "{} import a from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBefore("import") + errors: expectedBefore("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{}import* as a from \"a\"", output: "{} import * as a from \"a\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("import") + errors: expectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{} import {a}from\"foo\"", output: "{}import{a}from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("import") + errors: unexpectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{} import *as a from\"foo\"", output: "{}import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("import") + errors: unexpectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{}import{a}from\"foo\"", output: "{} import {a}from\"foo\"", options: [override("import", BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("import") + errors: expectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{}import*as a from\"foo\"", output: "{} import *as a from\"foo\"", options: [override("import", BOTH)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: expectedBeforeAndAfter("import") + errors: expectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{} import {a} from \"foo\"", output: "{}import{a} from \"foo\"", options: [override("import", NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("import") + errors: unexpectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "{} import * as a from \"foo\"", output: "{}import* as a from \"foo\"", options: [override("import", NEITHER)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: unexpectedBeforeAndAfter("import") + errors: unexpectedBeforeAndAfter("import"), + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -2968,29 +2977,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "for ([foo]in{foo: 0}) {}", output: "for ([foo] in {foo: 0}) {}", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("in") + errors: expectedBeforeAndAfter("in"), + languageOptions: { ecmaVersion: 6 } }, { code: "for([foo] in {foo: 0}) {}", output: "for([foo]in{foo: 0}) {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("in") + errors: unexpectedBeforeAndAfter("in"), + languageOptions: { ecmaVersion: 6 } }, { code: "for([foo]in{foo: 0}) {}", output: "for([foo] in {foo: 0}) {}", options: [override("in", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("in") + errors: expectedBeforeAndAfter("in"), + languageOptions: { ecmaVersion: 6 } }, { code: "for ([foo] in {foo: 0}) {}", output: "for ([foo]in{foo: 0}) {}", options: [override("in", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("in") + errors: unexpectedBeforeAndAfter("in"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -3006,29 +3015,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}let[a] = b", output: "{} let [a] = b", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("let") + errors: expectedBeforeAndAfter("let"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} let [a] = b", output: "{}let[a] = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("let") + errors: unexpectedBeforeAndAfter("let"), + languageOptions: { ecmaVersion: 6 } }, { code: "{}let[a] = b", output: "{} let [a] = b", options: [override("let", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("let") + errors: expectedBeforeAndAfter("let"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} let [a] = b", output: "{}let[a] = b", options: [override("let", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("let") + errors: unexpectedBeforeAndAfter("let"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -3066,29 +3075,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "for ([foo]of{foo: 0}) {}", output: "for ([foo] of {foo: 0}) {}", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("of") + errors: expectedBeforeAndAfter("of"), + languageOptions: { ecmaVersion: 6 } }, { code: "for([foo] of {foo: 0}) {}", output: "for([foo]of{foo: 0}) {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("of") + errors: unexpectedBeforeAndAfter("of"), + languageOptions: { ecmaVersion: 6 } }, { code: "for([foo]of{foo: 0}) {}", output: "for([foo] of {foo: 0}) {}", options: [override("of", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("of") + errors: expectedBeforeAndAfter("of"), + languageOptions: { ecmaVersion: 6 } }, { code: "for ([foo] of {foo: 0}) {}", output: "for ([foo]of{foo: 0}) {}", options: [override("of", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("of") + errors: unexpectedBeforeAndAfter("of"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -3103,8 +3112,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "function foo() { return

; }", output: "function foo() { return

; }", - parserOptions: { ecmaFeatures: { jsx: true } }, - errors: expectedAfter("return") + errors: expectedAfter("return"), + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "function foo() { {} return +a }", @@ -3116,8 +3125,8 @@ ruleTester.run("keyword-spacing", rule, { code: "function foo() { return

; }", output: "function foo() { return

; }", options: [{ after: false }], - parserOptions: { ecmaFeatures: { jsx: true } }, - errors: unexpectedAfter("return") + errors: unexpectedAfter("return"), + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "function foo() { {}return+a }", @@ -3139,75 +3148,75 @@ ruleTester.run("keyword-spacing", rule, { { code: "({ set[b](value) {} })", output: "({ set [b](value) {} })", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("set") + errors: expectedAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}set[b](value) {} }", output: "class A { a() {} set [b](value) {} }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("set") + errors: expectedBeforeAndAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} static set[b](value) {} }", output: "class A { a() {} static set [b](value) {} }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("set") + errors: expectedAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "({ set [b](value) {} })", output: "({ set[b](value) {} })", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("set") + errors: unexpectedAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} set [b](value) {} }", output: "class A { a() {}set[b](value) {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("set") + errors: unexpectedBeforeAndAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "({ set[b](value) {} })", output: "({ set [b](value) {} })", options: [override("set", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedAfter("set") + errors: expectedAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}set[b](value) {} }", output: "class A { a() {} set [b](value) {} }", options: [override("set", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("set") + errors: expectedBeforeAndAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "({ set [b](value) {} })", output: "({ set[b](value) {} })", options: [override("set", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedAfter("set") + errors: unexpectedAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} set [b](value) {} }", output: "class A { a() {}set[b](value) {} }", options: [override("set", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("set") + errors: unexpectedBeforeAndAfter("set"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a;set#b(x) {} }", output: "class A { a;set #b(x) {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: expectedAfter("set") + errors: expectedAfter("set"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a; set #b(x) {} }", output: "class A { a; set#b(x) {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedAfter("set") + errors: unexpectedAfter("set"), + languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- @@ -3217,121 +3226,121 @@ ruleTester.run("keyword-spacing", rule, { { code: "class A { a() {}static[b]() {} }", output: "class A { a() {} static [b]() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("static") + errors: expectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}static get [b]() {} }", output: "class A { a() {} static get [b]() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore("static") + errors: expectedBefore("static"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} static [b]() {} }", output: "class A { a() {}static[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("static") + errors: unexpectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} static get[b]() {} }", output: "class A { a() {}static get[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore("static") + errors: unexpectedBefore("static"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}static[b]() {} }", output: "class A { a() {} static [b]() {} }", options: [override("static", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("static") + errors: expectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {} static [b]() {} }", output: "class A { a() {}static[b]() {} }", options: [override("static", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("static") + errors: unexpectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a;static[b]; }", output: "class A { a;static [b]; }", - parserOptions: { ecmaVersion: 2022 }, - errors: expectedAfter("static") + errors: expectedAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a; static [b]; }", output: "class A { a; static[b]; }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedAfter("static") + errors: unexpectedAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a;static#b; }", output: "class A { a;static #b; }", - parserOptions: { ecmaVersion: 2022 }, - errors: expectedAfter("static") + errors: expectedAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a; static #b; }", output: "class A { a; static#b; }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedAfter("static") + errors: unexpectedAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {}static{} }", output: "class A { a() {} static {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: expectedBeforeAndAfter("static") + errors: expectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {}static{} }", output: "class A { a() {} static {} }", options: [override("static", BOTH)], - parserOptions: { ecmaVersion: 2022 }, - errors: expectedBeforeAndAfter("static") + errors: expectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {}static {} }", output: "class A { a() {} static {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: expectedBefore("static") + errors: expectedBefore("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {} static{} }", output: "class A { a() {} static {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: expectedAfter("static") + errors: expectedAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {} static {} }", output: "class A { a() {}static{} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedBeforeAndAfter("static") + errors: unexpectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {} static {} }", output: "class A { a() {}static{} }", options: [override("static", NEITHER)], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedBeforeAndAfter("static") + errors: unexpectedBeforeAndAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {} static{} }", output: "class A { a() {}static{} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedBefore("static") + errors: unexpectedBefore("static"), + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { a() {}static {} }", output: "class A { a() {}static{} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, - errors: unexpectedAfter("static") + errors: unexpectedAfter("static"), + languageOptions: { ecmaVersion: 2022 } }, //---------------------------------------------------------------------- @@ -3341,29 +3350,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "class A { a() { {}super[b]; } }", output: "class A { a() { {} super[b]; } }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore("super") + errors: expectedBefore("super"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() { {} super[b]; } }", output: "class A { a() { {}super[b]; } }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore("super") + errors: unexpectedBefore("super"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() { {}super[b]; } }", output: "class A { a() { {} super[b]; } }", options: [override("super", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore("super") + errors: expectedBefore("super"), + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() { {} super[b]; } }", output: "class A { a() { {}super[b]; } }", options: [override("super", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore("super") + errors: unexpectedBefore("super"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -3425,14 +3434,18 @@ ruleTester.run("keyword-spacing", rule, { code: " this.blah", output: "this.blah", options: [override("this", { before: false })], - parser: fixtureParser("keyword-spacing", "prefix-cast-operator-space"), - errors: unexpectedBefore("this") + errors: unexpectedBefore("this"), + languageOptions: { + parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-space")) + } }, { code: "this.blah", output: " this.blah", - parser: fixtureParser("keyword-spacing", "prefix-cast-operator-no-space"), - errors: expectedBefore("this") + errors: expectedBefore("this"), + languageOptions: { + parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-no-space")) + } }, //---------------------------------------------------------------------- @@ -3526,29 +3539,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}var[a] = b", output: "{} var [a] = b", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("var") + errors: expectedBeforeAndAfter("var"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} var [a] = b", output: "{}var[a] = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("var") + errors: unexpectedBeforeAndAfter("var"), + languageOptions: { ecmaVersion: 6 } }, { code: "{}var[a] = b", output: "{} var [a] = b", options: [override("var", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBeforeAndAfter("var") + errors: expectedBeforeAndAfter("var"), + languageOptions: { ecmaVersion: 6 } }, { code: "{} var [a] = b", output: "{}var[a] = b", options: [override("var", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBeforeAndAfter("var") + errors: unexpectedBeforeAndAfter("var"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -3665,29 +3678,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "function* foo() { {}yield foo }", output: "function* foo() { {} yield foo }", - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore("yield") + errors: expectedBefore("yield"), + languageOptions: { ecmaVersion: 6 } }, { code: "function* foo() { {} yield foo }", output: "function* foo() { {}yield foo }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore("yield") + errors: unexpectedBefore("yield"), + languageOptions: { ecmaVersion: 6 } }, { code: "function* foo() { {}yield foo }", output: "function* foo() { {} yield foo }", options: [override("yield", BOTH)], - parserOptions: { ecmaVersion: 6 }, - errors: expectedBefore("yield") + errors: expectedBefore("yield"), + languageOptions: { ecmaVersion: 6 } }, { code: "function* foo() { {} yield foo }", output: "function* foo() { {}yield foo }", options: [override("yield", NEITHER)], - parserOptions: { ecmaVersion: 6 }, - errors: unexpectedBefore("yield") + errors: unexpectedBefore("yield"), + languageOptions: { ecmaVersion: 6 } }, //---------------------------------------------------------------------- @@ -3698,8 +3711,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }", output: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }", - parser: parser("typescript-parsers/decorator-with-keywords-class-method"), - errors: expectedAfter("async") + errors: expectedAfter("async"), + languageOptions: { parser: require(parser("typescript-parsers/decorator-with-keywords-class-method")) } } ] diff --git a/tests/lib/rules/line-comment-position.js b/tests/lib/rules/line-comment-position.js index 02fb7201f3a..582d402938f 100644 --- a/tests/lib/rules/line-comment-position.js +++ b/tests/lib/rules/line-comment-position.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/line-comment-position"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/linebreak-style.js b/tests/lib/rules/linebreak-style.js index 60f247d39cb..2b942ed372f 100644 --- a/tests/lib/rules/linebreak-style.js +++ b/tests/lib/rules/linebreak-style.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/linebreak-style"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/lines-around-comment.js b/tests/lib/rules/lines-around-comment.js index a55d6fe2719..4c3b8bea786 100644 --- a/tests/lib/rules/lines-around-comment.js +++ b/tests/lib/rules/lines-around-comment.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/lines-around-comment"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), { unIndent } = require("../../_utils"); //------------------------------------------------------------------------------ @@ -222,14 +222,14 @@ ruleTester.run("lines-around-comment", rule, { options: [{ allowBlockStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A {\n/**\n* hi\n */\nconstructor() {}\n}", options: [{ allowClassStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A {\n/**\n* hi\n */\nconstructor() {}\n}", @@ -237,7 +237,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: false, allowClassStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "switch ('foo'){\ncase 'foo':\n/* block comment at switch case start */\nbreak;\n}", @@ -279,7 +279,7 @@ ruleTester.run("lines-around-comment", rule, { beforeLineComment: true, allowBlockStart: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -299,7 +299,7 @@ ruleTester.run("lines-around-comment", rule, { beforeLineComment: true, allowBlockStart: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -328,7 +328,7 @@ ruleTester.run("lines-around-comment", rule, { beforeBlockComment: true, allowBlockStart: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -361,19 +361,19 @@ ruleTester.run("lines-around-comment", rule, { beforeBlockComment: true, allowBlockStart: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/16131 { code: ` switch (foo) { - // this comment is allowed by allowBlockStart: true - - case 1: + // this comment is allowed by allowBlockStart: true + + case 1: bar(); break; - + // this comment is allowed by allowBlockEnd: true } `, @@ -388,9 +388,9 @@ ruleTester.run("lines-around-comment", rule, { code: ` switch (foo) { - // this comment is allowed by allowBlockStart: true - - case 1: + // this comment is allowed by allowBlockStart: true + + case 1: bar(); break; } @@ -580,7 +580,7 @@ ruleTester.run("lines-around-comment", rule, { afterBlockComment: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class B {\nconstructor() {}\n\n/**\n* hi\n */\n}", @@ -588,7 +588,7 @@ ruleTester.run("lines-around-comment", rule, { afterBlockComment: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class B {\nconstructor() {}\n\n/**\n* hi\n */\n}", @@ -597,7 +597,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockEnd: false, allowClassEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "switch ('foo'){\ncase 'foo':\nvar g = 1;\n\n/* block comment at switch case end */\n}", @@ -643,7 +643,7 @@ ruleTester.run("lines-around-comment", rule, { afterLineComment: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -673,7 +673,7 @@ ruleTester.run("lines-around-comment", rule, { afterBlockComment: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // check for object start comments @@ -749,7 +749,7 @@ ruleTester.run("lines-around-comment", rule, { beforeLineComment: true, allowObjectStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -761,7 +761,7 @@ ruleTester.run("lines-around-comment", rule, { beforeLineComment: true, allowObjectStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -773,7 +773,7 @@ ruleTester.run("lines-around-comment", rule, { beforeBlockComment: true, allowObjectStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -785,7 +785,7 @@ ruleTester.run("lines-around-comment", rule, { beforeBlockComment: true, allowObjectStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // check for object end comments @@ -863,7 +863,7 @@ ruleTester.run("lines-around-comment", rule, { afterLineComment: true, allowObjectEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -875,7 +875,7 @@ ruleTester.run("lines-around-comment", rule, { afterLineComment: true, allowObjectEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -888,7 +888,7 @@ ruleTester.run("lines-around-comment", rule, { afterBlockComment: true, allowObjectEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -901,7 +901,7 @@ ruleTester.run("lines-around-comment", rule, { afterBlockComment: true, allowObjectEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // check for array start comments @@ -947,7 +947,7 @@ ruleTester.run("lines-around-comment", rule, { beforeLineComment: true, allowArrayStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -959,7 +959,7 @@ ruleTester.run("lines-around-comment", rule, { beforeBlockComment: true, allowArrayStart: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // check for array end comments @@ -1006,7 +1006,7 @@ ruleTester.run("lines-around-comment", rule, { afterLineComment: true, allowArrayEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1019,7 +1019,7 @@ ruleTester.run("lines-around-comment", rule, { afterBlockComment: true, allowArrayEnd: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // ignorePattern @@ -1221,8 +1221,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Line", line: 2 }] + errors: [{ messageId: "before", type: "Line", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A {\n// line at class start\nconstructor() {}\n}", @@ -1232,8 +1232,8 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: false, beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Line", line: 2 }] + errors: [{ messageId: "before", type: "Line", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class B {\nconstructor() {}\n\n// line at class end\n}", @@ -1241,8 +1241,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Line", line: 4 }] + errors: [{ messageId: "after", type: "Line", line: 4 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class B {\nconstructor() {}\n\n// line at class end\n}", @@ -1252,8 +1252,8 @@ ruleTester.run("lines-around-comment", rule, { allowBlockEnd: true, allowClassEnd: false }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Line", line: 4 }] + errors: [{ messageId: "after", type: "Line", line: 4 }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch ('foo'){\ncase 'foo':\nvar g = 1;\n\n// line at switch case end\n}", @@ -1291,10 +1291,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Line", line: 2 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1318,10 +1318,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Block", line: 2 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1346,11 +1346,11 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 3 }, { messageId: "after", type: "Line", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1377,11 +1377,11 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 3 }, { messageId: "after", type: "Block", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1405,10 +1405,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Line", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1434,10 +1434,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Block", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1461,10 +1461,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 4 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1490,10 +1490,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 4 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1520,11 +1520,11 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 4 }, { messageId: "after", type: "Line", line: 4 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1553,11 +1553,11 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 4 }, { messageId: "after", type: "Block", line: 4 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1579,10 +1579,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: unIndent` @@ -1606,10 +1606,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // object start comments @@ -1712,8 +1712,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Line", line: 2 }] + errors: [{ messageId: "before", type: "Line", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1730,8 +1730,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Line", line: 2 }] + errors: [{ messageId: "before", type: "Line", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1748,8 +1748,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Block", line: 2 }] + errors: [{ messageId: "before", type: "Block", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1766,8 +1766,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Block", line: 2 }] + errors: [{ messageId: "before", type: "Block", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, // object end comments @@ -1874,8 +1874,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Line", line: 3 }] + errors: [{ messageId: "after", type: "Line", line: 3 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1892,8 +1892,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Line", line: 3 }] + errors: [{ messageId: "after", type: "Line", line: 3 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1912,8 +1912,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Block", line: 4 }] + errors: [{ messageId: "after", type: "Block", line: 4 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -1932,8 +1932,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Block", line: 4 }] + errors: [{ messageId: "after", type: "Block", line: 4 }], + languageOptions: { ecmaVersion: 6 } }, // array start comments @@ -1986,8 +1986,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Line", line: 2 }] + errors: [{ messageId: "before", type: "Line", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2004,8 +2004,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "before", type: "Block", line: 2 }] + errors: [{ messageId: "before", type: "Block", line: 2 }], + languageOptions: { ecmaVersion: 6 } }, // array end comments @@ -2060,8 +2060,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Line", line: 3 }] + errors: [{ messageId: "after", type: "Line", line: 3 }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -2080,8 +2080,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "after", type: "Block", line: 4 }] + errors: [{ messageId: "after", type: "Block", line: 4 }], + languageOptions: { ecmaVersion: 6 } }, // ignorePattern @@ -2187,8 +2187,8 @@ ruleTester.run("lines-around-comment", rule, { foo ) - { - case 1: + { + case 1: bar(); break; } @@ -2200,8 +2200,8 @@ ruleTester.run("lines-around-comment", rule, { foo ) - { - case 1: + { + case 1: bar(); break; } diff --git a/tests/lib/rules/lines-around-directive.js b/tests/lib/rules/lines-around-directive.js index 230daa786f0..e4b600b0f2a 100644 --- a/tests/lib/rules/lines-around-directive.js +++ b/tests/lib/rules/lines-around-directive.js @@ -11,7 +11,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/lines-around-directive"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -127,12 +127,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -147,12 +147,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, /* @@ -170,12 +170,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n\n'use strict';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -190,12 +190,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // is not affected by JSDoc comments when at top of function block @@ -296,12 +296,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -316,12 +316,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, /* @@ -339,12 +339,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n'use strict';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -359,12 +359,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // does not warn about blank newlines between directives @@ -463,12 +463,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -483,12 +483,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, /* @@ -506,12 +506,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -526,12 +526,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, /* @@ -620,12 +620,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -640,12 +640,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, /* @@ -663,12 +663,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -683,12 +683,12 @@ ruleTester.run("lines-around-directive", rule, { { code: "() => {\n//comment\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7450 @@ -841,8 +841,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\nvar foo;\n}", output: "() => {\n'use strict';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, - errors: [expectedAfterStrictError] + errors: [expectedAfterStrictError], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -856,8 +856,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, - errors: [expectedAfterAsmError] + errors: [expectedAfterAsmError], + languageOptions: { ecmaVersion: 6 } }, /* @@ -886,21 +886,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -926,21 +926,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, /* @@ -1080,8 +1080,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n\nvar foo;\n}", output: "() => {\n'use strict';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, - errors: [unexpectedAfterStrictError] + errors: [unexpectedAfterStrictError], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -1095,8 +1095,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, - errors: [unexpectedAfterAsmError] + errors: [unexpectedAfterAsmError], + languageOptions: { ecmaVersion: 6 } }, /* @@ -1125,21 +1125,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\n\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -1165,21 +1165,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, @@ -1308,15 +1308,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\nvar foo;\n}", output: "() => {\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, - errors: [expectedAfterStrictError] + errors: [expectedAfterStrictError], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\nvar foo;\n}", output: "() => {\n\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, - errors: [expectedAfterStrictError] + errors: [expectedAfterStrictError], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -1336,15 +1336,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, - errors: [expectedAfterAsmError] + errors: [expectedAfterAsmError], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, - errors: [expectedAfterAsmError] + errors: [expectedAfterAsmError], + languageOptions: { ecmaVersion: 6 } }, /* @@ -1373,21 +1373,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -1413,21 +1413,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, /* @@ -1555,15 +1555,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n\nvar foo;\n}", output: "() => {\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, - errors: [unexpectedAfterStrictError] + errors: [unexpectedAfterStrictError], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n\nvar foo;\n}", output: "() => {\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, - errors: [unexpectedAfterStrictError] + errors: [unexpectedAfterStrictError], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -1583,15 +1583,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, - errors: [unexpectedAfterAsmError] + errors: [unexpectedAfterAsmError], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, - errors: [unexpectedAfterAsmError] + errors: [unexpectedAfterAsmError], + languageOptions: { ecmaVersion: 6 } }, /* @@ -1620,21 +1620,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\n\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterStrictError - ] + ], + languageOptions: { ecmaVersion: 6 } }, // multiple directives @@ -1660,21 +1660,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterAsmError - ] + ], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7450 diff --git a/tests/lib/rules/lines-between-class-members.js b/tests/lib/rules/lines-between-class-members.js index 2ee17f713c3..590cf4a1c8d 100644 --- a/tests/lib/rules/lines-between-class-members.js +++ b/tests/lib/rules/lines-between-class-members.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/lines-between-class-members"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -23,7 +23,7 @@ const neverError = { messageId: "never" }; // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("lines-between-class-members", rule, { valid: [ @@ -765,7 +765,7 @@ ruleTester.run("lines-between-class-members", rule, { get area() { return this.method1(); } - + method2() {} } `, @@ -798,7 +798,7 @@ ruleTester.run("lines-between-class-members", rule, { get area() { return this.method1(); } - + method2() {} } `, @@ -1625,7 +1625,7 @@ ruleTester.run("lines-between-class-members", rule, { fieldA = 'Field A'; #fieldB = 'Field B'; method1() {} - + get area() { return this.method1(); } @@ -1787,7 +1787,7 @@ fieldA = 'Field A'; this.height = height; this.width = width; } - + fieldA = 'Field A'; #fieldB = 'Field B'; diff --git a/tests/lib/rules/logical-assignment-operators.js b/tests/lib/rules/logical-assignment-operators.js index 471416322d2..4afa51584e9 100644 --- a/tests/lib/rules/logical-assignment-operators.js +++ b/tests/lib/rules/logical-assignment-operators.js @@ -9,14 +9,19 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/logical-assignment-operators"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), parser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021 } }); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 2021, + sourceType: "script" + } +}); ruleTester.run("logical-assignment-operators", rule, { valid: [ @@ -76,10 +81,10 @@ ruleTester.run("logical-assignment-operators", rule, { "a?.b || (a.b = b)", { code: "class Class { #prop; constructor() { this.#prop || (this.prop = value) } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class Class { #prop; constructor() { this.prop || (this.#prop = value) } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // If @@ -751,8 +756,8 @@ ruleTester.run("logical-assignment-operators", rule, { }, { code: "class Class { #prop; constructor() { this.#prop || (this.#prop = value) } }", output: "class Class { #prop; constructor() { this.#prop ||= value } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "logical", type: "LogicalExpression", data: { operator: "||=" } }] + errors: [{ messageId: "logical", type: "LogicalExpression", data: { operator: "||=" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "a['b'] || (a['b'] = c)", output: "a['b'] ||= c", @@ -1486,13 +1491,14 @@ ruleTester.run("logical-assignment-operators", rule, { code: "a ||= b as number;", output: "a = a || (b as number);", options: ["never"], - parser: parser("typescript-parsers/logical-assignment-with-assertion"), - errors: [{ messageId: "unexpected", type: "AssignmentExpression", data: { operator: "||=" } }] + errors: [{ messageId: "unexpected", type: "AssignmentExpression", data: { operator: "||=" } }], + languageOptions: { + parser: require(parser("typescript-parsers/logical-assignment-with-assertion")) + } }, { code: "a.b.c || (a.b.c = d as number)", output: null, - parser: parser("typescript-parsers/logical-with-assignment-with-assertion-1"), errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1502,12 +1508,14 @@ ruleTester.run("logical-assignment-operators", rule, { data: { operator: "||=" }, output: "a.b.c ||= d as number" }] - }] + }], + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-1")) + } }, { code: "a.b.c || (a.b.c = (d as number))", output: null, - parser: parser("typescript-parsers/logical-with-assignment-with-assertion-2"), errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1517,12 +1525,14 @@ ruleTester.run("logical-assignment-operators", rule, { data: { operator: "||=" }, output: "a.b.c ||= (d as number)" }] - }] + }], + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-2")) + } }, { code: "(a.b.c || (a.b.c = d)) as number", output: null, - parser: parser("typescript-parsers/logical-with-assignment-with-assertion-3"), errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1532,7 +1542,10 @@ ruleTester.run("logical-assignment-operators", rule, { data: { operator: "||=" }, output: "(a.b.c ||= d) as number" }] - }] + }], + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-3")) + } }, // 3 or more operands diff --git a/tests/lib/rules/max-classes-per-file.js b/tests/lib/rules/max-classes-per-file.js index b5e87261e72..7e6176af9e5 100644 --- a/tests/lib/rules/max-classes-per-file.js +++ b/tests/lib/rules/max-classes-per-file.js @@ -9,13 +9,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-classes-per-file"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "script" } }); ruleTester.run("max-classes-per-file", rule, { valid: [ diff --git a/tests/lib/rules/max-depth.js b/tests/lib/rules/max-depth.js index b35b60301c5..6253f04c5c1 100644 --- a/tests/lib/rules/max-depth.js +++ b/tests/lib/rules/max-depth.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-depth"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -22,29 +22,29 @@ ruleTester.run("max-depth", rule, { valid: [ { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [3] }, { code: "function foo() { if (true) { } else if (false) { } else if (true) { } else if (false) {} }", options: [3] }, - { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [3], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [3], languageOptions: { ecmaVersion: 6 } }, "function foo() { if (true) { if (false) { if (true) { } } } }", // object property options { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [{ max: 3 }] }, - { code: "class C { static { if (1) { if (2) {} } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { if (1) { if (2) {} } if (1) { if (2) {} } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { if (1) { if (2) {} } } static { if (1) { if (2) {} } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "if (1) { class C { static { if (1) { if (2) {} } } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { if (1) { class C { static { if (1) { if (2) {} } } } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { if (1) { if (2) {} } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { if (1) { if (2) {} } if (1) { if (2) {} } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { if (1) { if (2) {} } } static { if (1) { if (2) {} } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "if (1) { class C { static { if (1) { if (2) {} } } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { if (1) { class C { static { if (1) { if (2) {} } } } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, { code: "function foo() { if (1) { if (2) { class C { static { if (1) { if (2) {} } if (1) { if (2) {} } } } } } if (1) { if (2) {} } }", options: [2], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [2], errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }] }, - { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [2], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }] }, + { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [2], errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }], languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (true) {} else { for(;;) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "ForStatement" }] }, { code: "function foo() { while (true) { if (true) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }] }, - { code: "function foo() { for (let x of foo) { if (true) {} } }", options: [1], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }] }, + { code: "function foo() { for (let x of foo) { if (true) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }], languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { while (true) { if (true) { if (false) { } } } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }, { messageId: "tooDeeply", data: { depth: 3, maxDepth: 1 }, type: "IfStatement" }] }, { code: "function foo() { if (true) { if (false) { if (true) { if (false) { if (true) { } } } } } }", errors: [{ messageId: "tooDeeply", data: { depth: 5, maxDepth: 4 }, type: "IfStatement" }] }, @@ -57,46 +57,46 @@ ruleTester.run("max-depth", rule, { { code: "class C { static { if (1) { if (2) { if (3) {} } } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 38 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 47 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo() { if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 64 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo() { if (1) { class C { static { if (1) { if (2) {} } } } if (2) { if (3) {} } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 80 - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/max-len.js b/tests/lib/rules/max-len.js index 557b5506f89..091461d9d10 100644 --- a/tests/lib/rules/max-len.js +++ b/tests/lib/rules/max-len.js @@ -9,13 +9,13 @@ // Requirements //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-len"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const parserOptions = { ecmaVersion: 6 }; +const languageOptions = { ecmaVersion: 6 }; const ruleTester = new RuleTester(); @@ -118,22 +118,22 @@ ruleTester.run("max-len", rule, { { code: "var foo =

;", options: [29, 4, { ignoreStrings: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string`;", options: [29, 4, { ignoreTemplateLiterals: true }], - parserOptions + languageOptions }, { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string\nand this is another line that is very long`;", options: [29, 4, { ignoreTemplateLiterals: true }], - parserOptions + languageOptions }, { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string\nand this is another line that is very long\nand here is another\n and another!`;", options: [29, 4, { ignoreTemplateLiterals: true }], - parserOptions + languageOptions }, { code: "var foo = /this is a very long pattern/;", @@ -203,21 +203,21 @@ ruleTester.run("max-len", rule, { " { /* this line has 38 characters */}\n" + ")", options: [15, { comments: 38 }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + "\t\t{ /* this line has 40 characters */}\n" + ")", options: [15, 4, { comments: 44 }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + " <> text { /* this line has 49 characters */}\n" + ")", options: [13, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -225,7 +225,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line has 44 characters */}\n" + ")", options: [44, { comments: 37 }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -233,21 +233,21 @@ ruleTester.run("max-len", rule, { " <> {/* this line has 44 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx =
;", options: [57], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx =
;", options: [57], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx =
;", options: [50], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + " <> {/* this line with two separate comments */} {/* have 80 characters */}\n" + ")", options: [80], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -270,7 +270,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 80 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -278,7 +278,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 80 characters */}\n" + ")", options: [37, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -286,7 +286,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have > 80 characters */ /* another comment in same braces */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -294,7 +294,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have > 80 characters */ /* another comment in same braces */}\n" + ")", options: [37, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -303,7 +303,7 @@ ruleTester.run("max-len", rule, { " */}\n" + ")", options: [33, { comments: 34 }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -312,7 +312,7 @@ ruleTester.run("max-len", rule, { " */}\n" + ")", options: [33, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -320,7 +320,7 @@ ruleTester.run("max-len", rule, { " */}\n" + ")", options: [33, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -328,7 +328,7 @@ ruleTester.run("max-len", rule, { " */}\n" + ")", options: [33, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } } ], @@ -770,7 +770,6 @@ ruleTester.run("max-len", rule, { { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string`;", options: [29, { ignoreStrings: false, ignoreTemplateLiterals: false }], - parserOptions, errors: [ { messageId: "max", @@ -781,12 +780,12 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 40 } - ] + ], + languageOptions }, { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string\nand this is another line that is very long`;", options: [29, { ignoreStrings: false, ignoreTemplateLiterals: false }], - parserOptions, errors: [ { messageId: "max", @@ -806,12 +805,12 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 45 } - ] + ], + languageOptions }, { code: "var foo =
this is a very very very long string
;", options: [29, 4, { ignoreStrings: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -822,7 +821,8 @@ ruleTester.run("max-len", rule, { endLine: 1, endColumn: 59 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, // Multi-code-point unicode glyphs @@ -864,7 +864,6 @@ ruleTester.run("max-len", rule, { " { /* this line has 38 characters */}\n" + ")", options: [15, { comments: 37 }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "maxComment", @@ -875,14 +874,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + "\t\t{ /* this line has 40 characters */}\n" + ")", options: [15, 4, { comments: 40 }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "maxComment", @@ -893,14 +892,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + "{ 38/* this line has 38 characters */}\n" + ")", options: [15, { comments: 38 }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -911,14 +910,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + "{ 38/* this line has 38 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -929,14 +928,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + "{ 38/* this line has 38 characters */}\n" + ")", options: [37, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -947,14 +946,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + " <> 50 { 50/* this line has 50 characters */}\n" + ")", options: [49, { comments: 100 }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -965,7 +964,8 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 51 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -973,7 +973,6 @@ ruleTester.run("max-len", rule, { " <> {/* this line has 44 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -984,14 +983,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 45 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx =
;", options: [56], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1002,14 +1001,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 58 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx =
;", options: [56], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1020,14 +1019,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 58 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx =
;", options: [55, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1038,7 +1037,8 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 57 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx =
;", options: [30, { comments: 44 }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1057,7 +1056,8 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 52 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -1065,7 +1065,6 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 80 characters */}\n" + ")", options: [79], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1076,14 +1075,14 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 81 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + " <> {/* this line with two separate comments */} {/* have 87 characters */} <> \n" + ")", options: [85, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1094,7 +1093,8 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 88 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -1102,7 +1102,6 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 87 characters */} <> \n" + ")", options: [37, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1113,7 +1112,8 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 88 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -1121,7 +1121,6 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have > 80 characters */ /* another comment in same braces */}\n" + ")", options: [37], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1132,7 +1131,8 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 120 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -1140,7 +1140,6 @@ ruleTester.run("max-len", rule, { " <> {/* this is not treated as a comment */ a & b} {/* trailing */ /* comments */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1151,7 +1150,8 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 56 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -1159,7 +1159,6 @@ ruleTester.run("max-len", rule, { " <> {/* this is not treated as a comment */ a & b} {/* trailing */ /* comments */}\n" + ")", options: [37, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1170,7 +1169,8 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 56 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -1178,7 +1178,6 @@ ruleTester.run("max-len", rule, { "*/}\n" + ")", options: [14, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1189,7 +1188,8 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 16 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var jsx = (<>\n" + @@ -1197,7 +1197,6 @@ ruleTester.run("max-len", rule, { "this line has 31 characters */}\n" + ")", options: [30, { comments: 100 }], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "max", @@ -1208,7 +1207,8 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 32 } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } } ] }); diff --git a/tests/lib/rules/max-lines-per-function.js b/tests/lib/rules/max-lines-per-function.js index 621d66e312d..324afb21467 100644 --- a/tests/lib/rules/max-lines-per-function.js +++ b/tests/lib/rules/max-lines-per-function.js @@ -9,13 +9,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-lines-per-function"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("max-lines-per-function", rule, { valid: [ diff --git a/tests/lib/rules/max-lines.js b/tests/lib/rules/max-lines.js index 24c811928de..6e77c84d09e 100644 --- a/tests/lib/rules/max-lines.js +++ b/tests/lib/rules/max-lines.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-lines"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/max-nested-callbacks.js b/tests/lib/rules/max-nested-callbacks.js index 64341b1421f..9b5efd67d0d 100644 --- a/tests/lib/rules/max-nested-callbacks.js +++ b/tests/lib/rules/max-nested-callbacks.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-nested-callbacks"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -46,7 +46,7 @@ ruleTester.run("max-nested-callbacks", rule, { { code: "foo(function() { bar(thing, function(data) {}); });", options: [3] }, { code: "var foo = function() {}; bar(function(){ baz(function() { qux(foo); }) });", options: [2] }, { code: "fn(function(){}, function(){}, function(){});", options: [2] }, - { code: "fn(() => {}, function(){}, function(){});", options: [2], parserOptions: { ecmaVersion: 6 } }, + { code: "fn(() => {}, function(){}, function(){});", options: [2], languageOptions: { ecmaVersion: 6 } }, nestFunctions(10), // object property options @@ -61,14 +61,14 @@ ruleTester.run("max-nested-callbacks", rule, { { code: "foo(function() { bar(thing, (data) => { baz(function() {}); }); });", options: [2], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }] + errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo(() => { bar(thing, (data) => { baz( () => {}); }); });", options: [2], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "ArrowFunctionExpression" }] + errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo(function() { if (isTrue) { bar(function(data) { baz(function() {}); }); } });", diff --git a/tests/lib/rules/max-params.js b/tests/lib/rules/max-params.js index d5e1bf72e10..6b6c0a52329 100644 --- a/tests/lib/rules/max-params.js +++ b/tests/lib/rules/max-params.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-params"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -22,7 +22,7 @@ ruleTester.run("max-params", rule, { valid: [ "function test(d, e, f) {}", { code: "var test = function(a, b, c) {};", options: [3] }, - { code: "var test = (a, b, c) => {};", options: [3], parserOptions: { ecmaVersion: 6 } }, + { code: "var test = (a, b, c) => {};", options: [3], languageOptions: { ecmaVersion: 6 } }, { code: "var test = function test(a, b, c) {};", options: [3] }, // object property options @@ -58,12 +58,12 @@ ruleTester.run("max-params", rule, { { code: "var test = (a, b, c, d) => {};", options: [3], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { name: "Arrow function", count: 4, max: 3.0 }, type: "ArrowFunctionExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function(a, b, c, d) {});", diff --git a/tests/lib/rules/max-statements-per-line.js b/tests/lib/rules/max-statements-per-line.js index 2d33891d3f2..51ae79ef8c1 100644 --- a/tests/lib/rules/max-statements-per-line.js +++ b/tests/lib/rules/max-statements-per-line.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-statements-per-line"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -40,7 +40,7 @@ ruleTester.run("max-statements-per-line", rule, { { code: "(function() {\nvar bar = 1;\n})();", options: [{ max: 1 }] }, { code: "var foo = function foo() { };", options: [{ max: 1 }] }, { code: "var foo = function foo() {\nvar bar = 1;\n};", options: [{ max: 1 }] }, - { code: "var foo = { prop: () => { } };", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = { prop: () => { } };", options: [{ max: 1 }], languageOptions: { ecmaVersion: 6 } }, { code: "var bar = 1; var baz = 2;", options: [{ max: 2 }] }, { code: "if (condition) { var bar = 1; }", options: [{ max: 2 }] }, { code: "if (condition) {\nvar bar = 1; var baz = 2;\n} else {\nvar bar = 1; var baz = 2;\n}", options: [{ max: 2 }] }, @@ -56,18 +56,18 @@ ruleTester.run("max-statements-per-line", rule, { { code: "(function() {\nvar bar = 1; var baz = 2;\n})();", options: [{ max: 2 }] }, { code: "var foo = function foo() { var bar = 1; };", options: [{ max: 2 }] }, { code: "var foo = function foo() {\nvar bar = 1; var baz = 2;\n};", options: [{ max: 2 }] }, - { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 2 }], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 2 }], languageOptions: { ecmaVersion: 6 } }, { code: "var bar = 1; var baz = 2; var qux = 3;", options: [{ max: 3 }] }, { code: "if (condition) { var bar = 1; var baz = 2; }", options: [{ max: 3 }] }, { code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 3 }] }, { code: "switch (discriminant) { case 'test1': ; case 'test2': ; }", options: [{ max: 3 }] }, - { code: "let bar = bar => { a; }, baz = baz => { b; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo({[bar => { a; }]: baz = qux => { b; }}) { }", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } }, - { code: "bar => { a; }, baz => { b; }, qux => { c; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } }, - { code: "[bar => { a; }, baz => { b; }, qux => { c; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } }, - { code: "foo(bar => { a; }, baz => { c; }, qux => { c; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } }, - { code: "({ bar: bar => { a; }, baz: baz => { c; }, qux: qux => { ; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } }, - { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 } }, + { code: "let bar = bar => { a; }, baz = baz => { b; };", options: [{ max: 3 }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo({[bar => { a; }]: baz = qux => { b; }}) { }", options: [{ max: 3 }], languageOptions: { ecmaVersion: 6 } }, + { code: "bar => { a; }, baz => { b; }, qux => { c; };", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 } }, + { code: "[bar => { a; }, baz => { b; }, qux => { c; }];", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo(bar => { a; }, baz => { c; }, qux => { c; });", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 } }, + { code: "({ bar: bar => { a; }, baz: baz => { c; }, qux: qux => { ; }});", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 } }, + { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 } }, { code: [ "const name = 'ESLint'", @@ -76,7 +76,7 @@ ruleTester.run("max-statements-per-line", rule, { "})()" ].join("\n"), options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, [ "if (foo > 1)", @@ -87,7 +87,7 @@ ruleTester.run("max-statements-per-line", rule, { { code: "export default foo = 0;", options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: [ @@ -96,12 +96,12 @@ ruleTester.run("max-statements-per-line", rule, { "}" ].join("\n"), options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export let foo = 0;", options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: [ @@ -110,7 +110,7 @@ ruleTester.run("max-statements-per-line", rule, { "}" ].join("\n"), options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } } ], invalid: [ @@ -131,7 +131,7 @@ ruleTester.run("max-statements-per-line", rule, { { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] }, { code: "(function() { var bar = 1; })();", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] }, { code: "var foo = function foo() { var bar = 1; };", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] }, - { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed" }] }, + { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 1 }], errors: [{ messageId: "exceed" }], languageOptions: { ecmaVersion: 6 } }, { code: "var bar = 1; var baz = 2; var qux = 3;", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "if (condition) { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, @@ -142,19 +142,19 @@ ruleTester.run("max-statements-per-line", rule, { { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "(function() { var bar = 1; var baz = 2; })();", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "var foo = function foo() { var bar = 1; var baz = 2; };", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, - { code: "var foo = { prop: () => { var bar = 1; var baz = 2; } };", options: [{ max: 2 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, + { code: "var foo = { prop: () => { var bar = 1; var baz = 2; } };", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }], languageOptions: { ecmaVersion: 6 } }, { code: "var bar = 1; var baz = 2; var qux = 3; var waldo = 4;", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, { code: "if (condition) { var bar = 1; var baz = 2; var qux = 3; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, { code: "if (condition) { var bar = 1; var baz = 2; } else { var bar = 1; var baz = 2; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 3.0 } }] }, { code: "switch (discriminant) { case 'test': var bar = 1; break; default: var bar = 1; break; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 3.0 } }] }, - { code: "let bar = bar => { a; }, baz = baz => { b; }, qux = qux => { c; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, - { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, - { code: "bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, - { code: "[bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, - { code: "foo(bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, - { code: "({ bar: bar => { a; }, baz: baz => { b; }, qux: qux => { c; }, quux: quux => { d; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, + { code: "let bar = bar => { a; }, baz = baz => { b; }, qux = qux => { c; };", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }], languageOptions: { ecmaVersion: 6 } }, + { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }], languageOptions: { ecmaVersion: 6 } }, + { code: "bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; };", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, + { code: "[bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; }];", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo(bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; });", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({ bar: bar => { a; }, baz: baz => { b; }, qux: qux => { c; }, quux: quux => { d; }});", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, { code: "a; if (b) { c; d; }\nz;", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 2.0 } }] }, - { code: "export default function foo() { console.log('test') }", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "exceed" }] }, - { code: "export function foo() { console.log('test') }", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "exceed" }] } + { code: "export default function foo() { console.log('test') }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function foo() { console.log('test') }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } } ] }); diff --git a/tests/lib/rules/max-statements.js b/tests/lib/rules/max-statements.js index decdd8a56dc..9edbbe7fa04 100644 --- a/tests/lib/rules/max-statements.js +++ b/tests/lib/rules/max-statements.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/max-statements"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -30,35 +30,35 @@ ruleTester.run("max-statements", rule, { // object property options { code: "var foo = { thing: function() { var bar = 1; var baz = 2; } }", options: [2] }, - { code: "var foo = { thing() { var bar = 1; var baz = 2; } }", options: [2], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = { ['thing']() { var bar = 1; var baz = 2; } }", options: [2], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = { thing: () => { var bar = 1; var baz = 2; } }", options: [2], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = { thing() { var bar = 1; var baz = 2; } }", options: [2], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = { ['thing']() { var bar = 1; var baz = 2; } }", options: [2], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = { thing: () => { var bar = 1; var baz = 2; } }", options: [2], languageOptions: { ecmaVersion: 6 } }, { code: "var foo = { thing: function() { var bar = 1; var baz = 2; } }", options: [{ max: 2 }] }, // this rule does not apply to class static blocks, and statements in them should not count as statements in the enclosing function - { code: "class C { static { one; two; three; { four; five; six; } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "function foo() { class C { static { one; two; three; { four; five; six; } } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { one; two; three; function foo() { 1; 2; } four; five; six; } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { { one; two; three; function foo() { 1; 2; } four; five; six; } } }", options: [2], parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { one; two; three; { four; five; six; } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "function foo() { class C { static { one; two; three; { four; five; six; } } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { one; two; three; function foo() { 1; 2; } four; five; six; } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { { one; two; three; function foo() { 1; 2; } four; five; six; } } }", options: [2], languageOptions: { ecmaVersion: 2022 } }, { code: "function top_level() { 1; /* 2 */ class C { static { one; two; three; { four; five; six; } } } 3;}", options: [2, { ignoreTopLevelFunctions: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "function top_level() { 1; 2; } class C { static { one; two; three; { four; five; six; } } }", options: [1, { ignoreTopLevelFunctions: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { one; two; three; { four; five; six; } } } function top_level() { 1; 2; } ", options: [1, { ignoreTopLevelFunctions: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "function foo() { let one; let two = class { static { let three; let four; let five; if (six) { let seven; let eight; let nine; } } }; }", options: [2], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -70,8 +70,8 @@ ruleTester.run("max-statements", rule, { { code: "var foo = () => { var bar = 1; var baz = 2; var qux = 3; };", options: [2], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "exceed", data: { name: "Arrow function", count: "3", max: 2 } }] + errors: [{ messageId: "exceed", data: { name: "Arrow function", count: "3", max: 2 } }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() { var bar = 1; var baz = 2; var qux = 3; };", @@ -135,8 +135,8 @@ ruleTester.run("max-statements", rule, { { code: "var foo = { thing() { var bar = 1; var baz = 2; var baz2; } }", options: [2], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }] + errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }], + languageOptions: { ecmaVersion: 6 } }, /* @@ -144,7 +144,7 @@ ruleTester.run("max-statements", rule, { * { * code: "var foo = { ['thing']() { var bar = 1; var baz = 2; var baz2; } }", * options: [2], - * parserOptions: { ecmaVersion: 6 }, + * languageOptions: { ecmaVersion: 6 }, * errors: [{ messageId: "exceed", data: {name: "Method ''thing''", count: "3", max: 2} }] * }, */ @@ -152,8 +152,8 @@ ruleTester.run("max-statements", rule, { { code: "var foo = { thing: () => { var bar = 1; var baz = 2; var baz2; } }", options: [2], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }] + errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = { thing: function() { var bar = 1; var baz = 2; var baz2; } }", @@ -173,26 +173,26 @@ ruleTester.run("max-statements", rule, { { code: "function foo() { foo_1; /* foo_ 2 */ class C { static { one; two; three; four; { five; six; seven; eight; } } } foo_3 }", options: [2], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: 3, max: 2 } }] + errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: 3, max: 2 } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { one; two; three; four; function not_top_level() { 1; 2; 3; } five; six; seven; eight; } }", options: [2, { ignoreTopLevelFunctions: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }] + errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { { one; two; three; four; function not_top_level() { 1; 2; 3; } five; six; seven; eight; } } }", options: [2, { ignoreTopLevelFunctions: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }] + errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { { one; two; three; four; } function not_top_level() { 1; 2; 3; } { five; six; seven; eight; } } }", options: [2, { ignoreTopLevelFunctions: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }] + errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/multiline-comment-style.js b/tests/lib/rules/multiline-comment-style.js index a127d7ec4cb..9f6ef8a811b 100644 --- a/tests/lib/rules/multiline-comment-style.js +++ b/tests/lib/rules/multiline-comment-style.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/multiline-comment-style"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/multiline-ternary.js b/tests/lib/rules/multiline-ternary.js index 04698ae9513..a26833e92b2 100644 --- a/tests/lib/rules/multiline-ternary.js +++ b/tests/lib/rules/multiline-ternary.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/multiline-ternary"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/new-cap.js b/tests/lib/rules/new-cap.js index 5953c87c24a..bef4e0350c1 100644 --- a/tests/lib/rules/new-cap.js +++ b/tests/lib/rules/new-cap.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/new-cap"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -76,33 +76,33 @@ ruleTester.run("new-cap", rule, { // Optional chaining { code: "foo?.bar();", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.bar)();", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "new (foo?.Bar)();", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.Bar)();", options: [{ properties: false }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "new (foo?.bar)();", options: [{ properties: false }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "Date?.UTC();", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "(Date?.UTC)();", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } } ], invalid: [ @@ -272,7 +272,6 @@ ruleTester.run("new-cap", rule, { }, { code: "var a = new b[ ( 'foo' ) ]();", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "lower", @@ -282,11 +281,11 @@ ruleTester.run("new-cap", rule, { endLine: 1, endColumn: 23 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = new b[`foo`];", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "lower", @@ -296,11 +295,11 @@ ruleTester.run("new-cap", rule, { endLine: 1, endColumn: 20 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = b[`\\\nFoo`]();", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "upper", @@ -310,7 +309,8 @@ ruleTester.run("new-cap", rule, { endLine: 2, endColumn: 5 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { @@ -339,18 +339,18 @@ ruleTester.run("new-cap", rule, { // Optional chaining { code: "new (foo?.bar)();", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "lower", column: 11, endColumn: 14 }] + errors: [{ messageId: "lower", column: 11, endColumn: 14 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.Bar();", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "upper", column: 6, endColumn: 9 }] + errors: [{ messageId: "upper", column: 6, endColumn: 9 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.Bar)();", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "upper", column: 7, endColumn: 10 }] + errors: [{ messageId: "upper", column: 7, endColumn: 10 }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/new-parens.js b/tests/lib/rules/new-parens.js index 2b93711491b..ac9a6b80d5e 100644 --- a/tests/lib/rules/new-parens.js +++ b/tests/lib/rules/new-parens.js @@ -11,7 +11,7 @@ const parser = require("../../fixtures/fixture-parser"), rule = require("../../../lib/rules/new-parens"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -35,7 +35,9 @@ ruleTester.run("new-parens", rule, { "var a = (new Foo()).bar;", { code: "new Storage('state');", - parser: parser("typescript-parsers/new-parens") + languageOptions: { + parser: require(parser("typescript-parsers/new-parens")) + } }, // Explicit Always diff --git a/tests/lib/rules/newline-after-var.js b/tests/lib/rules/newline-after-var.js index 5787d742cac..a93ef59c059 100644 --- a/tests/lib/rules/newline-after-var.js +++ b/tests/lib/rules/newline-after-var.js @@ -11,7 +11,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/newline-after-var"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Fixtures @@ -179,39 +179,39 @@ ruleTester.run("newline-after-var", rule, { { code: MULTI_LINE_NEXT_LINE_BLOCK_COMMENT, options: ["never"] }, // should handle ES6 `let` block binding - { code: LET_ONE_BLANK, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: LET_NO_BLANK, options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: LET_ONE_BLANK, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: LET_NO_BLANK, options: ["never"], languageOptions: { ecmaVersion: 6 } }, // should handle ES6 `const` block binding - { code: CONST_ONE_BLANK, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: CONST_NO_BLANK, options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: CONST_ONE_BLANK, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: CONST_NO_BLANK, options: ["never"], languageOptions: { ecmaVersion: 6 } }, // should handle a mix of `var`, `let`, or `const` - { code: MIXED_LET_VAR, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: MIXED_CONST_VAR, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: MIXED_LET_CONST, options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: MIXED_LET_VAR, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: MIXED_CONST_VAR, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: MIXED_LET_CONST, options: ["always"], languageOptions: { ecmaVersion: 6 } }, // should handle a mix of `var` or `let` inside for variations - { code: FOR_LOOP_WITH_LET, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_LOOP_WITH_VAR, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_LOOP_WITH_LET, options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_LOOP_WITH_VAR, options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_IN_LOOP_WITH_LET, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_IN_LOOP_WITH_VAR, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_IN_LOOP_WITH_LET, options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_IN_LOOP_WITH_VAR, options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_OF_LOOP_WITH_LET, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_OF_LOOP_WITH_VAR, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_OF_LOOP_WITH_LET, options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: FOR_OF_LOOP_WITH_VAR, options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: FOR_LOOP_WITH_LET, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_LOOP_WITH_VAR, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_LOOP_WITH_LET, options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_LOOP_WITH_VAR, options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_IN_LOOP_WITH_LET, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_IN_LOOP_WITH_VAR, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_IN_LOOP_WITH_LET, options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_IN_LOOP_WITH_VAR, options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_OF_LOOP_WITH_LET, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_OF_LOOP_WITH_VAR, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_OF_LOOP_WITH_LET, options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: FOR_OF_LOOP_WITH_VAR, options: ["never"], languageOptions: { ecmaVersion: 6 } }, // should handle export specifiers - { code: EXPORT_WITH_LET, options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: EXPORT_WITH_LET, options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: EXPORT_WITH_VAR, options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: EXPORT_WITH_VAR, options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: EXPORT_WITH_CONST, options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: EXPORT_WITH_CONST, options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: EXPORT_WITH_LET, options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: EXPORT_WITH_LET, options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: EXPORT_WITH_VAR, options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: EXPORT_WITH_VAR, options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: EXPORT_WITH_CONST, options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: EXPORT_WITH_CONST, options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // should allow no blank line at end of block { code: END_OF_FUNCTION, options: ["always"] }, @@ -220,9 +220,9 @@ ruleTester.run("newline-after-var", rule, { { code: END_OF_FUNCTION_EXPRESSION, options: ["always"] }, { code: END_OF_FUNCTION_EXPRESSION, options: ["never"] }, { code: NOT_END_OF_FUNCTION_EXPRESSION, options: ["never"] }, - { code: END_OF_ARROW_FUNCTION, options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: END_OF_ARROW_FUNCTION, options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: NOT_END_OF_ARROW_FUNCTION, options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: END_OF_ARROW_FUNCTION, options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: END_OF_ARROW_FUNCTION, options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: NOT_END_OF_ARROW_FUNCTION, options: ["never"], languageOptions: { ecmaVersion: 6 } }, { code: END_OF_BLOCK, options: ["always"] }, { code: END_OF_BLOCK, options: ["never"] }, { code: END_OF_IF, options: ["always"] }, @@ -274,11 +274,11 @@ ruleTester.run("newline-after-var", rule, { { code: MULTI_VAR_NO_BLANK, output: MULTI_VAR_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, { code: MULTI_DEC_NO_BLANK, output: MULTI_DEC_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, { code: MULTI_LINE_NO_BLANK, output: MULTI_LINE_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, - { code: LET_NO_BLANK, output: LET_ONE_BLANK, options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [ALWAYS_ERROR] }, - { code: CONST_NO_BLANK, output: CONST_ONE_BLANK, options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [ALWAYS_ERROR] }, + { code: LET_NO_BLANK, output: LET_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR], languageOptions: { ecmaVersion: 6 } }, + { code: CONST_NO_BLANK, output: CONST_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR], languageOptions: { ecmaVersion: 6 } }, { code: NOT_END_OF_FUNCTION, output: NOT_END_OF_FUNCTION_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, { code: NOT_END_OF_FUNCTION_EXPRESSION, output: NOT_END_OF_FUNCTION_EXPRESSION_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, - { code: NOT_END_OF_ARROW_FUNCTION, output: NOT_END_OF_ARROW_FUNCTION_ONE_BLANK, options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [ALWAYS_ERROR] }, + { code: NOT_END_OF_ARROW_FUNCTION, output: NOT_END_OF_ARROW_FUNCTION_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR], languageOptions: { ecmaVersion: 6 } }, { code: NO_BLANK_BEFORE_CASE, output: ONE_BLANK_BEFORE_CASE, options: ["always"], errors: [ALWAYS_ERROR] }, // should disallow blank lines in "never" mode @@ -291,8 +291,8 @@ ruleTester.run("newline-after-var", rule, { { code: MULTI_DEC_ONE_BLANK, output: MULTI_DEC_NO_BLANK, options: ["never"], errors: [NEVER_ERROR] }, { code: MULTI_LINE_ONE_BLANK, output: MULTI_LINE_NO_BLANK, options: ["never"], errors: [NEVER_ERROR] }, { code: MULTI_LINE_ONE_BLANK_WITH_COMMENTS, output: MULTI_LINE_NO_BLANK_WITH_COMMENTS, options: ["never"], errors: [NEVER_ERROR] }, - { code: LET_ONE_BLANK, output: LET_NO_BLANK, options: ["never"], parserOptions: { ecmaVersion: 6 }, errors: [NEVER_ERROR] }, - { code: CONST_ONE_BLANK, output: CONST_NO_BLANK, options: ["never"], parserOptions: { ecmaVersion: 6 }, errors: [NEVER_ERROR] }, + { code: LET_ONE_BLANK, output: LET_NO_BLANK, options: ["never"], errors: [NEVER_ERROR], languageOptions: { ecmaVersion: 6 } }, + { code: CONST_ONE_BLANK, output: CONST_NO_BLANK, options: ["never"], errors: [NEVER_ERROR], languageOptions: { ecmaVersion: 6 } }, { code: ONE_BLANK_BEFORE_CASE, output: NO_BLANK_BEFORE_CASE, options: ["never"], errors: [NEVER_ERROR] }, // should disallow a comment on the next line that's not in turn followed by a blank in "always" mode diff --git a/tests/lib/rules/newline-before-return.js b/tests/lib/rules/newline-before-return.js index 4923706a986..ae3525fc642 100644 --- a/tests/lib/rules/newline-before-return.js +++ b/tests/lib/rules/newline-before-return.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/newline-before-return"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); const error = { messageId: "expected" }; ruleTester.run("newline-before-return", rule, { @@ -61,19 +66,19 @@ ruleTester.run("newline-before-return", rule, { "function a() {\nfor (b in c) {\nd();\n\nreturn;\n}\n}", { code: "function a() {\nfor (b of c) return;\n}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function a() {\nfor (b of c)\nreturn;\n}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function a() {\nfor (b of c) {\nreturn;\n}\n}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function a() {\nfor (b of c) {\nd();\n\nreturn;\n}\n}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, "function a() {\nswitch (b) {\ncase 'b': return;\n}\n}", "function a() {\nswitch (b) {\ncase 'b':\nreturn;\n}\n}", @@ -91,23 +96,23 @@ ruleTester.run("newline-before-return", rule, { "function a() {\nif (b) { return; }\n\n/*multi-line\ncomment*/ return c;\n}", { code: "return;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a;\n\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "// comment\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "/* comment */\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "/* multi-line\ncomment */\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } } ], @@ -155,8 +160,8 @@ ruleTester.run("newline-before-return", rule, { { code: "function a() {\nfor (b of c) {\nd();\nreturn;\n}\n}", output: "function a() {\nfor (b of c) {\nd();\n\nreturn;\n}\n}", - parserOptions: { ecmaVersion: 6 }, - errors: [error] + errors: [error], + languageOptions: { ecmaVersion: 6 } }, { code: "function a() {\nif (b) {\nc();\n}\n//comment\nreturn b;\n}", @@ -191,14 +196,14 @@ ruleTester.run("newline-before-return", rule, { { code: "var a;\nreturn;", output: "var a;\n\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: [error] + errors: [error], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a; return;", output: "var a; \n\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: [error] + errors: [error], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "function a() {\n{\n//comment\n}\nreturn\n}", diff --git a/tests/lib/rules/newline-per-chained-call.js b/tests/lib/rules/newline-per-chained-call.js index ce7719b7146..0d13fb4e551 100644 --- a/tests/lib/rules/newline-per-chained-call.js +++ b/tests/lib/rules/newline-per-chained-call.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/newline-per-chained-call"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -351,61 +351,61 @@ ruleTester.run("newline-per-chained-call", rule, { code: "obj?.foo1()?.foo2()?.foo3()", output: "obj?.foo1()\n?.foo2()\n?.foo3()", options: [{ ignoreChainWithDepth: 1 }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.foo1()?.foo2)()?.foo3()", output: "(obj?.foo1()\n?.foo2)()\n?.foo3()", options: [{ ignoreChainWithDepth: 1 }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.foo1())?.foo2()?.foo3()", output: "(obj?.foo1())\n?.foo2()\n?.foo3()", options: [{ ignoreChainWithDepth: 1 }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.[foo1]()?.[foo2]()?.[foo3]()", output: "obj?.[foo1]()\n?.[foo2]()\n?.[foo3]()", options: [{ ignoreChainWithDepth: 1 }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.[foo1]()?.[foo2])()?.[foo3]()", output: "(obj?.[foo1]()\n?.[foo2])()\n?.[foo3]()", options: [{ ignoreChainWithDepth: 1 }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.[foo1]())?.[foo2]()?.[foo3]()", output: "(obj?.[foo1]())\n?.[foo2]()\n?.[foo3]()", options: [{ ignoreChainWithDepth: 1 }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } } ] diff --git a/tests/lib/rules/no-alert.js b/tests/lib/rules/no-alert.js index 03fcddb6994..6f85bc39e5f 100644 --- a/tests/lib/rules/no-alert.js +++ b/tests/lib/rules/no-alert.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-alert"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-alert", rule, { valid: [ @@ -36,10 +41,10 @@ ruleTester.run("no-alert", rule, { "function foo() { this.alert(); }", "function foo() { var window = bar; window.alert(); }", "globalThis.alert();", - { code: "globalThis['alert']();", env: { es6: true } }, - { code: "globalThis.alert();", env: { es2017: true } }, - { code: "var globalThis = foo; globalThis.alert();", env: { es2020: true } }, - { code: "function foo() { var globalThis = foo; globalThis.alert(); }", env: { es2020: true } } + { code: "globalThis['alert']();", languageOptions: { ecmaVersion: 6 } }, + { code: "globalThis.alert();", languageOptions: { ecmaVersion: 2017 } }, + { code: "var globalThis = foo; globalThis.alert();", languageOptions: { ecmaVersion: 2020 } }, + { code: "function foo() { var globalThis = foo; globalThis.alert(); }", languageOptions: { ecmaVersion: 2020 } } ], invalid: [ { @@ -112,30 +117,30 @@ ruleTester.run("no-alert", rule, { }, { code: "globalThis['alert'](foo)", - env: { es2020: true }, - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.alert();", - env: { es2020: true }, - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "function foo() { var globalThis = bar; globalThis.alert(); }\nglobalThis.alert();", - env: { es2020: true }, - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }], + languageOptions: { ecmaVersion: 2020 } }, // Optional chaining { code: "window?.alert(foo)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected", data: { name: "alert" } }] + errors: [{ messageId: "unexpected", data: { name: "alert" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(window?.alert)(foo)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected", data: { name: "alert" } }] + errors: [{ messageId: "unexpected", data: { name: "alert" } }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-array-constructor.js b/tests/lib/rules/no-array-constructor.js index 07d0b650a69..73fa01c3cff 100644 --- a/tests/lib/rules/no-array-constructor.js +++ b/tests/lib/rules/no-array-constructor.js @@ -10,13 +10,17 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-array-constructor"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } }); +const ruleTester = new RuleTester({ + languageOptions: { + sourceType: "script" + } +}); ruleTester.run("no-array-constructor", rule, { valid: [ @@ -33,8 +37,10 @@ ruleTester.run("no-array-constructor", rule, { "var Array; new Array;", { code: "new Array()", - globals: { - Array: "off" + languageOptions: { + globals: { + Array: "off" + } } } ], @@ -218,14 +224,14 @@ ruleTester.run("no-array-constructor", rule, { Array() `, - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: ` Array() `, - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } } ].map(props => ({ ...props, @@ -276,7 +282,7 @@ ruleTester.run("no-array-constructor", rule, { { code: "for (let i = 0; i < 10; i++) Array();" }, { code: "for (const prop in obj) Array();" }, { code: "for (const element of iterable) Array();" }, - { code: "with (obj) Array();" }, + { code: "with (obj) Array();", languageOptions: { sourceType: "script" } }, // No semicolon required before array literal because ASI still occurs { @@ -360,28 +366,28 @@ ruleTester.run("no-array-constructor", rule, { export { foo } Array() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` export { foo } from 'bar' Array() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` export * as foo from 'bar' Array() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` import foo from 'bar' Array() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` diff --git a/tests/lib/rules/no-async-promise-executor.js b/tests/lib/rules/no-async-promise-executor.js index 4318bee6d4f..4d48bab55ed 100644 --- a/tests/lib/rules/no-async-promise-executor.js +++ b/tests/lib/rules/no-async-promise-executor.js @@ -9,14 +9,14 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-async-promise-executor"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 8 } }); ruleTester.run("no-async-promise-executor", rule, { diff --git a/tests/lib/rules/no-await-in-loop.js b/tests/lib/rules/no-await-in-loop.js index efca8819b07..cb159382dfa 100644 --- a/tests/lib/rules/no-await-in-loop.js +++ b/tests/lib/rules/no-await-in-loop.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-await-in-loop"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -18,7 +18,7 @@ const rule = require("../../../lib/rules/no-await-in-loop"), const error = { messageId: "unexpectedAwait", type: "AwaitExpression" }; -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2018, sourceType: "script" } }); ruleTester.run("no-await-in-loop", rule, { valid: [ diff --git a/tests/lib/rules/no-bitwise.js b/tests/lib/rules/no-bitwise.js index 25cc286f95e..4ef01788da9 100644 --- a/tests/lib/rules/no-bitwise.js +++ b/tests/lib/rules/no-bitwise.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-bitwise"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -25,9 +25,9 @@ ruleTester.run("no-bitwise", rule, { "a && b", "a || b", "a += b", - { code: "a &&= b", parserOptions: { ecmaVersion: 2021 } }, - { code: "a ||= b", parserOptions: { ecmaVersion: 2021 } }, - { code: "a ??= b", parserOptions: { ecmaVersion: 2021 } }, + { code: "a &&= b", languageOptions: { ecmaVersion: 2021 } }, + { code: "a ||= b", languageOptions: { ecmaVersion: 2021 } }, + { code: "a ??= b", languageOptions: { ecmaVersion: 2021 } }, { code: "~[1, 2, 3].indexOf(1)", options: [{ allow: ["~"] }] }, { code: "~1<<2 === -8", options: [{ allow: ["~", "<<"] }] }, { code: "a|0", options: [{ int32Hint: true }] }, diff --git a/tests/lib/rules/no-buffer-constructor.js b/tests/lib/rules/no-buffer-constructor.js index 14568f08aa3..b9fb655c3fb 100644 --- a/tests/lib/rules/no-buffer-constructor.js +++ b/tests/lib/rules/no-buffer-constructor.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-buffer-constructor"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-caller.js b/tests/lib/rules/no-caller.js index 4c3a83bd938..f41de2260fe 100644 --- a/tests/lib/rules/no-caller.js +++ b/tests/lib/rules/no-caller.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-caller"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-case-declarations.js b/tests/lib/rules/no-case-declarations.js index bee630a1bad..815b48e191c 100644 --- a/tests/lib/rules/no-case-declarations.js +++ b/tests/lib/rules/no-case-declarations.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-case-declarations"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -22,94 +22,94 @@ ruleTester.run("no-case-declarations", rule, { valid: [ { code: "switch (a) { case 1: { let x = 1; break; } default: { let x = 2; break; } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { case 1: { const x = 1; break; } default: { const x = 2; break; } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { case 1: { function f() {} break; } default: { function f() {} break; } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { case 1: { class C {} break; } default: { class C {} break; } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, ` - switch (a) { - case 1: - case 2: {} + switch (a) { + case 1: + case 2: {} } `, ` switch (a) { - case 1: var x; + case 1: var x; } ` ], invalid: [ { code: ` - switch (a) { - case 1: - {} - function f() {} - break; + switch (a) { + case 1: + {} + function f() {} + break; } `, errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }] }, { code: ` - switch (a) { - case 1: - case 2: - let x; + switch (a) { + case 1: + case 2: + let x; } `, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { case 1: let x = 1; break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { default: let x = 2; break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { case 1: const x = 1; break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { default: const x = 2; break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { case 1: function f() {} break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }] + errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { default: function f() {} break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }] + errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { case 1: class C {} break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "ClassDeclaration" }] + errors: [{ messageId: "unexpected", type: "ClassDeclaration" }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (a) { default: class C {} break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "ClassDeclaration" }] + errors: [{ messageId: "unexpected", type: "ClassDeclaration" }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-catch-shadow.js b/tests/lib/rules/no-catch-shadow.js index 76a5a1d33d4..9c38d77ab38 100644 --- a/tests/lib/rules/no-catch-shadow.js +++ b/tests/lib/rules/no-catch-shadow.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-catch-shadow"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -35,15 +35,12 @@ ruleTester.run("no-catch-shadow", rule, { "", "module.exports = broken;" ].join("\n"), - parserOptions: { ecmaVersion: 6 } - }, - { - code: "try {} catch (error) {}", - env: { shelljs: false } + languageOptions: { ecmaVersion: 6 } }, + "try {} catch (error) {}", { code: "try {} catch {}", - parserOptions: { ecmaVersion: 2019 } + languageOptions: { ecmaVersion: 2019 } } ], invalid: [ diff --git a/tests/lib/rules/no-class-assign.js b/tests/lib/rules/no-class-assign.js index a59d2c20436..1aa3a5c7ea7 100644 --- a/tests/lib/rules/no-class-assign.js +++ b/tests/lib/rules/no-class-assign.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-class-assign"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("no-class-assign", rule, { valid: [ diff --git a/tests/lib/rules/no-compare-neg-zero.js b/tests/lib/rules/no-compare-neg-zero.js index 68478dde908..3b9fa65a5bb 100644 --- a/tests/lib/rules/no-compare-neg-zero.js +++ b/tests/lib/rules/no-compare-neg-zero.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-compare-neg-zero"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-cond-assign.js b/tests/lib/rules/no-cond-assign.js index 77e4c785e72..3868aa3d79a 100644 --- a/tests/lib/rules/no-cond-assign.js +++ b/tests/lib/rules/no-cond-assign.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-cond-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -36,8 +36,8 @@ ruleTester.run("no-cond-assign", rule, { "for (;someNode || (someNode = parentNode););", { code: "if ((function(node) { return node = parentNode; })(someNode)) { }", options: ["except-parens"] }, { code: "if ((function(node) { return node = parentNode; })(someNode)) { }", options: ["always"] }, - { code: "if ((node => node = parentNode)(someNode)) { }", options: ["except-parens"], parserOptions: { ecmaVersion: 6 } }, - { code: "if ((node => node = parentNode)(someNode)) { }", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "if ((node => node = parentNode)(someNode)) { }", options: ["except-parens"], languageOptions: { ecmaVersion: 6 } }, + { code: "if ((node => node = parentNode)(someNode)) { }", options: ["always"], languageOptions: { ecmaVersion: 6 } }, { code: "if (function(node) { return node = parentNode; }) { }", options: ["except-parens"] }, { code: "if (function(node) { return node = parentNode; }) { }", options: ["always"] }, { code: "x = 0;", options: ["always"] }, diff --git a/tests/lib/rules/no-confusing-arrow.js b/tests/lib/rules/no-confusing-arrow.js index 372f2057bbf..7cdc6c6de76 100644 --- a/tests/lib/rules/no-confusing-arrow.js +++ b/tests/lib/rules/no-confusing-arrow.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-confusing-arrow"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("no-confusing-arrow", rule, { valid: [ diff --git a/tests/lib/rules/no-console.js b/tests/lib/rules/no-console.js index d55cf5c2d58..12d769023d8 100644 --- a/tests/lib/rules/no-console.js +++ b/tests/lib/rules/no-console.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-console"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -142,7 +142,6 @@ ruleTester.run("no-console", rule, { }, { code: "class A { static { console.info(foo) } }", - parserOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -151,29 +150,29 @@ ruleTester.run("no-console", rule, { data: { propertyName: "info" }, output: "class A { static { } }" }] - }] + }], + languageOptions: { ecmaVersion: "latest" } }, { code: "a()\nconsole.log(foo);\n[1, 2, 3].forEach(a => doSomething(a))", - parserOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", suggestions: null - }] + }], + languageOptions: { ecmaVersion: "latest" } }, { code: "a++\nconsole.log();\n/b/", - parserOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", suggestions: null - }] + }], + languageOptions: { ecmaVersion: "latest" } }, { code: "a();\nconsole.log(foo);\n[1, 2, 3].forEach(a => doSomething(a));", - parserOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -182,7 +181,8 @@ ruleTester.run("no-console", rule, { data: { propertyName: "log" }, output: "a();\n\n[1, 2, 3].forEach(a => doSomething(a));" }] - }] + }], + languageOptions: { ecmaVersion: "latest" } }, // one option @@ -285,7 +285,6 @@ ruleTester.run("no-console", rule, { { code: "class A { static { console.error(foo) } }", options: [{ allow: ["log"] }], - parserOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -294,7 +293,8 @@ ruleTester.run("no-console", rule, { data: { propertyName: "error" }, output: "class A { static { } }" }] - }] + }], + languageOptions: { ecmaVersion: "latest" } }, // multiple options @@ -397,7 +397,6 @@ ruleTester.run("no-console", rule, { { code: "class A { static { console.info(foo) } }", options: [{ allow: ["log", "error", "warn"] }], - parserOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -406,13 +405,13 @@ ruleTester.run("no-console", rule, { data: { propertyName: "info" }, output: "class A { static { } }" }] - }] + }], + languageOptions: { ecmaVersion: "latest" } }, // In case that implicit global variable of 'console' exists { code: "console.log(foo)", - env: { node: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -421,7 +420,12 @@ ruleTester.run("no-console", rule, { data: { propertyName: "log" }, output: "" }] - }] + }], + languageOptions: { + globals: { + console: "readonly" + } + } } ] }); diff --git a/tests/lib/rules/no-const-assign.js b/tests/lib/rules/no-const-assign.js index ab44e5c9c04..1e752261c04 100644 --- a/tests/lib/rules/no-const-assign.js +++ b/tests/lib/rules/no-const-assign.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-const-assign"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("no-const-assign", rule, { valid: [ diff --git a/tests/lib/rules/no-constant-binary-expression.js b/tests/lib/rules/no-constant-binary-expression.js index d931e835d73..a2af011b115 100644 --- a/tests/lib/rules/no-constant-binary-expression.js +++ b/tests/lib/rules/no-constant-binary-expression.js @@ -10,13 +10,21 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-constant-binary-expression"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021, ecmaFeatures: { jsx: true } } }); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 2021, + sourceType: "script", + parserOptions: { + ecmaFeatures: { jsx: true } + } + } +}); ruleTester.run("no-constant-binary-expression", rule, { valid: [ @@ -59,7 +67,7 @@ ruleTester.run("no-constant-binary-expression", rule, { "function foo(undefined) { undefined === true;}", "[...arr, 1] == true", "[,,,] == true", - { code: "new Foo() === bar;", globals: { Foo: "writable" } }, + { code: "new Foo() === bar;", languageOptions: { globals: { Foo: "writable" } } }, "(foo && true) ?? bar", "foo ?? null ?? bar", "a ?? (doSomething(), undefined) ?? b", @@ -304,8 +312,8 @@ ruleTester.run("no-constant-binary-expression", rule, { { code: "x === (function() {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === (class {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === new Boolean()", errors: [{ messageId: "alwaysNew" }] }, - { code: "x === new Promise()", env: { es6: true }, errors: [{ messageId: "alwaysNew" }] }, - { code: "x === new WeakSet()", env: { es6: true }, errors: [{ messageId: "alwaysNew" }] }, + { code: "x === new Promise()", errors: [{ messageId: "alwaysNew" }], languageOptions: { ecmaVersion: 6 } }, + { code: "x === new WeakSet()", errors: [{ messageId: "alwaysNew" }], languageOptions: { ecmaVersion: 6 } }, { code: "x === (foo, {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === (y = {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === (y ? {} : [])", errors: [{ messageId: "alwaysNew" }] }, diff --git a/tests/lib/rules/no-constant-condition.js b/tests/lib/rules/no-constant-condition.js index af7bd355db4..b74deec078d 100644 --- a/tests/lib/rules/no-constant-condition.js +++ b/tests/lib/rules/no-constant-condition.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-constant-condition"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2021 } }); ruleTester.run("no-constant-condition", rule, { valid: [ @@ -141,15 +141,15 @@ ruleTester.run("no-constant-condition", rule, { "if ((foo || 'bar' || 'bar') === 'bar');", { code: "if ((foo || 1n) === 'baz') {}", - parserOptions: { ecmaVersion: 11 } + languageOptions: { ecmaVersion: 11 } }, { code: "if (a && 0n || b);", - parserOptions: { ecmaVersion: 11 } + languageOptions: { ecmaVersion: 11 } }, { code: "if(1n && a){};", - parserOptions: { ecmaVersion: 11 } + languageOptions: { ecmaVersion: 11 } }, // #12225 @@ -193,9 +193,9 @@ ruleTester.run("no-constant-condition", rule, { "if (foo.Boolean(1)) {}", "function foo(Boolean) { if (Boolean(1)) {} }", "const Boolean = () => {}; if (Boolean(1)) {}", - { code: "if (Boolean()) {}", globals: { Boolean: "off" } }, + { code: "if (Boolean()) {}", languageOptions: { globals: { Boolean: "off" } } }, "const undefined = 'lol'; if (undefined) {}", - { code: "if (undefined) {}", globals: { undefined: "off" } } + { code: "if (undefined) {}", languageOptions: { globals: { undefined: "off" } } } ], invalid: [ { code: "for(;true;);", errors: [{ messageId: "unexpected", type: "Literal" }] }, @@ -386,15 +386,15 @@ ruleTester.run("no-constant-condition", rule, { }, // #13238 - { code: "if(/foo/ui);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0n);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0b0n);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0o0n);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0x0n);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0b1n);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0o1n);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0x1n);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "if(0x1n || foo);", parserOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(/foo/ui);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0b0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0o0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0x0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0b1n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0o1n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0x1n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(0x1n || foo);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }], languageOptions: { ecmaVersion: 11 } }, // Classes and instances are always truthy { code: "if(class {}) {}", errors: [{ messageId: "unexpected" }] }, diff --git a/tests/lib/rules/no-constructor-return.js b/tests/lib/rules/no-constructor-return.js index 0a8d3b0aeb3..c430a7980fd 100644 --- a/tests/lib/rules/no-constructor-return.js +++ b/tests/lib/rules/no-constructor-return.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-constructor-return"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2015, sourceType: "script" } }); const errors = [{ type: "ReturnStatement", messageId: "unexpected" }]; @@ -30,7 +30,7 @@ ruleTester.run("no-constructor-return", rule, { "const fn = () => { if (kumiko) { return kumiko } }", { code: "return 'Kumiko Oumae'", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, "class C { }", diff --git a/tests/lib/rules/no-continue.js b/tests/lib/rules/no-continue.js index 32ab554fa10..2f7b0741ffb 100644 --- a/tests/lib/rules/no-continue.js +++ b/tests/lib/rules/no-continue.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-continue"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-control-regex.js b/tests/lib/rules/no-control-regex.js index 3bfc87bace1..4904685960d 100644 --- a/tests/lib/rules/no-control-regex.js +++ b/tests/lib/rules/no-control-regex.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-control-regex"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -27,7 +27,7 @@ ruleTester.run("no-control-regex", rule, { "new RegExp('[')", "RegExp('[')", "new (function foo(){})('\\x1f')", - { code: String.raw`/\u{20}/u`, parserOptions: { ecmaVersion: 2015 } }, + { code: String.raw`/\u{20}/u`, languageOptions: { ecmaVersion: 2015 } }, String.raw`/\u{1F}/`, String.raw`/\u{1F}/g`, String.raw`new RegExp("\\u{20}", "u")`, @@ -35,7 +35,7 @@ ruleTester.run("no-control-regex", rule, { String.raw`new RegExp("\\u{1F}", "g")`, String.raw`new RegExp("\\u{1F}", flags)`, // when flags are unknown, this rule assumes there's no `u` flag String.raw`new RegExp("[\\q{\\u{20}}]", "v")`, - { code: String.raw`/[\u{20}--B]/v`, parserOptions: { ecmaVersion: 2024 } } + { code: String.raw`/[\u{20}--B]/v`, languageOptions: { ecmaVersion: 2024 } } ], invalid: [ @@ -49,13 +49,13 @@ ruleTester.run("no-control-regex", rule, { { code: "var regex = RegExp('\\x1f')", errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: "var regex = /(?\\x1f)/", - parserOptions: { ecmaVersion: 2018 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], + languageOptions: { ecmaVersion: 2018 } }, { code: String.raw`var regex = /(?<\u{1d49c}>.)\x1f/`, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], + languageOptions: { ecmaVersion: 2020 } }, { code: String.raw`new RegExp("\\u001F", flags)`, @@ -63,23 +63,23 @@ ruleTester.run("no-control-regex", rule, { }, { code: String.raw`/\u{1111}*\x1F/u`, - parserOptions: { ecmaVersion: 2015 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], + languageOptions: { ecmaVersion: 2015 } }, { code: String.raw`new RegExp("\\u{1111}*\\x1F", "u")`, - parserOptions: { ecmaVersion: 2015 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], + languageOptions: { ecmaVersion: 2015 } }, { code: String.raw`/\u{1F}/u`, - parserOptions: { ecmaVersion: 2015 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], + languageOptions: { ecmaVersion: 2015 } }, { code: String.raw`/\u{1F}/gui`, - parserOptions: { ecmaVersion: 2015 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], + languageOptions: { ecmaVersion: 2015 } }, { code: String.raw`new RegExp("\\u{1F}", "u")`, @@ -95,13 +95,13 @@ ruleTester.run("no-control-regex", rule, { }, { code: String.raw`/[\u{1F}--B]/v`, - parserOptions: { ecmaVersion: 2024 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/\x11/; RegExp("foo", "uv");`, - parserOptions: { ecmaVersion: 2024 }, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x11" }, type: "Literal", column: 1 }] + errors: [{ messageId: "unexpected", data: { controlChars: "\\x11" }, type: "Literal", column: 1 }], + languageOptions: { ecmaVersion: 2024 } } ] }); diff --git a/tests/lib/rules/no-debugger.js b/tests/lib/rules/no-debugger.js index ac8586d1235..ef5f4d2ba70 100644 --- a/tests/lib/rules/no-debugger.js +++ b/tests/lib/rules/no-debugger.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-debugger"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-delete-var.js b/tests/lib/rules/no-delete-var.js index 67419342ef8..a4fc2ca9600 100644 --- a/tests/lib/rules/no-delete-var.js +++ b/tests/lib/rules/no-delete-var.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-delete-var"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-delete-var", rule, { valid: [ diff --git a/tests/lib/rules/no-div-regex.js b/tests/lib/rules/no-div-regex.js index 4627e20ef29..48ed61f34c6 100644 --- a/tests/lib/rules/no-div-regex.js +++ b/tests/lib/rules/no-div-regex.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-div-regex"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-dupe-args.js b/tests/lib/rules/no-dupe-args.js index 671f3c77730..a6b16d4a275 100644 --- a/tests/lib/rules/no-dupe-args.js +++ b/tests/lib/rules/no-dupe-args.js @@ -10,21 +10,26 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-dupe-args"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-dupe-args", rule, { valid: [ "function a(a, b, c){}", "var a = function(a, b, c){}", - { code: "function a({a, b}, {c, d}){}", parserOptions: { ecmaVersion: 6 } }, - { code: "function a([ , a]) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo([[a, b], [c, d]]) {}", parserOptions: { ecmaVersion: 6 } } + { code: "function a({a, b}, {c, d}){}", languageOptions: { ecmaVersion: 6 } }, + { code: "function a([ , a]) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo([[a, b], [c, d]]) {}", languageOptions: { ecmaVersion: 6 } } ], invalid: [ { code: "function a(a, b, b) {}", errors: [{ messageId: "unexpected", data: { name: "b" } }] }, diff --git a/tests/lib/rules/no-dupe-class-members.js b/tests/lib/rules/no-dupe-class-members.js index a37784bc3fa..7484261d9b3 100644 --- a/tests/lib/rules/no-dupe-class-members.js +++ b/tests/lib/rules/no-dupe-class-members.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-dupe-class-members"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("no-dupe-class-members", rule, { valid: [ @@ -187,10 +187,10 @@ ruleTester.run("no-dupe-class-members", rule, { }, { code: "class A { [123n]() {} 123() {} }", - parserOptions: { ecmaVersion: 2020 }, errors: [ { type: "MethodDefinition", line: 1, column: 23, messageId: "unexpected", data: { name: "123" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "class A { [null]() {} 'null'() {} }", diff --git a/tests/lib/rules/no-dupe-else-if.js b/tests/lib/rules/no-dupe-else-if.js index 156c22fd5a0..e391f60dda5 100644 --- a/tests/lib/rules/no-dupe-else-if.js +++ b/tests/lib/rules/no-dupe-else-if.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-dupe-else-if"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-dupe-keys.js b/tests/lib/rules/no-dupe-keys.js index 6c650db485f..a00bad3dc90 100644 --- a/tests/lib/rules/no-dupe-keys.js +++ b/tests/lib/rules/no-dupe-keys.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-dupe-keys"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-dupe-keys", rule, { valid: [ @@ -24,35 +29,35 @@ ruleTester.run("no-dupe-keys", rule, { "var x = { foo: 1, bar: 2 };", "var x = { '': 1, bar: 2 };", "var x = { '': 1, ' ': 2 };", - { code: "var x = { '': 1, [null]: 2 };", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = { '': 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = { [a]: 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } }, + { code: "var x = { '': 1, [null]: 2 };", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { '': 1, [a]: 2 };", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { [a]: 1, [a]: 2 };", languageOptions: { ecmaVersion: 6 } }, "+{ get a() { }, set a(b) { } };", - { code: "var x = { a: b, [a]: b };", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = { a: b, ...c }", parserOptions: { ecmaVersion: 2018 } }, - { code: "var x = { get a() {}, set a (value) {} };", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = { a: 1, b: { a: 2 } };", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = ({ null: 1, [/(?0)/]: 2 })", parserOptions: { ecmaVersion: 2018 } }, - { code: "var {a, a} = obj", parserOptions: { ecmaVersion: 6 } }, + { code: "var x = { a: b, [a]: b };", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { a: b, ...c }", languageOptions: { ecmaVersion: 2018 } }, + { code: "var x = { get a() {}, set a (value) {} };", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { a: 1, b: { a: 2 } };", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = ({ null: 1, [/(?0)/]: 2 })", languageOptions: { ecmaVersion: 2018 } }, + { code: "var {a, a} = obj", languageOptions: { ecmaVersion: 6 } }, "var x = { 012: 1, 12: 2 };", - { code: "var x = { 1_0: 1, 1: 2 };", parserOptions: { ecmaVersion: 2021 } } + { code: "var x = { 1_0: 1, 1: 2 };", languageOptions: { ecmaVersion: 2021 } } ], invalid: [ - { code: "var x = { a: b, ['a']: b };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, + { code: "var x = { a: b, ['a']: b };", errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, { code: "var x = { y: 1, y: 2 };", errors: [{ messageId: "unexpected", data: { name: "y" }, type: "ObjectExpression" }] }, { code: "var x = { '': 1, '': 2 };", errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] }, - { code: "var x = { '': 1, [``]: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] }, + { code: "var x = { '': 1, [``]: 2 };", errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, { code: "var foo = { 0x1: 1, 1: 2};", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, { code: "var x = { 012: 1, 10: 2 };", errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }] }, - { code: "var x = { 0b1: 1, 1: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, - { code: "var x = { 0o1: 1, 1: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, - { code: "var x = { 1n: 1, 1: 2 };", parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, - { code: "var x = { 1_0: 1, 10: 2 };", parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }] }, + { code: "var x = { 0b1: 1, 1: 2 };", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { 0o1: 1, 1: 2 };", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { 1n: 1, 1: 2 };", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 2020 } }, + { code: "var x = { 1_0: 1, 10: 2 };", errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 2021 } }, { code: "var x = { \"z\": 1, z: 2 };", errors: [{ messageId: "unexpected", data: { name: "z" }, type: "ObjectExpression" }] }, { code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ messageId: "unexpected", data: { name: "bar" }, line: 3, column: 3 }] }, - { code: "var x = { a: 1, get a() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, - { code: "var x = { a: 1, set a(value) {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, - { code: "var x = { a: 1, b: { a: 2 }, get b() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "b" }, type: "ObjectExpression" }] }, - { code: "var x = ({ '/(?0)/': 1, [/(?0)/]: 2 })", parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "unexpected", data: { name: "/(?0)/" }, type: "ObjectExpression" }] } + { code: "var x = { a: 1, get a() {} };", errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { a: 1, set a(value) {} };", errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { a: 1, b: { a: 2 }, get b() {} };", errors: [{ messageId: "unexpected", data: { name: "b" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = ({ '/(?0)/': 1, [/(?0)/]: 2 })", errors: [{ messageId: "unexpected", data: { name: "/(?0)/" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 2018 } } ] }); diff --git a/tests/lib/rules/no-duplicate-case.js b/tests/lib/rules/no-duplicate-case.js index 42dbda3f18d..73ac5fcac95 100644 --- a/tests/lib/rules/no-duplicate-case.js +++ b/tests/lib/rules/no-duplicate-case.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-duplicate-case"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-duplicate-imports.js b/tests/lib/rules/no-duplicate-imports.js index e200bbc704d..6bae8bd0c29 100644 --- a/tests/lib/rules/no-duplicate-imports.js +++ b/tests/lib/rules/no-duplicate-imports.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-duplicate-imports"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 12, sourceType: "module" } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 12, sourceType: "module" } }); ruleTester.run("no-duplicate-imports", rule, { valid: [ diff --git a/tests/lib/rules/no-else-return.js b/tests/lib/rules/no-else-return.js index 5486bbbdc3a..21963809f4c 100644 --- a/tests/lib/rules/no-else-return.js +++ b/tests/lib/rules/no-else-return.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-else-return"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-else-return", rule, { valid: [ @@ -198,307 +203,307 @@ ruleTester.run("no-else-return", rule, { { code: "function foo() { var a; if (bar) { return true; } else { var a; } }", output: "function foo() { var a; if (bar) { return true; } var a; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", output: "function foo() { if (bar) { var a; if (baz) { return true; } var a; } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class foo { bar() { let a; if (baz) { return true; } else { let a; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { let a; if (baz) { return true; } else { let a; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() {let a; if (bar) { if (baz) { return true; } else { let a; } } }", output: "function foo() {let a; if (bar) { if (baz) { return true; } let a; } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { const a = 1; if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { const a = 1; if (baz) { return true; } else { let a; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; if (bar) { return true; } else { const a = 1 } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { let a; if (baz) { return true; } else { const a = 1; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { class a {}; if (bar) { return true; } else { const a = 1; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { class a {}; if (baz) { return true; } else { const a = 1; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { const a = 1; if (bar) { return true; } else { class a {} } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { const a = 1; if (baz) { return true; } else { class a {} } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var a; if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { var a; return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let a; } while (baz) { var a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "BlockStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a = 1) { if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a, b = a) { if (bar) { return true; } else { let a; } if (bar) { return true; } else { let b; }}", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "BlockStatement" }, { messageId: "unexpected", type: "BlockStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(...args) { if (bar) { return true; } else { let args; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { try {} catch (a) { if (bar) { return true; } else { let a; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } else { let a; } } } }", output: "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } let a; } } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { try {} catch ({bar, a = 1}) { if (baz) { return true; } else { let a; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let arguments; } }", output: "function foo() { if (bar) { return true; } let arguments; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let arguments; } return arguments[0]; }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let arguments; } if (baz) { return arguments[0]; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let arguments; } } }", output: "function foo() { if (bar) { if (baz) { return true; } let arguments; } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let a; } a; }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let a; } if (baz) { a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } a; }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } a; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { a; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function a() { if (foo) { return true; } else { let a; } a(); }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function a() { if (a) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function a() { if (foo) { return a; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let a; } function baz() { a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } (() => a) } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let a; } var a; }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } var a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } var { a } = {}; } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { var a; } } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { var a; } }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { var a; } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } else { let a; } } }", output: "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } let a; } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else { let a; } function a(){} }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (baz) { if (bar) { return true; } else { let a; } function a(){} } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { function a(){} } }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { function a(){} } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } function a(){} }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } function a(){} }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; if (bar) { return true; } else { function a(){} } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var a; if (bar) { return true; } else { function a(){} } }", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { if (bar) { return true; } else function baz() {} };", @@ -508,16 +513,14 @@ ruleTester.run("no-else-return", rule, { { code: "if (foo) { return true; } else { let a; }", output: "if (foo) { return true; } let a; ", - parserOptions: { ecmaVersion: 6 }, - env: { node: true }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, { code: "let a; if (foo) { return true; } else { let a; }", output: null, - parserOptions: { ecmaVersion: 6 }, - env: { node: true }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } } ] }); diff --git a/tests/lib/rules/no-empty-character-class.js b/tests/lib/rules/no-empty-character-class.js index 81b66c4b300..2b07a50d294 100644 --- a/tests/lib/rules/no-empty-character-class.js +++ b/tests/lib/rules/no-empty-character-class.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-empty-character-class"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -33,18 +33,18 @@ ruleTester.run("no-empty-character-class", rule, { "var foo = /\\s*:\\s*/gim;", "var foo = /[^]/;", // this rule allows negated empty character classes "var foo = /\\[][^]/;", - { code: "var foo = /[\\]]/uy;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = /[\\]]/s;", parserOptions: { ecmaVersion: 2018 } }, - { code: "var foo = /[\\]]/d;", parserOptions: { ecmaVersion: 2022 } }, + { code: "var foo = /[\\]]/uy;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = /[\\]]/s;", languageOptions: { ecmaVersion: 2018 } }, + { code: "var foo = /[\\]]/d;", languageOptions: { ecmaVersion: 2022 } }, "var foo = /\\[]/", - { code: "var foo = /[[^]]/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[\\]]]/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[\\[]]/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[a--b]/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[a&&b]/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[a][b]]/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[\\q{}]/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[^]--\\p{ASCII}]/v;", parserOptions: { ecmaVersion: 2024 } } + { code: "var foo = /[[^]]/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[\\]]]/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[\\[]]/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[a--b]/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[a&&b]/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[a][b]]/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[\\q{}]/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[^]--\\p{ASCII}]/v;", languageOptions: { ecmaVersion: 2024 } } ], invalid: [ { code: "var foo = /^abc[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, @@ -54,15 +54,15 @@ ruleTester.run("no-empty-character-class", rule, { { code: "var foo = /[]]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "var foo = /\\[[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "var foo = /\\[\\[\\]a-z[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[]]/d;", parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[(]\\u{0}*[]/u;", parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[[]]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[[a][]]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[a[[b[]c]]d]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[a--[]]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[[]--b]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[a&&[]]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[[]&&b]/v;", parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] } + { code: "var foo = /[]]/d;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2022 } }, + { code: "var foo = /[(]\\u{0}*[]/u;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2015 } }, + { code: "var foo = /[]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[a][]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[a[[b[]c]]d]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[a--[]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[]--b]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[a&&[]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[[]&&b]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } } ] }); diff --git a/tests/lib/rules/no-empty-function.js b/tests/lib/rules/no-empty-function.js index f42c2325f25..9c2e9c73858 100644 --- a/tests/lib/rules/no-empty-function.js +++ b/tests/lib/rules/no-empty-function.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-empty-function"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -39,28 +39,28 @@ const ALLOW_OPTIONS = Object.freeze([ function toValidInvalid(patterns, item) { const ecmaVersion = - item.parserOptions && item.parserOptions.ecmaVersion - ? item.parserOptions.ecmaVersion + item.languageOptions && item.languageOptions.ecmaVersion + ? item.languageOptions.ecmaVersion : 6; // Valid Patterns patterns.valid.push( { code: item.code.replace("{}", "{ bar(); }"), - parserOptions: { ecmaVersion } + languageOptions: { ecmaVersion } }, { code: item.code.replace("{}", "{ /* empty */ }"), - parserOptions: { ecmaVersion } + languageOptions: { ecmaVersion } }, { code: item.code.replace("{}", "{\n // empty\n}"), - parserOptions: { ecmaVersion } + languageOptions: { ecmaVersion } }, { code: `${item.code} // allow: ${item.allow}`, options: [{ allow: [item.allow] }], - parserOptions: { ecmaVersion } + languageOptions: { ecmaVersion } } ); @@ -70,7 +70,7 @@ function toValidInvalid(patterns, item) { patterns.invalid.push({ code: item.code, errors: [error], - parserOptions: { ecmaVersion } + languageOptions: { ecmaVersion } }); ALLOW_OPTIONS .filter(allow => allow !== item.allow) @@ -81,7 +81,7 @@ function toValidInvalid(patterns, item) { code: `${item.code} // allow: ${allow}`, errors: [error], options: [{ allow: [allow] }], - parserOptions: { ecmaVersion } + languageOptions: { ecmaVersion } }); }); @@ -274,41 +274,41 @@ ruleTester.run("no-empty-function", rule, [ allow: "asyncMethods", messageId: "unexpected", data: { name: "async method 'method'" }, - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function a(){}", allow: "asyncFunctions", messageId: "unexpected", data: { name: "async function 'a'" }, - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "const foo = async function () {}", messageId: "unexpected", data: { name: "async function" }, allow: "asyncFunctions", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "class Foo { async bar() {} }", messageId: "unexpected", data: { name: "async method 'bar'" }, allow: "asyncMethods", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "const foo = async () => {};", messageId: "unexpected", data: { name: "async arrow function" }, allow: "arrowFunctions", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } } ].reduce(toValidInvalid, { valid: [ { code: "var foo = () => 0;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -339,7 +339,7 @@ ruleTester.run("no-empty-function", rule, [ }, { code: "var foo = () => { \n\n }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "arrow function" }, @@ -351,7 +351,7 @@ ruleTester.run("no-empty-function", rule, [ }, { code: "var obj = {\n\tfoo() {\n\t}\n}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "method 'foo'" }, @@ -363,7 +363,7 @@ ruleTester.run("no-empty-function", rule, [ }, { code: "class A { foo() { } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "method 'foo'" }, diff --git a/tests/lib/rules/no-empty-pattern.js b/tests/lib/rules/no-empty-pattern.js index 2cd06c4be37..47ec0f86cd4 100644 --- a/tests/lib/rules/no-empty-pattern.js +++ b/tests/lib/rules/no-empty-pattern.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-empty-pattern"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,202 +21,202 @@ ruleTester.run("no-empty-pattern", rule, { // Examples of code that should not trigger the rule valid: [ - { code: "var {a = {}} = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var {a, b = {}} = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var {a = []} = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo({a = {}}) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo({a = []}) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a] = foo", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo({}) {}", options: [{ allowObjectPatternsAsParameters: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = function({}) {}", options: [{ allowObjectPatternsAsParameters: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = ({}) => {}", options: [{ allowObjectPatternsAsParameters: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo({} = {}) {}", options: [{ allowObjectPatternsAsParameters: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = function({} = {}) {}", options: [{ allowObjectPatternsAsParameters: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = ({} = {}) => {}", options: [{ allowObjectPatternsAsParameters: true }], parserOptions: { ecmaVersion: 6 } } + { code: "var {a = {}} = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var {a, b = {}} = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var {a = []} = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo({a = {}}) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo({a = []}) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a] = foo", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo({}) {}", options: [{ allowObjectPatternsAsParameters: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = function({}) {}", options: [{ allowObjectPatternsAsParameters: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = ({}) => {}", options: [{ allowObjectPatternsAsParameters: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo({} = {}) {}", options: [{ allowObjectPatternsAsParameters: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = function({} = {}) {}", options: [{ allowObjectPatternsAsParameters: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = ({} = {}) => {}", options: [{ allowObjectPatternsAsParameters: true }], languageOptions: { ecmaVersion: 6 } } ], // Examples of code that should trigger the rule invalid: [ { code: "var {} = foo", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [] = foo", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a: {}} = foo", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a, b: {}} = foo", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a: []} = foo", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({}) {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo([]) {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({a: {}}) {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({a: []}) {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function({}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = ({}) => {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo({} = {}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function({} = {}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = ({} = {}) => {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = ({a: {}}) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = ({} = bar) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = ({} = { bar: 1 }) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = ([]) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-empty-static-block.js b/tests/lib/rules/no-empty-static-block.js index 592c840ff3d..73bc06512cd 100644 --- a/tests/lib/rules/no-empty-static-block.js +++ b/tests/lib/rules/no-empty-static-block.js @@ -9,14 +9,14 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-empty-static-block"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("no-empty-static-block", rule, { diff --git a/tests/lib/rules/no-empty.js b/tests/lib/rules/no-empty.js index 812aa8de994..89d0825428d 100644 --- a/tests/lib/rules/no-empty.js +++ b/tests/lib/rules/no-empty.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-empty"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -26,7 +26,7 @@ ruleTester.run("no-empty", rule, { "try { foo() } catch (ex) { foo() }", "switch(foo) {case 'foo': break;}", "(function() { }())", - { code: "var foo = () => {};", parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => {};", languageOptions: { ecmaVersion: 6 } }, "function foo() { }", "if (foo) {/* empty */}", "while (foo) {/* empty */}", diff --git a/tests/lib/rules/no-eq-null.js b/tests/lib/rules/no-eq-null.js index 6ac277f2872..52f3be7d6a2 100644 --- a/tests/lib/rules/no-eq-null.js +++ b/tests/lib/rules/no-eq-null.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-eq-null"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-eval.js b/tests/lib/rules/no-eval.js index de1e11df19e..7b057cb728a 100644 --- a/tests/lib/rules/no-eval.js +++ b/tests/lib/rules/no-eval.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-eval"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-eval", rule, { valid: [ @@ -28,34 +33,32 @@ ruleTester.run("no-eval", rule, { // User-defined eval methods. "window.eval('foo')", - { code: "window.eval('foo')", env: { node: true } }, - { code: "window.noeval('foo')", env: { browser: true } }, - { code: "function foo() { var eval = 'foo'; window[eval]('foo') }", env: { browser: true } }, + { code: "window.eval('foo')", languageOptions: { sourceType: "commonjs" } }, + { code: "window.noeval('foo')", languageOptions: { globals: { window: "readonly" } } }, + { code: "function foo() { var eval = 'foo'; window[eval]('foo') }", languageOptions: { globals: { window: "readonly" } } }, "global.eval('foo')", - { code: "global.eval('foo')", env: { browser: true } }, - { code: "global.noeval('foo')", env: { node: true } }, - { code: "function foo() { var eval = 'foo'; global[eval]('foo') }", env: { node: true } }, + { code: "global.noeval('foo')", languageOptions: { sourceType: "commonjs" } }, + { code: "function foo() { var eval = 'foo'; global[eval]('foo') }", languageOptions: { sourceType: "commonjs", globals: { global: "readonly" } } }, "globalThis.eval('foo')", - { code: "globalThis.eval('foo')", env: { es2017: true } }, - { code: "globalThis.eval('foo')", env: { browser: true } }, - { code: "globalThis.noneval('foo')", env: { es2020: true } }, - { code: "function foo() { var eval = 'foo'; globalThis[eval]('foo') }", env: { es2020: true } }, + { code: "globalThis.eval('foo')", languageOptions: { ecmaVersion: 2017 } }, + { code: "globalThis.noneval('foo')", languageOptions: { ecmaVersion: 2020 } }, + { code: "function foo() { var eval = 'foo'; globalThis[eval]('foo') }", languageOptions: { ecmaVersion: 2020 } }, "this.noeval('foo');", "function foo() { 'use strict'; this.eval('foo'); }", - { code: "'use strict'; this.eval('foo');", parserOptions: { ecmaFeatures: { globalReturn: true } } }, - { code: "this.eval('foo');", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function foo() { this.eval('foo'); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function foo() { this.eval('foo'); }", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, + { code: "'use strict'; this.eval('foo');", languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, + { code: "this.eval('foo');", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { this.eval('foo'); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { this.eval('foo'); }", languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, "var obj = {foo: function() { this.eval('foo'); }}", "var obj = {}; obj.foo = function() { this.eval('foo'); }", - { code: "() => { this.eval('foo') }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function f() { 'use strict'; () => { this.eval('foo') } }", parserOptions: { ecmaVersion: 6 } }, - { code: "(function f() { 'use strict'; () => { this.eval('foo') } })", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { foo() { this.eval(); } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { static foo() { this.eval(); } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { field = this.eval(); }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { field = () => this.eval(); }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { static { this.eval(); } }", parserOptions: { ecmaVersion: 2022 } }, + { code: "() => { this.eval('foo') }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function f() { 'use strict'; () => { this.eval('foo') } }", languageOptions: { ecmaVersion: 6 } }, + { code: "(function f() { 'use strict'; () => { this.eval('foo') } })", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { foo() { this.eval(); } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { static foo() { this.eval(); } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { field = this.eval(); }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { field = () => this.eval(); }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { static { this.eval(); } }", languageOptions: { ecmaVersion: 2022 } }, // User-defined this.eval in callbacks "array.findLast(function (x) { return this.eval.includes(x); }, { eval: ['foo', 'bar'] });", @@ -64,26 +67,26 @@ ruleTester.run("no-eval", rule, { // Allows indirect eval { code: "(0, eval)('foo')", options: [{ allowIndirect: true }] }, - { code: "(0, window.eval)('foo')", options: [{ allowIndirect: true }], env: { browser: true } }, - { code: "(0, window['eval'])('foo')", options: [{ allowIndirect: true }], env: { browser: true } }, + { code: "(0, window.eval)('foo')", options: [{ allowIndirect: true }], languageOptions: { globals: { window: "readonly" } } }, + { code: "(0, window['eval'])('foo')", options: [{ allowIndirect: true }], languageOptions: { globals: { window: "readonly" } } }, { code: "var EVAL = eval; EVAL('foo')", options: [{ allowIndirect: true }] }, { code: "var EVAL = this.eval; EVAL('foo')", options: [{ allowIndirect: true }] }, { code: "(function(exe){ exe('foo') })(eval);", options: [{ allowIndirect: true }] }, - { code: "window.eval('foo')", options: [{ allowIndirect: true }], env: { browser: true } }, - { code: "window.window.eval('foo')", options: [{ allowIndirect: true }], env: { browser: true } }, - { code: "window.window['eval']('foo')", options: [{ allowIndirect: true }], env: { browser: true } }, - { code: "global.eval('foo')", options: [{ allowIndirect: true }], env: { node: true } }, - { code: "global.global.eval('foo')", options: [{ allowIndirect: true }], env: { node: true } }, + { code: "window.eval('foo')", options: [{ allowIndirect: true }], languageOptions: { globals: { window: "readonly" } } }, + { code: "window.window.eval('foo')", options: [{ allowIndirect: true }], languageOptions: { globals: { window: "readonly" } } }, + { code: "window.window['eval']('foo')", options: [{ allowIndirect: true }], languageOptions: { globals: { window: "readonly" } } }, + { code: "global.eval('foo')", options: [{ allowIndirect: true }], languageOptions: { sourceType: "commonjs" } }, + { code: "global.global.eval('foo')", options: [{ allowIndirect: true }], languageOptions: { sourceType: "commonjs" } }, { code: "this.eval('foo')", options: [{ allowIndirect: true }] }, { code: "function foo() { this.eval('foo') }", options: [{ allowIndirect: true }] }, - { code: "(0, globalThis.eval)('foo')", options: [{ allowIndirect: true }], env: { es2020: true } }, - { code: "(0, globalThis['eval'])('foo')", options: [{ allowIndirect: true }], env: { es2020: true } }, + { code: "(0, globalThis.eval)('foo')", options: [{ allowIndirect: true }], languageOptions: { ecmaVersion: 2020 } }, + { code: "(0, globalThis['eval'])('foo')", options: [{ allowIndirect: true }], languageOptions: { ecmaVersion: 2020 } }, { code: "var EVAL = globalThis.eval; EVAL('foo')", options: [{ allowIndirect: true }] }, - { code: "function foo() { globalThis.eval('foo') }", options: [{ allowIndirect: true }], env: { es2020: true } }, - { code: "globalThis.globalThis.eval('foo');", options: [{ allowIndirect: true }], env: { es2020: true } }, - { code: "eval?.('foo')", options: [{ allowIndirect: true }], parserOptions: { ecmaVersion: 2020 } }, - { code: "window?.eval('foo')", options: [{ allowIndirect: true }], parserOptions: { ecmaVersion: 2020 }, env: { browser: true } }, - { code: "(window?.eval)('foo')", options: [{ allowIndirect: true }], parserOptions: { ecmaVersion: 2020 }, env: { browser: true } } + { code: "function foo() { globalThis.eval('foo') }", options: [{ allowIndirect: true }], languageOptions: { ecmaVersion: 2020 } }, + { code: "globalThis.globalThis.eval('foo');", options: [{ allowIndirect: true }], languageOptions: { ecmaVersion: 2020 } }, + { code: "eval?.('foo')", options: [{ allowIndirect: true }], languageOptions: { ecmaVersion: 2020 } }, + { code: "window?.eval('foo')", options: [{ allowIndirect: true }], languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } }, + { code: "(window?.eval)('foo')", options: [{ allowIndirect: true }], languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } } ], invalid: [ @@ -98,82 +101,79 @@ ruleTester.run("no-eval", rule, { // Indirect eval { code: "(0, eval)('foo')", errors: [{ messageId: "unexpected", type: "Identifier", column: 5, endColumn: 9 }] }, - { code: "(0, window.eval)('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 16 }] }, - { code: "(0, window['eval'])('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 18 }] }, + { code: "(0, window.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 16 }], languageOptions: { globals: { window: "readonly" } } }, + { code: "(0, window['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 18 }], languageOptions: { globals: { window: "readonly" } } }, { code: "var EVAL = eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "Identifier", column: 12, endColumn: 16 }] }, { code: "var EVAL = this.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 17, endColumn: 21 }] }, { code: "'use strict'; var EVAL = this.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 31, endColumn: 35 }] }, - { code: "() => { this.eval('foo'); }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 14, endColumn: 18 }] }, - { code: "() => { 'use strict'; this.eval('foo'); }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }] }, - { code: "'use strict'; () => { this.eval('foo'); }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }] }, - { code: "() => { 'use strict'; () => { this.eval('foo'); } }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 36, endColumn: 40 }] }, + { code: "() => { this.eval('foo'); }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 14, endColumn: 18 }], languageOptions: { ecmaVersion: 6 } }, + { code: "() => { 'use strict'; this.eval('foo'); }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }], languageOptions: { ecmaVersion: 6 } }, + { code: "'use strict'; () => { this.eval('foo'); }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }], languageOptions: { ecmaVersion: 6 } }, + { code: "() => { 'use strict'; () => { this.eval('foo'); } }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 36, endColumn: 40 }], languageOptions: { ecmaVersion: 6 } }, { code: "(function(exe){ exe('foo') })(eval);", errors: [{ messageId: "unexpected", type: "Identifier", column: 31, endColumn: 35 }] }, - { code: "window.eval('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }] }, - { code: "window.window.eval('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }] }, - { code: "window.window['eval']('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }] }, - { code: "global.eval('foo')", env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }] }, - { code: "global.global.eval('foo')", env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }] }, - { code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }] }, + { code: "window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], languageOptions: { globals: { window: "readonly" } } }, + { code: "window.window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], languageOptions: { globals: { window: "readonly" } } }, + { code: "window.window['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], languageOptions: { globals: { window: "readonly" } } }, + { code: "global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], languageOptions: { sourceType: "commonjs" } }, + { code: "global.global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], languageOptions: { sourceType: "commonjs" } }, + { code: "global.global[`eval`]('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, { code: "this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 6, endColumn: 10 }] }, { code: "'use strict'; this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 20, endColumn: 24 }] }, { code: "function foo() { this.eval('foo') }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }] }, - { code: "var EVAL = globalThis.eval; EVAL('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 23, endColumn: 27 }] }, - { code: "globalThis.eval('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 12, endColumn: 16 }] }, - { code: "globalThis.globalThis.eval('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }] }, - { code: "globalThis.globalThis['eval']('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 29 }] }, - { code: "(0, globalThis.eval)('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 20 }] }, - { code: "(0, globalThis['eval'])('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 22 }] }, + { code: "var EVAL = globalThis.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 23, endColumn: 27 }], languageOptions: { ecmaVersion: 2020 } }, + { code: "globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 12, endColumn: 16 }], languageOptions: { ecmaVersion: 2020 } }, + { code: "globalThis.globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }], languageOptions: { ecmaVersion: 2020 } }, + { code: "globalThis.globalThis['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 29 }], languageOptions: { ecmaVersion: 2020 } }, + { code: "(0, globalThis.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 20 }], languageOptions: { ecmaVersion: 2020 } }, + { code: "(0, globalThis['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 22 }], languageOptions: { ecmaVersion: 2020 } }, // Optional chaining { code: "window?.eval('foo')", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } }, { code: "(window?.eval)('foo')", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } }, { code: "(window?.window).eval('foo')", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } }, // Class fields { code: "class C { [this.eval('foo')] }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "'use strict'; class C { [this.eval('foo')] }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { static {} [this.eval()]; }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2022 } }, // in es3, "use strict" directives do not apply { code: "function foo() { 'use strict'; this.eval(); }", - parserOptions: { ecmaVersion: 3 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 3 } }, // this.eval in callbacks (not user-defined) { code: "array.findLast(x => this.eval.includes(x), { eval: 'abc' });", - parserOptions: { ecmaVersion: 2023 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2023 } }, { code: "callbacks.findLastIndex(function (cb) { return cb(eval); }, this);", diff --git a/tests/lib/rules/no-ex-assign.js b/tests/lib/rules/no-ex-assign.js index 0c00dba65e1..ec7d0268c33 100644 --- a/tests/lib/rules/no-ex-assign.js +++ b/tests/lib/rules/no-ex-assign.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-ex-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,14 +21,14 @@ const ruleTester = new RuleTester(); ruleTester.run("no-ex-assign", rule, { valid: [ "try { } catch (e) { three = 2 + 1; }", - { code: "try { } catch ({e}) { this.something = 2; }", parserOptions: { ecmaVersion: 6 } }, + { code: "try { } catch ({e}) { this.something = 2; }", languageOptions: { ecmaVersion: 6 } }, "function foo() { try { } catch (e) { return false; } }" ], invalid: [ { code: "try { } catch (e) { e = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "try { } catch (ex) { ex = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }] }, - { code: "try { } catch (ex) { [ex] = []; }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, - { code: "try { } catch (ex) { ({x: ex = 0} = {}); }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, - { code: "try { } catch ({message}) { message = 10; }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] } + { code: "try { } catch (ex) { [ex] = []; }", errors: [{ messageId: "unexpected", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, + { code: "try { } catch (ex) { ({x: ex = 0} = {}); }", errors: [{ messageId: "unexpected", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, + { code: "try { } catch ({message}) { message = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-extend-native.js b/tests/lib/rules/no-extend-native.js index 4cb4a64b35c..2d36848d2b5 100644 --- a/tests/lib/rules/no-extend-native.js +++ b/tests/lib/rules/no-extend-native.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-extend-native"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-extend-native", rule, { valid: [ @@ -47,7 +52,7 @@ ruleTester.run("no-extend-native", rule, { "function foo() { var Object = function() {}; Object.prototype.p = 0 }", { code: "{ let Object = function() {}; Object.prototype.p = 0 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], invalid: [{ @@ -59,36 +64,36 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "BigInt.prototype.p = 0", - env: { es2020: true }, errors: [{ messageId: "unexpected", data: { builtin: "BigInt" }, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "WeakRef.prototype.p = 0", - env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "WeakRef" }, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "FinalizationRegistry.prototype.p = 0", - env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "FinalizationRegistry" }, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "AggregateError.prototype.p = 0", - env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "AggregateError" }, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "Function.prototype['p'] = 0", errors: [{ @@ -167,40 +172,40 @@ ruleTester.run("no-extend-native", rule, { // Optional chaining { code: "(Object?.prototype).p = 0", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object.defineProperty(Object?.prototype, 'p', { value: 0 })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "Object?.defineProperty(Object.prototype, 'p', { value: 0 })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperty)(Object.prototype, 'p', { value: 0 })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], + languageOptions: { ecmaVersion: 2020 } }, // Logical assignments { code: "Array.prototype.p &&= 0", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] + errors: [{ messageId: "unexpected", data: { builtin: "Array" } }], + languageOptions: { ecmaVersion: 2021 } }, { code: "Array.prototype.p ||= 0", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] + errors: [{ messageId: "unexpected", data: { builtin: "Array" } }], + languageOptions: { ecmaVersion: 2021 } }, { code: "Array.prototype.p ??= 0", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] + errors: [{ messageId: "unexpected", data: { builtin: "Array" } }], + languageOptions: { ecmaVersion: 2021 } } ] diff --git a/tests/lib/rules/no-extra-bind.js b/tests/lib/rules/no-extra-bind.js index 8422f3de771..f6ab33f737e 100644 --- a/tests/lib/rules/no-extra-bind.js +++ b/tests/lib/rules/no-extra-bind.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-extra-bind"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,16 +21,16 @@ const errors = [{ messageId: "unexpected", type: "CallExpression" }]; ruleTester.run("no-extra-bind", rule, { valid: [ "var a = function(b) { return b }.bind(c, d)", - { code: "var a = function(b) { return b }.bind(...c)", parserOptions: { ecmaVersion: 6 } }, + { code: "var a = function(b) { return b }.bind(...c)", languageOptions: { ecmaVersion: 6 } }, "var a = function() { this.b }()", "var a = function() { this.b }.foo()", "var a = f.bind(a)", "var a = function() { return this.b }.bind(c)", - { code: "var a = (() => { return b }).bind(c, d)", parserOptions: { ecmaVersion: 6 } }, + { code: "var a = (() => { return b }).bind(c, d)", languageOptions: { ecmaVersion: 6 } }, "(function() { (function() { this.b }.bind(this)) }.bind(c))", "var a = function() { return 1; }[bind](b)", - { code: "var a = function() { return 1; }[`bi${n}d`](b)", parserOptions: { ecmaVersion: 6 } }, - { code: "var a = function() { return () => this; }.bind(b)", parserOptions: { ecmaVersion: 6 } } + { code: "var a = function() { return 1; }[`bi${n}d`](b)", languageOptions: { ecmaVersion: 6 } }, + { code: "var a = function() { return () => this; }.bind(b)", languageOptions: { ecmaVersion: 6 } } ], invalid: [ { @@ -60,7 +60,6 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { return 1; }[`bind`](b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", @@ -68,19 +67,20 @@ ruleTester.run("no-extra-bind", rule, { column: 34, endLine: 1, endColumn: 40 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = (() => { return 1; }).bind(b)", output: "var a = (() => { return 1; })", - parserOptions: { ecmaVersion: 6 }, - errors + errors, + languageOptions: { ecmaVersion: 6 } }, { code: "var a = (() => { return this; }).bind(b)", output: "var a = (() => { return this; })", - parserOptions: { ecmaVersion: 6 }, - errors + errors, + languageOptions: { ecmaVersion: 6 } }, { code: "var a = function() { (function(){ this.c }) }.bind(b)", @@ -196,38 +196,38 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { return 1; }.bind?.(b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = function() { return 1; }?.bind(b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = (function() { return 1; }?.bind)(b)", output: "var a = (function() { return 1; })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = function() { return 1; }['bind']?.(b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = function() { return 1; }?.['bind'](b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = (function() { return 1; }?.['bind'])(b)", output: "var a = (function() { return 1; })", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-extra-boolean-cast.js b/tests/lib/rules/no-extra-boolean-cast.js index 2e95cb740bb..97dde6504b8 100644 --- a/tests/lib/rules/no-extra-boolean-cast.js +++ b/tests/lib/rules/no-extra-boolean-cast.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-extra-boolean-cast"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), parser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -110,7 +110,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "if (!!foo ?? bar) {}", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } } ], @@ -279,11 +279,11 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "!Boolean(...foo);", output: null, - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "!Boolean(foo, bar());", @@ -379,56 +379,56 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield!!a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield!! a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield! !a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield !!a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield(!!a) ? b : c }", output: "function *foo() { yield(a) ? b : c }", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield/**/!!a ? b : c }", output: "function *foo() { yield/**/a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "x=!!a ? b : c ", @@ -934,11 +934,11 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(...foo) || bar;", output: null, options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "!Boolean(foo, bar()) || bar;", @@ -1028,51 +1028,51 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "function *foo() { yield(!!a || d) ? b : c }", output: "function *foo() { yield(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield(!! a || d) ? b : c }", output: "function *foo() { yield(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield(! !a || d) ? b : c }", output: "function *foo() { yield(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield (!!a || d) ? b : c }", output: "function *foo() { yield (a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield/**/(!!a || d) ? b : c }", output: "function *foo() { yield/**/(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "x=!!a || d ? b : c ", @@ -1371,13 +1371,13 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "function *foo() { yield!!a || d ? b : c }", output: "function *foo() { yield a || d ? b : c }", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression", column: 24, endColumn: 27 - }] + }], + languageOptions: { ecmaVersion: 6 } }, // test parentheses in autofix @@ -2005,26 +2005,26 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "!!!(a ** b)", output: "!(a ** b)", - parserOptions: { ecmaVersion: 2016 }, - errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }] + errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }], + languageOptions: { ecmaVersion: 2016 } }, { code: "!Boolean(a ** b)", output: "!(a ** b)", - parserOptions: { ecmaVersion: 2016 }, - errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", type: "CallExpression" }], + languageOptions: { ecmaVersion: 2016 } }, { code: "async function f() { !!!(await a) }", output: "async function f() { !await a }", - parserOptions: { ecmaVersion: 2017 }, - errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }] + errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }], + languageOptions: { ecmaVersion: 2017 } }, { code: "async function f() { !Boolean(await a) }", output: "async function f() { !await a }", - parserOptions: { ecmaVersion: 2017 }, - errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", type: "CallExpression" }], + languageOptions: { ecmaVersion: 2017 } }, { code: "!!!!a", @@ -2207,11 +2207,11 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "if (Boolean(a **= b) && Boolean(c **= d)) {}", output: "if ((a **= b) && (c **= d)) {}", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2016 }, errors: [ { messageId: "unexpectedCall", type: "CallExpression" }, { messageId: "unexpectedCall", type: "CallExpression" } - ] + ], + languageOptions: { ecmaVersion: 2016 } }, { code: "if (!!(a ? b : c) || !!(d ? e : f)) {}", @@ -2407,32 +2407,34 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "if (Boolean(a ?? b) || c) {}", output: "if ((a ?? b) || c) {}", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, // Optional chaining { code: "if (Boolean?.(foo)) ;", output: "if (foo) ;", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedCall" }] + errors: [{ messageId: "unexpectedCall" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "if (Boolean?.(a ?? b) || c) {}", output: "if ((a ?? b) || c) {}", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedCall" }] + errors: [{ messageId: "unexpectedCall" }], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/17173 { code: "if (!Boolean(a as any)) { }", output: "if (!(a as any)) { }", - parser: parser("typescript-parsers/boolean-cast-with-assertion"), - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedCall" }] + errors: [{ messageId: "unexpectedCall" }], + languageOptions: { + parser: require(parser("typescript-parsers/boolean-cast-with-assertion")), + ecmaVersion: 2020 + } } ] }); diff --git a/tests/lib/rules/no-extra-label.js b/tests/lib/rules/no-extra-label.js index e810ef4e320..0437bad774d 100644 --- a/tests/lib/rules/no-extra-label.js +++ b/tests/lib/rules/no-extra-label.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-extra-label"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -34,7 +34,7 @@ ruleTester.run("no-extra-label", rule, { "A: for (;;) { while (b) { break A; } }", "A: do { switch (b) { case 0: break A; break; } } while (a);", "A: for (a in obj) { while (b) { break A; } }", - { code: "A: for (a of ary) { switch (b) { case 0: break A; } }", parserOptions: { ecmaVersion: 6 } } + { code: "A: for (a of ary) { switch (b) { case 0: break A; } }", languageOptions: { ecmaVersion: 6 } } ], invalid: [ { @@ -70,8 +70,8 @@ ruleTester.run("no-extra-label", rule, { { code: "A: for (a of ary) { break A; }", output: "A: for (a of ary) { break; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", data: { name: "A" } }] + errors: [{ messageId: "unexpected", data: { name: "A" } }], + languageOptions: { ecmaVersion: 6 } }, { code: "A: switch (a) { case 0: break A; }", diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index 2d61522cb72..dbedafa254d 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-extra-parens"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), parser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -31,7 +31,7 @@ function invalid(code, output, type, line, config) { const result = { code, output, - parserOptions: config && config.parserOptions || {}, + languageOptions: config && config.languageOptions || {}, errors: [ { messageId: "unexpected", @@ -52,10 +52,12 @@ function invalid(code, output, type, line, config) { //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { - ecmaVersion: 2022, - ecmaFeatures: { - jsx: true + languageOptions: { + sourceType: "script", + parserOptions: { + ecmaFeatures: { + jsx: true + } } } }); @@ -590,13 +592,13 @@ ruleTester.run("no-extra-parens", rule, { "let a = { ...b }", { code: "let a = { ...b }", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, "let a = [ ...(b, c) ]", "let a = { ...(b, c) }", { code: "let a = { ...(b, c) }", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, "var [x = (1, foo)] = bar", "class A extends B {}", @@ -610,15 +612,15 @@ ruleTester.run("no-extra-parens", rule, { "() => ({ foo: 1 }.foo().bar + baz)", { code: "export default (a, b)", - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: "export default (function(){}).foo", - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: "export default (class{}).foo", - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, "({}).hasOwnProperty.call(foo, bar)", "({}) ? foo() : bar()", @@ -712,38 +714,38 @@ ruleTester.run("no-extra-parens", rule, { "new (a.b()).c", // Nullish coalescing - { code: "var v = (a ?? b) || c", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = a ?? (b || c)", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (a ?? b) && c", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = a ?? (b && c)", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (a || b) ?? c", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = a || (b ?? c)", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (a && b) ?? c", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = a && (b ?? c)", parserOptions: { ecmaVersion: 2020 } }, + { code: "var v = (a ?? b) || c", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = a ?? (b || c)", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (a ?? b) && c", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = a ?? (b && c)", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (a || b) ?? c", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = a || (b ?? c)", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (a && b) ?? c", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = a && (b ?? c)", languageOptions: { ecmaVersion: 2020 } }, // Optional chaining - { code: "var v = (obj?.aaa).bbb", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (obj?.aaa)()", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = new (obj?.aaa)()", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = new (obj?.aaa)", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (obj?.aaa)`template`", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (obj?.()).bbb", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (obj?.())()", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = new (obj?.())()", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = new (obj?.())", parserOptions: { ecmaVersion: 2020 } }, - { code: "var v = (obj?.())`template`", parserOptions: { ecmaVersion: 2020 } }, - { code: "(obj?.aaa).bbb = 0", parserOptions: { ecmaVersion: 2020 } }, - { code: "var foo = (function(){})?.()", parserOptions: { ecmaVersion: 2020 } }, - { code: "var foo = (function(){}?.())", parserOptions: { ecmaVersion: 2020 } }, + { code: "var v = (obj?.aaa).bbb", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (obj?.aaa)()", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = new (obj?.aaa)()", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = new (obj?.aaa)", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (obj?.aaa)`template`", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (obj?.()).bbb", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (obj?.())()", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = new (obj?.())()", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = new (obj?.())", languageOptions: { ecmaVersion: 2020 } }, + { code: "var v = (obj?.())`template`", languageOptions: { ecmaVersion: 2020 } }, + { code: "(obj?.aaa).bbb = 0", languageOptions: { ecmaVersion: 2020 } }, + { code: "var foo = (function(){})?.()", languageOptions: { ecmaVersion: 2020 } }, + { code: "var foo = (function(){}?.())", languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = (function(){})?.call()", options: ["all", { enforceForFunctionPrototypeMethods: false }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = (function(){}?.call())", options: ["all", { enforceForFunctionPrototypeMethods: false }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object.prototype.toString.call())", @@ -797,7 +799,9 @@ ruleTester.run("no-extra-parens", rule, { // https://github.com/eslint/eslint/issues/17173 { code: "const x = (1 satisfies number).toFixed();", - parser: parser("typescript-parsers/member-call-expr-with-assertion") + languageOptions: { + parser: require(parser("typescript-parsers/member-call-expr-with-assertion")) + } } ], @@ -1886,7 +1890,7 @@ ruleTester.run("no-extra-parens", rule, { "let a = {...b}", "Identifier", 1, - { parserOptions: { ecmaVersion: 2018 } } + { languageOptions: { ecmaVersion: 2018 } } ), invalid( "let a = [...((b, c))]", @@ -1905,7 +1909,7 @@ ruleTester.run("no-extra-parens", rule, { "let a = {...(b, c)}", "SequenceExpression", 1, - { parserOptions: { ecmaVersion: 2018 } } + { languageOptions: { ecmaVersion: 2018 } } ), invalid( "class A extends (B) {}", @@ -1942,49 +1946,49 @@ ruleTester.run("no-extra-parens", rule, { "export default (a, b)", "SequenceExpression", 1, - { parserOptions: { sourceType: "module" } } + { languageOptions: { sourceType: "module" } } ), invalid( "export default (() => {})", "export default () => {}", "ArrowFunctionExpression", 1, - { parserOptions: { sourceType: "module" } } + { languageOptions: { sourceType: "module" } } ), invalid( "export default ((a, b) => a + b)", "export default (a, b) => a + b", "ArrowFunctionExpression", 1, - { parserOptions: { sourceType: "module" } } + { languageOptions: { sourceType: "module" } } ), invalid( "export default (a => a)", "export default a => a", "ArrowFunctionExpression", 1, - { parserOptions: { sourceType: "module" } } + { languageOptions: { sourceType: "module" } } ), invalid( "export default (a = b)", "export default a = b", "AssignmentExpression", 1, - { parserOptions: { sourceType: "module" } } + { languageOptions: { sourceType: "module" } } ), invalid( "export default (a ? b : c)", "export default a ? b : c", "ConditionalExpression", 1, - { parserOptions: { sourceType: "module" } } + { languageOptions: { sourceType: "module" } } ), invalid( "export default (a)", "export default a", "Identifier", 1, - { parserOptions: { sourceType: "module" } } + { languageOptions: { sourceType: "module" } } ), invalid( "for (foo of(bar));", @@ -3062,21 +3066,21 @@ ruleTester.run("no-extra-parens", rule, { "import(source)", "Identifier", 1, - { parserOptions: { ecmaVersion: 2020 } } + { languageOptions: { ecmaVersion: 2020 } } ), invalid( "import((source = 'foo.js'))", "import(source = 'foo.js')", "AssignmentExpression", 1, - { parserOptions: { ecmaVersion: 2020 } } + { languageOptions: { ecmaVersion: 2020 } } ), invalid( "import(((s,t)))", "import((s,t))", "SequenceExpression", 1, - { parserOptions: { ecmaVersion: 2020 } } + { languageOptions: { ecmaVersion: 2020 } } ), // https://github.com/eslint/eslint/issues/12127 @@ -3190,68 +3194,68 @@ ruleTester.run("no-extra-parens", rule, { { code: "var v = ((a ?? b)) || c", output: "var v = (a ?? b) || c", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = a ?? ((b || c))", output: "var v = a ?? (b || c)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = ((a ?? b)) && c", output: "var v = (a ?? b) && c", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = a ?? ((b && c))", output: "var v = a ?? (b && c)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = ((a || b)) ?? c", output: "var v = (a || b) ?? c", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = a || ((b ?? c))", output: "var v = a || (b ?? c)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = ((a && b)) ?? c", output: "var v = (a && b) ?? c", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = a && ((b ?? c))", output: "var v = a && (b ?? c)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = (a ?? b) ? b : c", output: "var v = a ?? b ? b : c", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = (a | b) ?? c | d", output: "var v = a | b ?? c | d", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = a | b ?? (c | d)", output: "var v = a | b ?? c | d", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, // "allowParensAfterCommentPattern" option (off by default) @@ -3412,35 +3416,35 @@ ruleTester.run("no-extra-parens", rule, { { code: "var v = (obj?.aaa)?.aaa", output: "var v = obj?.aaa?.aaa", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var v = (obj.aaa)?.aaa", output: "var v = obj.aaa?.aaa", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = (function(){})?.call()", output: "var foo = function(){}?.call()", options: ["all", { enforceForFunctionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = (function(){}?.call())", output: "var foo = function(){}?.call()", options: ["all", { enforceForFunctionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object.prototype.toString.call())", output: "Object.prototype.toString.call()", options: ["all"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/16850 diff --git a/tests/lib/rules/no-extra-semi.js b/tests/lib/rules/no-extra-semi.js index 9a2d9a31bee..560d2f6bcde 100644 --- a/tests/lib/rules/no-extra-semi.js +++ b/tests/lib/rules/no-extra-semi.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-extra-semi"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-extra-semi", rule, { valid: [ @@ -26,25 +31,25 @@ ruleTester.run("no-extra-semi", rule, { "while(0);", "do;while(0);", "for(a in b);", - { code: "for(a of b);", parserOptions: { ecmaVersion: 6 } }, + { code: "for(a of b);", languageOptions: { ecmaVersion: 6 } }, "if(true);", "if(true); else;", "foo: ;", "with(foo);", // Class body. - { code: "class A { }", parserOptions: { ecmaVersion: 6 } }, - { code: "var A = class { };", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { a() { this; } }", parserOptions: { ecmaVersion: 6 } }, - { code: "var A = class { a() { this; } };", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { } a;", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { field; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { field = 0; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A { static { foo; } }", parserOptions: { ecmaVersion: 2022 } }, + { code: "class A { }", languageOptions: { ecmaVersion: 6 } }, + { code: "var A = class { };", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { a() { this; } }", languageOptions: { ecmaVersion: 6 } }, + { code: "var A = class { a() { this; } };", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { } a;", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { field; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { field = 0; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A { static { foo; } }", languageOptions: { ecmaVersion: 2022 } }, // modules - { code: "export const x = 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } } + { code: "export const x = 42;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default 42;", languageOptions: { ecmaVersion: 6, sourceType: "module" } } ], invalid: [ { @@ -80,8 +85,8 @@ ruleTester.run("no-extra-semi", rule, { { code: "for(a of b);;", output: "for(a of b);", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "EmptyStatement" }] + errors: [{ messageId: "unexpected", type: "EmptyStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "if(true);;", @@ -116,80 +121,80 @@ ruleTester.run("no-extra-semi", rule, { { code: "class A { static { ; } }", output: "class A { static { } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 20 }] + errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 20 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { static { a;; } }", output: "class A { static { a; } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 22 }] + errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 22 }], + languageOptions: { ecmaVersion: 2022 } }, // Class body. { code: "class A { ; }", output: "class A { }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { /*a*/; }", output: "class A { /*a*/ }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 16 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 16 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { ; a() {} }", output: "class A { a() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}; }", output: "class A { a() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}; b() {} }", output: "class A { a() {} b() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A {; a() {}; b() {}; }", output: "class A { a() {} b() {} }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "Punctuator", column: 10 }, { messageId: "unexpected", type: "Punctuator", column: 18 }, { messageId: "unexpected", type: "Punctuator", column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { a() {}; get b() {} }", output: "class A { a() {} get b() {} }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { field;; }", output: "class A { field; }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { static {}; }", output: "class A { static {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 20 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 20 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { static { a; }; foo(){} }", output: "class A { static { a; } foo(){} }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpected", type: "Punctuator", column: 24 }] + errors: [{ messageId: "unexpected", type: "Punctuator", column: 24 }], + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/16988 diff --git a/tests/lib/rules/no-fallthrough.js b/tests/lib/rules/no-fallthrough.js index 80fa61733f3..7061425ce85 100644 --- a/tests/lib/rules/no-fallthrough.js +++ b/tests/lib/rules/no-fallthrough.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-fallthrough"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -63,7 +63,7 @@ ruleTester.run("no-fallthrough", rule, { "switch (foo) { case 0: try {} finally { break; } default: b(); }", "switch (foo) { case 0: try { throw 0; } catch (err) { break; } default: b(); }", "switch (foo) { case 0: do { throw 0; } while(a); default: b(); }", - "switch (foo) { case 0: a(); \n// eslint-disable-next-line no-fallthrough\n case 1: }", + "switch (foo) { case 0: a(); \n// eslint-disable-next-line rule-to-test/no-fallthrough\n case 1: }", { code: "switch(foo) { case 0: a(); /* no break */ case 1: b(); }", options: [{ diff --git a/tests/lib/rules/no-floating-decimal.js b/tests/lib/rules/no-floating-decimal.js index 18d1b165722..10a4d2ce1aa 100644 --- a/tests/lib/rules/no-floating-decimal.js +++ b/tests/lib/rules/no-floating-decimal.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-floating-decimal"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -54,8 +54,8 @@ ruleTester.run("no-floating-decimal", rule, { { code: "for(foo of.2);", output: "for(foo of 0.2);", - parserOptions: { ecmaVersion: 2015 }, - errors: [leadingError] + errors: [leadingError], + languageOptions: { ecmaVersion: 2015 } } ] }); diff --git a/tests/lib/rules/no-func-assign.js b/tests/lib/rules/no-func-assign.js index 85a6bdcc5bb..dbcbef1f7c0 100644 --- a/tests/lib/rules/no-func-assign.js +++ b/tests/lib/rules/no-func-assign.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-func-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -23,10 +23,10 @@ ruleTester.run("no-func-assign", rule, { "function foo() { var foo = bar; }", "function foo(foo) { foo = bar; }", "function foo() { var foo; foo = bar; }", - { code: "var foo = () => {}; foo = bar;", parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => {}; foo = bar;", languageOptions: { ecmaVersion: 6 } }, "var foo = function() {}; foo = bar;", "var foo = function() { foo = bar; };", - { code: "import bar from 'bar'; function foo() { var foo = bar; }", parserOptions: { ecmaVersion: 6, sourceType: "module" } } + { code: "import bar from 'bar'; function foo() { var foo = bar; }", languageOptions: { ecmaVersion: 6, sourceType: "module" } } ], invalid: [ { @@ -55,39 +55,39 @@ ruleTester.run("no-func-assign", rule, { }, { code: "[foo] = bar; function foo() { };", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "({x: foo = 0} = bar); function foo() { };", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { [foo] = bar; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { ({x: foo = 0} = bar); function foo() { }; })();", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = function foo() { foo = 123; };", diff --git a/tests/lib/rules/no-global-assign.js b/tests/lib/rules/no-global-assign.js index 41f0ac0f305..48d04920dde 100644 --- a/tests/lib/rules/no-global-assign.js +++ b/tests/lib/rules/no-global-assign.js @@ -10,13 +10,19 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-global-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-global-assign", rule, { valid: [ @@ -24,9 +30,9 @@ ruleTester.run("no-global-assign", rule, { "var string;", { code: "Object = 0;", options: [{ exceptions: ["Object"] }] }, "top = 0;", - { code: "onload = 0;", env: { browser: true } }, + { code: "onload = 0;", languageOptions: { globals: globals.browser } }, "require = 0;", - { code: "a = 1", globals: { a: true } }, + { code: "a = 1", languageOptions: { globals: { a: true } } }, "/*global a:true*/ a = 1" ], invalid: [ @@ -48,7 +54,6 @@ ruleTester.run("no-global-assign", rule, { }, { code: "({Object = 0, String = 0} = {});", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "globalShouldNotBeModified", @@ -60,25 +65,26 @@ ruleTester.run("no-global-assign", rule, { data: { name: "String" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "top = 0;", - env: { browser: true }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "top" }, type: "Identifier" - }] + }], + languageOptions: { globals: globals.browser } }, { code: "require = 0;", - env: { node: true }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "require" }, type: "Identifier" - }] + }], + languageOptions: { sourceType: "commonjs" } }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 @@ -92,12 +98,12 @@ ruleTester.run("no-global-assign", rule, { }, { code: "function f() { b = 1; }", - globals: { b: false }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "b" }, type: "Identifier" - }] + }], + languageOptions: { globals: { b: false } } }, { code: "/*global b:false*/ function f() { b++; }", diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index e935081e6f3..beec5c9b851 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-implicit-coercion"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -64,7 +64,7 @@ ruleTester.run("no-implicit-coercion", rule, { "0 + foo", "~foo.bar()", "foo + 'bar'", - { code: "foo + `${bar}`", parserOptions: { ecmaVersion: 6 } }, + { code: "foo + `${bar}`", languageOptions: { ecmaVersion: 6 } }, { code: "!!foo", options: [{ boolean: false }] }, { code: "~foo.indexOf(1)", options: [{ boolean: false }] }, @@ -81,30 +81,30 @@ ruleTester.run("no-implicit-coercion", rule, { // https://github.com/eslint/eslint/issues/7057 "'' + 'foo'", - { code: "`` + 'foo'", parserOptions: { ecmaVersion: 6 } }, - { code: "'' + `${foo}`", parserOptions: { ecmaVersion: 6 } }, + { code: "`` + 'foo'", languageOptions: { ecmaVersion: 6 } }, + { code: "'' + `${foo}`", languageOptions: { ecmaVersion: 6 } }, "'foo' + ''", - { code: "'foo' + ``", parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}` + ''", parserOptions: { ecmaVersion: 6 } }, + { code: "'foo' + ``", languageOptions: { ecmaVersion: 6 } }, + { code: "`${foo}` + ''", languageOptions: { ecmaVersion: 6 } }, "foo += 'bar'", - { code: "foo += `${bar}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`a${foo}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}b`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}${bar}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "tag`${foo}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}`", options: [{ }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}`", options: [{ disallowTemplateShorthand: false }], parserOptions: { ecmaVersion: 6 } }, + { code: "foo += `${bar}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`a${foo}`", options: [{ disallowTemplateShorthand: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`${foo}b`", options: [{ disallowTemplateShorthand: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`${foo}${bar}`", options: [{ disallowTemplateShorthand: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "tag`${foo}`", options: [{ disallowTemplateShorthand: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`${foo}`", languageOptions: { ecmaVersion: 6 } }, + { code: "`${foo}`", options: [{ }], languageOptions: { ecmaVersion: 6 } }, + { code: "`${foo}`", options: [{ disallowTemplateShorthand: false }], languageOptions: { ecmaVersion: 6 } }, "+42", // https://github.com/eslint/eslint/issues/14623 "'' + String(foo)", "String(foo) + ''", - { code: "`` + String(foo)", parserOptions: { ecmaVersion: 6 } }, - { code: "String(foo) + ``", parserOptions: { ecmaVersion: 6 } }, - { code: "`${'foo'}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${`foo`}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${String(foo)}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`` + String(foo)", languageOptions: { ecmaVersion: 6 } }, + { code: "String(foo) + ``", languageOptions: { ecmaVersion: 6 } }, + { code: "`${'foo'}`", options: [{ disallowTemplateShorthand: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`${`foo`}`", options: [{ disallowTemplateShorthand: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`${String(foo)}`", options: [{ disallowTemplateShorthand: true }], languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/16373 "console.log(Math.PI * 1/4)", @@ -205,12 +205,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "``+foo", output: "String(foo)", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "BinaryExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo+\"\"", @@ -224,12 +224,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo+``", output: "String(foo)", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "BinaryExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "\"\"+foo.bar", @@ -243,12 +243,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "``+foo.bar", output: "String(foo.bar)", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo.bar)" }, type: "BinaryExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo.bar+\"\"", @@ -262,45 +262,45 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo.bar+``", output: "String(foo.bar)", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo.bar)" }, type: "BinaryExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`${foo}`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`\\\n${foo}`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`${foo}\\\n`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo += \"\"", @@ -314,12 +314,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo += ``", output: "foo = String(foo)", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "foo = String(foo)" }, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = !!foo", @@ -375,12 +375,12 @@ ruleTester.run("no-implicit-coercion", rule, { code: "var a = `` + foo", output: "var a = String(foo)", options: [{ boolean: true, allow: ["*"] }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "BinaryExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "typeof+foo", @@ -403,34 +403,34 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "let x ='' + 1n;", output: "let x =String(1n);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(1n)" }, type: "BinaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, // Optional chaining { code: "~foo?.indexOf(1)", output: null, - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "foo?.indexOf(1) >= 0" }, type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "~(foo?.indexOf)(1)", output: null, - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "(foo?.indexOf)(1) !== -1" }, type: "UnaryExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/16373 regression tests diff --git a/tests/lib/rules/no-implicit-globals.js b/tests/lib/rules/no-implicit-globals.js index 412ba766134..56921d208d2 100644 --- a/tests/lib/rules/no-implicit-globals.js +++ b/tests/lib/rules/no-implicit-globals.js @@ -10,13 +10,19 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-implicit-globals"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); const varMessage = "Unexpected 'var' declaration in the global scope, wrap in an IIFE for a local variable, assign as global property for a global variable."; const functionMessage = "Unexpected function declaration in the global scope, wrap in an IIFE for a local variable, assign as global property for a global variable."; @@ -37,72 +43,90 @@ ruleTester.run("no-implicit-globals", rule, { // Recommended way to create a global variable in the browser { code: "window.foo = 1;", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "window.foo = function() {};", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "window.foo = function foo() {};", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "window.foo = function bar() {};", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "window.foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2015, + globals: globals.browser + } }, { code: "window.foo = function *foo() {};", - parserOptions: { ecmaVersion: 2015 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2015, + globals: globals.browser + } }, { code: "window.foo = async function() {};", - parserOptions: { ecmaVersion: 2017 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2017, + globals: globals.browser + } }, { code: "window.foo = async function foo() {};", - parserOptions: { ecmaVersion: 2017 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2017, + globals: globals.browser + } }, { code: "window.foo = async function*() {};", - parserOptions: { ecmaVersion: 2018 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2018, + globals: globals.browser + } }, { code: "window.foo = async function *foo() {};", - parserOptions: { ecmaVersion: 2018 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2018, + globals: globals.browser + } }, { code: "window.foo = class {};", - parserOptions: { ecmaVersion: 2015 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2015, + globals: globals.browser + } }, { code: "window.foo = class foo {};", - parserOptions: { ecmaVersion: 2015 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2015, + globals: globals.browser + } }, { code: "window.foo = class bar {};", - parserOptions: { ecmaVersion: 2015 }, - env: { browser: true } + languageOptions: { + ecmaVersion: 2015, + globals: globals.browser + } }, { code: "self.foo = 1;", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "self.foo = function() {};", - env: { browser: true } + languageOptions: { globals: globals.browser } }, // Another way to create a global variable. Not the best practice, but that isn't the responsibility of this rule. @@ -117,19 +141,19 @@ ruleTester.run("no-implicit-globals", rule, { "/*global Array:writable*/", { code: "/*global foo:readonly*/", - globals: { foo: "readonly" } + languageOptions: { globals: { foo: "readonly" } } }, { code: "/*global foo:writable*/", - globals: { foo: "readonly" } + languageOptions: { globals: { foo: "readonly" } } }, { code: "/*global foo:readonly*/", - globals: { foo: "writable" } + languageOptions: { globals: { foo: "writable" } } }, { code: "/*global foo:writable*/", - globals: { foo: "writable" } + languageOptions: { globals: { foo: "writable" } } }, //------------------------------------------------------------------------------ @@ -142,15 +166,15 @@ ruleTester.run("no-implicit-globals", rule, { "(function() {}) + (function foo() {})", { code: "typeof function *foo() {}", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "typeof async function foo() {}", - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "typeof async function *foo() {}", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // Recommended way to create local variables @@ -158,49 +182,49 @@ ruleTester.run("no-implicit-globals", rule, { "(function() { function foo() {} })();", { code: "(function() { function *foo() {} })();", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "(function() { async function foo() {} })();", - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "(function() { async function *foo() {} })();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "window.foo = (function() { var bar; function foo () {}; return function bar() {} })();", - env: { browser: true } + languageOptions: { globals: globals.browser } }, // Different scoping { code: "var foo = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "function foo() {}", - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "function *foo() {}", - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "var foo = 1;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "function foo() {}", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var foo = 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, { code: "function foo() {}", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, //------------------------------------------------------------------------------ @@ -210,112 +234,114 @@ ruleTester.run("no-implicit-globals", rule, { // Test default option { code: "const foo = 1; let bar; class Baz {}", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "const foo = 1; let bar; class Baz {}", options: [{ lexicalBindings: false }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // If the option is not set to true, even the redeclarations of read-only global variables are allowed. { code: "const Array = 1; let Object; class Math {}", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly, bar:readonly, Baz:readonly*/ const foo = 1; let bar; class Baz {}", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // Doesn't report class expressions { code: "typeof class {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "typeof class foo {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // Recommended ways to create local variables { code: "{ const foo = 1; let bar; class Baz {} }", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "(function() { const foo = 1; let bar; class Baz {} })();", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "window.foo = (function() { const bar = 1; let baz; class Quux {} return function () {} })();", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // different scoping { code: "const foo = 1; let bar; class Baz {}", - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "const foo = 1; let bar; class Baz {}", - parserOptions: { ecmaVersion: 2015 }, - env: { node: true } + languageOptions: { + ecmaVersion: 2015, + sourceType: "commonjs" + } }, { code: "const foo = 1; let bar; class Baz {}", - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } } + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // Regression tests { code: "const foo = 1;", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "let foo = 1;", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "let foo = function() {};", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "const foo = function() {};", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "class Foo {}", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "(function() { let foo = 1; })();", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "(function() { const foo = 1; })();", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "let foo = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "const foo = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "let foo = 1;", - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } } + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "const foo = 1;", - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } } + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, //------------------------------------------------------------------------------ @@ -332,11 +358,11 @@ ruleTester.run("no-implicit-globals", rule, { "(function() {'use strict'; foo = 1; })();", { code: "{ class Foo { constructor() { bar = 1; } baz() { bar = 1; } } }", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "foo = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, // This rule doesn't check the existence of the objects in property assignments. These are reference errors, not leaks. Note that the env is not set. @@ -356,19 +382,19 @@ ruleTester.run("no-implicit-globals", rule, { // Not a leak { code: "foo = 1;", - globals: { foo: "writable" } + languageOptions: { globals: { foo: "writable" } } }, { code: "window.foo = function bar() { bar = 1; };", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "window.foo = function bar(baz) { baz = 1; };", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "window.foo = function bar() { var baz; function quux() { quux = 1; } };", - env: { browser: true } + languageOptions: { globals: globals.browser } }, //------------------------------------------------------------------------------ @@ -379,33 +405,33 @@ ruleTester.run("no-implicit-globals", rule, { "/*global foo:writable*/ var foo = 1;", { code: "function foo() {}", - globals: { foo: "writable" } + languageOptions: { globals: { foo: "writable" } } }, { code: "/*global foo:writable*/ function *foo() {}", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:writable*/ const foo = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:writable*/ let foo;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global Foo:writable*/ class Foo {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // Assignments to writable global variables are allowed "/*global foo:writable*/ foo = 1;", { code: "foo = 1", - globals: { foo: "writable" } + languageOptions: { globals: { foo: "writable" } } }, @@ -424,25 +450,25 @@ ruleTester.run("no-implicit-globals", rule, { "/* exported foo */ function foo() {}", { code: "/* exported foo */ function *foo() {}", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported foo */ async function foo() {}", - parserOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 } }, { code: "/* exported foo */ async function *foo() {}", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, "/* exported foo */ var foo = function() {};", "/* exported foo */ var foo = function foo() {};", { code: "/* exported foo */ var foo = function*() {};", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported foo */ var foo = function *foo() {};", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, "/* exported foo, bar */ var foo = 1, bar = 2;", @@ -451,52 +477,52 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported a */ const a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ let a;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ let a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported A */ class A {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a, b */ const a = 1; const b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a, b */ const a = 1, b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a, b */ let a, b = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a, b, C */ const a = 1; let b; class C {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a, b, c */ const [a, b, ...c] = [];", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a, b, c */ let { a, foo: b, bar: { c } } = {};", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } } ], @@ -526,33 +552,33 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "function *foo() {}", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "async function foo() {}", - parserOptions: { ecmaVersion: 2017 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2017 } }, { code: "async function *foo() {}", - parserOptions: { ecmaVersion: 2018 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var foo = function() {};", @@ -574,23 +600,23 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "var foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "var foo = function *foo() {};", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "var foo = 1, bar = 2;", @@ -615,93 +641,93 @@ ruleTester.run("no-implicit-globals", rule, { { code: "const a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ message: constMessage - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let a;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ message: letMessage - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ message: letMessage - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "class A {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ message: classMessage - }] + }], + languageOptions: { ecmaVersion: 2015 } }, // Multiple and mixed tests { code: "const a = 1; const b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "const a = 1, b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "let a, b = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage }, { message: letMessage } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "const a = 1; let b; class C {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: letMessage }, { message: classMessage } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "const [a, b, ...c] = [];", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage }, { message: constMessage } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "let { a, foo: b, bar: { c } } = {};", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage }, { message: letMessage }, { message: letMessage } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, //------------------------------------------------------------------------------ @@ -729,13 +755,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "window.foo = function() { bar = 1; }", @@ -766,45 +792,45 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "for (foo of []);", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "ForOfStatement" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, // Not implicit strict { code: "window.foo = { bar() { foo = 1 } }", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "foo = 1", - env: { node: true }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { sourceType: "commonjs" } }, { code: "foo = 1;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // Multiple and mixed @@ -898,7 +924,6 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "[foo, bar] = [];", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -908,27 +933,28 @@ ruleTester.run("no-implicit-globals", rule, { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:writable*/ [foo, bar] = [];", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global bar:writable*/ [foo, bar] = [];", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, //------------------------------------------------------------------------------ @@ -947,13 +973,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "window = 1;", - env: { browser: true }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { globals: globals.browser } }, { code: "/*global foo:readonly*/ foo = 1", @@ -966,13 +992,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1;", - globals: { foo: "readonly" }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { globals: { foo: "readonly" } } }, { code: "/*global foo:readonly*/ for (foo in {});", @@ -985,13 +1011,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/*global foo:readonly*/ for (foo of []);", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyAssignmentMessage, type: "ForOfStatement" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, // Basic redeclaration tests @@ -1034,46 +1060,46 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly*/ const foo = 1", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly*/ let foo", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly*/ let foo = 1", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global Foo:readonly*/ class Foo {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "ClassDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, // Multiple and mixed assignments @@ -1196,7 +1222,6 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly, bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1206,34 +1231,34 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:writable, bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly, bar: writable*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1243,12 +1268,12 @@ ruleTester.run("no-implicit-globals", rule, { message: constMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1258,12 +1283,12 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly, bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1273,34 +1298,34 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:writable, bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly, bar: writable*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global foo:readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1310,12 +1335,12 @@ ruleTester.run("no-implicit-globals", rule, { message: letMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/*global bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1325,7 +1350,8 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, //------------------------------------------------------------------------------ @@ -1353,33 +1379,33 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ function *foo() {}", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported bar */ async function foo() {}", - parserOptions: { ecmaVersion: 2017 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2017 } }, { code: "/* exported bar */ async function *foo() {}", - parserOptions: { ecmaVersion: 2018 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "/* exported bar */ var foo = function() {};", @@ -1401,23 +1427,23 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ var foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported bar */ var foo = function *foo() {};", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported bar */ var foo = 1, bar = 2;", @@ -1433,84 +1459,83 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported b */ const a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported b */ let a;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported b */ let a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported B */ class A {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: classMessage, type: "ClassDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ const a = 1; const b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ const a = 1, b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ let a, b = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ const a = 1; let b; class C {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1520,12 +1545,12 @@ ruleTester.run("no-implicit-globals", rule, { message: classMessage, type: "ClassDeclaration" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ const [a, b, ...c] = [];", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1535,12 +1560,12 @@ ruleTester.run("no-implicit-globals", rule, { message: constMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported a */ let { a, foo: b, bar: { c } } = {};", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1550,7 +1575,8 @@ ruleTester.run("no-implicit-globals", rule, { message: letMessage, type: "VariableDeclarator" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, // Global variable leaks @@ -1574,13 +1600,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported foo */ foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "/* exported foo */ window.foo = function() { bar = 1; }", @@ -1611,13 +1637,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported foo */ for (foo of []);", - parserOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "ForOfStatement" } - ] + ], + languageOptions: { ecmaVersion: 2015 } } ] }); diff --git a/tests/lib/rules/no-implied-eval.js b/tests/lib/rules/no-implied-eval.js index ce06f662043..952c3c24986 100644 --- a/tests/lib/rules/no-implied-eval.js +++ b/tests/lib/rules/no-implied-eval.js @@ -10,70 +10,76 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-implied-eval"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(), - expectedError = { messageId: "impliedEval", type: "CallExpression" }; +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); +const expectedError = { messageId: "impliedEval", type: "CallExpression" }; ruleTester.run("no-implied-eval", rule, { valid: [ "setTimeout();", - { code: "setTimeout;", env: { browser: true } }, - { code: "setTimeout = foo;", env: { browser: true } }, - { code: "window.setTimeout;", env: { browser: true } }, - { code: "window.setTimeout = foo;", env: { browser: true } }, - { code: "window['setTimeout'];", env: { browser: true } }, - { code: "window['setTimeout'] = foo;", env: { browser: true } }, - { code: "global.setTimeout;", env: { node: true } }, - { code: "global.setTimeout = foo;", env: { node: true } }, - { code: "global['setTimeout'];", env: { node: true } }, - { code: "global['setTimeout'] = foo;", env: { node: true } }, - { code: "globalThis['setTimeout'] = foo;", env: { es2020: true } }, + { code: "setTimeout;", languageOptions: { globals: globals.browser } }, + { code: "setTimeout = foo;", languageOptions: { globals: globals.browser } }, + { code: "window.setTimeout;", languageOptions: { globals: globals.browser } }, + { code: "window.setTimeout = foo;", languageOptions: { globals: globals.browser } }, + { code: "window['setTimeout'];", languageOptions: { globals: globals.browser } }, + { code: "window['setTimeout'] = foo;", languageOptions: { globals: globals.browser } }, + { code: "global.setTimeout;", languageOptions: { sourceType: "commonjs" } }, + { code: "global.setTimeout = foo;", languageOptions: { sourceType: "commonjs" } }, + { code: "global['setTimeout'];", languageOptions: { sourceType: "commonjs" } }, + { code: "global['setTimeout'] = foo;", languageOptions: { sourceType: "commonjs" } }, + { code: "globalThis['setTimeout'] = foo;", languageOptions: { ecmaVersion: 2020 } }, "window.setTimeout('foo')", "window.setInterval('foo')", "window['setTimeout']('foo')", "window['setInterval']('foo')", - { code: "window.setTimeout('foo')", env: { node: true } }, - { code: "window.setInterval('foo')", env: { node: true } }, - { code: "window['setTimeout']('foo')", env: { node: true } }, - { code: "window['setInterval']('foo')", env: { node: true } }, - { code: "global.setTimeout('foo')", env: { browser: true } }, - { code: "global.setInterval('foo')", env: { browser: true } }, - { code: "global['setTimeout']('foo')", env: { browser: true } }, - { code: "global['setInterval']('foo')", env: { browser: true } }, - { code: "globalThis.setTimeout('foo')", env: { es6: true } }, - { code: "globalThis['setInterval']('foo')", env: { es2017: true } }, - - { code: "window[`SetTimeOut`]('foo', 100);", parserOptions: { ecmaVersion: 6 }, env: { browser: true } }, - { code: "global[`SetTimeOut`]('foo', 100);", parserOptions: { ecmaVersion: 6 }, env: { node: true } }, - { code: "global[`setTimeout${foo}`]('foo', 100);", parserOptions: { ecmaVersion: 6 }, env: { browser: true } }, - { code: "global[`setTimeout${foo}`]('foo', 100);", parserOptions: { ecmaVersion: 6 }, env: { node: true } }, - { code: "globalThis[`setTimeout${foo}`]('foo', 100);", parserOptions: { ecmaVersion: 6 }, env: { es2020: true } }, + { code: "window.setTimeout('foo')", languageOptions: { sourceType: "commonjs" } }, + { code: "window.setInterval('foo')", languageOptions: { sourceType: "commonjs" } }, + { code: "window['setTimeout']('foo')", languageOptions: { sourceType: "commonjs" } }, + { code: "window['setInterval']('foo')", languageOptions: { sourceType: "commonjs" } }, + { code: "global.setTimeout('foo')", languageOptions: { globals: globals.browser } }, + { code: "global.setInterval('foo')", languageOptions: { globals: globals.browser } }, + { code: "global['setTimeout']('foo')", languageOptions: { globals: globals.browser } }, + { code: "global['setInterval']('foo')", languageOptions: { globals: globals.browser } }, + { code: "globalThis.setTimeout('foo')", languageOptions: { ecmaVersion: 6 } }, + { code: "globalThis['setInterval']('foo')", languageOptions: { ecmaVersion: 2017 } }, + + { code: "window[`SetTimeOut`]('foo', 100);", languageOptions: { ecmaVersion: 6, globals: globals.browser } }, + { code: "global[`SetTimeOut`]('foo', 100);", languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, + { code: "global[`setTimeout${foo}`]('foo', 100);", languageOptions: { ecmaVersion: 6, globals: globals.browser } }, + { code: "global[`setTimeout${foo}`]('foo', 100);", languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, + { code: "globalThis[`setTimeout${foo}`]('foo', 100);", languageOptions: { ecmaVersion: 2020 } }, // normal usage "setTimeout(function() { x = 1; }, 100);", "setInterval(function() { x = 1; }, 100)", "execScript(function() { x = 1; }, 100)", - { code: "window.setTimeout(function() { x = 1; }, 100);", env: { browser: true } }, - { code: "window.setInterval(function() { x = 1; }, 100);", env: { browser: true } }, - { code: "window.execScript(function() { x = 1; }, 100);", env: { browser: true } }, - { code: "window.setTimeout(foo, 100);", env: { browser: true } }, - { code: "window.setInterval(foo, 100);", env: { browser: true } }, - { code: "window.execScript(foo, 100);", env: { browser: true } }, - { code: "global.setTimeout(function() { x = 1; }, 100);", env: { node: true } }, - { code: "global.setInterval(function() { x = 1; }, 100);", env: { node: true } }, - { code: "global.execScript(function() { x = 1; }, 100);", env: { node: true } }, - { code: "global.setTimeout(foo, 100);", env: { node: true } }, - { code: "global.setInterval(foo, 100);", env: { node: true } }, - { code: "global.execScript(foo, 100);", env: { node: true } }, - { code: "globalThis.setTimeout(foo, 100);", env: { es2020: true } }, + { code: "window.setTimeout(function() { x = 1; }, 100);", languageOptions: { globals: globals.browser } }, + { code: "window.setInterval(function() { x = 1; }, 100);", languageOptions: { globals: globals.browser } }, + { code: "window.execScript(function() { x = 1; }, 100);", languageOptions: { globals: globals.browser } }, + { code: "window.setTimeout(foo, 100);", languageOptions: { globals: globals.browser } }, + { code: "window.setInterval(foo, 100);", languageOptions: { globals: globals.browser } }, + { code: "window.execScript(foo, 100);", languageOptions: { globals: globals.browser } }, + { code: "global.setTimeout(function() { x = 1; }, 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "global.setInterval(function() { x = 1; }, 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "global.execScript(function() { x = 1; }, 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "global.setTimeout(foo, 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "global.setInterval(foo, 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "global.execScript(foo, 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "globalThis.setTimeout(foo, 100);", languageOptions: { ecmaVersion: 2020 } }, // only checks on top-level statements or window.* "foo.setTimeout('hi')", @@ -109,14 +115,14 @@ ruleTester.run("no-implied-eval", rule, { // https://github.com/eslint/eslint/issues/7821 "setTimeoutFooBar('Foo Bar')", - { code: "foo.window.setTimeout('foo', 100);", env: { browser: true } }, - { code: "foo.global.setTimeout('foo', 100);", env: { node: true } }, - { code: "var window; window.setTimeout('foo', 100);", env: { browser: true } }, - { code: "var global; global.setTimeout('foo', 100);", env: { node: true } }, - { code: "function foo(window) { window.setTimeout('foo', 100); }", env: { browser: true } }, - { code: "function foo(global) { global.setTimeout('foo', 100); }", env: { node: true } }, - { code: "foo('', window.setTimeout);", env: { browser: true } }, - { code: "foo('', global.setTimeout);", env: { node: true } } + { code: "foo.window.setTimeout('foo', 100);", languageOptions: { globals: globals.browser } }, + { code: "foo.global.setTimeout('foo', 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "var window; window.setTimeout('foo', 100);", languageOptions: { globals: globals.browser } }, + { code: "var global; global.setTimeout('foo', 100);", languageOptions: { sourceType: "commonjs" } }, + { code: "function foo(window) { window.setTimeout('foo', 100); }", languageOptions: { globals: globals.browser } }, + { code: "function foo(global) { global.setTimeout('foo', 100); }", languageOptions: { sourceType: "commonjs" } }, + { code: "foo('', window.setTimeout);", languageOptions: { globals: globals.browser } }, + { code: "foo('', global.setTimeout);", languageOptions: { sourceType: "commonjs" } } ], invalid: [ @@ -125,47 +131,47 @@ ruleTester.run("no-implied-eval", rule, { { code: "setInterval(\"x = 1;\");", errors: [expectedError] }, { code: "execScript(\"x = 1;\");", errors: [expectedError] }, - { code: "const s = 'x=1'; setTimeout(s, 100);", parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, - { code: "setTimeout(String('x=1'), 100);", parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, + { code: "const s = 'x=1'; setTimeout(s, 100);", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, + { code: "setTimeout(String('x=1'), 100);", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, // member expressions - { code: "window.setTimeout('foo')", env: { browser: true }, errors: [expectedError] }, - { code: "window.setInterval('foo')", env: { browser: true }, errors: [expectedError] }, - { code: "window['setTimeout']('foo')", env: { browser: true }, errors: [expectedError] }, - { code: "window['setInterval']('foo')", env: { browser: true }, errors: [expectedError] }, - { code: "window[`setInterval`]('foo')", parserOptions: { ecmaVersion: 6 }, env: { browser: true }, errors: [expectedError] }, - { code: "window.window['setInterval']('foo')", env: { browser: true }, errors: [expectedError] }, - { code: "global.setTimeout('foo')", env: { node: true }, errors: [expectedError] }, - { code: "global.setInterval('foo')", env: { node: true }, errors: [expectedError] }, - { code: "global['setTimeout']('foo')", env: { node: true }, errors: [expectedError] }, - { code: "global['setInterval']('foo')", env: { node: true }, errors: [expectedError] }, - { code: "global[`setInterval`]('foo')", parserOptions: { ecmaVersion: 6 }, env: { node: true }, errors: [expectedError] }, - { code: "global.global['setInterval']('foo')", env: { node: true }, errors: [expectedError] }, - { code: "globalThis.setTimeout('foo')", env: { es2020: true }, errors: [expectedError] }, - { code: "globalThis.setInterval('foo')", env: { es2020: true }, errors: [expectedError] }, + { code: "window.setTimeout('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "window.setInterval('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "window['setTimeout']('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "window['setInterval']('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "window[`setInterval`]('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, + { code: "window.window['setInterval']('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "global.setTimeout('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "global.setInterval('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "global['setTimeout']('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "global['setInterval']('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "global[`setInterval`]('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, + { code: "global.global['setInterval']('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "globalThis.setTimeout('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 2020 } }, + { code: "globalThis.setInterval('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 2020 } }, // template literals - { code: "setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, - { code: "window.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, env: { browser: true }, errors: [expectedError] }, - { code: "window.window.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, env: { browser: true }, errors: [expectedError] }, - { code: "global.global.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, env: { node: true }, errors: [expectedError] }, + { code: "setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, + { code: "window.setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, + { code: "window.window.setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, + { code: "global.global.setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.node } }, // string concatenation { code: "setTimeout('foo' + bar)", errors: [expectedError] }, { code: "setTimeout(foo + 'bar')", errors: [expectedError] }, - { code: "setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, + { code: "setTimeout(`foo` + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, { code: "setTimeout(1 + ';' + 1)", errors: [expectedError] }, - { code: "window.setTimeout('foo' + bar)", env: { browser: true }, errors: [expectedError] }, - { code: "window.setTimeout(foo + 'bar')", env: { browser: true }, errors: [expectedError] }, - { code: "window.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, env: { browser: true }, errors: [expectedError] }, - { code: "window.setTimeout(1 + ';' + 1)", env: { browser: true }, errors: [expectedError] }, - { code: "window.window.setTimeout(1 + ';' + 1)", env: { browser: true }, errors: [expectedError] }, - { code: "global.setTimeout('foo' + bar)", env: { node: true }, errors: [expectedError] }, - { code: "global.setTimeout(foo + 'bar')", env: { node: true }, errors: [expectedError] }, - { code: "global.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, env: { node: true }, errors: [expectedError] }, - { code: "global.setTimeout(1 + ';' + 1)", env: { node: true }, errors: [expectedError] }, - { code: "global.global.setTimeout(1 + ';' + 1)", env: { node: true }, errors: [expectedError] }, - { code: "globalThis.setTimeout('foo' + bar)", env: { es2020: true }, errors: [expectedError] }, + { code: "window.setTimeout('foo' + bar)", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "window.setTimeout(foo + 'bar')", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "window.setTimeout(`foo` + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, + { code: "window.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "window.window.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { globals: globals.browser } }, + { code: "global.setTimeout('foo' + bar)", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "global.setTimeout(foo + 'bar')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "global.setTimeout(`foo` + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, + { code: "global.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "global.global.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, + { code: "globalThis.setTimeout('foo' + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 2020 } }, // gives the correct node when dealing with nesting { @@ -197,7 +203,6 @@ ruleTester.run("no-implied-eval", rule, { " window.execScript('str');\n" + " return 'bar';\n" + "})())", - env: { browser: true }, errors: [ { messageId: "impliedEval", @@ -211,7 +216,8 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ] + ], + languageOptions: { globals: globals.browser } }, { code: @@ -220,7 +226,6 @@ ruleTester.run("no-implied-eval", rule, { " global.execScript('str');\n" + " return 'bar';\n" + "})())", - env: { node: true }, errors: [ { messageId: "impliedEval", @@ -234,21 +239,26 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ] + ], + languageOptions: { sourceType: "commonjs" } }, // Optional chaining { code: "window?.setTimeout('code', 0)", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "impliedEval" }] + errors: [{ messageId: "impliedEval" }], + languageOptions: { + ecmaVersion: 2020, + globals: { window: "readonly" } + } }, { code: "(window?.setTimeout)('code', 0)", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "impliedEval" }] + errors: [{ messageId: "impliedEval" }], + languageOptions: { + ecmaVersion: 2020, + globals: { window: "readonly" } + } } ] }); diff --git a/tests/lib/rules/no-import-assign.js b/tests/lib/rules/no-import-assign.js index babfdfc3445..b410b515537 100644 --- a/tests/lib/rules/no-import-assign.js +++ b/tests/lib/rules/no-import-assign.js @@ -10,19 +10,19 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-import-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2018, - sourceType: "module" - }, - globals: { - Reflect: "readonly" + sourceType: "module", + globals: { + Reflect: "readonly" + } } }); @@ -315,18 +315,18 @@ ruleTester.run("no-import-assign", rule, { // Optional chaining { code: "import * as mod from 'mod'; Object?.defineProperty(mod, key, d)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] + errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "import * as mod from 'mod'; (Object?.defineProperty)(mod, key, d)", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] + errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "import * as mod from 'mod'; delete mod?.prop", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] + errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-inline-comments.js b/tests/lib/rules/no-inline-comments.js index 7eb0cac730f..f88b242d297 100644 --- a/tests/lib/rules/no-inline-comments.js +++ b/tests/lib/rules/no-inline-comments.js @@ -9,16 +9,20 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-inline-comments"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + ecmaVersion: 5, + sourceType: "script", + parserOptions: { + ecmaFeatures: { + jsx: true + } } } }), @@ -99,7 +103,7 @@ ruleTester.run("no-inline-comments", rule, { ignorePattern: "(?:webpackChunkName):\\s.+" } ], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = 2; // Note: This comment is legal.", diff --git a/tests/lib/rules/no-inner-declarations.js b/tests/lib/rules/no-inner-declarations.js index 5fcb2f3c866..9dcc5274fc5 100644 --- a/tests/lib/rules/no-inner-declarations.js +++ b/tests/lib/rules/no-inner-declarations.js @@ -9,13 +9,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-inner-declarations"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-inner-declarations", rule, { @@ -28,43 +33,43 @@ ruleTester.run("no-inner-declarations", rule, { "if (test) { var fn = function expr() { }; }", "function decl() { var fn = function expr() { }; }", "function decl(arg) { var fn; if (arg) { fn = function() { }; } }", - { code: "var x = {doSomething() {function doSomethingElse() {}}}", parserOptions: { ecmaVersion: 6 } }, - { code: "function decl(arg) { var fn; if (arg) { fn = function expr() { }; } }", parserOptions: { ecmaVersion: 6 } }, + { code: "var x = {doSomething() {function doSomethingElse() {}}}", languageOptions: { ecmaVersion: 6 } }, + { code: "function decl(arg) { var fn; if (arg) { fn = function expr() { }; } }", languageOptions: { ecmaVersion: 6 } }, "function decl(arg) { var fn; if (arg) { fn = function expr() { }; } }", "if (test) { var foo; }", - { code: "if (test) { let x = 1; }", options: ["both"], parserOptions: { ecmaVersion: 6 } }, - { code: "if (test) { const x = 1; }", options: ["both"], parserOptions: { ecmaVersion: 6 } }, + { code: "if (test) { let x = 1; }", options: ["both"], languageOptions: { ecmaVersion: 6 } }, + { code: "if (test) { const x = 1; }", options: ["both"], languageOptions: { ecmaVersion: 6 } }, "function doSomething() { while (test) { var foo; } }", { code: "var foo;", options: ["both"] }, { code: "var foo = 42;", options: ["both"] }, { code: "function doSomething() { var foo; }", options: ["both"] }, { code: "(function() { var foo; }());", options: ["both"] }, - { code: "foo(() => { function bar() { } });", parserOptions: { ecmaVersion: 6 } }, - { code: "var fn = () => {var foo;}", options: ["both"], parserOptions: { ecmaVersion: 6 } }, + { code: "foo(() => { function bar() { } });", languageOptions: { ecmaVersion: 6 } }, + { code: "var fn = () => {var foo;}", options: ["both"], languageOptions: { ecmaVersion: 6 } }, { code: "var x = {doSomething() {var foo;}}", options: ["both"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "export var foo;", options: ["both"], - parserOptions: { sourceType: "module", ecmaVersion: 6 } + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "export function bar() {}", options: ["both"], - parserOptions: { sourceType: "module", ecmaVersion: 6 } + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "export default function baz() {}", options: ["both"], - parserOptions: { sourceType: "module", ecmaVersion: 6 } + languageOptions: { sourceType: "module", ecmaVersion: 6 } }, { code: "exports.foo = () => {}", options: ["both"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "exports.foo = function(){}", @@ -77,22 +82,22 @@ ruleTester.run("no-inner-declarations", rule, { { code: "class C { method() { function foo() {} } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { method() { var x; } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { function foo() {} } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var x; } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -281,7 +286,6 @@ ruleTester.run("no-inner-declarations", rule, { }, { code: "const doSomething = () => { if (test) { var foo = 42; } }", options: ["both"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -289,11 +293,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "function body" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C { method() { if(test) { var foo; } } }", options: ["both"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -301,11 +305,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "function body" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C { static { if (test) { function foo() {} } } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -313,11 +317,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "class static block body" }, type: "FunctionDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (test) { var foo; } } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -325,11 +329,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "class static block body" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (test) { if (anotherTest) { var foo; } } } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -337,7 +341,8 @@ ruleTester.run("no-inner-declarations", rule, { body: "class static block body" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-invalid-regexp.js b/tests/lib/rules/no-invalid-regexp.js index dfd662bad27..063cf2ef713 100644 --- a/tests/lib/rules/no-invalid-regexp.js +++ b/tests/lib/rules/no-invalid-regexp.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-invalid-regexp"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-invalid-this.js b/tests/lib/rules/no-invalid-this.js index 7e8d4776d9b..bf334218a51 100644 --- a/tests/lib/rules/no-invalid-this.js +++ b/tests/lib/rules/no-invalid-this.js @@ -12,7 +12,7 @@ const merge = require("lodash.merge"); const rule = require("../../../lib/rules/no-invalid-this"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -45,8 +45,10 @@ function USE_STRICT(pattern) { */ function IMPLIED_STRICT(pattern) { pattern.code = `/* implied strict mode */ ${pattern.code}`; - pattern.parserOptions.ecmaFeatures = pattern.parserOptions.ecmaFeatures || {}; - pattern.parserOptions.ecmaFeatures.impliedStrict = true; + pattern.languageOptions = pattern.languageOptions || {}; + pattern.languageOptions.parserOptions = pattern.languageOptions.parserOptions || {}; + pattern.languageOptions.parserOptions.ecmaFeatures = pattern.languageOptions.parserOptions.ecmaFeatures || {}; + pattern.languageOptions.parserOptions.ecmaFeatures.impliedStrict = true; } /** @@ -57,7 +59,7 @@ function IMPLIED_STRICT(pattern) { */ function MODULES(pattern) { pattern.code = `/* modules */ ${pattern.code}`; - pattern.parserOptions.sourceType = "module"; + pattern.languageOptions.sourceType = "module"; } /** @@ -103,16 +105,18 @@ const patterns = [ // Global. { code: "console.log(this); z(x => console.log(x, this));", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT], invalid: [MODULES] }, { code: "console.log(this); z(x => console.log(x, this));", - parserOptions: { + languageOptions: { ecmaVersion: 6, - ecmaFeatures: { globalReturn: true } + parserOptions: { + ecmaFeatures: { globalReturn: true } + } }, errors, valid: [NORMAL], @@ -120,7 +124,7 @@ const patterns = [ }, { code: "() => { this }; this;", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors, @@ -129,7 +133,7 @@ const patterns = [ }, { code: "this.eval('foo');", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }], @@ -140,7 +144,7 @@ const patterns = [ // IIFE. { code: "(function() { console.log(this); z(x => console.log(x, this)); })();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] @@ -149,14 +153,14 @@ const patterns = [ // Just functions. { code: "function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: false }], // test that the option doesn't reverse the logic and mistakenly allows lowercase functions errors, valid: [NORMAL], @@ -164,7 +168,7 @@ const patterns = [ }, { code: "function Foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: false }], errors, valid: [NORMAL], @@ -172,14 +176,14 @@ const patterns = [ }, { code: "function foo() { \"use strict\"; console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [], invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "function Foo() { \"use strict\"; console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: false }], errors, valid: [], @@ -187,9 +191,11 @@ const patterns = [ }, { code: "return function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { + languageOptions: { ecmaVersion: 6, - ecmaFeatures: { globalReturn: true } + parserOptions: { + ecmaFeatures: { globalReturn: true } + } }, errors, valid: [NORMAL], @@ -197,7 +203,7 @@ const patterns = [ }, { code: "var foo = (function() { console.log(this); z(x => console.log(x, this)); }).bar(obj);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] @@ -206,49 +212,49 @@ const patterns = [ // Functions in methods. { code: "var obj = {foo: function() { function foo() { console.log(this); z(x => console.log(x, this)); } foo(); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "var obj = {foo() { function foo() { console.log(this); z(x => console.log(x, this)); } foo(); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "var obj = {foo: function() { return function() { console.log(this); z(x => console.log(x, this)); }; }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "var obj = {foo: function() { \"use strict\"; return function() { console.log(this); z(x => console.log(x, this)); }; }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [], invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "obj.foo = function() { return function() { console.log(this); z(x => console.log(x, this)); }; };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "obj.foo = function() { \"use strict\"; return function() { console.log(this); z(x => console.log(x, this)); }; };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [], invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "class A { foo() { return function() { console.log(this); z(x => console.log(x, this)); }; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [], invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] @@ -257,7 +263,7 @@ const patterns = [ // Class Static methods. { code: "class A {static foo() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] @@ -266,33 +272,33 @@ const patterns = [ // Constructors. { code: "function Foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "function Foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{}], // test the default value in schema valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "function Foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: true }], // test explicitly set option to the default value valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var Foo = function Foo() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class A {constructor() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -300,43 +306,43 @@ const patterns = [ // On a property. { code: "var obj = {foo: function() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var obj = {foo() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var obj = {foo: foo || function() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var obj = {foo: hasNative ? foo : function() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var obj = {foo: (function() { return function() { console.log(this); z(x => console.log(x, this)); }; })()};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "Object.defineProperty(obj, \"foo\", {value: function() { console.log(this); z(x => console.log(x, this)); }})", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "Object.defineProperties(obj, {foo: {value: function() { console.log(this); z(x => console.log(x, this)); }}})", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -344,51 +350,51 @@ const patterns = [ // Assigns to a property. { code: "obj.foo = function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "obj.foo = foo || function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "obj.foo = foo ? bar : function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "obj.foo = (function() { return function() { console.log(this); z(x => console.log(x, this)); }; })();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "obj.foo = (() => function() { console.log(this); z(x => console.log(x, this)); })();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "obj.foo = (function() { return () => { console.log(this); z(x => console.log(x, this)); }; })();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], errors }, { code: "obj.foo = (() => () => { console.log(this); z(x => console.log(x, this)); })();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT], invalid: [MODULES], errors }, { code: "obj.foo = (function() { return function() { console.log(this); z(x => console.log(x, this)); }; })?.();", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -396,7 +402,7 @@ const patterns = [ // Class Instance Methods. { code: "class A {foo() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -404,64 +410,64 @@ const patterns = [ // Bind/Call/Apply { code: "var foo = function() { console.log(this); z(x => console.log(x, this)); }.bind(obj);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var foo = function() { console.log(this); z(x => console.log(x, this)); }.bind(null);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "(function() { console.log(this); z(x => console.log(x, this)); }).call(obj);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "(function() { console.log(this); z(x => console.log(x, this)); }).call(undefined);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "(function() { console.log(this); z(x => console.log(x, this)); }).apply(obj);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "(function() { console.log(this); z(x => console.log(x, this)); }).apply(void 0);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "Reflect.apply(function() { console.log(this); z(x => console.log(x, this)); }, obj, []);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var foo = function() { console.log(this); z(x => console.log(x, this)); }?.bind(obj);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var foo = (function() { console.log(this); z(x => console.log(x, this)); }?.bind)(obj);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var foo = function() { console.log(this); z(x => console.log(x, this)); }.bind?.(obj);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -469,7 +475,7 @@ const patterns = [ // Array methods. { code: "Array.from([], function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] @@ -487,14 +493,14 @@ const patterns = [ "some" ].map(methodName => ({ code: `foo.${methodName}(function() { console.log(this); z(x => console.log(x, this)); });`, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] })), { code: "Array.from([], function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -511,38 +517,38 @@ const patterns = [ "some" ].map(methodName => ({ code: `foo.${methodName}(function() { console.log(this); z(x => console.log(x, this)); }, obj);`, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] })), { code: "foo.forEach(function() { console.log(this); z(x => console.log(x, this)); }, null);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "Array?.from([], function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "foo?.every(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "(Array?.from)([], function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "(foo?.every)(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -550,33 +556,33 @@ const patterns = [ // @this tag. { code: "/** @this Obj */ function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "/**\n * @returns {void}\n * @this Obj\n */\nfunction foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "/** @returns {void} */ function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "/** @this Obj */ foo(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "foo(/* @this Obj */ function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] @@ -585,7 +591,7 @@ const patterns = [ // https://github.com/eslint/eslint/issues/3254 { code: "function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] @@ -594,7 +600,7 @@ const patterns = [ // https://github.com/eslint/eslint/issues/3287 { code: "function foo() { /** @this Obj*/ return function bar() { console.log(this); z(x => console.log(x, this)); }; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -602,13 +608,13 @@ const patterns = [ // https://github.com/eslint/eslint/issues/6824 { code: "var Ctor = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "var Ctor = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: false }], errors, valid: [NORMAL], @@ -616,14 +622,14 @@ const patterns = [ }, { code: "var func = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "var func = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: false }], errors, valid: [NORMAL], @@ -631,13 +637,13 @@ const patterns = [ }, { code: "Ctor = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "Ctor = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: false }], errors, valid: [NORMAL], @@ -645,14 +651,14 @@ const patterns = [ }, { code: "func = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "func = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, options: [{ capIsConstructor: false }], errors, valid: [NORMAL], @@ -660,26 +666,26 @@ const patterns = [ }, { code: "function foo(Ctor = function() { console.log(this); z(x => console.log(x, this)); }) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "function foo(func = function() { console.log(this); z(x => console.log(x, this)); }) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] }, { code: "[obj.method = function() { console.log(this); z(x => console.log(x, this)); }] = a", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "[func = function() { console.log(this); z(x => console.log(x, this)); }] = a", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors, valid: [NORMAL], invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] @@ -688,19 +694,19 @@ const patterns = [ // Logical assignments { code: "obj.method &&= function () { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "obj.method ||= function () { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "obj.method ??= function () { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, @@ -708,57 +714,57 @@ const patterns = [ // Class fields. { code: "class C { field = this }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { static field = this }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { field = console.log(this); }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { field = z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { field = function () { console.log(this); z(x => console.log(x, this)); }; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { #field = function () { console.log(this); z(x => console.log(x, this)); }; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { [this.foo]; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT], // `this` is the top-level `this` invalid: [MODULES], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] }, { code: "class C { foo = () => this; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] }, { code: "class C { foo = () => { this }; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] @@ -767,53 +773,53 @@ const patterns = [ // Class static blocks { code: "class C { static { this.x; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { static { () => { this.x; } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { static { class D { [this.x]; } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, { code: "class C { static { function foo() { this.x; } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [], invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] }, { code: "class C { static { (function() { this.x; }); } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [], invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] }, { code: "class C { static { (function() { this.x; })(); } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [], invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] }, { code: "class C { static {} [this]; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT], invalid: [MODULES], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] }, { code: "class C { static {} [this.x]; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT], invalid: [MODULES], errors: [{ messageId: "unexpectedThis", type: "ThisExpression" }] @@ -822,13 +828,18 @@ const patterns = [ // in es3, "use strict" directives do not apply { code: "function foo() { 'use strict'; this.eval(); }", - parserOptions: { ecmaVersion: 3 }, + languageOptions: { ecmaVersion: 3 }, valid: [NORMAL, USE_STRICT, IMPLIED_STRICT], invalid: [] } ]; -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-invalid-this", rule, { valid: extractPatterns(patterns, "valid"), diff --git a/tests/lib/rules/no-irregular-whitespace.js b/tests/lib/rules/no-irregular-whitespace.js index e6ca5d111b6..48fc2f0d1af 100644 --- a/tests/lib/rules/no-irregular-whitespace.js +++ b/tests/lib/rules/no-irregular-whitespace.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-irregular-whitespace"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -142,56 +142,56 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "/\u202F/", options: [{ skipRegExps: true }] }, { code: "/\u205f/", options: [{ skipRegExps: true }] }, { code: "/\u3000/", options: [{ skipRegExps: true }] }, - { code: "`\u000B`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u000C`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u0085`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u00A0`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u180E`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\ufeff`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2000`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2001`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2002`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2003`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2004`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2005`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2006`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2007`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2008`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u2009`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u200A`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u200B`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u202F`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u205f`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`\u3000`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`\u000B`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u000C`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u0085`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u00A0`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u180E`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\ufeff`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2000`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2001`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2002`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2003`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2004`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2005`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2006`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2007`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2008`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u2009`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u200A`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u200B`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u202F`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u205f`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "`\u3000`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, - { code: "`\u3000${foo}\u3000`", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const error = ` \u3000 `;", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const error = `\n\u3000`;", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const error = `\u3000\n`;", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const error = `\n\u3000\n`;", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const error = `foo\u3000bar\nfoo\u3000bar`;", options: [{ skipTemplates: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`\u3000${foo}\u3000`", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const error = ` \u3000 `;", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const error = `\n\u3000`;", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const error = `\u3000\n`;", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const error = `\n\u3000\n`;", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const error = `foo\u3000bar\nfoo\u3000bar`;", options: [{ skipTemplates: true }], languageOptions: { ecmaVersion: 6 } }, - { code: "
\u000B
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u000C
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u0085
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u00A0
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u180E
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\ufeff
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2000
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2001
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2002
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2003
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2004
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2005
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2006
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2007
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2008
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u2009
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u200A
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u200B
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u202F
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u205f
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
\u3000
;", options: [{ skipJSXText: true }], parserOptions: { ecmaFeatures: { jsx: true } } }, + { code: "
\u000B
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u000C
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u0085
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u00A0
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u180E
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\ufeff
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2000
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2001
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2002
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2003
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2004
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2005
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2006
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2007
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2008
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u2009
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u200A
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u200B
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u202F
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u205f
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
\u3000
;", options: [{ skipJSXText: true }], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, // Unicode BOM. "\uFEFFconsole.log('hello BOM');" @@ -541,7 +541,6 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "var any = `\u3000`, other = `\u000B`;", options: [{ skipTemplates: false }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -555,12 +554,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 25 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`something ${\u3000 10} another thing`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -568,12 +567,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`something ${10\u3000} another thing`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -581,12 +580,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "\u3000\n`\u3000template`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -594,12 +593,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "\u3000\n`\u3000multiline\ntemplate`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -607,12 +606,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "\u3000`\u3000template`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -620,12 +619,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "\u3000`\u3000multiline\ntemplate`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -633,12 +632,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`\u3000template`\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -646,12 +645,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`\u3000multiline\ntemplate`\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -659,12 +658,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 2, column: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`\u3000template`\n\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -672,12 +671,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 2, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`\u3000multiline\ntemplate`\n\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -685,7 +684,8 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 3, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // full location tests @@ -1018,11 +1018,6 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u000B
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1030,15 +1025,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u000C
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1046,15 +1043,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u0085
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1062,15 +1061,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u00A0
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1078,15 +1079,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u180E
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1094,15 +1097,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\ufeff
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1110,15 +1115,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2000
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1126,15 +1133,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2001
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1142,15 +1151,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2002
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1158,15 +1169,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2003
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1174,15 +1187,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2004
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1190,15 +1205,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2005
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1206,15 +1223,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2006
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1222,15 +1241,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2007
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1238,15 +1259,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2008
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1254,15 +1277,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u2009
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1270,15 +1295,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u200A
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1286,15 +1313,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u200B
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1302,15 +1331,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u202F
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1318,15 +1349,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u205f
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1334,15 +1367,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "
\u3000
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noIrregularWhitespace", @@ -1350,7 +1385,14 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } } ] }); diff --git a/tests/lib/rules/no-iterator.js b/tests/lib/rules/no-iterator.js index 04aa795c179..10160b109d8 100644 --- a/tests/lib/rules/no-iterator.js +++ b/tests/lib/rules/no-iterator.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-iterator"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -22,8 +22,8 @@ ruleTester.run("no-iterator", rule, { valid: [ "var a = test[__iterator__];", "var __iterator__ = null;", - { code: "foo[`__iterator`] = null;", parserOptions: { ecmaVersion: 6 } }, - { code: "foo[`__iterator__\n`] = null;", parserOptions: { ecmaVersion: 6 } } + { code: "foo[`__iterator`] = null;", languageOptions: { ecmaVersion: 6 } }, + { code: "foo[`__iterator__\n`] = null;", languageOptions: { ecmaVersion: 6 } } ], invalid: [ { @@ -49,19 +49,19 @@ ruleTester.run("no-iterator", rule, { }, { code: "var a = test[`__iterator__`];", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noIterator", type: "MemberExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "test[`__iterator__`] = function () {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noIterator", type: "MemberExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-label-var.js b/tests/lib/rules/no-label-var.js index 297fe55cf0e..a6c7ba93fcf 100644 --- a/tests/lib/rules/no-label-var.js +++ b/tests/lib/rules/no-label-var.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-label-var"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-labels.js b/tests/lib/rules/no-labels.js index bdf8a19807b..ecc6b4005d5 100644 --- a/tests/lib/rules/no-labels.js +++ b/tests/lib/rules/no-labels.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-labels"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-lone-blocks.js b/tests/lib/rules/no-lone-blocks.js index ab81caf8ec7..ec7a4f56d7f 100644 --- a/tests/lib/rules/no-lone-blocks.js +++ b/tests/lib/rules/no-lone-blocks.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-lone-blocks"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-lone-blocks", rule, { valid: [ @@ -25,13 +30,13 @@ ruleTester.run("no-lone-blocks", rule, { "function foo() { while (bar) { baz() } }", // Block-level bindings - { code: "{ let x = 1; }", parserOptions: { ecmaVersion: 6 } }, - { code: "{ const x = 1; }", parserOptions: { ecmaVersion: 6 } }, - { code: "'use strict'; { function bar() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "{ function bar() {} }", parserOptions: { ecmaVersion: 6, ecmaFeatures: { impliedStrict: true } } }, - { code: "{ class Bar {} }", parserOptions: { ecmaVersion: 6 } }, + { code: "{ let x = 1; }", languageOptions: { ecmaVersion: 6 } }, + { code: "{ const x = 1; }", languageOptions: { ecmaVersion: 6 } }, + { code: "'use strict'; { function bar() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "{ function bar() {} }", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, + { code: "{ class Bar {} }", languageOptions: { ecmaVersion: 6 } }, - { code: "{ {let y = 1;} let x = 1; }", parserOptions: { ecmaVersion: 6 } }, + { code: "{ {let y = 1;} let x = 1; }", languageOptions: { ecmaVersion: 6 } }, ` switch (foo) { case bar: { @@ -57,16 +62,16 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - { code: "function foo() { { const x = 4 } const x = 3 }", parserOptions: { ecmaVersion: 6 } }, + { code: "function foo() { { const x = 4 } const x = 3 }", languageOptions: { ecmaVersion: 6 } }, - { code: "class C { static {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { if (foo) { block; } } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { lbl: { block; } } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { { let block; } something; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { something; { const block = 1; } } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { { function block(){} } something; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { something; { class block {} } } }", parserOptions: { ecmaVersion: 2022 } } + { code: "class C { static {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { if (foo) { block; } } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { lbl: { block; } } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { { let block; } something; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { something; { const block = 1; } } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { { function block(){} } something; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { something; { class block {} } } }", languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { @@ -130,42 +135,41 @@ ruleTester.run("no-lone-blocks", rule, { // Non-block-level bindings, even in ES6 { code: "{ function bar() {} }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{var x = 1;}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ \n{var x = 1;}\n let y = 2; } {let z = 1;}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 2 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ \n{let x = 1;}\n var y = 2; } {let z = 1;}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement", line: 1 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ \n{var x = 1;}\n var y = 2; }\n {var z = 1;}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "redundantBlock", @@ -182,7 +186,8 @@ ruleTester.run("no-lone-blocks", rule, { type: "BlockStatement", line: 4 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -224,12 +229,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 3 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -257,12 +262,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -277,12 +282,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -294,12 +299,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -311,12 +316,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -328,12 +333,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -345,12 +350,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -362,12 +367,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -380,12 +385,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -398,12 +403,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -416,12 +421,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -434,12 +439,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-lonely-if.js b/tests/lib/rules/no-lonely-if.js index 9a35184f6f1..e04a302f0fa 100644 --- a/tests/lib/rules/no-lonely-if.js +++ b/tests/lib/rules/no-lonely-if.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-lonely-if"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -177,8 +177,8 @@ ruleTester.run("no-lonely-if", rule, { "}\n" + "`template literal`;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors + errors, + languageOptions: { ecmaVersion: 6 } }, { code: diff --git a/tests/lib/rules/no-loop-func.js b/tests/lib/rules/no-loop-func.js index f1311000f91..4586703c142 100644 --- a/tests/lib/rules/no-loop-func.js +++ b/tests/lib/rules/no-loop-func.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-loop-func"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -26,7 +26,7 @@ ruleTester.run("no-loop-func", rule, { "for (var x in xs.filter(function(x) { return x != upper; })) { }", { code: "for (var x of xs.filter(function(x) { return x != upper; })) { }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // no refers to variables that declared on upper scope. @@ -34,61 +34,61 @@ ruleTester.run("no-loop-func", rule, { "for (var i in {}) { (function() {}) }", { code: "for (var i of {}) { (function() {}) }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // functions which are using unmodified variables are OK. { code: "for (let i=0; i x != i)) { } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; for (let i=0; i { (function() { a; }); }); }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0; for (let i=0; i x != undeclared)) { } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -174,13 +174,13 @@ ruleTester.run("no-loop-func", rule, { }, { code: "for (var i of {}) { (function() { i; }) }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var i=0; i < l; i++) { (() => { i; }) }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var i=0; i < l; i++) { var a = function() { i; } }", @@ -202,73 +202,73 @@ ruleTester.run("no-loop-func", rule, { // Warns functions which are using modified variables. { code: "let a; for (let i=0; i { (function() { a; }); }); } a = 1;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "ArrowFunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var i = 0; i < 10; ++i) { for (let x in xs.filter(x => x != i)) { } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for (let x of xs) { let a; for (let y of ys) { a = 1; (function() { a; }); } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var x of xs) { for (let y of ys) { (function() { x; }); } }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var x of xs) { (function() { x; }); }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a; for (let x of xs) { a = 1; (function() { a; }); }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a; for (let x of xs) { (function() { a; }); a = 1; }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; function foo() { a = 10; } for (let x of xs) { (function() { a; }); } foo();", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; function foo() { a = 10; for (let x of xs) { (function() { a; }); } } foo();", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-loss-of-precision.js b/tests/lib/rules/no-loss-of-precision.js index f268f117e92..9d51eb6d694 100644 --- a/tests/lib/rules/no-loss-of-precision.js +++ b/tests/lib/rules/no-loss-of-precision.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-loss-of-precision"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-loss-of-precision", rule, { valid: [ @@ -47,31 +52,31 @@ ruleTester.run("no-loss-of-precision", rule, { "var x = 0195", "var x = 0e5", - { code: "var x = 12_34_56", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 12_3.4_56", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = -12_3.4_56", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = -12_34_56", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 12_3e3_4", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 123.0e3_4", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 12_3e-3_4", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 12_3.0e-3_4", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = -1_23e-3_4", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = -1_23.8e-3_4", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 1_230000000_00000000_00000_000", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = -1_230000000_00000000_00000_000", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 0.0_00_000000000_000000000_00123", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = -0.0_00_000000000_000000000_00123", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 0e5_3", parserOptions: { ecmaVersion: 2021 } }, + { code: "var x = 12_34_56", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 12_3.4_56", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = -12_3.4_56", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = -12_34_56", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 12_3e3_4", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 123.0e3_4", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 12_3e-3_4", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 12_3.0e-3_4", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = -1_23e-3_4", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = -1_23.8e-3_4", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 1_230000000_00000000_00000_000", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = -1_230000000_00000000_00000_000", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 0.0_00_000000000_000000000_00123", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = -0.0_00_000000000_000000000_00123", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 0e5_3", languageOptions: { ecmaVersion: 2021 } }, - { code: "var x = 0b11111111111111111111111111111111111111111111111111111", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 0b111_111_111_111_1111_11111_111_11111_1111111111_11111111_111_111", parserOptions: { ecmaVersion: 2021 } }, + { code: "var x = 0b11111111111111111111111111111111111111111111111111111", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 0b111_111_111_111_1111_11111_111_11111_1111111111_11111111_111_111", languageOptions: { ecmaVersion: 2021 } }, - { code: "var x = 0B11111111111111111111111111111111111111111111111111111", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 0B111_111_111_111_1111_11111_111_11111_1111111111_11111111_111_111", parserOptions: { ecmaVersion: 2021 } }, + { code: "var x = 0B11111111111111111111111111111111111111111111111111111", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 0B111_111_111_111_1111_11111_111_11111_1111111111_11111111_111_111", languageOptions: { ecmaVersion: 2021 } }, - { code: "var x = 0o377777777777777777", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 0o3_77_777_777_777_777_777", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 0O377777777777777777", parserOptions: { ecmaVersion: 6 } }, + { code: "var x = 0o377777777777777777", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 0o3_77_777_777_777_777_777", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 0O377777777777777777", languageOptions: { ecmaVersion: 6 } }, "var x = 0377777777777777777", "var x = 0x1FFFFFFFFFFFFF", @@ -86,8 +91,8 @@ ruleTester.run("no-loss-of-precision", rule, { "var x = new Date()", "var x = '9007199254740993'", - { code: "var x = 0x1FFF_FFFF_FFF_FFF", parserOptions: { ecmaVersion: 2021 } }, - { code: "var x = 0X1_FFF_FFFF_FFF_FFF", parserOptions: { ecmaVersion: 2021 } } + { code: "var x = 0x1FFF_FFFF_FFF_FFF", languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = 0X1_FFF_FFFF_FFF_FFF", languageOptions: { ecmaVersion: 2021 } } ], invalid: [ { @@ -116,33 +121,33 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 900719925474099_3", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 90_0719925_4740.9_93e3", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 9.0_0719925_474099_3e15", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = -9_00719_9254_740993", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 900_719.92_54740_994", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = -900_719.92_5474_0994", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 5123000000000000000000000000001", @@ -174,23 +179,23 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 0b100000000000000000000000000000000000000000000000000001", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = 0B100000000000000000000000000000000000000000000000000001", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = 0o400000000000000001", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = 0O400000000000000001", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = 0400000000000000001", @@ -206,68 +211,68 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 5123_00000000000000000000000000_1", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = -5_12300000000000000000000_0000001", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 123_00000000000000000000_00.0_0", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 1.0_00000000000000000_0000123", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 174_980057982_640953949800178169_409709228253554471456994_914061648512796239935950073857881054_1618443059_2", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 2e9_99", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = .1_23000000000000_00000_0000_0", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 0b1_0000000000000000000000000000000000000000000000000000_1", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 0B10000000000_0000000000000000000000000000_000000000000001", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 0o4_00000000000000_001", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 0O4_0000000000000000_1", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 0x2_0000000000001", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "var x = 0X200000_0000000_1", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noLossOfPrecision" }] + errors: [{ messageId: "noLossOfPrecision" }], + languageOptions: { ecmaVersion: 2021 } } ] }); diff --git a/tests/lib/rules/no-magic-numbers.js b/tests/lib/rules/no-magic-numbers.js index e168249d117..18c2b82949b 100644 --- a/tests/lib/rules/no-magic-numbers.js +++ b/tests/lib/rules/no-magic-numbers.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-magic-numbers"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -25,14 +25,14 @@ ruleTester.run("no-magic-numbers", rule, { "var x = Number.parseInt(y, 10);", { code: "const foo = 42;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = 42;", options: [{ enforceConst: false }], - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "var foo = -42;", { @@ -113,14 +113,14 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "foo[0o71]", options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "foo[0xABC]", @@ -132,7 +132,10 @@ ruleTester.run("no-magic-numbers", rule, { code: "foo[0123]", options: [{ ignoreArrayIndexes: true - }] + }], + languageOptions: { + sourceType: "script" + } }, { code: "foo[5.0000000000000001]", // loses precision and evaluates to 5 @@ -151,139 +154,143 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[-0n]", // Allowed. -0n evaluates to 0n which will be coerced to "0", so foo[-0n] refers to the element at index 0. options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[1n]", // Allowed. 1n will be coerced to "1", so foo[1n] refers to the element at index 1. options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[100n]", // Allowed. 100n will be coerced to "100", so foo[100n] refers to the element at index 100. options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[0xABn]", // Allowed. 0xABn is evaluated to 171n and will be coerced to "171", so foo[0xABn] refers to the element at index 171. options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[4294967294n]", // max array index options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = ;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } } }, { code: "var a =
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } } }, { code: "f(100n)", options: [{ ignore: ["100n"] }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "f(-100n)", options: [{ ignore: ["-100n"] }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "const { param = 123 } = sourceObject;", options: [{ ignoreDefaultValues: true }], - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "const func = (param = 123) => {}", options: [{ ignoreDefaultValues: true }], - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "const func = ({ param = 123 }) => {}", options: [{ ignoreDefaultValues: true }], - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "const [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: true }], - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "var one, two; [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: true }], - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, // Optional chaining { code: "var x = parseInt?.(y, 10);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = Number?.parseInt(y, 10);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = (Number?.parseInt)(y, 10);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.[777]", options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // ignoreClassFieldInitialValues { code: "class C { foo = 2; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = -2; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static foo = 2; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #foo = 2; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static #foo = 2; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -292,8 +299,8 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - env: { es6: true }, - errors: [{ messageId: "useConst" }] + errors: [{ messageId: "useConst" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = 0 + 1;", @@ -307,20 +314,20 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - parserOptions: { + errors: [{ messageId: "useConst" }], + languageOptions: { ecmaVersion: 2020 - }, - errors: [{ messageId: "useConst" }] + } }, { code: "var foo = 0n + 1n;", - parserOptions: { - ecmaVersion: 2020 - }, errors: [ { messageId: "noMagic", data: { raw: "0n" } }, { messageId: "noMagic", data: { raw: "1n" } } - ] + ], + languageOptions: { + ecmaVersion: 2020 + } }, { code: "a = a + 5;", @@ -366,7 +373,10 @@ ruleTester.run("no-magic-numbers", rule, { { messageId: "noMagic", data: { raw: "0x1A" } }, { messageId: "noMagic", data: { raw: "0x02" } }, { messageId: "noMagic", data: { raw: "071" } } - ] + ], + languageOptions: { + sourceType: "script" + } }, { code: "var stats = {avg: 42};", options: [{ @@ -418,7 +428,6 @@ ruleTester.run("no-magic-numbers", rule, { "function invokeInTen(func) {\n" + "setTimeout(func, 10);\n" + "}\n", - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "10" }, line: 7 }, { messageId: "noMagic", data: { raw: "10" }, line: 7 }, @@ -426,7 +435,8 @@ ruleTester.run("no-magic-numbers", rule, { { messageId: "noMagic", data: { raw: "1000" }, line: 15 }, { messageId: "noMagic", data: { raw: "0" }, line: 19 }, { messageId: "noMagic", data: { raw: "10" }, line: 22 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var data = ['foo', 'bar', 'baz']; var third = data[3];", @@ -491,20 +501,20 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "noMagic", data: { raw: "-0b110" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "foo[-0o71]", options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "noMagic", data: { raw: "-0o71" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "foo[-0x12]", @@ -522,7 +532,8 @@ ruleTester.run("no-magic-numbers", rule, { }], errors: [{ messageId: "noMagic", data: { raw: "-012" }, line: 1 - }] + }], + languageOptions: { sourceType: "script" } }, { code: "foo[0.1]", @@ -628,40 +639,40 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-1n" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[-100n]", options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-100n" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[-0x12n]", options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-0x12n" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[4294967295n]", // first above the max index options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "4294967295n" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[+0]", // Consistent with the default behavior, which doesn't allow: var foo = +0 @@ -695,30 +706,30 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "0n" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[+1n]", // Consistent with the default behavior, which doesn't allow: var foo = +1n options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "1n" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo[- -1n]", // Consistent with the default behavior, which doesn't allow: var foo = - -1n options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-1n" }, line: 1 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "100 .toString()", @@ -740,16 +751,18 @@ ruleTester.run("no-magic-numbers", rule, { }, { code: "var a =
;", - parserOptions: { - ecmaFeatures: { - jsx: true - } - }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 }, { messageId: "noMagic", data: { raw: "3" }, line: 1 } - ] + ], + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + } }, { code: "var min, max, mean; min = 1; max = 10; mean = 4;", @@ -763,26 +776,26 @@ ruleTester.run("no-magic-numbers", rule, { { code: "f(100n)", options: [{ ignore: [100] }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "100n" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "f(-100n)", options: [{ ignore: ["100n"] }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "-100n" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "f(100n)", options: [{ ignore: ["-100n"] }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "100n" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "f(100)", @@ -794,133 +807,133 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const func = (param = 123) => {}", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { param = 123 } = sourceObject;", options: [{}], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { param = 123 } = sourceObject;", - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const { param = 123 } = sourceObject;", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var one, two; [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // ignoreClassFieldInitialValues { code: "class C { foo = 2; }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = 2; }", options: [{}], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = -2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "-2" }, line: 1, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 24 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 18 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static #foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 25 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = 2 + 3; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 }, { messageId: "noMagic", data: { raw: "3" }, line: 1, column: 21 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 2; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 11 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [2]; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 12 } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-misleading-character-class.js b/tests/lib/rules/no-misleading-character-class.js index 9ee29a4631d..3bb2a33accb 100644 --- a/tests/lib/rules/no-misleading-character-class.js +++ b/tests/lib/rules/no-misleading-character-class.js @@ -9,15 +9,14 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-misleading-character-class"), - { RuleTester } = require("../../../lib/rule-tester"), - FlatRuleTester = require("../../../lib/rule-tester/flat-rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }); /* @@ -69,15 +68,15 @@ ruleTester.run("no-misleading-character-class", rule, { // don't report and don't crash on invalid regex "var r = new RegExp('[Á] [ ');", "var r = RegExp('{ [Á]', 'u');", - { code: "var r = new globalThis.RegExp('[Á] [ ');", env: { es2020: true } }, - { code: "var r = globalThis.RegExp('{ [Á]', 'u');", env: { es2020: true } }, + { code: "var r = new globalThis.RegExp('[Á] [ ');", languageOptions: { ecmaVersion: 2020 } }, + { code: "var r = globalThis.RegExp('{ [Á]', 'u');", languageOptions: { ecmaVersion: 2020 } }, // ES2024 - { code: "var r = /[👍]/v", parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`var r = /^[\q{👶🏻}]$/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`var r = /[🇯\q{abc}🇵]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: "var r = /[🇯[A]🇵]/v", parserOptions: { ecmaVersion: 2024 } }, - { code: "var r = /[🇯[A--B]🇵]/v", parserOptions: { ecmaVersion: 2024 } } + { code: "var r = /[👍]/v", languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`var r = /^[\q{👶🏻}]$/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`var r = /[🇯\q{abc}🇵]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: "var r = /[🇯[A]🇵]/v", languageOptions: { ecmaVersion: 2024 } }, + { code: "var r = /[🇯[A--B]🇵]/v", languageOptions: { ecmaVersion: 2024 } } ], invalid: [ @@ -98,19 +97,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /[👍]/", - parserOptions: { ecmaVersion: 3 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }] + }], + languageOptions: { ecmaVersion: 3, sourceType: "script" } }, { code: "var r = /[👍]/", - parserOptions: { ecmaVersion: 5 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }] + }], + languageOptions: { ecmaVersion: 5, sourceType: "script" } }, { code: "var r = /[👍]\\a/", @@ -121,19 +120,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /(?<=[👍])/", - parserOptions: { ecmaVersion: 9 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /(?<=[👍])/u" }] - }] + }], + languageOptions: { ecmaVersion: 9 } }, { code: "var r = /(?<=[👍])/", - parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /(?<=[👍])/u" }] - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "var r = /[Á]/", @@ -341,19 +340,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("[👍]", "")`, - parserOptions: { ecmaVersion: 3 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }] + }], + languageOptions: { ecmaVersion: 3, sourceType: "script" } }, { code: String.raw`var r = new RegExp("[👍]", "")`, - parserOptions: { ecmaVersion: 5 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }] + }], + languageOptions: { ecmaVersion: 5, sourceType: "script" } }, { code: String.raw`var r = new RegExp("[👍]\\a", "")`, @@ -364,19 +363,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("/(?<=[👍])", "")`, - parserOptions: { ecmaVersion: 9 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("/(?<=[👍])", "u")` }] - }] + }], + languageOptions: { ecmaVersion: 9 } }, { code: String.raw`var r = new RegExp("/(?<=[👍])", "")`, - parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("/(?<=[👍])", "u")` }] - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: String.raw`var r = new RegExp("[Á]", "")`, @@ -513,11 +512,11 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("[🇯🇵]",)`, - parserOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("[🇯🇵]", "u",)` }] - }] + }], + languageOptions: { ecmaVersion: 2017 } }, { code: String.raw`var r = new RegExp(("[🇯🇵]"))`, @@ -535,11 +534,11 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp(("[🇯🇵]"),)`, - parserOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp(("[🇯🇵]"), "u",)` }] - }] + }], + languageOptions: { ecmaVersion: 2017 } }, { code: String.raw`var r = new RegExp("[🇯🇵]", "u")`, @@ -598,35 +597,35 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[❇️]", "")`, - env: { es2020: true }, errors: [{ messageId: "combiningClass", suggestions: null - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: String.raw`var r = new globalThis.RegExp("[👶🏻]", "u")`, - env: { es2020: true }, errors: [{ messageId: "emojiModifier", suggestions: null - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "")`, - env: { es2020: true }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "u")` }] - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: String.raw`var r = new globalThis.RegExp("[\\u{1F468}\\u{200D}\\u{1F469}\\u{200D}\\u{1F466}]", "u")`, - env: { es2020: true }, errors: [{ messageId: "zwj", suggestions: null - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: String.raw`/[\ud83d\u{dc4d}]/u`, @@ -661,41 +660,33 @@ ruleTester.run("no-misleading-character-class", rule, { // ES2024 { code: "var r = /[[👶🏻]]/v", - parserOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "emojiModifier", suggestions: null - }] - } - ] -}); - -const flatRuleTester = new FlatRuleTester(); - -flatRuleTester.run("no-misleading-character-class", rule, { - valid: [], - - invalid: [ + }], + languageOptions: { ecmaVersion: 2024 } + }, { code: "var r = /[👍]/", - languageOptions: { - ecmaVersion: 5, - sourceType: "script" - }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }] + }], + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } }, { code: "var r = /[👍]/", - languageOptions: { - ecmaVersion: 2015 - }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /[👍]/u" }] - }] + }], + languageOptions: { + ecmaVersion: 2015 + } } + ] }); diff --git a/tests/lib/rules/no-mixed-operators.js b/tests/lib/rules/no-mixed-operators.js index 782af07e310..144770a70d7 100644 --- a/tests/lib/rules/no-mixed-operators.js +++ b/tests/lib/rules/no-mixed-operators.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-mixed-operators"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -383,7 +383,6 @@ ruleTester.run("no-mixed-operators", rule, { { code: "a + b ?? c", options: [{ groups: [["+", "??"]] }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { column: 3, @@ -403,7 +402,8 @@ ruleTester.run("no-mixed-operators", rule, { rightOperator: "??" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-mixed-requires.js b/tests/lib/rules/no-mixed-requires.js index 5f1c316aa11..61695161a9c 100644 --- a/tests/lib/rules/no-mixed-requires.js +++ b/tests/lib/rules/no-mixed-requires.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-mixed-requires"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-mixed-spaces-and-tabs.js b/tests/lib/rules/no-mixed-spaces-and-tabs.js index 4dd475d4b60..e60e4f08e79 100644 --- a/tests/lib/rules/no-mixed-spaces-and-tabs.js +++ b/tests/lib/rules/no-mixed-spaces-and-tabs.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-mixed-spaces-and-tabs"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -44,43 +44,43 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { }, { code: "/*\n\t */`\n\t `;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "/*\n\t */var a = `\n\t `, b = `\n\t `/*\t \n\t \n*/;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "/*\t `template inside comment` */", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `\t /* comment inside template\t */`;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "`\n\t `;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "`\n\t \n`;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "`\t `;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "const foo = `${console}\n\t foo`;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "`\t `;` \t`", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "`foo${ 5 }\t `;", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "' \t\\\n\t multiline string';", "'\t \\\n \tmultiline string';", @@ -278,7 +278,6 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { { code: "`foo${\n \t 5 }bar`;", options: ["smart-tabs"], - env: { es6: true }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -288,11 +287,11 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`foo${\n\t 5 }bar`;", - env: { es6: true }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -302,7 +301,8 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: " \t'';", diff --git a/tests/lib/rules/no-multi-assign.js b/tests/lib/rules/no-multi-assign.js index 94db78ff81d..38daffc10e9 100644 --- a/tests/lib/rules/no-multi-assign.js +++ b/tests/lib/rules/no-multi-assign.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-multi-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -44,18 +44,18 @@ ruleTester.run("no-multi-assign", rule, { "var a, b, c,\nd = 0;", "var a = 1; var b = 2; var c = 3;\nvar d = 0;", "var a = 1 + (b === 10 ? 5 : 4);", - { code: "const a = 1, b = 2, c = 3;", parserOptions: { ecmaVersion: 6 } }, - { code: "const a = 1;\nconst b = 2;\n const c = 3;", parserOptions: { ecmaVersion: 6 } }, + { code: "const a = 1, b = 2, c = 3;", languageOptions: { ecmaVersion: 6 } }, + { code: "const a = 1;\nconst b = 2;\n const c = 3;", languageOptions: { ecmaVersion: 6 } }, "for(var a = 0, b = 0;;){}", - { code: "for(let a = 0, b = 0;;){}", parserOptions: { ecmaVersion: 6 } }, - { code: "for(const a = 0, b = 0;;){}", parserOptions: { ecmaVersion: 6 } }, - { code: "export let a, b;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export let a,\n b = 0;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "const x = {};const y = {};x.one = y.one = 1;", options: [{ ignoreNonDeclaration: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "let a, b;a = b = 1", options: [{ ignoreNonDeclaration: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "for(let a = 0, b = 0;;){}", languageOptions: { ecmaVersion: 6 } }, + { code: "for(const a = 0, b = 0;;){}", languageOptions: { ecmaVersion: 6 } }, + { code: "export let a, b;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export let a,\n b = 0;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "const x = {};const y = {};x.one = y.one = 1;", options: [{ ignoreNonDeclaration: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "let a, b;a = b = 1", options: [{ ignoreNonDeclaration: true }], languageOptions: { ecmaVersion: 6 } }, { code: "class C { [foo = 0] = 0 }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -75,11 +75,11 @@ ruleTester.run("no-multi-assign", rule, { }, { code: "let foo = bar = cee = 100;", - parserOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 11, "AssignmentExpression"), errorAt(1, 17, "AssignmentExpression") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "a=b=c=d=e", @@ -146,50 +146,50 @@ ruleTester.run("no-multi-assign", rule, { { code: "const x = {};\nconst y = x.one = 1;", options: [{ ignoreNonDeclaration: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ errorAt(2, 11, "AssignmentExpression") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let a, b;a = b = 1", options: [{}], - parserOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 14, "AssignmentExpression") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let x, y;x = y = 'baz'", options: [{ ignoreNonDeclaration: false }], - parserOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 14, "AssignmentExpression") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = b = 1", options: [{ ignoreNonDeclaration: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 11, "AssignmentExpression") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class C { field = foo = 0 }", - parserOptions: { ecmaVersion: 2022 }, errors: [ errorAt(1, 19, "AssignmentExpression") - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { field = foo = 0 }", options: [{ ignoreNonDeclaration: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ errorAt(1, 19, "AssignmentExpression") - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-multi-spaces.js b/tests/lib/rules/no-multi-spaces.js index 5534f111548..19643842c00 100644 --- a/tests/lib/rules/no-multi-spaces.js +++ b/tests/lib/rules/no-multi-spaces.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-multi-spaces"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -69,7 +69,7 @@ ruleTester.run("no-multi-spaces", rule, { "var foo = \"hello world\";", "function foo() {\n return;\n}", "function foo() {\n if (foo) {\n return;\n }\n}", - { code: "var foo = `hello world`;", parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = `hello world`;", languageOptions: { ecmaVersion: 6 } }, "({ a: b })", { code: "var answer = 6 * 7;", @@ -121,14 +121,14 @@ ruleTester.run("no-multi-spaces", rule, { { code: "var foo = (a, b) => {}", output: "var foo = (a, b) => {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "multipleSpaces", data: { displayValue: "b" }, type: "Identifier", column: 14, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 1", diff --git a/tests/lib/rules/no-multi-str.js b/tests/lib/rules/no-multi-str.js index 1447f863f65..c592332388f 100644 --- a/tests/lib/rules/no-multi-str.js +++ b/tests/lib/rules/no-multi-str.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-multi-str"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,7 +21,15 @@ const ruleTester = new RuleTester(); ruleTester.run("no-multi-str", rule, { valid: [ "var a = 'Line 1 Line 2';", - { code: "var a =
\n

Wat

\n
;", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } } + { + code: "var a =
\n

Wat

\n
;", + languageOptions: { + ecmaVersion: 6, + parserOptions: { + ecmaFeatures: { jsx: true } + } + } + } ], invalid: [ { diff --git a/tests/lib/rules/no-multiple-empty-lines.js b/tests/lib/rules/no-multiple-empty-lines.js index bcec4e44c4c..2c9f33d6448 100644 --- a/tests/lib/rules/no-multiple-empty-lines.js +++ b/tests/lib/rules/no-multiple-empty-lines.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-multiple-empty-lines"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -129,22 +129,22 @@ ruleTester.run("no-multiple-empty-lines", rule, { { code: "// valid 12\nx = `\n\n\n\nhi\n\n\n\n`", options: [{ max: 2 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "// valid 13\n`\n\n`", options: [{ max: 0 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "// valid 14\nvar a = 5;`\n\n\n\n\n`", options: [{ max: 0, maxEOF: 0 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "`\n\n\n\n\n`\n// valid 15\nvar a = 5;", options: [{ max: 0, maxBOF: 0 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "\n\n\n\n// valid 16\nvar a = 5;\n", @@ -301,15 +301,15 @@ ruleTester.run("no-multiple-empty-lines", rule, { "`bar`;\n" + "`baz`;", options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6 }, - errors: [getExpectedError(1)] + errors: [getExpectedError(1)], + languageOptions: { ecmaVersion: 6 } }, { code: "`template ${foo\n\n\n} literal`;", output: "`template ${foo\n\n} literal`;", options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6 }, - errors: [getExpectedError(1)] + errors: [getExpectedError(1)], + languageOptions: { ecmaVersion: 6 } }, { diff --git a/tests/lib/rules/no-native-reassign.js b/tests/lib/rules/no-native-reassign.js index 8bb14d70c5d..df17114295d 100644 --- a/tests/lib/rules/no-native-reassign.js +++ b/tests/lib/rules/no-native-reassign.js @@ -11,7 +11,8 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-native-reassign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests @@ -25,9 +26,9 @@ ruleTester.run("no-native-reassign", rule, { "var string;", { code: "Object = 0;", options: [{ exceptions: ["Object"] }] }, "top = 0;", - { code: "onload = 0;", env: { browser: true } }, + { code: "onload = 0;", languageOptions: { globals: globals.browser } }, "require = 0;", - { code: "a = 1", globals: { a: true } }, + { code: "a = 1", languageOptions: { globals: { a: true } } }, "/*global a:true*/ a = 1" ], invalid: [ @@ -35,26 +36,26 @@ ruleTester.run("no-native-reassign", rule, { { code: "String++;", errors: [{ messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" }] }, { code: "({Object = 0, String = 0} = {});", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "nativeReassign", data: { name: "Object" }, type: "Identifier" }, { messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "top = 0;", - env: { browser: true }, - errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }] + errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }], + languageOptions: { globals: globals.browser } }, { code: "require = 0;", - env: { node: true }, - errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }] + errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }], + languageOptions: { sourceType: "commonjs" } }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 { code: "/*global b:false*/ function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, - { code: "function f() { b = 1; }", globals: { b: false }, errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, + { code: "function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }], languageOptions: { globals: { b: false } } }, { code: "/*global b:false*/ function f() { b++; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, { code: "/*global b*/ b = 1;", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, { code: "Array = 1;", errors: [{ messageId: "nativeReassign", data: { name: "Array" }, type: "Identifier" }] } diff --git a/tests/lib/rules/no-negated-condition.js b/tests/lib/rules/no-negated-condition.js index bd29b0b9b5a..ca14e574e37 100644 --- a/tests/lib/rules/no-negated-condition.js +++ b/tests/lib/rules/no-negated-condition.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-negated-condition"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-negated-in-lhs.js b/tests/lib/rules/no-negated-in-lhs.js index 7cb9429f670..20a5759026b 100644 --- a/tests/lib/rules/no-negated-in-lhs.js +++ b/tests/lib/rules/no-negated-in-lhs.js @@ -11,7 +11,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-negated-in-lhs"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-nested-ternary.js b/tests/lib/rules/no-nested-ternary.js index 01cbe01bbd7..1c60558c260 100644 --- a/tests/lib/rules/no-nested-ternary.js +++ b/tests/lib/rules/no-nested-ternary.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-nested-ternary"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-new-func.js b/tests/lib/rules/no-new-func.js index 1ac02d97465..426a74694ac 100644 --- a/tests/lib/rules/no-new-func.js +++ b/tests/lib/rules/no-new-func.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-new-func"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -24,13 +24,13 @@ ruleTester.run("no-new-func", rule, { "var a = _function(\"b\", \"c\", \"return b+c\");", { code: "class Function {}; new Function()", - parserOptions: { + languageOptions: { ecmaVersion: 2015 } }, { code: "const fn = () => { class Function {}; new Function() }", - parserOptions: { + languageOptions: { ecmaVersion: 2015 } }, @@ -96,21 +96,21 @@ ruleTester.run("no-new-func", rule, { }, { code: "var a = (Function?.call)(null, \"b\", \"c\", \"return b+c\");", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noFunctionConstructor", type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "const fn = () => { class Function {} }; new Function('', '')", - parserOptions: { - ecmaVersion: 2015 - }, errors: [{ messageId: "noFunctionConstructor", type: "NewExpression" - }] + }], + languageOptions: { + ecmaVersion: 2015 + } }, { code: "var fn = function () { function Function() {} }; Function('', '')", diff --git a/tests/lib/rules/no-new-native-nonconstructor.js b/tests/lib/rules/no-new-native-nonconstructor.js index 9637ad79959..0a29ba66ed7 100644 --- a/tests/lib/rules/no-new-native-nonconstructor.js +++ b/tests/lib/rules/no-new-native-nonconstructor.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-new-native-nonconstructor"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ env: { es2022: true } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("no-new-native-nonconstructor", rule, { valid: [ diff --git a/tests/lib/rules/no-new-object.js b/tests/lib/rules/no-new-object.js index 0e8f5eb9957..acef865ad46 100644 --- a/tests/lib/rules/no-new-object.js +++ b/tests/lib/rules/no-new-object.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-new-object"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -36,14 +36,14 @@ ruleTester.run("no-new-object", rule, { } new Object(); `, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` import { Object } from './' new Object(); `, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } } ], invalid: [ @@ -62,8 +62,8 @@ ruleTester.run("no-new-object", rule, { }, { code: "const a = new Object()", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "preferLiteral", type: "NewExpression" }] + errors: [{ messageId: "preferLiteral", type: "NewExpression" }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-new-require.js b/tests/lib/rules/no-new-require.js index 8fb8b1a10fd..7b779b18e8e 100644 --- a/tests/lib/rules/no-new-require.js +++ b/tests/lib/rules/no-new-require.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-new-require"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-new-symbol.js b/tests/lib/rules/no-new-symbol.js index 198cc50e1f3..2f965ff6910 100644 --- a/tests/lib/rules/no-new-symbol.js +++ b/tests/lib/rules/no-new-symbol.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-new-symbol"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ env: { es6: true } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("no-new-symbol", rule, { valid: [ diff --git a/tests/lib/rules/no-new-wrappers.js b/tests/lib/rules/no-new-wrappers.js index 0b5b686aef1..62181bc99fd 100644 --- a/tests/lib/rules/no-new-wrappers.js +++ b/tests/lib/rules/no-new-wrappers.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-new-wrappers"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -32,7 +32,7 @@ ruleTester.run("no-new-wrappers", rule, { import String from "./string"; const str = new String(42); `, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, ` if (foo) { @@ -43,8 +43,10 @@ ruleTester.run("no-new-wrappers", rule, { `, { code: "new String()", - globals: { - String: "off" + languageOptions: { + globals: { + String: "off" + } } }, ` @@ -91,7 +93,6 @@ ruleTester.run("no-new-wrappers", rule, { const b = new String('foo'); } `, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noConstructor", data: { @@ -99,7 +100,8 @@ ruleTester.run("no-new-wrappers", rule, { }, type: "NewExpression", line: 2 - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-new.js b/tests/lib/rules/no-new.js index 4aece10f8f1..67a5c6a5bd9 100644 --- a/tests/lib/rules/no-new.js +++ b/tests/lib/rules/no-new.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-new"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-nonoctal-decimal-escape.js b/tests/lib/rules/no-nonoctal-decimal-escape.js index ecaf5109fc0..25eafb5da53 100644 --- a/tests/lib/rules/no-nonoctal-decimal-escape.js +++ b/tests/lib/rules/no-nonoctal-decimal-escape.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-nonoctal-decimal-escape"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -58,7 +58,12 @@ function error(decimalEscape, column, refactorOutput, escapeBackslashOutput) { // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-nonoctal-decimal-escape", rule, { valid: [ diff --git a/tests/lib/rules/no-obj-calls.js b/tests/lib/rules/no-obj-calls.js index febb13fda03..3595ae0149c 100644 --- a/tests/lib/rules/no-obj-calls.js +++ b/tests/lib/rules/no-obj-calls.js @@ -10,13 +10,19 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-obj-calls"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-obj-calls", rule, { valid: [ @@ -31,54 +37,60 @@ ruleTester.run("no-obj-calls", rule, { "new JSON.parse", { code: "Reflect.get(foo, 'x')", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "new Reflect.foo(a, b)", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "Atomics.load(foo, 0)", - env: { es2017: true } + languageOptions: { ecmaVersion: 2017 } }, { code: "new Atomics.foo()", - env: { es2017: true } + languageOptions: { ecmaVersion: 2017 } }, { code: "new Intl.Segmenter()", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "Intl.foo()", - env: { browser: true } + languageOptions: { globals: globals.browser } }, - { code: "globalThis.Math();", env: { es6: true } }, - { code: "var x = globalThis.Math();", env: { es6: true } }, - { code: "f(globalThis.Math());", env: { es6: true } }, - { code: "globalThis.Math().foo;", env: { es6: true } }, - { code: "var x = globalThis.JSON();", env: { es6: true } }, - { code: "x = globalThis.JSON(str);", env: { es6: true } }, - { code: "globalThis.Math( globalThis.JSON() );", env: { es6: true } }, - { code: "var x = globalThis.Reflect();", env: { es6: true } }, - { code: "var x = globalThis.Reflect();", env: { es2017: true } }, - { code: "/*globals Reflect: true*/ globalThis.Reflect();", env: { es2017: true } }, - { code: "var x = globalThis.Atomics();", env: { es2017: true } }, - { code: "var x = globalThis.Atomics();", globals: { Atomics: false }, env: { es2017: true } }, - { code: "var x = globalThis.Intl();", env: { browser: true } }, - { code: "var x = globalThis.Intl();", globals: { Intl: false }, env: { browser: true } }, + { code: "globalThis.Math();", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = globalThis.Math();", languageOptions: { ecmaVersion: 6 } }, + { code: "f(globalThis.Math());", languageOptions: { ecmaVersion: 6 } }, + { code: "globalThis.Math().foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = globalThis.JSON();", languageOptions: { ecmaVersion: 6 } }, + { code: "x = globalThis.JSON(str);", languageOptions: { ecmaVersion: 6 } }, + { code: "globalThis.Math( globalThis.JSON() );", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = globalThis.Reflect();", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = globalThis.Reflect();", languageOptions: { ecmaVersion: 2017 } }, + { code: "/*globals Reflect: true*/ globalThis.Reflect();", languageOptions: { ecmaVersion: 2017 } }, + { code: "var x = globalThis.Atomics();", languageOptions: { ecmaVersion: 2017 } }, + { code: "var x = globalThis.Atomics();", languageOptions: { ecmaVersion: 2017, globals: { Atomics: false } } }, + { code: "var x = globalThis.Intl();", languageOptions: { globals: globals.browser } }, + { + code: "var x = globalThis.Intl();", languageOptions: { globals: { ...globals.browser, Intl: false } } + }, // non-existing variables "/*globals Math: off*/ Math();", "/*globals Math: off*/ new Math();", { code: "JSON();", - globals: { JSON: "off" } + languageOptions: { + globals: { JSON: "off" } + } }, { code: "new JSON();", - globals: { JSON: "off" } + languageOptions: { + globals: { JSON: "off" } + } }, "Reflect();", "Atomics();", @@ -86,7 +98,7 @@ ruleTester.run("no-obj-calls", rule, { "new Atomics();", { code: "Atomics();", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Intl()", "new Intl()", @@ -96,55 +108,50 @@ ruleTester.run("no-obj-calls", rule, { "var Math; new Math();", { code: "let JSON; JSON();", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "let JSON; new JSON();", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (foo) { const Reflect = 1; Reflect(); }", - parserOptions: { ecmaVersion: 2015 }, - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { const Reflect = 1; new Reflect(); }", - parserOptions: { ecmaVersion: 2015 }, - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "function foo(Math) { Math(); }", "function foo(JSON) { new JSON(); }", { code: "function foo(Atomics) { Atomics(); }", - env: { es2017: true } + languageOptions: { ecmaVersion: 2017 } }, { code: "function foo() { if (bar) { let Atomics; if (baz) { new Atomics(); } } }", - parserOptions: { ecmaVersion: 2015 }, - env: { es2017: true } + languageOptions: { ecmaVersion: 2017 } }, "function foo() { var JSON; JSON(); }", { code: "function foo() { var Atomics = bar(); var baz = Atomics(5); }", - globals: { Atomics: false } + languageOptions: { globals: { Atomics: false } } }, { code: "var construct = typeof Reflect !== \"undefined\" ? Reflect.construct : undefined; construct();", - globals: { Reflect: false } + languageOptions: { globals: { Reflect: false } } }, { code: "function foo(Intl) { Intl(); }", - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "if (foo) { const Intl = 1; Intl(); }", - parserOptions: { ecmaVersion: 2015 }, - env: { browser: true } + languageOptions: { ecmaVersion: 2015, globals: globals.browser } }, { code: "if (foo) { const Intl = 1; new Intl(); }", - parserOptions: { ecmaVersion: 2015 }, - env: { browser: true } + languageOptions: { ecmaVersion: 2015, globals: globals.browser } } ], invalid: [ @@ -205,18 +212,18 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Reflect();", - env: { es6: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = new Reflect();", - env: { es6: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = Reflect();", - env: { es2017: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2017 } }, { code: "/*globals Reflect: true*/ Reflect();", @@ -228,38 +235,38 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Atomics();", - env: { es2017: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2017 } }, { code: "var x = new Atomics();", - env: { es2017: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], + languageOptions: { ecmaVersion: 2017 } }, { code: "var x = Atomics();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = Atomics();", - globals: { Atomics: false }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + languageOptions: { globals: { Atomics: false } } }, { code: "var x = new Atomics();", - globals: { Atomics: "writable" }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], + languageOptions: { globals: { Atomics: "writable" } } }, { code: "var x = Intl();", - env: { browser: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }], + languageOptions: { globals: globals.browser } }, { code: "var x = new Intl();", - env: { browser: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }], + languageOptions: { globals: globals.browser } }, { code: "/*globals Intl: true*/ Intl();", @@ -271,81 +278,81 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = globalThis.Math();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = new globalThis.Math();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "f(globalThis.Math());", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.Math().foo;", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "new globalThis.Math().foo;", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = globalThis.JSON();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "x = globalThis.JSON(str);", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.Math( globalThis.JSON() );", - env: { es2020: true }, errors: [ { messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 37 }, { messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression", column: 18, endColumn: 35 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = globalThis.Reflect();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = new globalThis.Reflect;", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "/*globals Reflect: true*/ Reflect();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = globalThis.Atomics();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = globalThis.Intl();", - env: { browser: true, es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }], + languageOptions: { globals: globals.browser, ecmaVersion: 2020 } }, { code: "var x = new globalThis.Intl;", - env: { browser: true, es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }], + languageOptions: { globals: globals.browser, ecmaVersion: 2020 } }, { code: "/*globals Intl: true*/ Intl();", - env: { browser: true, es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }], + languageOptions: { globals: globals.browser, ecmaVersion: 2020 } }, { code: "var foo = bar ? baz: JSON; foo();", @@ -357,45 +364,45 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var foo = bar ? baz: globalThis.JSON; foo();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = bar ? baz: globalThis.JSON; new foo();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = window.Atomics; foo();", - env: { es2020: true, browser: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020, globals: globals.browser } }, { code: "var foo = window.Atomics; new foo;", - env: { es2020: true, browser: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }], + languageOptions: { ecmaVersion: 2020, globals: globals.browser } }, { code: "var foo = window.Intl; foo();", - env: { es2020: true, browser: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020, globals: globals.browser } }, { code: "var foo = window.Intl; new foo;", - env: { es2020: true, browser: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "NewExpression" }], + languageOptions: { ecmaVersion: 2020, globals: globals.browser } }, // Optional chaining { code: "var x = globalThis?.Reflect();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var x = (globalThis?.Reflect)();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-object-constructor.js b/tests/lib/rules/no-object-constructor.js index 464a0779bc7..6fb58435f78 100644 --- a/tests/lib/rules/no-object-constructor.js +++ b/tests/lib/rules/no-object-constructor.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-object-constructor"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: "latest", sourceType: "script" } }); ruleTester.run("no-object-constructor", rule, { valid: [ @@ -27,8 +27,10 @@ ruleTester.run("no-object-constructor", rule, { "var Object; new Object;", { code: "new Object()", - globals: { - Object: "off" + languageOptions: { + globals: { + Object: "off" + } } } ], @@ -174,14 +176,14 @@ ruleTester.run("no-object-constructor", rule, { Object() `, - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: ` Object() `, - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } } ].map(props => ({ ...props, @@ -316,28 +318,28 @@ ruleTester.run("no-object-constructor", rule, { export { foo } Object() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` export { foo } from 'bar' Object() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` export * as foo from 'bar' Object() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` import foo from 'bar' Object() `, - parserOptions: { sourceType: "module" } + languageOptions: { sourceType: "module" } }, { code: ` diff --git a/tests/lib/rules/no-octal-escape.js b/tests/lib/rules/no-octal-escape.js index 03d702e2900..4216f7a1de0 100644 --- a/tests/lib/rules/no-octal-escape.js +++ b/tests/lib/rules/no-octal-escape.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-octal-escape"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-octal-escape", rule, { valid: [ diff --git a/tests/lib/rules/no-octal.js b/tests/lib/rules/no-octal.js index a48bf5a1031..949741149e6 100644 --- a/tests/lib/rules/no-octal.js +++ b/tests/lib/rules/no-octal.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-octal"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-octal", rule, { valid: [ diff --git a/tests/lib/rules/no-param-reassign.js b/tests/lib/rules/no-param-reassign.js index 5f521cbc3cd..43c78dfd7bd 100644 --- a/tests/lib/rules/no-param-reassign.js +++ b/tests/lib/rules/no-param-reassign.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-param-reassign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -22,17 +22,17 @@ ruleTester.run("no-param-reassign", rule, { valid: [ "function foo(a) { var b = a; }", "function foo(a) { for (b in a); }", - { code: "function foo(a) { for (b of a); }", parserOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { for (b of a); }", languageOptions: { ecmaVersion: 6 } }, "function foo(a) { a.prop = 'value'; }", "function foo(a) { for (a.prop in obj); }", - { code: "function foo(a) { for (a.prop of arr); }", parserOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { for (a.prop of arr); }", languageOptions: { ecmaVersion: 6 } }, "function foo(a) { (function() { var a = 12; a++; })(); }", "function foo() { someGlobal = 13; }", - { code: "function foo() { someGlobal = 13; }", globals: { someGlobal: false } }, + { code: "function foo() { someGlobal = 13; }", languageOptions: { globals: { someGlobal: false } } }, "function foo(a) { a.b = 0; }", "function foo(a) { delete a.b; }", "function foo(a) { ++a.b; }", - { code: "function foo(a) { [a.b] = []; }", parserOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { [a.b] = []; }", languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { bar(a.b).c = 0; }", options: [{ props: true }] }, { code: "function foo(a) { data[a.b] = 0; }", options: [{ props: true }] }, { code: "function foo(a) { +a.b; }", options: [{ props: true }] }, @@ -42,7 +42,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { ++a.b; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }] }, { code: "function foo(a) { delete a.b; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }] }, { code: "function foo(a) { for (a.b in obj); }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }] }, - { code: "function foo(a) { for (a.b of arr); }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }], parserOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { for (a.b of arr); }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }], languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a, z) { a.b = 0; x.y = 0; }", options: [{ props: true, ignorePropertyModificationsFor: ["a", "x"] }] }, { code: "function foo(a) { a.b.c = 0;}", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }] }, { code: "function foo(aFoo) { aFoo.b = 0; }", options: [{ props: true, ignorePropertyModificationsForRegex: ["^a.*$"] }] }, @@ -53,17 +53,17 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { ({ [a]: variable } = value) }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { ([...a.b] = obj); }", options: [{ props: false }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "function foo(a) { ({...a.b} = obj); }", options: [{ props: false }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "function foo(a) { for (obj[a.b] in obj); }", @@ -72,7 +72,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { for (obj[a.b] of arr); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { for (bar in a.b); }", @@ -81,7 +81,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { for (bar of a.b); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { for (bar in baz) a.b; }", @@ -90,7 +90,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { for (bar of baz) a.b; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar, baz) { bar.a = true; baz.b = false; }", @@ -154,35 +154,35 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo({bar}) { bar = 13; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo([, {bar}]) { bar = 13; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { ({bar} = {}); }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { ({x: [, bar = 0]} = {}); }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { for (bar in baz); }", @@ -193,11 +193,11 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(bar) { for (bar of baz); }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { @@ -243,11 +243,11 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { for (bar.a of []); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { (bar ? bar : [])[0] = 1; }", @@ -260,165 +260,165 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsForRegex: ["^a.*$"] }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsForRegex: ["^B.*$"] }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(bar) { ({foo: bar.a} = {}); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { ({a} = obj); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { ([...a] = obj); }", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function foo(a) { ({...a} = obj); }", - parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "function foo(a) { ([...a.b] = obj); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "function foo(a) { ({...a.b} = obj); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "function foo(a) { for ({bar: a.b} in {}); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { for ([a.b] of []); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { a &&= b; }", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "function foo(a) { a ||= b; }", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "function foo(a) { a ??= b; }", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "function foo(a) { a.b &&= c; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "function foo(a) { a.b.c ||= d; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "function foo(a) { a[b] ??= c; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2021 } } ] }); diff --git a/tests/lib/rules/no-path-concat.js b/tests/lib/rules/no-path-concat.js index ffd474e0af4..5585db1a3ae 100644 --- a/tests/lib/rules/no-path-concat.js +++ b/tests/lib/rules/no-path-concat.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-path-concat"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-plusplus.js b/tests/lib/rules/no-plusplus.js index af3b62f47fd..2fbbdb4e8f4 100644 --- a/tests/lib/rules/no-plusplus.js +++ b/tests/lib/rules/no-plusplus.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-plusplus"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-process-env.js b/tests/lib/rules/no-process-env.js index 9c6724b5164..6465da61f91 100644 --- a/tests/lib/rules/no-process-env.js +++ b/tests/lib/rules/no-process-env.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-process-env"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-process-exit.js b/tests/lib/rules/no-process-exit.js index 6637ae32aae..9d5b7471023 100644 --- a/tests/lib/rules/no-process-exit.js +++ b/tests/lib/rules/no-process-exit.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-process-exit"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-promise-executor-return.js b/tests/lib/rules/no-promise-executor-return.js index ee8a53929fb..7d75595efe8 100644 --- a/tests/lib/rules/no-promise-executor-return.js +++ b/tests/lib/rules/no-promise-executor-return.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-promise-executor-return"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 }, env: { es6: true } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2015 } }); ruleTester.run("no-promise-executor-return", rule, { valid: [ @@ -67,11 +67,9 @@ ruleTester.run("no-promise-executor-return", rule, { "/* globals Promise:off */ new Promise(function (resolve, reject) { return 1; });", { code: "new Promise((resolve, reject) => { return 1; });", - globals: { Promise: "off" } - }, - { - code: "new Promise((resolve, reject) => 1);", - env: { es6: false } + languageOptions: { + globals: { Promise: "off" } + } }, // global Promise is shadowed @@ -109,23 +107,23 @@ ruleTester.run("no-promise-executor-return", rule, { // does not report global return { code: "return 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, { code: "return 1;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { sourceType: "script", parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "return 1; function foo(){ return 1; } return 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, { code: "function foo(){} return 1; var bar = function*(){ return 1; }; return 1; var baz = () => {}; return 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, { code: "new Promise(function (resolve, reject) {}); return 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, /* @@ -875,9 +873,6 @@ ruleTester.run("no-promise-executor-return", rule, { }, { code: "() => new Promise(() => async () => 1);", - parserOptions: { ecmaVersion: 2017 }, - - // for async errors: [{ messageId: "returnsValue", type: "ArrowFunctionExpression", @@ -888,7 +883,10 @@ ruleTester.run("no-promise-executor-return", rule, { output: "() => new Promise(() => {async () => 1});" } ] - }] + }], + + // for async + languageOptions: { ecmaVersion: 2017 } }, { code: "() => new Promise(() => function () {});", diff --git a/tests/lib/rules/no-proto.js b/tests/lib/rules/no-proto.js index c9b71357156..9c28b67fc4d 100644 --- a/tests/lib/rules/no-proto.js +++ b/tests/lib/rules/no-proto.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-proto"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -22,14 +22,14 @@ ruleTester.run("no-proto", rule, { valid: [ "var a = test[__proto__];", "var __proto__ = null;", - { code: "foo[`__proto`] = null;", parserOptions: { ecmaVersion: 6 } }, - { code: "foo[`__proto__\n`] = null;", parserOptions: { ecmaVersion: 6 } }, - { code: "class C { #__proto__; foo() { this.#__proto__; } }", parserOptions: { ecmaVersion: 2022 } } + { code: "foo[`__proto`] = null;", languageOptions: { ecmaVersion: 6 } }, + { code: "foo[`__proto__\n`] = null;", languageOptions: { ecmaVersion: 6 } }, + { code: "class C { #__proto__; foo() { this.#__proto__; } }", languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { code: "var a = test.__proto__;", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, { code: "var a = test['__proto__'];", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, - { code: "var a = test[`__proto__`];", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, - { code: "test[`__proto__`] = function () {};", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] } + { code: "var a = test[`__proto__`];", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "test[`__proto__`] = function () {};", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-prototype-builtins.js b/tests/lib/rules/no-prototype-builtins.js index 80755a6d878..0be0755280b 100644 --- a/tests/lib/rules/no-prototype-builtins.js +++ b/tests/lib/rules/no-prototype-builtins.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-prototype-builtins"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -40,15 +40,15 @@ ruleTester.run("no-prototype-builtins", rule, { "({}.propertyIsEnumerable.apply(foo, ['bar']))", "foo[hasOwnProperty]('bar')", "foo['HasOwnProperty']('bar')", - { code: "foo[`isPrototypeOff`]('bar')", parserOptions: { ecmaVersion: 2015 } }, - { code: "foo?.['propertyIsEnumerabl']('bar')", parserOptions: { ecmaVersion: 2020 } }, + { code: "foo[`isPrototypeOff`]('bar')", languageOptions: { ecmaVersion: 2015 } }, + { code: "foo?.['propertyIsEnumerabl']('bar')", languageOptions: { ecmaVersion: 2020 } }, "foo[1]('bar')", "foo[null]('bar')", - { code: "class C { #hasOwnProperty; foo() { obj.#hasOwnProperty('bar'); } }", parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { #hasOwnProperty; foo() { obj.#hasOwnProperty('bar'); } }", languageOptions: { ecmaVersion: 2022 } }, // out of scope for this rule "foo['hasOwn' + 'Property']('bar')", - { code: "foo[`hasOwnProperty${''}`]('bar')", parserOptions: { ecmaVersion: 2015 } } + { code: "foo[`hasOwnProperty${''}`]('bar')", languageOptions: { ecmaVersion: 2015 } } ], invalid: [ @@ -161,7 +161,6 @@ ruleTester.run("no-prototype-builtins", rule, { }, { code: "foo[`isPrototypeOf`]('bar').baz", - parserOptions: { ecmaVersion: 2015 }, errors: [{ line: 1, column: 5, @@ -176,7 +175,8 @@ ruleTester.run("no-prototype-builtins", rule, { } ], type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: String.raw`foo.bar["propertyIsEnumerable"]('baz')`, @@ -204,28 +204,30 @@ ruleTester.run("no-prototype-builtins", rule, { }, { code: "foo.hasOwnProperty('bar')", - globals: { - Object: "off" - }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { + globals: { + Object: "off" + } + }, name: "Can't suggest Object.prototype when there is no Object global variable" }, // Optional chaining { code: "foo?.hasOwnProperty('bar')", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.bar.hasOwnProperty('baz')", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo.hasOwnProperty?.('bar')", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } }, { @@ -234,8 +236,8 @@ ruleTester.run("no-prototype-builtins", rule, { * and the optional part is before it, then don't suggest the fix */ code: "foo?.hasOwnProperty('bar').baz", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } }, { @@ -244,7 +246,6 @@ ruleTester.run("no-prototype-builtins", rule, { * but the optional part is after it, then the fix is safe */ code: "foo.hasOwnProperty('bar')?.baz", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, @@ -254,12 +255,12 @@ ruleTester.run("no-prototype-builtins", rule, { output: "Object.prototype.hasOwnProperty.call(foo, 'bar')?.baz" } ] - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(a,b).hasOwnProperty('bar')", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, @@ -271,32 +272,33 @@ ruleTester.run("no-prototype-builtins", rule, { output: "Object.prototype.hasOwnProperty.call((a,b), 'bar')" } ] - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { // No suggestion where no-unsafe-optional-chaining is reported on the call code: "(foo?.hasOwnProperty)('bar')", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.hasOwnProperty)?.('bar')", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.['hasOwnProperty']('bar')", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } }, { // No suggestion where no-unsafe-optional-chaining is reported on the call code: "(foo?.[`hasOwnProperty`])('bar')", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-redeclare.js b/tests/lib/rules/no-redeclare.js index 5754d19945f..672f121beb7 100644 --- a/tests/lib/rules/no-redeclare.js +++ b/tests/lib/rules/no-redeclare.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-redeclare"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); +const globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + sourceType: "script" + } +}); ruleTester.run("no-redeclare", rule, { valid: [ @@ -24,89 +29,88 @@ ruleTester.run("no-redeclare", rule, { "var a = 3; a = 10;", { code: "if (true) {\n let b = 2;\n} else { \nlet b = 3;\n}", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "var a; class C { static { var a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; } } var a; ", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "function a(){} class C { static { var a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "var a; class C { static { function a(){} } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; } static { var a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { function a(){} } static { function a(){} } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; { function a(){} } } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { function a(){}; { function a(){} } } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; { let a; } } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; { let a; } } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { { let a; } { let a; } } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, { code: "var Object = 0;", options: [{ builtinGlobals: false }] }, - { code: "var Object = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var Object = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaFeatures: { globalReturn: true } } }, + { code: "var Object = 0;", options: [{ builtinGlobals: true }], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var Object = 0;", options: [{ builtinGlobals: true }], languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var top = 0;", options: [{ builtinGlobals: true }] }, - { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaFeatures: { globalReturn: true } }, env: { browser: true } }, - { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, env: { browser: true } }, + { code: "var top = 0;", options: [{ builtinGlobals: true }], languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } }, globals: globals.browser } }, + { code: "var top = 0;", options: [{ builtinGlobals: true }], languageOptions: { ecmaVersion: 6, sourceType: "module", globals: globals.browser } }, { code: "var self = 1", - options: [{ builtinGlobals: true }], - env: { browser: false } + options: [{ builtinGlobals: true }] }, - { code: "var globalThis = foo", options: [{ builtinGlobals: true }], env: { es6: true } }, - { code: "var globalThis = foo", options: [{ builtinGlobals: true }], env: { es2017: true } }, + { code: "var globalThis = foo", options: [{ builtinGlobals: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var globalThis = foo", options: [{ builtinGlobals: true }], languageOptions: { ecmaVersion: 2017 } }, // Comments and built-ins. { @@ -116,26 +120,34 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */", options: [{ builtinGlobals: false }], - globals: { a: "readonly" } + languageOptions: { + globals: { a: "readonly" } + } }, { code: "/*globals a */", options: [{ builtinGlobals: false }], - globals: { a: "writable" } + languageOptions: { + globals: { a: "writable" } + } }, { code: "/*globals a:off */", options: [{ builtinGlobals: true }], - globals: { a: "readonly" } + languageOptions: { + globals: { a: "readonly" } + } }, { code: "/*globals a */", options: [{ builtinGlobals: true }], - globals: { a: "off" } + languageOptions: { + globals: { a: "off" } + } } ], invalid: [ - { code: "var a = 3; var a = 10;", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, + { code: "var a = 3; var a = 10;", errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, { code: "switch(foo) { case a: var b = 3;\ncase b: var b = 4}", errors: [{ message: "'b' is already defined.", type: "Identifier" }] }, { code: "var a = 3; var a = 10;", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "var a = {}; var a = [];", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, @@ -144,37 +156,37 @@ ruleTester.run("no-redeclare", rule, { { code: "var a = function() { }; var a = function() { }", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "var a = function() { }; var a = new Date();", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "var a = 3; var a = 10; var a = 15;", errors: [{ message: "'a' is already defined.", type: "Identifier" }, { message: "'a' is already defined.", type: "Identifier" }] }, - { code: "var a; var a;", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, - { code: "export var a; var a;", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, + { code: "var a; var a;", errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export var a; var a;", errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // `var` redeclaration in class static blocks. Redeclaration of functions is not allowed in class static blocks. { code: "class C { static { var a; var a; } }", - parserOptions: { + errors: [{ message: "'a' is already defined.", type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ message: "'a' is already defined.", type: "Identifier" }] + } }, { code: "class C { static { var a; { var a; } } }", - parserOptions: { + errors: [{ message: "'a' is already defined.", type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ message: "'a' is already defined.", type: "Identifier" }] + } }, { code: "class C { static { { var a; } var a; } }", - parserOptions: { + errors: [{ message: "'a' is already defined.", type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ message: "'a' is already defined.", type: "Identifier" }] + } }, { code: "class C { static { { var a; } { var a; } } }", - parserOptions: { + errors: [{ message: "'a' is already defined.", type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ message: "'a' is already defined.", type: "Identifier" }] + } }, { @@ -185,57 +197,56 @@ ruleTester.run("no-redeclare", rule, { { code: "var top = 0;", options: [{ builtinGlobals: true }], - env: { browser: true }, - errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }] + errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }], + languageOptions: { globals: globals.browser } }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "'a' is already defined.", type: "Identifier" }, { message: "'Object' is already defined as a built-in global variable.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "'a' is already defined.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } }, errors: [ { message: "'a' is already defined.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: false }], - parserOptions: { ecmaVersion: 6 }, errors: [ { message: "'a' is already defined.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var globalThis = 0;", options: [{ builtinGlobals: true }], - env: { es2020: true }, - errors: [{ message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" }] + errors: [{ message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var a; var {a = 0, b: globalThis = 0} = {};", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6 }, - env: { es2020: true }, errors: [ { message: "'a' is already defined.", type: "Identifier" }, { message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "/*global b:false*/ var b = 1;", @@ -294,10 +305,10 @@ ruleTester.run("no-redeclare", rule, { }, { code: "var top = 0;", - env: { browser: true }, errors: [ { message: "'top' is already defined as a built-in global variable.", type: "Identifier" } - ] + ], + languageOptions: { globals: globals.browser } }, // Comments and built-ins. @@ -448,7 +459,6 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */", options: [{ builtinGlobals: true }], - globals: { a: "readonly" }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -456,12 +466,12 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }] + }], + languageOptions: { globals: { a: "readonly" } } }, { code: "/*globals a */", options: [{ builtinGlobals: true }], - globals: { a: "writable" }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -469,7 +479,8 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }] + }], + languageOptions: { globals: { a: "writable" } } }, { code: "/*globals a */ /*globals a */", @@ -485,7 +496,6 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */ /*globals a */ var a = 0", options: [{ builtinGlobals: true }], - globals: { a: "writable" }, errors: [ { message: "'a' is already defined as a built-in global variable.", @@ -511,7 +521,8 @@ ruleTester.run("no-redeclare", rule, { endLine: 1, endColumn: 36 } - ] + ], + languageOptions: { globals: { a: "writable" } } } ] }); diff --git a/tests/lib/rules/no-regex-spaces.js b/tests/lib/rules/no-regex-spaces.js index fdc3eaa1817..f47661d31b9 100644 --- a/tests/lib/rules/no-regex-spaces.js +++ b/tests/lib/rules/no-regex-spaces.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-regex-spaces"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -63,8 +63,8 @@ ruleTester.run("no-regex-spaces", rule, { "var foo = new RegExp(' \\[ \\] ');", // ES2024 - { code: "var foo = / {2}/v;", parserOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[\\q{ }]/v;", parserOptions: { ecmaVersion: 2024 } }, + { code: "var foo = / {2}/v;", languageOptions: { ecmaVersion: 2024 } }, + { code: "var foo = /[\\q{ }]/v;", languageOptions: { ecmaVersion: 2024 } }, // don't report invalid regex "var foo = new RegExp('[ ');", @@ -148,14 +148,14 @@ ruleTester.run("no-regex-spaces", rule, { // `RegExp` is not shadowed in the scope where it's called code: "{ let RegExp = function() {}; } var foo = RegExp('bar baz');", output: "{ let RegExp = function() {}; } var foo = RegExp('bar {4}baz');", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "multipleSpaces", data: { length: "4" }, type: "CallExpression" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = /bar {3}baz/;", @@ -386,16 +386,16 @@ ruleTester.run("no-regex-spaces", rule, { { code: "var foo = /[[ ] ] /v;", output: "var foo = /[[ ] ] {4}/v;", - parserOptions: { - ecmaVersion: 2024 - }, errors: [ { messageId: "multipleSpaces", data: { length: "4" }, type: "Literal" } - ] + ], + languageOptions: { + ecmaVersion: 2024 + } }, { code: "var foo = new RegExp('[[ ] ] ', 'v');", diff --git a/tests/lib/rules/no-restricted-exports.js b/tests/lib/rules/no-restricted-exports.js index 9505e8ff6c3..161a6ba2233 100644 --- a/tests/lib/rules/no-restricted-exports.js +++ b/tests/lib/rules/no-restricted-exports.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-restricted-exports"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022, sourceType: "module" } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022, sourceType: "module" } }); ruleTester.run("no-restricted-exports", rule, { valid: [ diff --git a/tests/lib/rules/no-restricted-globals.js b/tests/lib/rules/no-restricted-globals.js index c8b5232e8ef..38f37a5e12a 100644 --- a/tests/lib/rules/no-restricted-globals.js +++ b/tests/lib/rules/no-restricted-globals.js @@ -10,7 +10,8 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-restricted-globals"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests @@ -33,12 +34,12 @@ ruleTester.run("no-restricted-globals", rule, { { code: "event", options: ["bar"], - env: { browser: true } + languageOptions: { globals: globals.browser } }, { code: "import foo from 'bar';", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "function foo() {}", @@ -79,32 +80,36 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: ["foo"], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { + globals: { foo: false } + } }, { code: "event", options: ["foo", "event"], - env: { browser: true }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }] + }], + languageOptions: { globals: globals.browser } }, { code: "foo", options: ["foo"], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { + globals: { foo: false } + } }, { code: "foo()", @@ -145,32 +150,36 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo" }], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { + globals: { foo: false } + } }, { code: "event", options: ["foo", { name: "event" }], - env: { browser: true }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }] + }], + languageOptions: { globals: globals.browser } }, { code: "foo", options: [{ name: "foo" }], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + languageOptions: { + globals: { foo: false } + } }, { code: "foo()", @@ -211,32 +220,36 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo", message: customMessage }], - globals: { foo: false }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }] + }], + languageOptions: { + globals: { foo: false } + } }, { code: "event", options: ["foo", { name: "event", message: "Use local event parameter." }], - env: { browser: true }, errors: [{ messageId: "customMessage", data: { name: "event", customMessage: "Use local event parameter." }, type: "Identifier" - }] + }], + languageOptions: { globals: globals.browser } }, { code: "foo", options: [{ name: "foo", message: customMessage }], - globals: { foo: false }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }] + }], + languageOptions: { + globals: { foo: false } + } }, { code: "foo()", @@ -259,12 +272,12 @@ ruleTester.run("no-restricted-globals", rule, { { code: "var foo = obj => hasOwnProperty(obj, 'name');", options: ["hasOwnProperty"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "defaultMessage", data: { name: "hasOwnProperty" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-restricted-imports.js b/tests/lib/rules/no-restricted-imports.js index 5403812de36..154eb78ee5d 100644 --- a/tests/lib/rules/no-restricted-imports.js +++ b/tests/lib/rules/no-restricted-imports.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-restricted-imports"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022, sourceType: "module" } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022, sourceType: "module" } }); ruleTester.run("no-restricted-imports", rule, { valid: [ diff --git a/tests/lib/rules/no-restricted-modules.js b/tests/lib/rules/no-restricted-modules.js index 5e89a6a7329..735e49f9e68 100644 --- a/tests/lib/rules/no-restricted-modules.js +++ b/tests/lib/rules/no-restricted-modules.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-restricted-modules"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -31,8 +31,8 @@ ruleTester.run("no-restricted-modules", rule, { { code: "var withPatterns = require(\"foo/bar\");", options: [{ patterns: ["foo/c*"] }] }, { code: "var withPatternsAndPaths = require(\"foo/bar\");", options: [{ paths: ["foo"], patterns: ["foo/c*"] }] }, { code: "var withGitignores = require(\"foo/bar\");", options: [{ paths: ["foo"], patterns: ["foo/*", "!foo/bar"] }] }, - { code: "require(`fs`)", options: ["crypto"], parserOptions: { ecmaVersion: 6 } }, - { code: "require(`foo${bar}`)", options: ["foo"], parserOptions: { ecmaVersion: 6 } }, + { code: "require(`fs`)", options: ["crypto"], languageOptions: { ecmaVersion: 6 } }, + { code: "require(`foo${bar}`)", options: ["foo"], languageOptions: { ecmaVersion: 6 } }, { code: "var foo = require('foo');", options: ["../foo"] }, { code: "var foo = require('foo');", options: [{ paths: ["../foo"] }] }, { code: "var foo = require('foo');", options: [{ patterns: ["../foo"] }] }, @@ -117,13 +117,13 @@ ruleTester.run("no-restricted-modules", rule, { }, { code: "require(`fs`)", options: ["fs"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "defaultMessage", data: { name: "fs" }, type: "CallExpression" }] + errors: [{ messageId: "defaultMessage", data: { name: "fs" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "require(`crypt\\o`);", options: ["crypto"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "defaultMessage", data: { name: "crypto" }, type: "CallExpression" }] + errors: [{ messageId: "defaultMessage", data: { name: "crypto" }, type: "CallExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var relative = require('../foo');", diff --git a/tests/lib/rules/no-restricted-properties.js b/tests/lib/rules/no-restricted-properties.js index 7c557bcdc06..2cca4fbcc27 100644 --- a/tests/lib/rules/no-restricted-properties.js +++ b/tests/lib/rules/no-restricted-properties.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-restricted-properties"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -100,79 +100,79 @@ ruleTester.run("no-restricted-properties", rule, { options: [{ property: "null" }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let bar = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let {baz: bar} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let {unrelated} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let {baz: {bar: qux}} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let {bar} = foo.baz;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let {baz: bar} = foo;", options: [{ property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let baz; ({baz: bar} = foo)", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let bar;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let bar; ([bar = 5] = foo);", options: [{ object: "foo", property: "1" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function qux({baz: bar} = foo) {}", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let [bar, baz] = foo;", options: [{ object: "foo", property: "1" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let [, bar] = foo;", options: [{ object: "foo", property: "0" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let [, bar = 5] = foo;", options: [{ object: "foo", property: "1" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let bar; ([bar = 5] = foo);", options: [{ object: "foo", property: "0" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function qux([bar] = foo) {}", options: [{ object: "foo", property: "0" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function qux([, bar] = foo) {}", options: [{ object: "foo", property: "0" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function qux([, bar] = foo) {}", options: [{ object: "foo", property: "1" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class C { #foo; foo() { this.#foo; } }", options: [{ property: "#foo" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -339,7 +339,6 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "foo[/(?0)/]", options: [{ property: "/(?0)/" }], - parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "restrictedProperty", data: { @@ -348,7 +347,8 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "MemberExpression" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "require.call({}, 'foo')", options: [{ @@ -381,7 +381,6 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -390,11 +389,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let {bar: baz} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -403,11 +402,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let {'bar': baz} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -416,11 +415,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let {bar: {baz: qux}} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -429,11 +428,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let {bar} = foo;", options: [{ object: "foo" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -442,11 +441,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let {bar: baz} = foo;", options: [{ object: "foo" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -455,11 +454,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let {bar} = foo;", options: [{ property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedProperty", data: { @@ -468,11 +467,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let bar; ({bar} = foo);", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -481,11 +480,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let bar; ({bar: baz = 1} = foo);", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -494,11 +493,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function qux({bar} = foo) {}", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -507,11 +506,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function qux({bar: baz} = foo) {}", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -520,11 +519,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {['foo']: qux, bar} = baz", options: [{ object: "baz", property: "foo" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -533,7 +532,8 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "obj['#foo']", options: [{ property: "#foo" }], diff --git a/tests/lib/rules/no-restricted-syntax.js b/tests/lib/rules/no-restricted-syntax.js index d5fb36aa472..fd17c72df5a 100644 --- a/tests/lib/rules/no-restricted-syntax.js +++ b/tests/lib/rules/no-restricted-syntax.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-restricted-syntax"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -25,7 +25,7 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "var foo = 42;", options: ["ConditionalExpression"] }, { code: "foo += 42;", options: ["VariableDeclaration", "FunctionExpression"] }, { code: "foo;", options: ["Identifier[name=\"bar\"]"] }, - { code: "() => 5", options: ["ArrowFunctionExpression > BlockStatement"], parserOptions: { ecmaVersion: 6 } }, + { code: "() => 5", options: ["ArrowFunctionExpression > BlockStatement"], languageOptions: { ecmaVersion: 6 } }, { code: "({ foo: 1, bar: 2 })", options: ["Property > Literal.key"] }, { code: "A: for (;;) break;", options: ["BreakStatement[label]"] }, { code: "function foo(bar, baz) {}", options: ["FunctionDeclaration[params.length>2]"] }, @@ -80,8 +80,8 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "() => {}", options: ["ArrowFunctionExpression > BlockStatement"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ArrowFunctionExpression > BlockStatement' is not allowed." }, type: "BlockStatement" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ArrowFunctionExpression > BlockStatement' is not allowed." }, type: "BlockStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "({ foo: 1, 'bar': 2 })", @@ -134,37 +134,37 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "var foo = foo?.bar?.();", options: ["ChainExpression"], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ChainExpression' is not allowed." }, type: "ChainExpression" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ChainExpression' is not allowed." }, type: "ChainExpression" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "var foo = foo?.bar?.();", options: ["[optional=true]"], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using '[optional=true]' is not allowed." }, type: "CallExpression" }, { messageId: "restrictedSyntax", data: { message: "Using '[optional=true]' is not allowed." }, type: "MemberExpression" } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, // fix https://github.com/estools/esquery/issues/110 { code: "a?.b", options: [":nth-child(1)"], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using ':nth-child(1)' is not allowed." }, type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/13639#issuecomment-683976062 { code: "const foo = [
,
]", options: ["* ~ *"], - parserOptions: { ecmaVersion: 2020, ecmaFeatures: { jsx: true } }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using '* ~ *' is not allowed." }, type: "JSXElement" } - ] + ], + languageOptions: { ecmaVersion: 2020, parserOptions: { ecmaFeatures: { jsx: true } } } } ] }); diff --git a/tests/lib/rules/no-return-assign.js b/tests/lib/rules/no-return-assign.js index 600503c2de0..f93fb39723a 100644 --- a/tests/lib/rules/no-return-assign.js +++ b/tests/lib/rules/no-return-assign.js @@ -10,19 +10,19 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-return-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("no-return-assign", rule, { valid: [ { code: "module.exports = {'a': 1};", - parserOptions: { + languageOptions: { sourceType: "module" } }, @@ -64,7 +64,7 @@ ruleTester.run("no-return-assign", rule, { }`, { code: "const foo = (a) => (b) => (a = b)", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -138,25 +138,25 @@ ruleTester.run("no-return-assign", rule, { code: `function doSomething() { return foo = () => a }`, - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "returnAssignment", type: "ReturnStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: `function doSomething() { return () => a = () => b }`, - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "arrowAssignment", type: "ArrowFunctionExpression" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: `function foo(a){ @@ -168,13 +168,13 @@ ruleTester.run("no-return-assign", rule, { }, { code: "const foo = (a) => (b) => a = b", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "arrowAssignment", type: "ArrowFunctionExpression" } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-return-await.js b/tests/lib/rules/no-return-await.js index b9184a0a532..0d5cb7d0143 100644 --- a/tests/lib/rules/no-return-await.js +++ b/tests/lib/rules/no-return-await.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-return-await"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ @@ -35,7 +35,7 @@ function createErrorList({ suggestionOutput: output } = {}) { } -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2017 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2017 } }); ruleTester.run("no-return-await", rule, { diff --git a/tests/lib/rules/no-script-url.js b/tests/lib/rules/no-script-url.js index 8dd296161a8..af7472aa26b 100644 --- a/tests/lib/rules/no-script-url.js +++ b/tests/lib/rules/no-script-url.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-script-url"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -25,15 +25,15 @@ ruleTester.run("no-script-url", rule, { "var url = 'xjavascript:'", { code: "var url = `xjavascript:`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var url = `${foo}javascript:`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = foo`javaScript:`;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -51,17 +51,17 @@ ruleTester.run("no-script-url", rule, { }, { code: "var a = `javascript:`;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedScriptURL", type: "TemplateLiteral" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = `JavaScript:`;", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedScriptURL", type: "TemplateLiteral" } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-self-assign.js b/tests/lib/rules/no-self-assign.js index 0fe04040d7a..f67dbb7e473 100644 --- a/tests/lib/rules/no-self-assign.js +++ b/tests/lib/rules/no-self-assign.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-self-assign"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -27,32 +27,32 @@ ruleTester.run("no-self-assign", rule, { "a = [a]", "a &= a", "a |= a", - { code: "let a = a", parserOptions: { ecmaVersion: 6 } }, - { code: "const a = a", parserOptions: { ecmaVersion: 6 } }, - { code: "[a] = a", parserOptions: { ecmaVersion: 6 } }, - { code: "[a = 1] = [a]", parserOptions: { ecmaVersion: 6 } }, - { code: "[a, b] = [b, a]", parserOptions: { ecmaVersion: 6 } }, - { code: "[a,, b] = [, b, a]", parserOptions: { ecmaVersion: 6 } }, - { code: "[x, a] = [...x, a]", parserOptions: { ecmaVersion: 6 } }, - { code: "[...a] = [...a, 1]", parserOptions: { ecmaVersion: 6 } }, - { code: "[a, ...b] = [0, ...b, 1]", parserOptions: { ecmaVersion: 6 } }, - { code: "[a, b] = {a, b}", parserOptions: { ecmaVersion: 6 } }, - { code: "({a} = a)", parserOptions: { ecmaVersion: 6 } }, - { code: "({a = 1} = {a})", parserOptions: { ecmaVersion: 6 } }, - { code: "({a: b} = {a})", parserOptions: { ecmaVersion: 6 } }, - { code: "({a} = {a: b})", parserOptions: { ecmaVersion: 6 } }, - { code: "({a} = {a() {}})", parserOptions: { ecmaVersion: 6 } }, - { code: "({a} = {[a]: a})", parserOptions: { ecmaVersion: 6 } }, - { code: "({[a]: b} = {[a]: b})", parserOptions: { ecmaVersion: 6 } }, - { code: "({'foo': a, 1: a} = {'bar': a, 2: a})", parserOptions: { ecmaVersion: 6 } }, - { code: "({a, ...b} = {a, ...b})", parserOptions: { ecmaVersion: 2018 } }, + { code: "let a = a", languageOptions: { ecmaVersion: 6 } }, + { code: "const a = a", languageOptions: { ecmaVersion: 6 } }, + { code: "[a] = a", languageOptions: { ecmaVersion: 6 } }, + { code: "[a = 1] = [a]", languageOptions: { ecmaVersion: 6 } }, + { code: "[a, b] = [b, a]", languageOptions: { ecmaVersion: 6 } }, + { code: "[a,, b] = [, b, a]", languageOptions: { ecmaVersion: 6 } }, + { code: "[x, a] = [...x, a]", languageOptions: { ecmaVersion: 6 } }, + { code: "[...a] = [...a, 1]", languageOptions: { ecmaVersion: 6 } }, + { code: "[a, ...b] = [0, ...b, 1]", languageOptions: { ecmaVersion: 6 } }, + { code: "[a, b] = {a, b}", languageOptions: { ecmaVersion: 6 } }, + { code: "({a} = a)", languageOptions: { ecmaVersion: 6 } }, + { code: "({a = 1} = {a})", languageOptions: { ecmaVersion: 6 } }, + { code: "({a: b} = {a})", languageOptions: { ecmaVersion: 6 } }, + { code: "({a} = {a: b})", languageOptions: { ecmaVersion: 6 } }, + { code: "({a} = {a() {}})", languageOptions: { ecmaVersion: 6 } }, + { code: "({a} = {[a]: a})", languageOptions: { ecmaVersion: 6 } }, + { code: "({[a]: b} = {[a]: b})", languageOptions: { ecmaVersion: 6 } }, + { code: "({'foo': a, 1: a} = {'bar': a, 2: a})", languageOptions: { ecmaVersion: 6 } }, + { code: "({a, ...b} = {a, ...b})", languageOptions: { ecmaVersion: 2018 } }, { code: "a.b = a.c", options: [{ props: true }] }, { code: "a.b = c.b", options: [{ props: true }] }, { code: "a.b = a[b]", options: [{ props: true }] }, { code: "a[b] = a.b", options: [{ props: true }] }, { code: "a.b().c = a.b().c", options: [{ props: true }] }, { code: "b().c = b().c", options: [{ props: true }] }, - { code: "a.null = a[/(?0)/]", options: [{ props: true }], parserOptions: { ecmaVersion: 2018 } }, + { code: "a.null = a[/(?0)/]", options: [{ props: true }], languageOptions: { ecmaVersion: 2018 } }, { code: "a[b + 1] = a[b + 1]", options: [{ props: true }] }, // it ignores non-simple computed properties. { code: "a.b = a.b", @@ -84,37 +84,37 @@ ruleTester.run("no-self-assign", rule, { }, { code: "class C { #field; foo() { this['#field'] = this.#field; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #field; foo() { this.#field = this['#field']; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { code: "a = a", errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, - { code: "[a] = [a]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, - { code: "[a, b] = [a, b]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "[a, b] = [a, c]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, - { code: "[a, b] = [, b]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "[a, ...b] = [a, ...b]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "[[a], {b}] = [[a], {b}]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({a} = {a})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, - { code: "({a: b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({'a': b} = {'a': b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({a: b} = {'a': b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({'a': b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({1: b} = {1: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({1: b} = {'1': b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({'1': b} = {1: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({['a']: b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({'a': b} = {[`a`]: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({1: b} = {[1]: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({a, b} = {a, b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, - { code: "({a, b} = {b, a})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "a" } }] }, - { code: "({a, b} = {c, a})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, - { code: "({a: {b}, c: [d]} = {a: {b}, c: [d]})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "d" } }] }, - { code: "({a, b} = {a, ...x, b})", parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "[a] = [a]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "[a, b] = [a, b]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "[a, b] = [a, c]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "[a, b] = [, b]", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "[a, ...b] = [a, ...b]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "[[a], {b}] = [[a], {b}]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a} = {a})", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a: b} = {a: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({'a': b} = {'a': b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a: b} = {'a': b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({'a': b} = {a: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({1: b} = {1: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({1: b} = {'1': b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({'1': b} = {1: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({['a']: b} = {a: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({'a': b} = {[`a`]: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({1: b} = {[1]: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a, b} = {a, b})", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a, b} = {b, a})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a, b} = {c, a})", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a: {b}, c: [d]} = {a: {b}, c: [d]})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "d" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a, b} = {a, ...x, b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 2018 } }, { code: "a.b = a.b", errors: [{ messageId: "selfAssignment", data: { name: "a.b" } }] @@ -145,47 +145,47 @@ ruleTester.run("no-self-assign", rule, { options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "this.x" } }] }, - { code: "a['/(?0)/'] = a[/(?0)/]", options: [{ props: true }], parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "selfAssignment", data: { name: "a[/(?0)/]" } }] }, + { code: "a['/(?0)/'] = a[/(?0)/]", options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "a[/(?0)/]" } }], languageOptions: { ecmaVersion: 2018 } }, // Optional chaining { code: "(a?.b).c = (a?.b).c", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "selfAssignment", data: { name: "(a?.b).c" } }] + errors: [{ messageId: "selfAssignment", data: { name: "(a?.b).c" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "a.b = a?.b", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "selfAssignment", data: { name: "a?.b" } }] + errors: [{ messageId: "selfAssignment", data: { name: "a?.b" } }], + languageOptions: { ecmaVersion: 2020 } }, // Private members { code: "class C { #field; foo() { this.#field = this.#field; } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }] + errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #field; foo() { [this.#field] = [this.#field]; } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }] + errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }], + languageOptions: { ecmaVersion: 2022 } }, // logical assignment { code: "a &&= a", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "selfAssignment", data: { name: "a" } }] + errors: [{ messageId: "selfAssignment", data: { name: "a" } }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a ||= a", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "selfAssignment", data: { name: "a" } }] + errors: [{ messageId: "selfAssignment", data: { name: "a" } }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a ??= a", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "selfAssignment", data: { name: "a" } }] + errors: [{ messageId: "selfAssignment", data: { name: "a" } }], + languageOptions: { ecmaVersion: 2021 } } ] }); diff --git a/tests/lib/rules/no-self-compare.js b/tests/lib/rules/no-self-compare.js index ad4d30a892f..ee927174ddb 100644 --- a/tests/lib/rules/no-self-compare.js +++ b/tests/lib/rules/no-self-compare.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-self-compare"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -26,11 +26,11 @@ ruleTester.run("no-self-compare", rule, { "foo.bar.baz === foo.bar.qux", { code: "class C { #field; foo() { this.#field === this['#field']; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #field; foo() { this['#field'] === this.#field; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -50,8 +50,8 @@ ruleTester.run("no-self-compare", rule, { { code: "foo.bar().baz.qux >= foo.bar ().baz .qux", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, { code: "class C { #field; foo() { this.#field === this.#field; } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] + errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-sequences.js b/tests/lib/rules/no-sequences.js index 1ac7c4a6c6e..5b8a664fb8f 100644 --- a/tests/lib/rules/no-sequences.js +++ b/tests/lib/rules/no-sequences.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-sequences"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -30,7 +30,12 @@ function errors(column) { }]; } -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-sequences", rule, { @@ -49,7 +54,7 @@ ruleTester.run("no-sequences", rule, { "switch ((doSomething(), val)) {}", "while ((doSomething(), !!test));", "with ((doSomething(), val)) {}", - { code: "a => ((doSomething(), a))", env: { es6: true } }, + { code: "a => ((doSomething(), a))", languageOptions: { ecmaVersion: 6 } }, // options object without "allowInParentheses" property { code: "var foo = (1, 2);", options: [{}] }, @@ -62,8 +67,8 @@ ruleTester.run("no-sequences", rule, { { code: "for (; test; (i++, j++));", options: [{ allowInParentheses: false }] }, // https://github.com/eslint/eslint/issues/14572 - { code: "const foo = () => { return ((bar = 123), 10) }", env: { es6: true } }, - { code: "const foo = () => (((bar = 123), 10));", env: { es6: true } } + { code: "const foo = () => { return ((bar = 123), 10) }", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = () => (((bar = 123), 10));", languageOptions: { ecmaVersion: 6 } } ], // Examples of code that should trigger the rule @@ -86,7 +91,7 @@ ruleTester.run("no-sequences", rule, { { code: "switch (doSomething(), val) {}", errors: errors(22) }, { code: "while (doSomething(), !!test);", errors: errors(21) }, { code: "with (doSomething(), val) {}", errors: errors(20) }, - { code: "a => (doSomething(), a)", env: { es6: true }, errors: errors(20) }, + { code: "a => (doSomething(), a)", errors: errors(20), languageOptions: { ecmaVersion: 6 } }, { code: "(1), 2", errors: errors(4) }, { code: "((1)) , (2)", errors: errors(7) }, { code: "while((1) , 2);", errors: errors(11) }, @@ -101,6 +106,6 @@ ruleTester.run("no-sequences", rule, { { code: "switch ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(23) }, { code: "while ((doSomething(), !!test));", options: [{ allowInParentheses: false }], errors: errors(22) }, { code: "with ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(21) }, - { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], env: { es6: true }, errors: errors(21) } + { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], errors: errors(21), languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-setter-return.js b/tests/lib/rules/no-setter-return.js index ab5b196b9f3..6c481516add 100644 --- a/tests/lib/rules/no-setter-return.js +++ b/tests/lib/rules/no-setter-return.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-setter-return"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -39,7 +39,7 @@ function error(column, type = "ReturnStatement") { // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022, sourceType: "script" } }); ruleTester.run("no-setter-return", rule, { valid: [ @@ -67,19 +67,19 @@ ruleTester.run("no-setter-return", rule, { // does not report global return { code: "return 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, { code: "return 1;", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { sourceType: "script", parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "return 1; function foo(){ return 1; } return 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, { code: "function foo(){} return 1; var bar = function*(){ return 1; }; return 1; var baz = () => {}; return 1;", - env: { node: true } + languageOptions: { sourceType: "commonjs" } }, //------------------------------------------------------------------------------ @@ -144,7 +144,7 @@ ruleTester.run("no-setter-return", rule, { "Object.defineProperty(foo, 'bar', { set(val) { return; } })", { code: "Reflect.defineProperty(foo, 'bar', { set(val) { if (val) { return; } } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Object.defineProperties(foo, { bar: { set(val) { try { return; } catch(e){} } } })", "Object.create(foo, { bar: { set: function(val) { return; } } })", @@ -155,21 +155,21 @@ ruleTester.run("no-setter-return", rule, { "Object.defineProperty(foo, 'bar', { value(val) { return 1; } })", { code: "Reflect.defineProperty(foo, 'bar', { value: function set(val) { return 1; } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Object.defineProperties(foo, { bar: { [set](val) { return 1; } } })", "Object.create(foo, { bar: { 'set ': function(val) { return 1; } } })", "Object.defineProperty(foo, 'bar', { [`set `]: (val) => { return 1; } })", { code: "Reflect.defineProperty(foo, 'bar', { Set(val) { return 1; } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Object.defineProperties(foo, { bar: { value: (val) => 1 } })", "Object.create(foo, { set: { value: function(val) { return 1; } } })", "Object.defineProperty(foo, 'bar', { baz(val) { return 1; } })", { code: "Reflect.defineProperty(foo, 'bar', { get(val) { return 1; } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Object.create(foo, { set: function(val) { return 1; } })", "Object.defineProperty(foo, { set: (val) => 1 })", @@ -178,7 +178,7 @@ ruleTester.run("no-setter-return", rule, { "Object.defineProperty(foo, 'bar', { set(val) { function foo() { return 1; } } })", { code: "Reflect.defineProperty(foo, 'bar', { set(val) { var foo = function() { return 1; } } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Object.defineProperties(foo, { bar: { set(val) { () => { return 1 }; } } })", "Object.create(foo, { bar: { set: (val) => { (val) => 1; } } })", @@ -189,15 +189,15 @@ ruleTester.run("no-setter-return", rule, { "Object.defineProperty({ set(val) { return 1; } }, foo, 'bar')", { code: "Reflect.defineProperty(foo, 'bar', 'baz', { set(val) { return 1; } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "Reflect.defineProperty(foo, { set(val) { return 1; } }, 'bar')", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "Reflect.defineProperty({ set(val) { return 1; } }, foo, 'bar')", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Object.defineProperties(foo, bar, { baz: { set(val) { return 1; } } })", "Object.defineProperties({ bar: { set(val) { return 1; } } }, foo)", @@ -208,7 +208,7 @@ ruleTester.run("no-setter-return", rule, { "Object.DefineProperty(foo, 'bar', { set(val) { return 1; } })", { code: "Reflect.DefineProperty(foo, 'bar', { set(val) { if (val) { return 1; } } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "Object.DefineProperties(foo, { bar: { set(val) { try { return 1; } catch(e){} } } })", "Object.Create(foo, { bar: { set: function(val) { return 1; } } })", @@ -217,27 +217,30 @@ ruleTester.run("no-setter-return", rule, { "object.defineProperty(foo, 'bar', { set(val) { return 1; } })", { code: "reflect.defineProperty(foo, 'bar', { set(val) { if (val) { return 1; } } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "Reflect.defineProperties(foo, { bar: { set(val) { try { return 1; } catch(e){} } } })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "object.create(foo, { bar: { set: function(val) { return 1; } } })", // global object doesn't exist - "Reflect.defineProperty(foo, 'bar', { set(val) { if (val) { return 1; } } })", + { + code: "Reflect.defineProperty(foo, 'bar', { set(val) { if (val) { return 1; } } })", + languageOptions: { globals: { Reflect: "off" } } + }, "/* globals Object:off */ Object.defineProperty(foo, 'bar', { set(val) { return 1; } })", { code: "Object.defineProperties(foo, { bar: { set(val) { try { return 1; } catch(e){} } } })", - globals: { Object: "off" } + languageOptions: { globals: { Object: "off" } } }, // global object is shadowed "let Object; Object.defineProperty(foo, 'bar', { set(val) { return 1; } })", { code: "function f() { Reflect.defineProperty(foo, 'bar', { set(val) { if (val) { return 1; } } }); var Reflect;}", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, "function f(Object) { Object.defineProperties(foo, { bar: { set(val) { try { return 1; } catch(e){} } } }) }", "if (x) { const Object = getObject(); Object.create(foo, { bar: { set: function(val) { return 1; } } }) }", @@ -401,8 +404,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "return; ({ set a(val) { return 1; } }); return 2;", - env: { node: true }, - errors: [error(25)] + errors: [error(25)], + languageOptions: { sourceType: "commonjs" } }, //------------------------------------------------------------------------------ @@ -416,8 +419,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { return 1; } })", - env: { es6: true }, - errors: [error()] + errors: [error()], + languageOptions: { ecmaVersion: 6 } }, { code: "Object.defineProperties(foo, { baz: { set(val) { return 1; } } })", @@ -435,8 +438,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set: val => f(val) })", - env: { es6: true }, - errors: [error(50, "CallExpression")] + errors: [error(50, "CallExpression")], + languageOptions: { ecmaVersion: 6 } }, { code: "Object.defineProperties(foo, { baz: { set: val => a + b } })", @@ -454,8 +457,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { try { return f(val) } catch (e) { return e }; } })", - env: { es6: true }, - errors: [error(55), error(83)] + errors: [error(55), error(83)], + languageOptions: { ecmaVersion: 6 } }, { code: "Object.defineProperties(foo, { bar: { get(){ return null; }, set(val) { return null; } } })", @@ -486,8 +489,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { 'set'(val) { return 1; } })", - env: { es6: true }, - errors: [error()] + errors: [error()], + languageOptions: { ecmaVersion: 6 } }, { code: "Object[`defineProperties`](foo, { baz: { ['set'](val) { return 1; } } })", @@ -511,13 +514,13 @@ ruleTester.run("no-setter-return", rule, { // Optional chaining { code: "Object?.defineProperty(foo, 'bar', { set(val) { return 1; } })", - parserOptions: { ecmaVersion: 2020 }, - errors: [error()] + errors: [error()], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Object?.defineProperty)(foo, 'bar', { set(val) { return 1; } })", - parserOptions: { ecmaVersion: 2020 }, - errors: [error()] + errors: [error()], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-shadow-restricted-names.js b/tests/lib/rules/no-shadow-restricted-names.js index 868cd8220b6..209f2a01663 100644 --- a/tests/lib/rules/no-shadow-restricted-names.js +++ b/tests/lib/rules/no-shadow-restricted-names.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-shadow-restricted-names"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-shadow-restricted-names", rule, { valid: [ @@ -24,17 +29,17 @@ ruleTester.run("no-shadow-restricted-names", rule, { "!function foo(bar){ var baz; }", "!function(bar){ var baz; }", "try {} catch(e) {}", - { code: "export default function() {}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default function() {}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "try {} catch {}", - parserOptions: { ecmaVersion: 2019 } + languageOptions: { ecmaVersion: 2019 } }, "var undefined;", "var undefined; doSomething(undefined);", "var undefined; var undefined;", { code: "let undefined", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } } ], invalid: [ @@ -94,7 +99,6 @@ ruleTester.run("no-shadow-restricted-names", rule, { }, { code: "var eval = (eval) => { var eval; !function eval(eval) { try {} catch(eval) {} }; }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, @@ -102,24 +106,25 @@ ruleTester.run("no-shadow-restricted-names", rule, { { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var [undefined] = [1]", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {undefined} = obj; var {a: undefined} = obj; var {a: {b: {undefined}}} = obj; var {a, ...undefined} = obj;", - parserOptions: { ecmaVersion: 9 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 9 } }, { code: "var undefined; undefined = 5;", diff --git a/tests/lib/rules/no-shadow.js b/tests/lib/rules/no-shadow.js index 0afcc3ff31b..09fa52324ae 100644 --- a/tests/lib/rules/no-shadow.js +++ b/tests/lib/rules/no-shadow.js @@ -10,88 +10,94 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-shadow"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-shadow", rule, { valid: [ "var a=3; function b(x) { a++; return x + a; }; setTimeout(function() { b(a); }, 0);", "(function() { var doSomething = function doSomething() {}; doSomething() }())", "var arguments;\nfunction bar() { }", - { code: "var a=3; var b = (x) => { a++; return x + a; }; setTimeout(() => { b(a); }, 0);", parserOptions: { ecmaVersion: 6 } }, - { code: "class A {}", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { constructor() { var a; } }", parserOptions: { ecmaVersion: 6 } }, - { code: "(function() { var A = class A {}; })()", parserOptions: { ecmaVersion: 6 } }, - { code: "{ var a; } var a;", parserOptions: { ecmaVersion: 6 } }, // this case reports `no-redeclare`, not shadowing. - { code: "{ let a; } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "{ let a; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "{ let a; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "{ const a = 0; } const a = 1;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "{ const a = 0; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "{ const a = 0; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { let a; } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { let a; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { let a; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { var a; } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { var a; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { var a; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(a) { } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(a) { } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(a) { } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "{ let a; } let a;", parserOptions: { ecmaVersion: 6 } }, - { code: "{ let a; } var a;", parserOptions: { ecmaVersion: 6 } }, - { code: "{ const a = 0; } const a = 1;", parserOptions: { ecmaVersion: 6 } }, - { code: "{ const a = 0; } var a;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { let a; } let a;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { let a; } var a;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { var a; } let a;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { var a; } var a;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(a) { } let a;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(a) { } var a;", parserOptions: { ecmaVersion: 6 } }, + { code: "var a=3; var b = (x) => { a++; return x + a; }; setTimeout(() => { b(a); }, 0);", languageOptions: { ecmaVersion: 6 } }, + { code: "class A {}", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { constructor() { var a; } }", languageOptions: { ecmaVersion: 6 } }, + { code: "(function() { var A = class A {}; })()", languageOptions: { ecmaVersion: 6 } }, + { code: "{ var a; } var a;", languageOptions: { ecmaVersion: 6 } }, // this case reports `no-redeclare`, not shadowing. + { code: "{ let a; } let a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "{ let a; } var a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "{ let a; } function a() {}", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "{ const a = 0; } const a = 1;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "{ const a = 0; } var a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "{ const a = 0; } function a() {}", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { let a; } let a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { let a; } var a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { let a; } function a() {}", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { var a; } let a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { var a; } var a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { var a; } function a() {}", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { } let a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { } var a;", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { } function a() {}", options: [{ hoist: "never" }], languageOptions: { ecmaVersion: 6 } }, + { code: "{ let a; } let a;", languageOptions: { ecmaVersion: 6 } }, + { code: "{ let a; } var a;", languageOptions: { ecmaVersion: 6 } }, + { code: "{ const a = 0; } const a = 1;", languageOptions: { ecmaVersion: 6 } }, + { code: "{ const a = 0; } var a;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { let a; } let a;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { let a; } var a;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { var a; } let a;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { var a; } var a;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { } let a;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(a) { } var a;", languageOptions: { ecmaVersion: 6 } }, "function foo() { var Object = 0; }", - { code: "function foo() { var top = 0; }", env: { browser: true } }, + { code: "function foo() { var top = 0; }", languageOptions: { globals: globals.browser } }, { code: "var Object = 0;", options: [{ builtinGlobals: true }] }, - { code: "var top = 0;", options: [{ builtinGlobals: true }], env: { browser: true } }, + { code: "var top = 0;", options: [{ builtinGlobals: true }], languageOptions: { globals: globals.browser } }, { code: "function foo(cb) { (function (cb) { cb(42); })(cb); }", options: [{ allow: ["cb"] }] }, - { code: "class C { foo; foo() { let foo; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { var x; } static { var x; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { let x; } static { let x; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { var x; { var x; /* redeclaration */ } } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { { var x; } { var x; /* redeclaration */ } } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { { let x; } { let x; } } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "const a = [].find(a => a)", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const a = [].find(function(a) { return a; })", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const [a = [].find(a => true)] = dummy", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const { a = [].find(a => true) } = dummy", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "function func(a = [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "for (const a in [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "for (const a of [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const a = [].map(a => true).filter(a => a === 'b')", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const a = [].map(a => true).filter(a => a === 'b').find(a => a === 'c')", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const { a } = (({ a }) => ({ a }))();", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const person = people.find(item => {const person = item.name; return person === 'foo'})", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = bar || foo(y => y);", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = bar && foo(y => y);", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var z = bar(foo(z => z));", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var z = boo(bar(foo(z => z)));", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var match = function (person) { return person.name === 'foo'; };\nconst person = [].find(match);", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const a = foo(x || (a => {}))", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const { a = 1 } = foo(a => {})", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const person = {...people.find((person) => person.firstName.startsWith('s'))}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 2021 } }, - { code: "const person = { firstName: people.filter((person) => person.firstName.startsWith('s')).map((person) => person.firstName)[0]}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 2021 } }, - { code: "() => { const y = foo(y => y); }", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const x = (x => x)()", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = bar || (y => y)();", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var y = bar && (y => y)();", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var x = (x => x)((y => y)());", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const { a = 1 } = (a => {})()", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "() => { const y = (y => y)(); }", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const [x = y => y] = [].map(y => y)", parserOptions: { ecmaVersion: 6 } } + { code: "class C { foo; foo() { let foo; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { var x; } static { var x; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { let x; } static { let x; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { var x; { var x; /* redeclaration */ } } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { { var x; } { var x; /* redeclaration */ } } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { { let x; } { let x; } } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "const a = [].find(a => a)", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const a = [].find(function(a) { return a; })", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const [a = [].find(a => true)] = dummy", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const { a = [].find(a => true) } = dummy", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "function func(a = [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "for (const a in [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "for (const a of [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const a = [].map(a => true).filter(a => a === 'b')", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const a = [].map(a => true).filter(a => a === 'b').find(a => a === 'c')", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const { a } = (({ a }) => ({ a }))();", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const person = people.find(item => {const person = item.name; return person === 'foo'})", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = bar || foo(y => y);", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = bar && foo(y => y);", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var z = bar(foo(z => z));", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var z = boo(bar(foo(z => z)));", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var match = function (person) { return person.name === 'foo'; };\nconst person = [].find(match);", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const a = foo(x || (a => {}))", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const { a = 1 } = foo(a => {})", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const person = {...people.find((person) => person.firstName.startsWith('s'))}", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 2021 } }, + { code: "const person = { firstName: people.filter((person) => person.firstName.startsWith('s')).map((person) => person.firstName)[0]}", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 2021 } }, + { code: "() => { const y = foo(y => y); }", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const x = (x => x)()", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = bar || (y => y)();", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var y = bar && (y => y)();", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = (x => x)((y => y)());", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const { a = 1 } = (a => {})()", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "() => { const y = (y => y)(); }", options: [{ ignoreOnInitialization: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const [x = y => y] = [].map(y => y)", languageOptions: { ecmaVersion: 6 } } ], invalid: [ { @@ -110,7 +116,6 @@ ruleTester.run("no-shadow", rule, { }, { code: "var a = (x) => { var b = () => { var x = 'foo'; }; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -121,7 +126,8 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 38 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function a(x) { var b = function () { var x = 'foo'; }; }", @@ -199,7 +205,6 @@ ruleTester.run("no-shadow", rule, { }, { code: "var x = 1; { let x = 2; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -208,11 +213,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 5 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let x = 1; { const x = 2; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -221,11 +226,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 5 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ let a; } function a() {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -234,11 +239,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 21 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ const a = 0; } function a() {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -247,11 +252,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 27 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; } function a() {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -260,11 +265,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var a; } function a() {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -273,11 +278,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { } function a() {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -286,12 +291,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 30 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ let a; } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -300,12 +305,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 16 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ let a; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -314,12 +319,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 16 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ let a; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -328,12 +333,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 21 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ const a = 0; } const a = 1;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -342,12 +347,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 24 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ const a = 0; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -356,12 +361,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 22 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ const a = 0; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -370,12 +375,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 27 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -384,12 +389,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -398,12 +403,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { let a; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -412,12 +417,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var a; } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -426,12 +431,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var a; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -440,12 +445,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { var a; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -454,12 +459,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -468,12 +473,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 25 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -482,12 +487,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 25 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a) { } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -496,7 +501,8 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 30 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function a() { function a(){} })()", @@ -512,7 +518,6 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function a() { class a{} })()", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -521,7 +526,8 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 11 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function a() { (function a(){}); })()", @@ -537,7 +543,6 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function a() { (class a{}); })()", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -546,7 +551,8 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 11 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { var a = function(a) {}; })()", @@ -574,7 +580,6 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function() { var a = function() { class a{} }; })()", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -583,7 +588,8 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 19 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { var a = function() { (function a() {}); }; })()", @@ -599,7 +605,6 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function() { var a = function() { (class a{}); }; })()", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -608,11 +613,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 19 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { var a = class { constructor() { class a {} } }; })()", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -621,11 +626,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 19 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { constructor() { var A; } }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -634,7 +639,8 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 7 }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function a() { function a(){ function a(){} } })()", @@ -677,64 +683,69 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var top = 0; }", options: [{ builtinGlobals: true }], - env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }] + }], + languageOptions: { globals: globals.browser } }, { code: "var Object = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "noShadowGlobal", data: { name: "Object" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var top = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }] + }], + languageOptions: { + ecmaVersion: 6, + sourceType: "module", + globals: globals.browser + } }, { code: "var Object = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [{ messageId: "noShadowGlobal", data: { name: "Object" }, type: "Identifier" - }] + }], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var top = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaFeatures: { globalReturn: true } }, - env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }] + }], + languageOptions: { + parserOptions: { ecmaFeatures: { globalReturn: true } }, + globals: globals.browser + } }, { code: "function foo(cb) { (function (cb) { cb(42); })(cb); }", @@ -752,7 +763,6 @@ ruleTester.run("no-shadow", rule, { }, { code: "class C { static { let a; { let a; } } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -763,11 +773,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 33 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var C; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -778,11 +788,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let C; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -793,11 +803,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "var a; class C { static { var a; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -808,12 +818,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 31 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; } } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -824,12 +834,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; } } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -840,12 +850,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; } } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -856,11 +866,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; class D { static { var a; } } } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -871,11 +881,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 50 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; class D { static { let a; } } } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -886,12 +896,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 50 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "let x = foo((x,y) => {});\nlet y;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noShadow", @@ -911,12 +921,12 @@ ruleTester.run("no-shadow", rule, { }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = fn(()=>{ class C { fn () { const a = 42; return a } } return new C() })", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -927,12 +937,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 44 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function a() {}\nfoo(a => {});", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -943,12 +953,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 2, column: 5 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = fn(()=>{ function C() { this.fn=function() { const a = 42; return a } } return new C() });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -959,12 +969,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 62 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const x = foo(() => { const bar = () => { return x => {}; }; return bar; });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -975,12 +985,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 50 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const x = foo(() => { return { bar(x) {} }; });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -991,12 +1001,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 36 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const x = () => { foo(x => x); }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1007,12 +1017,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 23 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const foo = () => { let x; bar(x => x); }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1023,12 +1033,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 32 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo(() => { const x = x => x; });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1039,12 +1049,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 23 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const foo = (x) => { bar(x => {}) }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1055,12 +1065,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 26 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let x = ((x,y) => {})();\nlet y;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noShadow", @@ -1080,12 +1090,12 @@ ruleTester.run("no-shadow", rule, { }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = (()=>{ class C { fn () { const a = 42; return a } } return new C() })()", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1096,12 +1106,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 42 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const x = () => { (x => x)(); }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1112,7 +1122,8 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 20 - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-spaced-func.js b/tests/lib/rules/no-spaced-func.js index 6afcbe6dcf4..00a63151d09 100644 --- a/tests/lib/rules/no-spaced-func.js +++ b/tests/lib/rules/no-spaced-func.js @@ -11,7 +11,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-spaced-func"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-sparse-arrays.js b/tests/lib/rules/no-sparse-arrays.js index 11536a3fa3c..b408551f913 100644 --- a/tests/lib/rules/no-sparse-arrays.js +++ b/tests/lib/rules/no-sparse-arrays.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-sparse-arrays"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-sync.js b/tests/lib/rules/no-sync.js index b69605da6b3..f04373e6660 100644 --- a/tests/lib/rules/no-sync.js +++ b/tests/lib/rules/no-sync.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-sync"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-tabs.js b/tests/lib/rules/no-tabs.js index 95319d89889..13681beedd4 100644 --- a/tests/lib/rules/no-tabs.js +++ b/tests/lib/rules/no-tabs.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-tabs"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-template-curly-in-string.js b/tests/lib/rules/no-template-curly-in-string.js index 04dfd49e885..93240aa3100 100644 --- a/tests/lib/rules/no-template-curly-in-string.js +++ b/tests/lib/rules/no-template-curly-in-string.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-template-curly-in-string"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ @@ -19,60 +19,52 @@ const rule = require("../../../lib/rules/no-template-curly-in-string"), const ruleTester = new RuleTester(); const messageId = "unexpectedTemplateExpression"; -const parserOptions = { ecmaVersion: 6 }; ruleTester.run("no-template-curly-in-string", rule, { valid: [ - { code: "`Hello, ${name}`;", parserOptions }, - { code: "templateFunction`Hello, ${name}`;", parserOptions }, - { code: "`Hello, name`;", parserOptions }, - { code: "'Hello, name';", parserOptions }, - { code: "'Hello, ' + name;", parserOptions }, - { code: "`Hello, ${index + 1}`", parserOptions }, - { code: "`Hello, ${name + \" foo\"}`", parserOptions }, - { code: "`Hello, ${name || \"foo\"}`", parserOptions }, - { code: "`Hello, ${{foo: \"bar\"}.foo}`", parserOptions }, - { code: "'$2'", parserOptions }, - { code: "'${'", parserOptions }, - { code: "'$}'", parserOptions }, - { code: "'{foo}'", parserOptions }, - { code: "'{foo: \"bar\"}'", parserOptions }, - { code: "const number = 3", parserOptions } + "`Hello, ${name}`;", + "templateFunction`Hello, ${name}`;", + "`Hello, name`;", + "'Hello, name';", + "'Hello, ' + name;", + "`Hello, ${index + 1}`", + "`Hello, ${name + \" foo\"}`", + "`Hello, ${name || \"foo\"}`", + "`Hello, ${{foo: \"bar\"}.foo}`", + "'$2'", + "'${'", + "'$}'", + "'{foo}'", + "'{foo: \"bar\"}'", + "const number = 3" ], invalid: [ { code: "'Hello, ${name}'", - parserOptions, errors: [{ messageId }] }, { code: "\"Hello, ${name}\"", - parserOptions, errors: [{ messageId }] }, { code: "'${greeting}, ${name}'", - parserOptions, errors: [{ messageId }] }, { code: "'Hello, ${index + 1}'", - parserOptions, errors: [{ messageId }] }, { code: "'Hello, ${name + \" foo\"}'", - parserOptions, errors: [{ messageId }] }, { code: "'Hello, ${name || \"foo\"}'", - parserOptions, errors: [{ messageId }] }, { code: "'Hello, ${{foo: \"bar\"}.foo}'", - parserOptions, errors: [{ messageId }] } ] diff --git a/tests/lib/rules/no-ternary.js b/tests/lib/rules/no-ternary.js index 35d025034e7..d2852932874 100644 --- a/tests/lib/rules/no-ternary.js +++ b/tests/lib/rules/no-ternary.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-ternary"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-this-before-super.js b/tests/lib/rules/no-this-before-super.js index 7b9a8a48a96..021f84b8c02 100644 --- a/tests/lib/rules/no-this-before-super.js +++ b/tests/lib/rules/no-this-before-super.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-this-before-super"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("no-this-before-super", rule, { valid: [ @@ -174,18 +174,18 @@ ruleTester.run("no-this-before-super", rule, { }, { code: "class A extends B { constructor() { foo &&= super().a; this.c(); } }", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "class A extends B { constructor() { foo ||= super().a; this.c(); } }", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }], + languageOptions: { ecmaVersion: 2021 } }, { code: "class A extends B { constructor() { foo ??= super().a; this.c(); } }", - parserOptions: { ecmaVersion: 2021 }, - errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }], + languageOptions: { ecmaVersion: 2021 } } ] }); diff --git a/tests/lib/rules/no-throw-literal.js b/tests/lib/rules/no-throw-literal.js index d50b2cea2b6..4d4d80b531e 100644 --- a/tests/lib/rules/no-throw-literal.js +++ b/tests/lib/rules/no-throw-literal.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-throw-literal"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -30,20 +30,20 @@ ruleTester.run("no-throw-literal", rule, { "throw new foo();", // NewExpression "throw foo.bar;", // MemberExpression "throw foo[bar];", // MemberExpression - { code: "class C { #field; foo() { throw foo.#field; } }", parserOptions: { ecmaVersion: 2022 } }, // MemberExpression + { code: "class C { #field; foo() { throw foo.#field; } }", languageOptions: { ecmaVersion: 2022 } }, // MemberExpression "throw foo = new Error();", // AssignmentExpression with the `=` operator - { code: "throw foo.bar ||= 'literal'", parserOptions: { ecmaVersion: 2021 } }, // AssignmentExpression with a logical operator - { code: "throw foo[bar] ??= 'literal'", parserOptions: { ecmaVersion: 2021 } }, // AssignmentExpression with a logical operator + { code: "throw foo.bar ||= 'literal'", languageOptions: { ecmaVersion: 2021 } }, // AssignmentExpression with a logical operator + { code: "throw foo[bar] ??= 'literal'", languageOptions: { ecmaVersion: 2021 } }, // AssignmentExpression with a logical operator "throw 1, 2, new Error();", // SequenceExpression "throw 'literal' && new Error();", // LogicalExpression (right) "throw new Error() || 'literal';", // LogicalExpression (left) "throw foo ? new Error() : 'literal';", // ConditionalExpression (consequent) "throw foo ? 'literal' : new Error();", // ConditionalExpression (alternate) - { code: "throw tag `${foo}`;", parserOptions: { ecmaVersion: 6 } }, // TaggedTemplateExpression - { code: "function* foo() { var index = 0; throw yield index++; }", parserOptions: { ecmaVersion: 6 } }, // YieldExpression - { code: "async function foo() { throw await bar; }", parserOptions: { ecmaVersion: 8 } }, // AwaitExpression - { code: "throw obj?.foo", parserOptions: { ecmaVersion: 2020 } }, // ChainExpression - { code: "throw obj?.foo()", parserOptions: { ecmaVersion: 2020 } } // ChainExpression + { code: "throw tag `${foo}`;", languageOptions: { ecmaVersion: 6 } }, // TaggedTemplateExpression + { code: "function* foo() { var index = 0; throw yield index++; }", languageOptions: { ecmaVersion: 6 } }, // YieldExpression + { code: "async function foo() { throw await bar; }", languageOptions: { ecmaVersion: 8 } }, // AwaitExpression + { code: "throw obj?.foo", languageOptions: { ecmaVersion: 2020 } }, // ChainExpression + { code: "throw obj?.foo()", languageOptions: { ecmaVersion: 2020 } } // ChainExpression ], invalid: [ { @@ -129,11 +129,11 @@ ruleTester.run("no-throw-literal", rule, { }, { code: "throw foo &&= 'literal'", // evaluates either to a falsy value of `foo` (which, then, cannot be an Error object), or to 'literal' - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "object", type: "ThrowStatement" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, // SequenceExpression @@ -173,12 +173,12 @@ ruleTester.run("no-throw-literal", rule, { // TemplateLiteral { code: "throw `${err}`;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "object", type: "ThrowStatement" - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-trailing-spaces.js b/tests/lib/rules/no-trailing-spaces.js index 1275e0708ca..7c36e56a608 100644 --- a/tests/lib/rules/no-trailing-spaces.js +++ b/tests/lib/rules/no-trailing-spaces.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-trailing-spaces"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -60,12 +60,12 @@ ruleTester.run("no-trailing-spaces", rule, { }, { code: "let str = `${a}\n \n${b}`;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let str = `${a}\n \n${b}`;\n \n ", options: [{ skipBlankLines: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "// Trailing comment test. ", @@ -173,11 +173,11 @@ ruleTester.run("no-trailing-spaces", rule, { " short,\n" + " short2\n" + "}\n", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "trailingSpace", type: "Program" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -366,7 +366,6 @@ ruleTester.run("no-trailing-spaces", rule, { { code: "let str = `${a}\n \n${b}`; \n", output: "let str = `${a}\n \n${b}`;\n", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "trailingSpace", type: "Program", @@ -374,12 +373,12 @@ ruleTester.run("no-trailing-spaces", rule, { column: 7, endLine: 3, endColumn: 9 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let str = `\n${a}\n \n${b}`; \n\t", output: "let str = `\n${a}\n \n${b}`;\n", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -397,12 +396,12 @@ ruleTester.run("no-trailing-spaces", rule, { endLine: 5, endColumn: 2 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let str = ` \n ${a}\n \n${b}`; \n", output: "let str = ` \n ${a}\n \n${b}`;\n", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -412,7 +411,8 @@ ruleTester.run("no-trailing-spaces", rule, { endLine: 4, endColumn: 9 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "let str = `${a}\n \n${b}`; \n \n", @@ -420,7 +420,6 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ skipBlankLines: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -430,7 +429,8 @@ ruleTester.run("no-trailing-spaces", rule, { endLine: 3, endColumn: 9 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/6933 diff --git a/tests/lib/rules/no-undef-init.js b/tests/lib/rules/no-undef-init.js index 7f134ba0b3a..38ef2ca8255 100644 --- a/tests/lib/rules/no-undef-init.js +++ b/tests/lib/rules/no-undef-init.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-undef-init"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,11 +21,11 @@ const ruleTester = new RuleTester(); ruleTester.run("no-undef-init", rule, { valid: [ "var a;", - { code: "const foo = undefined", parserOptions: { ecmaVersion: 6 } }, + { code: "const foo = undefined", languageOptions: { ecmaVersion: 6 } }, "var undefined = 5; var foo = undefined;", // doesn't apply to class fields - { code: "class C { field = undefined; }", parserOptions: { ecmaVersion: 2022 } } + { code: "class C { field = undefined; }", languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -47,14 +47,14 @@ ruleTester.run("no-undef-init", rule, { { code: "var [a] = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a} = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for(var i in [1,2,3]){var a = undefined; for(var j in [1,2,3]){}}", @@ -64,94 +64,94 @@ ruleTester.run("no-undef-init", rule, { { code: "let a = undefined;", output: "let a;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = undefined, b = 1;", output: "let a, b = 1;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 1, b = undefined, c = 5;", output: "let a = 1, b, c = 5;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "b" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "b" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let [a] = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let {a} = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "for(var i in [1,2,3]){let a = undefined; for(var j in [1,2,3]){}}", output: "for(var i in [1,2,3]){let a; for(var j in [1,2,3]){}}", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, // Should not autofix if it would remove comments { code: "let /* comment */a = undefined;", output: "let /* comment */a;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a/**/ = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a /**/ = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a//\n= undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = /**/undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = //\nundefined;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = undefined/* comment */;", output: "let a/* comment */;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = undefined/* comment */, b;", output: "let a/* comment */, b;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = undefined//comment\n, b;", output: "let a//comment\n, b;", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-undef.js b/tests/lib/rules/no-undef.js index 956bbc991ab..9574e05ed9c 100644 --- a/tests/lib/rules/no-undef.js +++ b/tests/lib/rules/no-undef.js @@ -10,27 +10,39 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-undef"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), + globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-undef", rule, { valid: [ "var a = 1, b = 2; a;", "/*global b*/ function f() { b; }", - { code: "function f() { b; }", globals: { b: false } }, + { code: "function f() { b; }", languageOptions: { globals: { b: false } } }, "/*global b a:false*/ a; function f() { b; a; }", "function a(){} a();", "function f(b) { b; }", "var a; a = 1; a++;", "var a; function f() { a = 1; }", "/*global b:true*/ b++;", - "/*eslint-env browser*/ window;", - "/*eslint-env node*/ require(\"a\");", + { + code: "window;", + languageOptions: { globals: globals.browser } + }, + { + code: "require(\"a\");", + languageOptions: { sourceType: "commonjs" } + }, "Object; isNaN();", "toString()", "hasOwnProperty()", @@ -40,118 +52,118 @@ ruleTester.run("no-undef", rule, { "var b = typeof a", "typeof a === 'undefined'", "if (typeof a === 'undefined') {}", - { code: "function foo() { var [a, b=4] = [1, 2]; return {a, b}; }", parserOptions: { ecmaVersion: 6 } }, - { code: "var toString = 1;", parserOptions: { ecmaVersion: 6 } }, - { code: "function myFunc(...foo) { return foo;}", parserOptions: { ecmaVersion: 6 } }, - { code: "var React, App, a=1; React.render();", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var console; [1,2,3].forEach(obj => {\n console.log(obj);\n});", parserOptions: { ecmaVersion: 6 } }, - { code: "var Foo; class Bar extends Foo { constructor() { super(); }}", parserOptions: { ecmaVersion: 6 } }, - { code: "import Warning from '../lib/warning'; var warn = new Warning('text');", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import * as Warning from '../lib/warning'; var warn = new Warning('text');", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var a; [a] = [0];", parserOptions: { ecmaVersion: 6 } }, - { code: "var a; ({a} = {});", parserOptions: { ecmaVersion: 6 } }, - { code: "var a; ({b: a} = {});", parserOptions: { ecmaVersion: 6 } }, - { code: "var obj; [obj.a, obj.b] = [0, 1];", parserOptions: { ecmaVersion: 6 } }, - { code: "URLSearchParams;", env: { browser: true } }, - { code: "Intl;", env: { browser: true } }, - { code: "IntersectionObserver;", env: { browser: true } }, - { code: "Credential;", env: { browser: true } }, - { code: "requestIdleCallback;", env: { browser: true } }, - { code: "customElements;", env: { browser: true } }, - { code: "PromiseRejectionEvent;", env: { browser: true } }, - { code: "(foo, bar) => { foo ||= WeakRef; bar ??= FinalizationRegistry; }", env: { es2021: true } }, + { code: "function foo() { var [a, b=4] = [1, 2]; return {a, b}; }", languageOptions: { ecmaVersion: 6 } }, + { code: "var toString = 1;", languageOptions: { ecmaVersion: 6 } }, + { code: "function myFunc(...foo) { return foo;}", languageOptions: { ecmaVersion: 6 } }, + { code: "var React, App, a=1; React.render();", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var console; [1,2,3].forEach(obj => {\n console.log(obj);\n});", languageOptions: { ecmaVersion: 6 } }, + { code: "var Foo; class Bar extends Foo { constructor() { super(); }}", languageOptions: { ecmaVersion: 6 } }, + { code: "import Warning from '../lib/warning'; var warn = new Warning('text');", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import * as Warning from '../lib/warning'; var warn = new Warning('text');", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a; [a] = [0];", languageOptions: { ecmaVersion: 6 } }, + { code: "var a; ({a} = {});", languageOptions: { ecmaVersion: 6 } }, + { code: "var a; ({b: a} = {});", languageOptions: { ecmaVersion: 6 } }, + { code: "var obj; [obj.a, obj.b] = [0, 1];", languageOptions: { ecmaVersion: 6 } }, + { code: "URLSearchParams;", languageOptions: { globals: globals.browser } }, + { code: "Intl;", languageOptions: { globals: globals.browser } }, + { code: "IntersectionObserver;", languageOptions: { globals: globals.browser } }, + { code: "Credential;", languageOptions: { globals: globals.browser } }, + { code: "requestIdleCallback;", languageOptions: { globals: globals.browser } }, + { code: "customElements;", languageOptions: { globals: globals.browser } }, + { code: "PromiseRejectionEvent;", languageOptions: { globals: globals.browser } }, + { code: "(foo, bar) => { foo ||= WeakRef; bar ??= FinalizationRegistry; }", languageOptions: { ecmaVersion: 2021 } }, // Notifications of readonly are removed: https://github.com/eslint/eslint/issues/4504 "/*global b:false*/ function f() { b = 1; }", - { code: "function f() { b = 1; }", globals: { b: false } }, + { code: "function f() { b = 1; }", languageOptions: { globals: { b: false } } }, "/*global b:false*/ function f() { b++; }", "/*global b*/ b = 1;", "/*global b:false*/ var b = 1;", "Array = 1;", // new.target: https://github.com/eslint/eslint/issues/5420 - { code: "class A { constructor() { new.target; } }", parserOptions: { ecmaVersion: 6 } }, + { code: "class A { constructor() { new.target; } }", languageOptions: { ecmaVersion: 6 } }, // Rest property { code: "var {bacon, ...others} = stuff; foo(others)", - parserOptions: { - ecmaVersion: 2018 - }, - globals: { stuff: false, foo: false } + languageOptions: { + ecmaVersion: 2018, + globals: { stuff: false, foo: false } + } }, // export * as ns from "source" { code: 'export * as ns from "source"', - parserOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, // import.meta { code: "import.meta", - parserOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, // class static blocks { code: "let a; class C { static {} } a;", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "undef", data: { name: "a" } }] + errors: [{ messageId: "undef", data: { name: "a" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "var a; class C { static {} } a;", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "undef", data: { name: "a" } }] + errors: [{ messageId: "undef", data: { name: "a" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "a; class C { static {} } var a;", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "undef", data: { name: "a" } }] + errors: [{ messageId: "undef", data: { name: "a" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { C; } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "const C = class { static { C; } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { a; } } var a;", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { a; } } let a;", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { var a; a; } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { a; var a; } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { a; { var a; } } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { let a; a; } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { a; let a; } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { function a() {} a; } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { a; function a() {} } }", - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } } ], invalid: [ @@ -161,113 +173,113 @@ ruleTester.run("no-undef", rule, { { code: "function f() { b; }", errors: [{ messageId: "undef", data: { name: "b" }, type: "Identifier" }] }, { code: "window;", errors: [{ messageId: "undef", data: { name: "window" }, type: "Identifier" }] }, { code: "require(\"a\");", errors: [{ messageId: "undef", data: { name: "require" }, type: "Identifier" }] }, - { code: "var React; React.render();", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, errors: [{ messageId: "undef", data: { name: "a" } }] }, - { code: "var React, App; React.render();", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, errors: [{ messageId: "undef", data: { name: "a" } }] }, - { code: "[a] = [0];", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, - { code: "({a} = {});", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, - { code: "({b: a} = {});", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, - { code: "[obj.a, obj.b] = [0, 1];", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "obj" } }, { messageId: "undef", data: { name: "obj" } }] }, + { code: "var React; React.render();", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var React, App; React.render();", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "[a] = [0];", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({a} = {});", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "({b: a} = {});", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "[obj.a, obj.b] = [0, 1];", errors: [{ messageId: "undef", data: { name: "obj" } }, { messageId: "undef", data: { name: "obj" } }], languageOptions: { ecmaVersion: 6 } }, // Experimental { code: "const c = 0; const a = {...b, c};", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "b" } }], + languageOptions: { ecmaVersion: 2018 - }, - errors: [{ messageId: "undef", data: { name: "b" } }] + } }, // class static blocks { code: "class C { static { a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" } }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" } }] + } }, { code: "class C { static { { let a; } a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }] + } }, { code: "class C { static { { function a() {} } a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 40 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 40 }] + } }, { code: "class C { static { function foo() { var a; } a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 47 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 47 }] + } }, { code: "class C { static { var a; } static { a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }] + } }, { code: "class C { static { let a; } static { a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }] + } }, { code: "class C { static { function a(){} } static { a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 46 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 46 }] + } }, { code: "class C { static { var a; } foo() { a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }] + } }, { code: "class C { static { let a; } foo() { a; } }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }] + } }, { code: "class C { static { var a; } [a]; }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }] + } }, { code: "class C { static { let a; } [a]; }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }] + } }, { code: "class C { static { function a() {} } [a]; }", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 39 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 39 }] + } }, { code: "class C { static { var a; } } a;", - parserOptions: { + errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }] + } } ] }); diff --git a/tests/lib/rules/no-undefined.js b/tests/lib/rules/no-undefined.js index 8afccc52bc4..a6801b29b4c 100644 --- a/tests/lib/rules/no-undefined.js +++ b/tests/lib/rules/no-undefined.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-undefined"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Helpers @@ -25,7 +25,7 @@ const ES6_MODULE = { ecmaVersion: 6, sourceType: "module" }; const errors = [{ messageId: "unexpectedUndefined", type: "Identifier" }]; -const ruleTester = new RuleTester({ parserOptions: ES6_SCRIPT }); +const ruleTester = new RuleTester({ languageOptions: ES6_SCRIPT }); ruleTester.run("no-undefined", rule, { valid: [ @@ -46,10 +46,10 @@ ruleTester.run("no-undefined", rule, { "({ undefined() {} })", "class Foo { undefined() {} }", "(class { undefined() {} })", - { code: "import { undefined as a } from 'foo'", parserOptions: ES6_MODULE }, - { code: "export { undefined } from 'foo'", parserOptions: ES6_MODULE }, - { code: "export { undefined as a } from 'foo'", parserOptions: ES6_MODULE }, - { code: "export { a as undefined } from 'foo'", parserOptions: ES6_MODULE } + { code: "import { undefined as a } from 'foo'", languageOptions: ES6_MODULE }, + { code: "export { undefined } from 'foo'", languageOptions: ES6_MODULE }, + { code: "export { undefined as a } from 'foo'", languageOptions: ES6_MODULE }, + { code: "export { a as undefined } from 'foo'", languageOptions: ES6_MODULE } ], invalid: [ { code: "undefined", errors }, @@ -93,30 +93,30 @@ ruleTester.run("no-undefined", rule, { }, { code: "import undefined from 'foo'", - parserOptions: ES6_MODULE, - errors + errors, + languageOptions: ES6_MODULE }, { code: "import * as undefined from 'foo'", - parserOptions: ES6_MODULE, - errors + errors, + languageOptions: ES6_MODULE }, { code: "import { undefined } from 'foo'", - parserOptions: ES6_MODULE, - errors + errors, + languageOptions: ES6_MODULE }, { code: "import { a as undefined } from 'foo'", - parserOptions: ES6_MODULE, - errors + errors, + languageOptions: ES6_MODULE }, /* * it will be warned "Parsing error: Export 'undefined' is not defined" (acorn@>=6.0.7) * { * code: "export { undefined }", - * parserOptions: ES6_MODULE, + * languageOptions: ES6_MODULE, * errors * }, */ diff --git a/tests/lib/rules/no-underscore-dangle.js b/tests/lib/rules/no-underscore-dangle.js index cec2c2ac722..37dd3f2b8f0 100644 --- a/tests/lib/rules/no-underscore-dangle.js +++ b/tests/lib/rules/no-underscore-dangle.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-underscore-dangle"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -30,62 +30,62 @@ ruleTester.run("no-underscore-dangle", rule, { "function foo(bar_) {}", "(function _foo() {})", { code: "function foo(_bar) {}", options: [{}] }, - { code: "function foo( _bar = 0) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = { onClick(_bar) { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = { onClick(_bar = 0) { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = (_bar) => {}", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = (_bar = 0) => {}", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo( ..._bar) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = (..._bar) => {}", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = { onClick(..._bar) { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "export default function() {}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo( _bar = 0) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(_bar) { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(_bar = 0) { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (_bar) => {}", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (_bar = 0) => {}", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo( ..._bar) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (..._bar) => {}", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(..._bar) { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "export default function() {}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var _foo = 1", options: [{ allow: ["_foo"] }] }, { code: "var __proto__ = 1;", options: [{ allow: ["__proto__"] }] }, { code: "foo._bar;", options: [{ allow: ["_bar"] }] }, { code: "function _foo() {}", options: [{ allow: ["_foo"] }] }, { code: "this._bar;", options: [{ allowAfterThis: true }] }, - { code: "class foo { constructor() { super._bar; } }", options: [{ allowAfterSuper: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "class foo { _onClick() { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "class foo { onClick_() { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "const o = { _onClick() { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "const o = { onClick_() { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "const o = { _onClick() { } }", options: [{ allow: ["_onClick"], enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const o = { _foo: 'bar' }", parserOptions: { ecmaVersion: 6 } }, - { code: "const o = { foo_: 'bar' }", parserOptions: { ecmaVersion: 6 } }, + { code: "class foo { constructor() { super._bar; } }", options: [{ allowAfterSuper: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "class foo { _onClick() { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "class foo { onClick_() { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "const o = { _onClick() { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "const o = { onClick_() { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "const o = { _onClick() { } }", options: [{ allow: ["_onClick"], enforceInMethodNames: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const o = { _foo: 'bar' }", languageOptions: { ecmaVersion: 6 } }, + { code: "const o = { foo_: 'bar' }", languageOptions: { ecmaVersion: 6 } }, { code: "this.constructor._bar", options: [{ allowAfterThisConstructor: true }] }, - { code: "const foo = { onClick(bar) { } }", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = (bar) => {}", parserOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(bar) { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (bar) => {}", languageOptions: { ecmaVersion: 6 } }, { code: "function foo(_bar) {}", options: [{ allowFunctionParams: true }] }, - { code: "function foo( _bar = 0) {}", options: [{ allowFunctionParams: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(bar) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = { onClick(bar) { } }", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = (bar) => {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } }, + { code: "function foo( _bar = 0) {}", options: [{ allowFunctionParams: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(bar) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(bar) { } }", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (bar) => {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 } }, { code: "function foo(_bar) {}", options: [{ allowFunctionParams: false, allow: ["_bar"] }] }, - { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo([_bar]) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo([_bar] = []) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo( { _bar }) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo( { _bar = 0 } = {}) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(...[_bar]) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 2016 } }, - { code: "const [_foo] = arr", parserOptions: { ecmaVersion: 6 } }, - { code: "const [_foo] = arr", options: [{}], parserOptions: { ecmaVersion: 6 } }, - { code: "const [_foo] = arr", options: [{ allowInArrayDestructuring: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const [foo, ...rest] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false }], parserOptions: { ecmaVersion: 2022 } }, - { code: "const [foo, _bar] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 2022 } }, - { code: "const { _foo } = obj", parserOptions: { ecmaVersion: 6 } }, - { code: "const { _foo } = obj", options: [{}], parserOptions: { ecmaVersion: 6 } }, - { code: "const { _foo } = obj", options: [{ allowInObjectDestructuring: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const { foo, bar: _bar } = { foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 2022 } }, - { code: "const { foo, _bar } = { foo: 1, _bar: 2 }", options: [{ allowInObjectDestructuring: false, allow: ["_bar"] }], parserOptions: { ecmaVersion: 2022 } }, - { code: "const { foo, _bar: bar } = { foo: 1, _bar: 2 }", options: [{ allowInObjectDestructuring: false }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class foo { _field; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class foo { _field; }", options: [{ enforceInClassFields: false }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class foo { #_field; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class foo { #_field; }", options: [{ enforceInClassFields: false }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class foo { _field; }", options: [{}], parserOptions: { ecmaVersion: 2022 } } + { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: false, allow: ["_bar"] }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: false, allow: ["_bar"] }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo([_bar]) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo([_bar] = []) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo( { _bar }) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo( { _bar = 0 } = {}) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(...[_bar]) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 2016 } }, + { code: "const [_foo] = arr", languageOptions: { ecmaVersion: 6 } }, + { code: "const [_foo] = arr", options: [{}], languageOptions: { ecmaVersion: 6 } }, + { code: "const [_foo] = arr", options: [{ allowInArrayDestructuring: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const [foo, ...rest] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false }], languageOptions: { ecmaVersion: 2022 } }, + { code: "const [foo, _bar] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false, allow: ["_bar"] }], languageOptions: { ecmaVersion: 2022 } }, + { code: "const { _foo } = obj", languageOptions: { ecmaVersion: 6 } }, + { code: "const { _foo } = obj", options: [{}], languageOptions: { ecmaVersion: 6 } }, + { code: "const { _foo } = obj", options: [{ allowInObjectDestructuring: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const { foo, bar: _bar } = { foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false, allow: ["_bar"] }], languageOptions: { ecmaVersion: 2022 } }, + { code: "const { foo, _bar } = { foo: 1, _bar: 2 }", options: [{ allowInObjectDestructuring: false, allow: ["_bar"] }], languageOptions: { ecmaVersion: 2022 } }, + { code: "const { foo, _bar: bar } = { foo: 1, _bar: 2 }", options: [{ allowInObjectDestructuring: false }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class foo { _field; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class foo { _field; }", options: [{ enforceInClassFields: false }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class foo { #_field; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class foo { #_field; }", options: [{ enforceInClassFields: false }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class foo { _field; }", options: [{}], languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { code: "var _foo = 1", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" }, type: "VariableDeclarator" }] }, @@ -95,129 +95,129 @@ ruleTester.run("no-underscore-dangle", rule, { { code: "var __proto__ = 1;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "__proto__" }, type: "VariableDeclarator" }] }, { code: "foo._bar;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "MemberExpression" }] }, { code: "this._prop;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, - { code: "class foo { constructor() { super._prop; } }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, - { code: "class foo { constructor() { this._prop; } }", options: [{ allowAfterSuper: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, - { code: "class foo { _onClick() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "MethodDefinition" }] }, - { code: "class foo { onClick_() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "MethodDefinition" }] }, - { code: "const o = { _onClick() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "Property" }] }, - { code: "const o = { onClick_() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "Property" }] }, + { code: "class foo { constructor() { super._prop; } }", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "class foo { constructor() { this._prop; } }", options: [{ allowAfterSuper: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "class foo { _onClick() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "MethodDefinition" }], languageOptions: { ecmaVersion: 6 } }, + { code: "class foo { onClick_() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "MethodDefinition" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const o = { _onClick() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "Property" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const o = { onClick_() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "Property" }], languageOptions: { ecmaVersion: 6 } }, { code: "this.constructor._bar", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "MemberExpression" }] }, { code: "function foo(_bar) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, { code: "(function foo(_bar) {})", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, { code: "function foo(bar, _foo) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" }, type: "Identifier" }] }, - { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, - { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, - { code: "function foo(_bar = 0) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }] }, - { code: "const foo = { onClick(_bar = 0) { } }", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }] }, - { code: "const foo = (_bar = 0) => {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }] }, - { code: "function foo(..._bar) {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] }, - { code: "const foo = { onClick(..._bar) { } }", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] }, - { code: "const foo = (..._bar) => {}", options: [{ allowFunctionParams: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] }, + { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(_bar = 0) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(_bar = 0) { } }", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (_bar = 0) => {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(..._bar) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(..._bar) { } }", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = (..._bar) => {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }], languageOptions: { ecmaVersion: 6 } }, { code: "const [foo, _bar] = [1, 2]", options: [{ allowInArrayDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const [_foo = 1] = arr", options: [{ allowInArrayDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const [foo, ..._rest] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const [foo, [bar_, baz]] = [1, [2, 3]]", options: [{ allowInArrayDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "bar_" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "bar_" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { _foo, bar } = { _foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { _foo = 1 } = obj", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { bar: _foo = 1 } = obj", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { foo: _foo, bar } = { foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { foo, ..._rest} = { foo: 1, bar: 2, baz: 3 }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { foo: [_bar, { a: _a, b } ] } = { foo: [1, { a: 'a', b: 'b' }] }", options: [{ allowInArrayDestructuring: false, allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }, { messageId: "unexpectedUnderscore", data: { identifier: "_a" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { foo: [_bar, { a: _a, b } ] } = { foo: [1, { a: 'a', b: 'b' }] }", options: [{ allowInArrayDestructuring: true, allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_a" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_a" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const [{ foo: [_bar, _, { bar: _baz }] }] = [{ foo: [1, 2, { bar: 'a' }] }]", options: [{ allowInArrayDestructuring: false, allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }, { messageId: "unexpectedUnderscore", data: { identifier: "_baz" } } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "const { foo, bar: { baz, _qux } } = { foo: 1, bar: { baz: 3, _qux: 4 } }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_qux" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_qux" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class foo { #_bar() {} }", options: [{ enforceInMethodNames: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_bar" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_bar" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class foo { #bar_() {} }", options: [{ enforceInMethodNames: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class foo { _field; }", options: [{ enforceInClassFields: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class foo { #_field; }", options: [{ enforceInClassFields: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class foo { field_; }", options: [{ enforceInClassFields: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "field_" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "field_" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class foo { #field_; }", options: [{ enforceInClassFields: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#field_" } }] + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#field_" } }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-unexpected-multiline.js b/tests/lib/rules/no-unexpected-multiline.js index 87044efe2a4..11e08b446d9 100644 --- a/tests/lib/rules/no-unexpected-multiline.js +++ b/tests/lib/rules/no-unexpected-multiline.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unexpected-multiline"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -33,31 +33,31 @@ ruleTester.run("no-unexpected-multiline", rule, { "(\nfunction () {}\n)[1]", { code: "let x = function() {};\n `hello`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let x = function() {}\nx `hello`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "String.raw `Hi\n${2+3}!`;", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "x\n.y\nz `Valid Test Case`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "f(x\n)`Valid Test Case`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "x.\ny `Valid Test Case`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(x\n)`Valid Test Case`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, ` foo @@ -107,7 +107,9 @@ ruleTester.run("no-unexpected-multiline", rule, { multiline \`; `, - parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-1") + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-1") + } }, { code: ` @@ -117,7 +119,9 @@ ruleTester.run("no-unexpected-multiline", rule, { multiline \`; `, - parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-2") + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-2") + } }, { code: ` @@ -125,47 +129,49 @@ ruleTester.run("no-unexpected-multiline", rule, { generic >\`multiline\`; `, - parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-3") + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-3") + } }, // Optional chaining { code: "var a = b\n ?.(x || y).doSomething()", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = b\n ?.[a, b, c].forEach(doSomething)", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = b?.\n (x || y).doSomething()", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "var a = b?.\n [a, b, c].forEach(doSomething)", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // Class fields { code: "class C { field1\n[field2]; }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { field1\n*gen() {} }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { // ArrowFunctionExpression doesn't connect to computed properties. code: "class C { field1 = () => {}\n[field2]; }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { // ArrowFunctionExpression doesn't connect to binary operators. code: "class C { field1 = () => {}\n*gen() {} }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -231,36 +237,36 @@ ruleTester.run("no-unexpected-multiline", rule, { }, { code: "let x = function() {}\n `hello`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 2, endLine: 2, endColumn: 3, messageId: "taggedTemplate" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let x = function() {}\nx\n`hello`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 3, column: 1, endLine: 3, endColumn: 2, messageId: "taggedTemplate" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "x\n.y\nz\n`Invalid Test Case`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, endLine: 4, endColumn: 2, messageId: "taggedTemplate" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -337,7 +343,6 @@ ruleTester.run("no-unexpected-multiline", rule, { "test", "*/`foo`" ].join("\n"), - parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment"), errors: [ { line: 5, @@ -346,13 +351,15 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 4, messageId: "taggedTemplate" } - ] + ], + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment") + } }, // Class fields { code: "class C { field1 = obj\n[field2]; }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { line: 2, @@ -361,11 +368,11 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 2, messageId: "property" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { field1 = function() {}\n[field2]; }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { line: 2, @@ -374,7 +381,8 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 2, messageId: "property" } - ] + ], + languageOptions: { ecmaVersion: 2022 } } // "class C { field1 = obj\n*gen() {} }" is syntax error: Unexpected token '{' diff --git a/tests/lib/rules/no-unmodified-loop-condition.js b/tests/lib/rules/no-unmodified-loop-condition.js index 90cc45d5f33..7cfe4ad0c7a 100644 --- a/tests/lib/rules/no-unmodified-loop-condition.js +++ b/tests/lib/rules/no-unmodified-loop-condition.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unmodified-loop-condition"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,7 +21,7 @@ const ruleTester = new RuleTester(); ruleTester.run("no-unmodified-loop-condition", rule, { valid: [ "var foo = 0; while (foo) { ++foo; }", - { code: "let foo = 0; while (foo) { ++foo; }", env: { es6: true } }, + { code: "let foo = 0; while (foo) { ++foo; }", languageOptions: { ecmaVersion: 6 } }, "var foo = 0; while (foo) { foo += 1; }", "var foo = 0; while (foo++) { }", "var foo = 0; while (foo = next()) { }", @@ -30,9 +30,9 @@ ruleTester.run("no-unmodified-loop-condition", rule, { "var foo = 0, obj = {}; while (foo === obj.bar) { }", "var foo = 0, f = {}, bar = {}; while (foo === f(bar)) { }", "var foo = 0, f = {}; while (foo === f()) { }", - { code: "var foo = 0, tag = 0; while (foo === tag`abc`) { }", env: { es6: true } }, - { code: "function* foo() { var foo = 0; while (yield foo) { } }", env: { es6: true } }, - { code: "function* foo() { var foo = 0; while (foo === (yield)) { } }", env: { es6: true } }, + { code: "var foo = 0, tag = 0; while (foo === tag`abc`) { }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { var foo = 0; while (yield foo) { } }", languageOptions: { ecmaVersion: 6 } }, + { code: "function* foo() { var foo = 0; while (foo === (yield)) { } }", languageOptions: { ecmaVersion: 6 } }, "var foo = 0; while (foo.ok) { }", "var foo = 0; while (foo) { update(); } function update() { ++foo; }", "var foo = 0, bar = 9; while (foo < bar) { foo += 1; }", diff --git a/tests/lib/rules/no-unneeded-ternary.js b/tests/lib/rules/no-unneeded-ternary.js index 3714e70bec8..334198e5f7a 100644 --- a/tests/lib/rules/no-unneeded-ternary.js +++ b/tests/lib/rules/no-unneeded-ternary.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unneeded-ternary"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), parser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -242,7 +242,6 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "function* fn() { foo ? foo : yield bar }", output: "function* fn() { foo || (yield bar) }", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -250,7 +249,8 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 18, endLine: 1, endColumn: 39 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = foo ? foo : 'No';", @@ -282,7 +282,6 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = b ? b : c => c;", output: "var a = b || (c => c);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -290,13 +289,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 23 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var a = b ? b : c = 0;", output: "var a = b || (c = 0);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -304,13 +303,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 22 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var a = b ? b : (c => c);", output: "var a = b || (c => c);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -318,13 +317,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var a = b ? b : (c = 0);", output: "var a = b || (c = 0);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -332,13 +331,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 24 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var a = b ? b : (c) => (c);", output: "var a = b || ((c) => (c));", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -346,13 +345,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 27 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var a = b ? b : c, d; // this is ((b ? b : c), (d))", output: "var a = b || c, d; // this is ((b ? b : c), (d))", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -360,13 +359,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 18 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var a = b ? b : (c, d);", output: "var a = b || (c, d);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -374,7 +373,8 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 23 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "f(x ? x : 1);", @@ -419,7 +419,6 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = foo ? foo : a ?? b;", output: "var a = foo || (a ?? b);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -427,30 +426,35 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 27 - }] + }], + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/17173 { code: "foo as any ? false : true", output: "!(foo as any)", - parser: parser("typescript-parsers/unneeded-ternary-1"), - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression" - }] + }], + languageOptions: { + parser: require(parser("typescript-parsers/unneeded-ternary-1")), + ecmaVersion: 6 + } }, { code: "foo ? foo : bar as any", output: "foo || (bar as any)", options: [{ defaultAssignment: false }], - parser: parser("typescript-parsers/unneeded-ternary-2"), - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression" - }] + }], + languageOptions: { + parser: require(parser("typescript-parsers/unneeded-ternary-2")), + ecmaVersion: 6 + } } ] }); diff --git a/tests/lib/rules/no-unreachable-loop.js b/tests/lib/rules/no-unreachable-loop.js index 10eaed40659..f1d68aeb891 100644 --- a/tests/lib/rules/no-unreachable-loop.js +++ b/tests/lib/rules/no-unreachable-loop.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unreachable-loop"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2018 } }); const loopTemplates = { WhileStatement: [ diff --git a/tests/lib/rules/no-unreachable.js b/tests/lib/rules/no-unreachable.js index 03816d7192f..f6e4be5e4d7 100644 --- a/tests/lib/rules/no-unreachable.js +++ b/tests/lib/rules/no-unreachable.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unreachable"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-unreachable", rule, { valid: [ @@ -35,7 +40,7 @@ ruleTester.run("no-unreachable", rule, { "switch (foo) { case 1: break; var x; default: throw true; };", { code: "const arrow_direction = arrow => { switch (arrow) { default: throw new Error(); };}", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -50,41 +55,41 @@ ruleTester.run("no-unreachable", rule, { "A: { break A; } foo()", { code: "function* foo() { try { yield 1; return; } catch (err) { return err; } }", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { try { bar(); return; } catch (err) { return err; } }", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { try { a.b.c = 1; return; } catch (err) { return err; } }", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "class C { foo = reachable; }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = reachable; constructor() {} }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C extends B { foo = reachable; }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C extends B { foo = reachable; constructor() { super(); } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C extends B { static foo = reachable; constructor() {} }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -110,7 +115,6 @@ ruleTester.run("no-unreachable", rule, { { code: "function foo() { var x = 1; while (true) { } x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, { code: "const arrow_direction = arrow => { switch (arrow) { default: throw new Error(); }; g() }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unreachableCode", @@ -120,7 +124,8 @@ ruleTester.run("no-unreachable", rule, { endLine: 1, endColumn: 89 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // Merge the warnings of continuous unreachable nodes. @@ -254,9 +259,6 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unreachableCode", @@ -266,7 +268,10 @@ ruleTester.run("no-unreachable", rule, { endLine: 7, endColumn: 22 } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: ` @@ -277,9 +282,6 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unreachableCode", @@ -289,7 +291,10 @@ ruleTester.run("no-unreachable", rule, { endLine: 7, endColumn: 22 } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: ` @@ -301,9 +306,6 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unreachableCode", @@ -321,7 +323,10 @@ ruleTester.run("no-unreachable", rule, { endLine: 8, endColumn: 22 } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, /* @@ -333,56 +338,56 @@ ruleTester.run("no-unreachable", rule, { */ { code: "class C extends B { foo; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unreachableCode", column: 21, endColumn: 25 }] + errors: [{ messageId: "unreachableCode", column: 21, endColumn: 25 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C extends B { foo = unreachable + code; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unreachableCode", column: 21, endColumn: 46 }] + errors: [{ messageId: "unreachableCode", column: 21, endColumn: 46 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C extends B { foo; bar; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unreachableCode", column: 21, endColumn: 30 }] + errors: [{ messageId: "unreachableCode", column: 21, endColumn: 30 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C extends B { foo; constructor() {} bar; }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 21, endColumn: 25 }, { messageId: "unreachableCode", column: 43, endColumn: 47 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class extends B { foo; constructor() {} bar; })", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 20, endColumn: 24 }, { messageId: "unreachableCode", column: 42, endColumn: 46 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class B extends A { x; constructor() { class C extends D { [super().x]; constructor() {} } } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 60, endColumn: 72 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class B extends A { x; constructor() { class C extends super().x { y; constructor() {} } } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 68, endColumn: 70 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class B extends A { x; static y; z; static q; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 21, endColumn: 23 }, { messageId: "unreachableCode", column: 34, endColumn: 36 } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-unsafe-finally.js b/tests/lib/rules/no-unsafe-finally.js index 814211882b9..68ec6c30127 100644 --- a/tests/lib/rules/no-unsafe-finally.js +++ b/tests/lib/rules/no-unsafe-finally.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unsafe-finally"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -32,15 +32,15 @@ ruleTester.run("no-unsafe-finally", rule, { "var foo = function() { try {} finally { do { break; } while (true) } }", { code: "var foo = function() { try { return 1; } catch(err) { return 2; } finally { var bar = () => { throw new Error(); }; } };", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() { try { return 1; } catch(err) { return 2 } finally { (x) => x } }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() { try { return 1; } finally { class bar { constructor() {} static ehm() { return 'Hola!'; } } } };", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], invalid: [ diff --git a/tests/lib/rules/no-unsafe-negation.js b/tests/lib/rules/no-unsafe-negation.js index bc7a23e2388..ce68e9be95a 100644 --- a/tests/lib/rules/no-unsafe-negation.js +++ b/tests/lib/rules/no-unsafe-negation.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unsafe-negation"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-unsafe-optional-chaining.js b/tests/lib/rules/no-unsafe-optional-chaining.js index 95b87a9972a..3ce551ab89a 100644 --- a/tests/lib/rules/no-unsafe-optional-chaining.js +++ b/tests/lib/rules/no-unsafe-optional-chaining.js @@ -6,18 +6,18 @@ "use strict"; const rule = require("../../../lib/rules/no-unsafe-optional-chaining"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const parserOptions = { +const languageOptions = { ecmaVersion: 2021, sourceType: "module" }; -const ruleTester = new RuleTester({ parserOptions }); +const ruleTester = new RuleTester({ languageOptions }); ruleTester.run("no-unsafe-optional-chaining", rule, { valid: [ @@ -296,9 +296,6 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { }, { code: "with (obj?.foo) {};", - parserOptions: { - sourceType: "script" - }, errors: [ { messageId: "unsafeOptionalChain", @@ -306,13 +303,13 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { line: 1, column: 7 } - ] + ], + languageOptions: { + sourceType: "script" + } }, { code: "async function foo() { with ( await obj?.foo) {}; }", - parserOptions: { - sourceType: "script" - }, errors: [ { messageId: "unsafeOptionalChain", @@ -320,7 +317,10 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { line: 1, column: 37 } - ] + ], + languageOptions: { + sourceType: "script" + } }, { code: "(foo ? obj?.foo : obj?.bar).bar", diff --git a/tests/lib/rules/no-unused-expressions.js b/tests/lib/rules/no-unused-expressions.js index 7cf11a9a3ea..f51447a04f0 100644 --- a/tests/lib/rules/no-unused-expressions.js +++ b/tests/lib/rules/no-unused-expressions.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unused-expressions"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -36,76 +36,76 @@ ruleTester.run("no-unused-expressions", rule, { "\"use strict\";", "\"directive one\"; \"directive two\"; f();", "function foo() {\"use strict\"; return true; }", - { code: "var foo = () => {\"use strict\"; return true; }", parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => {\"use strict\"; return true; }", languageOptions: { ecmaVersion: 6 } }, "function foo() {\"directive one\"; \"directive two\"; f(); }", "function foo() { var foo = \"use strict\"; return true; }", { code: "function* foo(){ yield 0; }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "async function foo() { await 5; }", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await foo.bar; }", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { bar && await baz; }", options: [{ allowShortCircuit: true }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { foo ? await bar : await baz; }", options: [{ allowTernary: true }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "tag`tagged template literal`", options: [{ allowTaggedTemplates: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "shouldNotBeAffectedByAllowTemplateTagsOption()", options: [{ allowTaggedTemplates: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "import(\"foo\")", - parserOptions: { ecmaVersion: 11 } + languageOptions: { ecmaVersion: 11 } }, { code: "func?.(\"foo\")", - parserOptions: { ecmaVersion: 11 } + languageOptions: { ecmaVersion: 11 } }, { code: "obj?.foo(\"bar\")", - parserOptions: { ecmaVersion: 11 } + languageOptions: { ecmaVersion: 11 } }, // JSX { code: "
", - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "<>", - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var partial =
", - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var partial =
", options: [{ enforceForJSX: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var partial = <>", options: [{ enforceForJSX: true }], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } } ], invalid: [ @@ -120,13 +120,13 @@ ruleTester.run("no-unused-expressions", rule, { { code: "a ? b() || (c = d) : e", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "`untagged template literal`", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unusedExpression" }] + errors: [{ messageId: "unusedExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "tag`tagged template literal`", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unusedExpression" }] + errors: [{ messageId: "unusedExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "a && b()", options: [{ allowTernary: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "a ? b() : c()", options: [{ allowShortCircuit: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, @@ -141,66 +141,65 @@ ruleTester.run("no-unused-expressions", rule, { { code: "function foo() {\"directive one\"; f(); \"directive two\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "if (0) { \"not a directive\"; f(); }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "function foo() { var foo = true; \"use strict\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, - { code: "var foo = () => { var foo = true; \"use strict\"; }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "var foo = () => { var foo = true; \"use strict\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], languageOptions: { ecmaVersion: 6 } }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unusedExpression" }] + errors: [{ messageId: "unusedExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: false }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unusedExpression" }] + errors: [{ messageId: "unusedExpression" }], + languageOptions: { ecmaVersion: 6 } }, { code: "tag`tagged template literal`", options: [{ allowTaggedTemplates: false }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unusedExpression" }] + errors: [{ messageId: "unusedExpression" }], + languageOptions: { ecmaVersion: 6 } }, // Optional chaining { code: "obj?.foo", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.foo.bar", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.foo().bar", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 2020 } }, // JSX { code: "
", options: [{ enforceForJSX: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "<>", options: [{ enforceForJSX: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, // class static blocks do not have directive prologues { code: "class C { static { 'use strict'; } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { \n'foo'\n'bar'\n } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unusedExpression", @@ -212,7 +211,8 @@ ruleTester.run("no-unused-expressions", rule, { type: "ExpressionStatement", line: 3 } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/no-unused-labels.js b/tests/lib/rules/no-unused-labels.js index 46b7b1e13e2..af8ed6db606 100644 --- a/tests/lib/rules/no-unused-labels.js +++ b/tests/lib/rules/no-unused-labels.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unused-labels"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -94,8 +94,8 @@ ruleTester.run("no-unused-labels", rule, { { code: "A: `use strict`", // `use strict` may be changed to "use strict" by another rule. output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unused" }] + errors: [{ messageId: "unused" }], + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { bar: 'baz' }", diff --git a/tests/lib/rules/no-unused-private-class-members.js b/tests/lib/rules/no-unused-private-class-members.js index 6e80baae968..49af27f8bbd 100644 --- a/tests/lib/rules/no-unused-private-class-members.js +++ b/tests/lib/rules/no-unused-private-class-members.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unused-private-class-members"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); /** * Returns an expected error for defined-but-not-used private class member. diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js index 2dea2614fd2..64fb566865c 100644 --- a/tests/lib/rules/no-unused-vars.js +++ b/tests/lib/rules/no-unused-vars.js @@ -10,35 +10,46 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-unused-vars"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); - -ruleTester.defineRule("use-every-a", { - create(context) { - - const sourceCode = context.sourceCode; - - /** - * Mark a variable as used - * @param {ASTNode} node The node representing the scope to search - * @returns {void} - * @private - */ - function useA(node) { - sourceCode.markVariableAsUsed("a", node); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + }, + plugins: { + custom: { + rules: { + "use-every-a": { + create(context) { + + const sourceCode = context.sourceCode; + + /** + * Mark a variable as used + * @param {ASTNode} node The node representing the scope to search + * @returns {void} + * @private + */ + function useA(node) { + sourceCode.markVariableAsUsed("a", node); + } + return { + VariableDeclaration: useA, + ReturnStatement: useA + }; + } + } + } } - return { - VariableDeclaration: useA, - ReturnStatement: useA - }; } }); + /** * Returns an expected error for defined-but-not-used variables. * @param {string} varName The name of the variable @@ -81,7 +92,7 @@ ruleTester.run("no-unused-vars", rule, { valid: [ "var foo = 5;\n\nlabel: while (true) {\n console.log(foo);\n break label;\n}", "var foo = 5;\n\nwhile (true) {\n console.log(foo);\n break;\n}", - { code: "for (let prop in box) {\n box[prop] = parseInt(box[prop]);\n}", parserOptions: { ecmaVersion: 6 } }, + { code: "for (let prop in box) {\n box[prop] = parseInt(box[prop]);\n}", languageOptions: { ecmaVersion: 6 } }, "var box = {a: 2};\n for (var prop in box) {\n box[prop] = parseInt(box[prop]);\n}", "f({ set foo(a) { return; } });", { code: "a; var a;", options: ["all"] }, @@ -112,90 +123,90 @@ ruleTester.run("no-unused-vars", rule, { { code: "function g(bar, baz) { return bar + baz; }; g();", options: [{ vars: "local", args: "all" }] }, { code: "var g = function(bar, baz) { return 2; }; g();", options: [{ vars: "all", args: "none" }] }, "(function z() { z(); })();", - { code: " ", globals: { a: true } }, - { code: "var who = \"Paul\";\nmodule.exports = `Hello ${who}!`;", parserOptions: { ecmaVersion: 6 } }, - { code: "export var foo = 123;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function foo () {}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "let toUpper = (partial) => partial.toUpperCase; export {toUpper}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export class foo {}", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "class Foo{}; var x = new Foo(); x.foo()", parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = \"hello!\";function bar(foobar = foo) { foobar.replace(/!$/, \" world!\");}\nbar();", parserOptions: { ecmaVersion: 6 } }, + { code: " ", languageOptions: { globals: { a: true } } }, + { code: "var who = \"Paul\";\nmodule.exports = `Hello ${who}!`;", languageOptions: { ecmaVersion: 6 } }, + { code: "export var foo = 123;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function foo () {}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "let toUpper = (partial) => partial.toUpperCase; export {toUpper}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export class foo {}", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "class Foo{}; var x = new Foo(); x.foo()", languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = \"hello!\";function bar(foobar = foo) { foobar.replace(/!$/, \" world!\");}\nbar();", languageOptions: { ecmaVersion: 6 } }, "function Foo(){}; var x = new Foo(); x.foo()", "function foo() {var foo = 1; return foo}; foo();", "function foo(foo) {return foo}; foo(1);", "function foo() {function foo() {return 1;}; return foo()}; foo();", - { code: "function foo() {var foo = 1; return foo}; foo();", parserOptions: { parserOptions: { ecmaVersion: 6 } } }, - { code: "function foo(foo) {return foo}; foo(1);", parserOptions: { parserOptions: { ecmaVersion: 6 } } }, - { code: "function foo() {function foo() {return 1;}; return foo()}; foo();", parserOptions: { parserOptions: { ecmaVersion: 6 } } }, - { code: "const x = 1; const [y = x] = []; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; const {y = x} = {}; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; const {z: [y = x]} = {}; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = []; const {z: [y] = x} = {}; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; let y; [y = x] = []; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; let y; ({z: [y = x]} = {}); foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = []; let y; ({z: [y] = x} = {}); foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; function foo(y = x) { bar(y); } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; function foo({y = x} = {}) { bar(y); } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "const x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1; var [y = x] = []; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1; var {y = x} = {}; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1; var {z: [y = x]} = {}; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = []; var {z: [y] = x} = {}; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1, y; [y = x] = []; foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1, y; ({z: [y = x]} = {}); foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = [], y; ({z: [y] = x} = {}); foo(y);", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1; function foo(y = x) { bar(y); } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1; function foo({y = x} = {}) { bar(y); } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "var x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", parserOptions: { ecmaVersion: 6 } }, + { code: "function foo() {var foo = 1; return foo}; foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(foo) {return foo}; foo(1);", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() {function foo() {return 1;}; return foo()}; foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; const [y = x] = []; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; const {y = x} = {}; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; const {z: [y = x]} = {}; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = []; const {z: [y] = x} = {}; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; let y; [y = x] = []; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; let y; ({z: [y = x]} = {}); foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = []; let y; ({z: [y] = x} = {}); foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; function foo(y = x) { bar(y); } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; function foo({y = x} = {}) { bar(y); } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "const x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1; var [y = x] = []; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1; var {y = x} = {}; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1; var {z: [y = x]} = {}; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = []; var {z: [y] = x} = {}; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1, y; [y = x] = []; foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1, y; ({z: [y = x]} = {}); foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = [], y; ({z: [y] = x} = {}); foo(y);", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1; function foo(y = x) { bar(y); } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1; function foo({y = x} = {}) { bar(y); } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "var x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", languageOptions: { ecmaVersion: 6 } }, // exported variables should work "/*exported toaster*/ var toaster = 'great'", "/*exported toaster, poster*/ var toaster = 1; poster = 0;", - { code: "/*exported x*/ var { x } = y", parserOptions: { ecmaVersion: 6 } }, - { code: "/*exported x, y*/ var { x, y } = z", parserOptions: { ecmaVersion: 6 } }, + { code: "/*exported x*/ var { x } = y", languageOptions: { ecmaVersion: 6 } }, + { code: "/*exported x, y*/ var { x, y } = z", languageOptions: { ecmaVersion: 6 } }, // Can mark variables as used via context.markVariableAsUsed() - "/*eslint use-every-a:1*/ var a;", - "/*eslint use-every-a:1*/ !function(a) { return 1; }", - "/*eslint use-every-a:1*/ !function() { var a; return 1 }", + "/*eslint custom/use-every-a:1*/ var a;", + "/*eslint custom/use-every-a:1*/ !function(a) { return 1; }", + "/*eslint custom/use-every-a:1*/ !function() { var a; return 1 }", // ignore pattern { code: "var _a;", options: [{ vars: "all", varsIgnorePattern: "^_" }] }, { code: "var a; function foo() { var _b; } foo();", options: [{ vars: "local", varsIgnorePattern: "^_" }] }, { code: "function foo(_a) { } foo();", options: [{ args: "all", argsIgnorePattern: "^_" }] }, { code: "function foo(a, _b) { return a; } foo();", options: [{ args: "after-used", argsIgnorePattern: "^_" }] }, - { code: "var [ firstItemIgnored, secondItem ] = items;\nconsole.log(secondItem);", options: [{ vars: "all", varsIgnorePattern: "[iI]gnored" }], parserOptions: { ecmaVersion: 6 } }, + { code: "var [ firstItemIgnored, secondItem ] = items;\nconsole.log(secondItem);", options: [{ vars: "all", varsIgnorePattern: "[iI]gnored" }], languageOptions: { ecmaVersion: 6 } }, { code: "const [ a, _b, c ] = items;\nconsole.log(a+c);", options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const [ [a, _b, c] ] = items;\nconsole.log(a+c);", options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const { x: [_a, foo] } = bar;\nconsole.log(foo);", options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function baz([_b, foo]) { foo; };\nbaz()", options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function baz({x: [_b, foo]}) {foo};\nbaz()", options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function baz([{x: [_b, foo]}]) {foo};\nbaz()", options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -206,7 +217,7 @@ ruleTester.run("no-unused-vars", rule, { }); `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -223,7 +234,7 @@ ruleTester.run("no-unused-vars", rule, { b; `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: ` @@ -240,7 +251,7 @@ ruleTester.run("no-unused-vars", rule, { b; `, options: [{ destructuredArrayIgnorePattern: "^_", ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // for-in loops (see #2342) @@ -249,27 +260,27 @@ ruleTester.run("no-unused-vars", rule, { "(function(obj) { for ( var name in obj ) { return true } })({})", "(function(obj) { for ( var name in obj ) return true })({})", - { code: "(function(obj) { let name; for ( name in obj ) return; })({});", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(obj) { let name; for ( name in obj ) { return; } })({});", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(obj) { for ( let name in obj ) { return true } })({})", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(obj) { for ( let name in obj ) return true })({})", parserOptions: { ecmaVersion: 6 } }, + { code: "(function(obj) { let name; for ( name in obj ) return; })({});", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(obj) { let name; for ( name in obj ) { return; } })({});", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(obj) { for ( let name in obj ) { return true } })({})", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(obj) { for ( let name in obj ) return true })({})", languageOptions: { ecmaVersion: 6 } }, - { code: "(function(obj) { for ( const name in obj ) { return true } })({})", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(obj) { for ( const name in obj ) return true })({})", parserOptions: { ecmaVersion: 6 } }, + { code: "(function(obj) { for ( const name in obj ) { return true } })({})", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(obj) { for ( const name in obj ) return true })({})", languageOptions: { ecmaVersion: 6 } }, // For-of loops - { code: "(function(iter) { let name; for ( name of iter ) return; })({});", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(iter) { let name; for ( name of iter ) { return; } })({});", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(iter) { for ( let name of iter ) { return true } })({})", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(iter) { for ( let name of iter ) return true })({})", parserOptions: { ecmaVersion: 6 } }, + { code: "(function(iter) { let name; for ( name of iter ) return; })({});", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(iter) { let name; for ( name of iter ) { return; } })({});", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(iter) { for ( let name of iter ) { return true } })({})", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(iter) { for ( let name of iter ) return true })({})", languageOptions: { ecmaVersion: 6 } }, - { code: "(function(iter) { for ( const name of iter ) { return true } })({})", parserOptions: { ecmaVersion: 6 } }, - { code: "(function(iter) { for ( const name of iter ) return true })({})", parserOptions: { ecmaVersion: 6 } }, + { code: "(function(iter) { for ( const name of iter ) { return true } })({})", languageOptions: { ecmaVersion: 6 } }, + { code: "(function(iter) { for ( const name of iter ) return true })({})", languageOptions: { ecmaVersion: 6 } }, // Sequence Expressions (See https://github.com/eslint/eslint/issues/14325) - { code: "let x = 0; foo = (0, x++);", parserOptions: { ecmaVersion: 6 } }, - { code: "let x = 0; foo = (0, x += 1);", parserOptions: { ecmaVersion: 6 } }, - { code: "let x = 0; foo = (0, x = x + 1);", parserOptions: { ecmaVersion: 6 } }, + { code: "let x = 0; foo = (0, x++);", languageOptions: { ecmaVersion: 6 } }, + { code: "let x = 0; foo = (0, x += 1);", languageOptions: { ecmaVersion: 6 } }, + { code: "let x = 0; foo = (0, x = x + 1);", languageOptions: { ecmaVersion: 6 } }, // caughtErrors { @@ -295,7 +306,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "const data = { type: 'coords', x: 1, y: 2 };\nconst { type, ...coords } = data;\n console.log(coords);", options: [{ ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/6348 @@ -330,8 +341,8 @@ ruleTester.run("no-unused-vars", rule, { "f();" ].join("\n"), "function foo(cb) { cb = function() { function something(a) { cb(1 + a); } register(something); }(); } foo();", - { code: "function* foo(cb) { cb = yield function(a) { cb(1 + a); }; } foo();", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(cb) { cb = tag`hello${function(a) { cb(1 + a); }}`; } foo();", parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo(cb) { cb = yield function(a) { cb(1 + a); }; } foo();", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(cb) { cb = tag`hello${function(a) { cb(1 + a); }}`; } foo();", languageOptions: { ecmaVersion: 6 } }, "function foo(cb) { var b; cb = b = function(a) { cb(1 + a); }; b(); } foo();", // https://github.com/eslint/eslint/issues/6646 @@ -349,12 +360,12 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(a, b, {c, d}) { d })", options: [{ argsIgnorePattern: "c" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(function(a, b, {c, d}) { c })", options: [{ argsIgnorePattern: "d" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7250 @@ -365,72 +376,72 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(a, b, {c, d}) { c })", options: [{ argsIgnorePattern: "[cd]" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7351 { code: "(class { set foo(UNUSED) {} })", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { set bar(UNUSED) {} } console.log(Foo)", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/8119 { code: "(({a, ...rest}) => rest)", options: [{ args: "all", ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/14163 { code: "let foo, rest;\n({ foo, ...rest } = something);\nconsole.log(rest);", options: [{ ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // https://github.com/eslint/eslint/issues/10952 - "/*eslint use-every-a:1*/ !function(b, a) { return 1 }", + "/*eslint custom/use-every-a:1*/ !function(b, a) { return 1 }", // https://github.com/eslint/eslint/issues/10982 "var a = function () { a(); }; a();", "var a = function(){ return function () { a(); } }; a();", { code: "const a = () => { a(); }; a();", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "const a = () => () => { a(); }; a();", - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // export * as ns from "source" { code: 'export * as ns from "source"', - parserOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, // import.meta { code: "import.meta", - parserOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" } }, // https://github.com/eslint/eslint/issues/17299 { code: "var a; a ||= 1;", - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "var a; a &&= 1;", - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "var a; a ??= 1;", - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } } ], invalid: [ @@ -471,13 +482,13 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function z(foo) { var bar = 33; })();", options: [{ vars: "all", args: "all" }], errors: [definedError("foo"), assignedError("bar")] }, { code: "(function z(foo) { z(); })();", options: [{}], errors: [definedError("foo")] }, { code: "function f() { var a = 1; return function(){ f(a = 2); }; }", options: [{}], errors: [definedError("f"), assignedError("a")] }, - { code: "import x from \"y\";", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("x")] }, - { code: "export function fn2({ x, y }) {\n console.log(x); \n};", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("y")] }, - { code: "export function fn2( x, y ) {\n console.log(x); \n};", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("y")] }, + { code: "import x from \"y\";", errors: [definedError("x")], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function fn2({ x, y }) {\n console.log(x); \n};", errors: [definedError("y")], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function fn2( x, y ) {\n console.log(x); \n};", errors: [definedError("y")], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // exported { code: "/*exported max*/ var max = 1, min = {min: 1}", errors: [assignedError("min")] }, - { code: "/*exported x*/ var { x, y } = z", parserOptions: { ecmaVersion: 6 }, errors: [assignedError("y")] }, + { code: "/*exported x*/ var { x, y } = z", errors: [assignedError("y")], languageOptions: { ecmaVersion: 6 } }, // ignore pattern { @@ -553,7 +564,6 @@ ruleTester.run("no-unused-vars", rule, { { code: "var [ firstItemIgnored, secondItem ] = items;", options: [{ vars: "all", varsIgnorePattern: "[iI]gnored" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 25, @@ -563,7 +573,8 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: ". Allowed unused vars must match /[iI]gnored/u" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/15611 @@ -574,12 +585,12 @@ ruleTester.run("no-unused-vars", rule, { const newArray = [a, c]; `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, errors: [ // should report only `newArray` { ...assignedError("newArray"), line: 4, column: 19 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -587,7 +598,6 @@ ruleTester.run("no-unused-vars", rule, { const [a, _b, c] = array; `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("a", ". Allowed unused elements of array destructuring patterns must match /^_/u"), @@ -599,7 +609,8 @@ ruleTester.run("no-unused-vars", rule, { line: 3, column: 27 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -610,7 +621,6 @@ ruleTester.run("no-unused-vars", rule, { const ignoreArray = ['ignore']; `, options: [{ destructuredArrayIgnorePattern: "^_", varsIgnorePattern: "ignore" }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("a", ". Allowed unused elements of array destructuring patterns must match /^_/u"), @@ -632,7 +642,8 @@ ruleTester.run("no-unused-vars", rule, { line: 5, column: 19 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -641,14 +652,14 @@ ruleTester.run("no-unused-vars", rule, { console.log(foo); `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("_a"), line: 3, column: 21 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -658,14 +669,14 @@ ruleTester.run("no-unused-vars", rule, { foo(); `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { ...definedError("_a"), line: 2, column: 28 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -676,7 +687,6 @@ ruleTester.run("no-unused-vars", rule, { }); `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, errors: [ { ...definedError("_a"), @@ -688,7 +698,8 @@ ruleTester.run("no-unused-vars", rule, { line: 2, column: 21 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, // for-in loops (see #2342) @@ -735,7 +746,6 @@ ruleTester.run("no-unused-vars", rule, { // For-of loops { code: "(function(iter) { var name; for ( name of iter ) { i(); return; } })({});", - env: { es6: true }, errors: [{ line: 1, column: 35, @@ -745,11 +755,11 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: "" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function(iter) { var name; for ( name of iter ) { } })({});", - env: { es6: true }, errors: [{ line: 1, column: 35, @@ -759,11 +769,11 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: "" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function(iter) { for ( var name of iter ) { } })({});", - env: { es6: true }, errors: [{ line: 1, column: 29, @@ -773,7 +783,8 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: "" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/3617 @@ -839,7 +850,6 @@ ruleTester.run("no-unused-vars", rule, { // Rest property sibling without ignoreRestSiblings { code: "const data = { type: 'coords', x: 1, y: 2 };\nconst { type, ...coords } = data;\n console.log(coords);", - parserOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -851,14 +861,14 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // Unused rest property with ignoreRestSiblings { code: "const data = { type: 'coords', x: 2, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", options: [{ ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -870,12 +880,12 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "let type, coords;\n({ type, ...coords } = data);\n console.log(type)", options: [{ ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -887,13 +897,13 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // Unused rest property without ignoreRestSiblings { code: "const data = { type: 'coords', x: 3, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", - parserOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -905,13 +915,13 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // Nested array destructuring with rest property { code: "const data = { vars: ['x','y'], x: 1, y: 2 };\nconst { vars: [x], ...coords } = data;\n console.log(coords)", - parserOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -923,13 +933,13 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // Nested object destructuring with rest property { code: "const data = { defaults: { x: 0 }, x: 1, y: 2 };\nconst { defaults: { x }, ...coords } = data;\n console.log(coords)", - parserOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -941,15 +951,16 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/8119 { code: "(({a, ...rest}) => {})", options: [{ args: "all", ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 }, - errors: [definedError("rest")] + errors: [definedError("rest")], + languageOptions: { ecmaVersion: 2018 } }, // https://github.com/eslint/eslint/issues/3714 @@ -1061,7 +1072,6 @@ ruleTester.run("no-unused-vars", rule, { // surrogate pair. { code: "/*global 𠮷𩸽, 𠮷*/\n\\u{20BB7}\\u{29E3D};", - env: { es6: true }, errors: [ { line: 1, @@ -1075,39 +1085,40 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/4047 { code: "export default function(a) {}", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [definedError("a")] + errors: [definedError("a")], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default function(a, b) { console.log(a); }", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [definedError("b")] + errors: [definedError("b")], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default (function(a) {});", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [definedError("a")] + errors: [definedError("a")], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default (function(a, b) { console.log(a); });", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [definedError("b")] + errors: [definedError("b")], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default (a) => {};", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [definedError("a")] + errors: [definedError("a")], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default (a, b) => { console.log(a); };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [definedError("b")] + errors: [definedError("b")], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // caughtErrors @@ -1214,31 +1225,31 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "[cd]" }], - parserOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /[cd]/u"), definedError("b", ". Allowed unused args must match /[cd]/u") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "c" }], - parserOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /c/u"), definedError("b", ". Allowed unused args must match /c/u"), definedError("d", ". Allowed unused args must match /c/u") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "d" }], - parserOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /d/u"), definedError("b", ". Allowed unused args must match /d/u"), definedError("c", ". Allowed unused args must match /d/u") - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "/*global\rfoo*/", @@ -1259,83 +1270,83 @@ ruleTester.run("no-unused-vars", rule, { // https://github.com/eslint/eslint/issues/8442 { code: "(function ({ a }, b ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, errors: [ definedError("a") - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "(function ({ a }, { b, c } ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ] + ], + languageOptions: { ecmaVersion: 2015 } }, // https://github.com/eslint/eslint/issues/14325 { code: `let x = 0; x++, x = 0;`, - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 2, column: 18 }] + errors: [{ ...assignedError("x"), line: 2, column: 18 }], + languageOptions: { ecmaVersion: 2015 } }, { code: `let x = 0; x++, x = 0; x=3;`, - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 3, column: 13 }] + errors: [{ ...assignedError("x"), line: 3, column: 13 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; x++, 0;", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 12 }] + errors: [{ ...assignedError("x"), line: 1, column: 12 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; 0, x++;", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 15 }] + errors: [{ ...assignedError("x"), line: 1, column: 15 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; 0, (1, x++);", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 19 }] + errors: [{ ...assignedError("x"), line: 1, column: 19 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; foo = (x++, 0);", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 19 }] + errors: [{ ...assignedError("x"), line: 1, column: 19 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; foo = ((0, x++), 0);", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 23 }] + errors: [{ ...assignedError("x"), line: 1, column: 23 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; x += 1, 0;", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 12 }] + errors: [{ ...assignedError("x"), line: 1, column: 12 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; 0, x += 1;", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 15 }] + errors: [{ ...assignedError("x"), line: 1, column: 15 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; 0, (1, x += 1);", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 19 }] + errors: [{ ...assignedError("x"), line: 1, column: 19 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; foo = (x += 1, 0);", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 19 }] + errors: [{ ...assignedError("x"), line: 1, column: 19 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "let x = 0; foo = ((0, x += 1), 0);", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 1, column: 23 }] + errors: [{ ...assignedError("x"), line: 1, column: 23 }], + languageOptions: { ecmaVersion: 2015 } }, // https://github.com/eslint/eslint/issues/14866 @@ -1343,79 +1354,79 @@ ruleTester.run("no-unused-vars", rule, { code: `let z = 0; z = z + 1, z = 2; `, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("z"), line: 2, column: 24 }] + errors: [{ ...assignedError("z"), line: 2, column: 24 }], + languageOptions: { ecmaVersion: 2020 } }, { code: `let z = 0; z = z+1, z = 2; z = 3;`, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("z"), line: 3, column: 13 }] + errors: [{ ...assignedError("z"), line: 3, column: 13 }], + languageOptions: { ecmaVersion: 2020 } }, { code: `let z = 0; z = z+1, z = 2; z = z+3; `, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("z"), line: 3, column: 13 }] + errors: [{ ...assignedError("z"), line: 3, column: 13 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "let x = 0; 0, x = x+1;", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("x"), line: 1, column: 15 }] + errors: [{ ...assignedError("x"), line: 1, column: 15 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "let x = 0; x = x+1, 0;", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("x"), line: 1, column: 12 }] + errors: [{ ...assignedError("x"), line: 1, column: 12 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "let x = 0; foo = ((0, x = x + 1), 0);", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("x"), line: 1, column: 23 }] + errors: [{ ...assignedError("x"), line: 1, column: 23 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "let x = 0; foo = (x = x+1, 0);", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("x"), line: 1, column: 19 }] + errors: [{ ...assignedError("x"), line: 1, column: 19 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "let x = 0; 0, (1, x=x+1);", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("x"), line: 1, column: 19 }] + errors: [{ ...assignedError("x"), line: 1, column: 19 }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(function ({ a, b }, { c } ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "(function ([ a ], b ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, errors: [ definedError("a") - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "(function ([ a ], [ b, c ] ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "(function ([ a, b ], [ c ] ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ] + ], + languageOptions: { ecmaVersion: 2015 } }, // https://github.com/eslint/eslint/issues/9774 @@ -1441,24 +1452,24 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "const a = () => { a(); };", - parserOptions: { ecmaVersion: 2015 }, - errors: [assignedError("a")] + errors: [assignedError("a")], + languageOptions: { ecmaVersion: 2015 } }, { code: "const a = () => () => { a(); };", - parserOptions: { ecmaVersion: 2015 }, - errors: [assignedError("a")] + errors: [assignedError("a")], + languageOptions: { ecmaVersion: 2015 } }, { code: `let myArray = [1,2,3,4].filter((x) => x == 0); myArray = myArray.filter((x) => x == 1);`, - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("myArray"), line: 2, column: 5 }] + errors: [{ ...assignedError("myArray"), line: 2, column: 5 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "const a = 1; a += 1;", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("a"), line: 1, column: 14 }] + errors: [{ ...assignedError("a"), line: 1, column: 14 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var a = function() { a(); };", @@ -1470,20 +1481,20 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "const a = () => { a(); };", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("a"), line: 1, column: 7 }] + errors: [{ ...assignedError("a"), line: 1, column: 7 }], + languageOptions: { ecmaVersion: 2015 } }, { code: "const a = () => () => { a(); };", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("a"), line: 1, column: 7 }] + errors: [{ ...assignedError("a"), line: 1, column: 7 }], + languageOptions: { ecmaVersion: 2015 } }, // https://github.com/eslint/eslint/issues/14324 { code: "let x = [];\nx = x.concat(x);", - parserOptions: { ecmaVersion: 2015 }, - errors: [{ ...assignedError("x"), line: 2, column: 1 }] + errors: [{ ...assignedError("x"), line: 2, column: 1 }], + languageOptions: { ecmaVersion: 2015 } }, { @@ -1495,8 +1506,8 @@ ruleTester.run("no-unused-vars", rule, { a = 13 } }`, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("a"), line: 2, column: 13 }, { ...definedError("foo"), line: 3, column: 22 }] + errors: [{ ...assignedError("a"), line: 2, column: 13 }, { ...definedError("foo"), line: 3, column: 22 }], + languageOptions: { ecmaVersion: 2020 } }, { code: `let foo; @@ -1505,16 +1516,16 @@ ruleTester.run("no-unused-vars", rule, { function init() { foo = 1; }`, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("foo"), line: 3, column: 13 }] + errors: [{ ...assignedError("foo"), line: 3, column: 13 }], + languageOptions: { ecmaVersion: 2020 } }, { code: `function foo(n) { if (n < 2) return 1; return n * foo(n - 1); }`, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...definedError("foo"), line: 1, column: 10 }] + errors: [{ ...definedError("foo"), line: 1, column: 10 }], + languageOptions: { ecmaVersion: 2020 } }, { code: `let c = 'c' @@ -1527,8 +1538,8 @@ function foo1() { } c = foo1`, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ ...assignedError("c"), line: 10, column: 1 }] + errors: [{ ...assignedError("c"), line: 10, column: 1 }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-use-before-define.js b/tests/lib/rules/no-use-before-define.js index dc858f75287..c1707bff484 100644 --- a/tests/lib/rules/no-use-before-define.js +++ b/tests/lib/rules/no-use-before-define.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-use-before-define"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-use-before-define", rule, { valid: [ @@ -28,29 +33,29 @@ ruleTester.run("no-use-before-define", rule, { "Object.hasOwnProperty.call(a);", "function a() { alert(arguments);}", { code: "a(); function a() { alert(arguments); }", options: ["nofunc"] }, - { code: "(() => { var a = 42; alert(a); })();", parserOptions: { ecmaVersion: 6 } }, + { code: "(() => { var a = 42; alert(a); })();", languageOptions: { ecmaVersion: 6 } }, "a(); try { throw new Error() } catch (a) {}", - { code: "class A {} new A();", parserOptions: { ecmaVersion: 6 } }, + { code: "class A {} new A();", languageOptions: { ecmaVersion: 6 } }, "var a = 0, b = a;", - { code: "var {a = 0, b = a} = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a = 0, b = a] = {};", parserOptions: { ecmaVersion: 6 } }, + { code: "var {a = 0, b = a} = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a = 0, b = a] = {};", languageOptions: { ecmaVersion: 6 } }, "function foo() { foo(); }", "var foo = function() { foo(); };", "var a; for (a in a) {}", - { code: "var a; for (a of a) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "let a; class C { static { a; } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { let a; a; } }", parserOptions: { ecmaVersion: 2022 } }, + { code: "var a; for (a of a) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "let a; class C { static { a; } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { let a; a; } }", languageOptions: { ecmaVersion: 2022 } }, // Block-level bindings - { code: "\"use strict\"; a(); { function a() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "\"use strict\"; { a(); function a() {} }", options: ["nofunc"], parserOptions: { ecmaVersion: 6 } }, - { code: "switch (foo) { case 1: { a(); } default: { let a; }}", parserOptions: { ecmaVersion: 6 } }, - { code: "a(); { let a = function () {}; }", parserOptions: { ecmaVersion: 6 } }, + { code: "\"use strict\"; a(); { function a() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "\"use strict\"; { a(); function a() {} }", options: ["nofunc"], languageOptions: { ecmaVersion: 6 } }, + { code: "switch (foo) { case 1: { a(); } default: { let a; }}", languageOptions: { ecmaVersion: 6 } }, + { code: "a(); { let a = function () {}; }", languageOptions: { ecmaVersion: 6 } }, // object style options { code: "a(); function a() { alert(arguments); }", options: [{ functions: false }] }, - { code: "\"use strict\"; { a(); function a() {} }", options: [{ functions: false }], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { new A(); } class A {};", options: [{ classes: false }], parserOptions: { ecmaVersion: 6 } }, + { code: "\"use strict\"; { a(); function a() {} }", options: [{ functions: false }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { new A(); } class A {};", options: [{ classes: false }], languageOptions: { ecmaVersion: 6 } }, // "variables" option { @@ -60,207 +65,207 @@ ruleTester.run("no-use-before-define", rule, { { code: "var foo = () => bar; var bar;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class C { static { () => foo; let foo; } }", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // Tests related to class definition evaluation. These are not TDZ errors. - { code: "class C extends (class { method() { C; } }) {}", parserOptions: { ecmaVersion: 6 } }, - { code: "(class extends (class { method() { C; } }) {});", parserOptions: { ecmaVersion: 6 } }, - { code: "const C = (class extends (class { method() { C; } }) {});", parserOptions: { ecmaVersion: 6 } }, - { code: "class C extends (class { field = C; }) {}", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class extends (class { field = C; }) {});", parserOptions: { ecmaVersion: 2022 } }, - { code: "const C = (class extends (class { field = C; }) {});", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { [() => C](){} }", parserOptions: { ecmaVersion: 6 } }, - { code: "(class C { [() => C](){} });", parserOptions: { ecmaVersion: 6 } }, - { code: "const C = class { [() => C](){} };", parserOptions: { ecmaVersion: 6 } }, - { code: "class C { static [() => C](){} }", parserOptions: { ecmaVersion: 6 } }, - { code: "(class C { static [() => C](){} });", parserOptions: { ecmaVersion: 6 } }, - { code: "const C = class { static [() => C](){} };", parserOptions: { ecmaVersion: 6 } }, - { code: "class C { [() => C]; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { [() => C]; });", parserOptions: { ecmaVersion: 2022 } }, - { code: "const C = class { [() => C]; };", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static [() => C]; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { static [() => C]; });", parserOptions: { ecmaVersion: 2022 } }, - { code: "const C = class { static [() => C]; };", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { method() { C; } }", parserOptions: { ecmaVersion: 6 } }, - { code: "(class C { method() { C; } });", parserOptions: { ecmaVersion: 6 } }, - { code: "const C = class { method() { C; } };", parserOptions: { ecmaVersion: 6 } }, - { code: "class C { static method() { C; } }", parserOptions: { ecmaVersion: 6 } }, - { code: "(class C { static method() { C; } });", parserOptions: { ecmaVersion: 6 } }, - { code: "const C = class { static method() { C; } };", parserOptions: { ecmaVersion: 6 } }, - { code: "class C { field = C; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { field = C; });", parserOptions: { ecmaVersion: 2022 } }, - { code: "const C = class { field = C; };", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static field = C; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { static field = C; });", parserOptions: { ecmaVersion: 2022 } }, // `const C = class { static field = C; };` is TDZ error - { code: "class C { static field = class { static field = C; }; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { static field = class { static field = C; }; });", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { field = () => C; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { field = () => C; });", parserOptions: { ecmaVersion: 2022 } }, - { code: "const C = class { field = () => C; };", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static field = () => C; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { static field = () => C; });", parserOptions: { ecmaVersion: 2022 } }, - { code: "const C = class { static field = () => C; };", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { field = class extends C {}; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { field = class extends C {}; });", parserOptions: { ecmaVersion: 2022 } }, - { code: "const C = class { field = class extends C {}; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static field = class extends C {}; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { static field = class extends C {}; });", parserOptions: { ecmaVersion: 2022 } }, // `const C = class { static field = class extends C {}; };` is TDZ error - { code: "class C { static field = class { [C]; }; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "(class C { static field = class { [C]; }; });", parserOptions: { ecmaVersion: 2022 } }, // `const C = class { static field = class { [C]; } };` is TDZ error - { code: "const C = class { static field = class { field = C; }; };", parserOptions: { ecmaVersion: 2022 } }, + { code: "class C extends (class { method() { C; } }) {}", languageOptions: { ecmaVersion: 6 } }, + { code: "(class extends (class { method() { C; } }) {});", languageOptions: { ecmaVersion: 6 } }, + { code: "const C = (class extends (class { method() { C; } }) {});", languageOptions: { ecmaVersion: 6 } }, + { code: "class C extends (class { field = C; }) {}", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class extends (class { field = C; }) {});", languageOptions: { ecmaVersion: 2022 } }, + { code: "const C = (class extends (class { field = C; }) {});", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { [() => C](){} }", languageOptions: { ecmaVersion: 6 } }, + { code: "(class C { [() => C](){} });", languageOptions: { ecmaVersion: 6 } }, + { code: "const C = class { [() => C](){} };", languageOptions: { ecmaVersion: 6 } }, + { code: "class C { static [() => C](){} }", languageOptions: { ecmaVersion: 6 } }, + { code: "(class C { static [() => C](){} });", languageOptions: { ecmaVersion: 6 } }, + { code: "const C = class { static [() => C](){} };", languageOptions: { ecmaVersion: 6 } }, + { code: "class C { [() => C]; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { [() => C]; });", languageOptions: { ecmaVersion: 2022 } }, + { code: "const C = class { [() => C]; };", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static [() => C]; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { static [() => C]; });", languageOptions: { ecmaVersion: 2022 } }, + { code: "const C = class { static [() => C]; };", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { method() { C; } }", languageOptions: { ecmaVersion: 6 } }, + { code: "(class C { method() { C; } });", languageOptions: { ecmaVersion: 6 } }, + { code: "const C = class { method() { C; } };", languageOptions: { ecmaVersion: 6 } }, + { code: "class C { static method() { C; } }", languageOptions: { ecmaVersion: 6 } }, + { code: "(class C { static method() { C; } });", languageOptions: { ecmaVersion: 6 } }, + { code: "const C = class { static method() { C; } };", languageOptions: { ecmaVersion: 6 } }, + { code: "class C { field = C; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { field = C; });", languageOptions: { ecmaVersion: 2022 } }, + { code: "const C = class { field = C; };", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static field = C; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { static field = C; });", languageOptions: { ecmaVersion: 2022 } }, // `const C = class { static field = C; };` is TDZ error + { code: "class C { static field = class { static field = C; }; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { static field = class { static field = C; }; });", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { field = () => C; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { field = () => C; });", languageOptions: { ecmaVersion: 2022 } }, + { code: "const C = class { field = () => C; };", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static field = () => C; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { static field = () => C; });", languageOptions: { ecmaVersion: 2022 } }, + { code: "const C = class { static field = () => C; };", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { field = class extends C {}; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { field = class extends C {}; });", languageOptions: { ecmaVersion: 2022 } }, + { code: "const C = class { field = class extends C {}; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static field = class extends C {}; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { static field = class extends C {}; });", languageOptions: { ecmaVersion: 2022 } }, // `const C = class { static field = class extends C {}; };` is TDZ error + { code: "class C { static field = class { [C]; }; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "(class C { static field = class { [C]; }; });", languageOptions: { ecmaVersion: 2022 } }, // `const C = class { static field = class { [C]; } };` is TDZ error + { code: "const C = class { static field = class { field = C; }; };", languageOptions: { ecmaVersion: 2022 } }, { code: "class C { method() { a; } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class C { static method() { a; } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class C { field = a; } let a;", // `class C { static field = a; } let a;` is TDZ error options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { field = D; } class D {}", // `class C { static field = D; } class D {}` is TDZ error options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { field = class extends D {}; } class D {}", // `class C { static field = class extends D {}; } class D {}` is TDZ error options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { field = () => a; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = () => a; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { field = () => D; } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = () => D; } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = class { field = a; }; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { C; } }", // `const C = class { static { C; } }` is TDZ error - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { C; } static {} static { C; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "(class C { static { C; } })", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { class D extends C {} } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { (class { static { C } }) } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { () => C; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "(class C { static { () => C; } })", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static { () => C; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { () => D; } } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { () => a; } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class C { static { C.x; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // "allowNamedExports" option { code: "export { a }; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a as b }; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a, b }; let a, b;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a }; var a;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { f }; function f() {}", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { C }; class C {}", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" } + languageOptions: { ecmaVersion: 2015, sourceType: "module" } } ], invalid: [ { code: "a++; var a=19;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "a++; var a=19;", - parserOptions: { parserOptions: { ecmaVersion: 6 } }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "a++; var a=19;", @@ -312,21 +317,21 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "(() => { alert(a); var a = 42; })();", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(() => a())(); function a() { }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "\"use strict\"; a(); { function a() {} }", @@ -346,95 +351,95 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var f = () => a; var a;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "new A(); class A {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { new A(); } class A {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "new A(); var A = class {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { new A(); } var A = class {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, // Block-level bindings { code: "a++; { var a; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "\"use strict\"; { a(); function a() {} }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{a; let a = 1}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "switch (foo) { case 1: a();\n default: \n let a;}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "if (true) { function foo() { a; } let a;}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, // object style options @@ -450,32 +455,32 @@ ruleTester.run("no-use-before-define", rule, { { code: "new A(); class A {};", options: [{ functions: false, classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "new A(); var A = class {};", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { new A(); } var A = class {};", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, // invalid initializers @@ -489,84 +494,84 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "let a = a + b;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = foo(a);", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a = a) {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a = a} = [];", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a = a] = [];", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {b = a, a} = {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [b = a, a] = {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a = 0} = a;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var [a = 0] = a;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "for (var a in a) {}", @@ -578,12 +583,12 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "for (var a of a) {}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }] + }], + languageOptions: { ecmaVersion: 6 } }, // "variables" option @@ -609,520 +614,520 @@ ruleTester.run("no-use-before-define", rule, { // https://github.com/eslint/eslint/issues/10227 { code: "for (let x = x;;); let x = 0", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "for (let x in xs); let xs = []", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "xs" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "for (let x of xs); let xs = []", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "xs" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "try {} catch ({message = x}) {} let x = ''", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "with (obj) x; let x = {}", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, // WithStatements. { code: "with (x); let x = {}", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "with (obj) { x } let x = {}", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "with (obj) { if (a) { x } } let x = {}", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "with (obj) { (() => { if (a) { x } })() } let x = {}", - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }] + }], + languageOptions: { ecmaVersion: 2015 } }, // Tests related to class definition evaluation. These are TDZ errors. { code: "class C extends C {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const C = class extends C {};", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C extends (class { [C](){} }) {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const C = class extends (class { [C](){} }) {};", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C extends (class { static field = C; }) {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class extends (class { static field = C; }) {};", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [C](){} }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(class C { [C](){} });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const C = class { [C](){} };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C { static [C](){} }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "(class C { static [C](){} });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const C = class { static [C](){} };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C { [C]; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class C { [C]; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { [C]; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [C] = foo; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class C { [C] = foo; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { [C] = foo; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static [C]; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class C { static [C]; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static [C]; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static [C] = foo; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "(class C { static [C] = foo; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static [C] = foo; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static field = C; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static field = class extends C {}; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static field = class { [C]; } };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static field = class { static field = C; }; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C extends D {} class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C extends (class { [a](){} }) {} let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C extends (class { static field = a; }) {} let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [a]() {} } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C { static [a]() {} } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C { [a]; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static [a]; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [a] = foo; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static [a] = foo; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = a; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = D; } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = class extends D {}; } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = class { [a](){} } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static field = class { static field = a; }; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static { C; } };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "const C = class { static { (class extends C {}); } };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a; } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { D; } } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { (class extends D {}); } } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { (class { [a](){} }); } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { (class { static field = a; }); } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, /* @@ -1130,7 +1135,7 @@ ruleTester.run("no-use-before-define", rule, { * { * code: "(class C extends C {});", * options: [{ classes: false }], - * parserOptions: { ecmaVersion: 6 }, + * languageOptions: { ecmaVersion: 6 }, * errors: [{ * messageId: "usedBeforeDefined", * data: { name: "C" } @@ -1139,7 +1144,7 @@ ruleTester.run("no-use-before-define", rule, { * { * code: "(class C extends (class { [C](){} }) {});", * options: [{ classes: false }], - * parserOptions: { ecmaVersion: 6 }, + * languageOptions: { ecmaVersion: 6 }, * errors: [{ * messageId: "usedBeforeDefined", * data: { name: "C" } @@ -1148,7 +1153,7 @@ ruleTester.run("no-use-before-define", rule, { * { * code: "(class C extends (class { static field = C; }) {});", * options: [{ classes: false }], - * parserOptions: { ecmaVersion: 2022 }, + * languageOptions: { ecmaVersion: 2022 }, * errors: [{ * messageId: "usedBeforeDefined", * data: { name: "C" } @@ -1159,50 +1164,49 @@ ruleTester.run("no-use-before-define", rule, { // "allowNamedExports" option { code: "export { a }; const a = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a }; const a = 1;", options: [{}], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a }; const a = 1;", options: [{ allowNamedExports: false }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a }; const a = 1;", options: ["nofunc"], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a as b }; const a = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a, b }; let a, b;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [ { messageId: "usedBeforeDefined", @@ -1212,67 +1216,68 @@ ruleTester.run("no-use-before-define", rule, { messageId: "usedBeforeDefined", data: { name: "b" } } - ] + ], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { a }; var a;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { f }; function f() {}", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "f" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export { C }; class C {}", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export const foo = a; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export default a; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export function foo() { return a; }; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } }, { code: "export class C { foo() { return a; } }; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }] + }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" } } ] }); diff --git a/tests/lib/rules/no-useless-backreference.js b/tests/lib/rules/no-useless-backreference.js index 3db83c65a4e..e59ea537ff9 100644 --- a/tests/lib/rules/no-useless-backreference.js +++ b/tests/lib/rules/no-useless-backreference.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-backreference"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2018, sourceType: "script" } }); ruleTester.run("no-useless-backreference", rule, { valid: [ @@ -42,7 +42,9 @@ ruleTester.run("no-useless-backreference", rule, { String.raw`/* globals RegExp:off */ new RegExp('\\1(a)');`, { code: String.raw`RegExp('\\1(a)');`, - globals: { RegExp: "off" } + languageOptions: { + globals: { RegExp: "off" } + } }, // no capturing groups diff --git a/tests/lib/rules/no-useless-call.js b/tests/lib/rules/no-useless-call.js index 43f9b7d71ea..2366c921d30 100644 --- a/tests/lib/rules/no-useless-call.js +++ b/tests/lib/rules/no-useless-call.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-call"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -49,13 +49,13 @@ ruleTester.run("no-useless-call", rule, { // Optional chaining { code: "obj?.foo.bar.call(obj.foo, 1, 2);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // Private members { code: "class C { #call; wrap(foo) { foo.#call(undefined, 1, 2); } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -187,81 +187,81 @@ ruleTester.run("no-useless-call", rule, { // Optional chaining { code: "foo.call?.(undefined, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] + errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.call(undefined, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] + errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.call)(undefined, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] + errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj.foo.call?.(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.foo.call(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.foo).call(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.foo.call)(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.foo.bar.call(obj?.foo, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(obj?.foo).bar.call(obj?.foo, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj.foo?.bar.call(obj.foo, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }] + }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-useless-catch.js b/tests/lib/rules/no-useless-catch.js index a8b7e342279..dff492c72ba 100644 --- a/tests/lib/rules/no-useless-catch.js +++ b/tests/lib/rules/no-useless-catch.js @@ -11,7 +11,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-catch"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -79,7 +79,7 @@ ruleTester.run("no-useless-catch", rule, { throw err; } `, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -89,7 +89,7 @@ ruleTester.run("no-useless-catch", rule, { throw err; } `, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -102,7 +102,7 @@ ruleTester.run("no-useless-catch", rule, { } } `, - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: ` @@ -112,7 +112,7 @@ ruleTester.run("no-useless-catch", rule, { throw new Error('foo'); } `, - parserOptions: { ecmaVersion: 2019 } + languageOptions: { ecmaVersion: 2019 } } ], @@ -185,11 +185,11 @@ ruleTester.run("no-useless-catch", rule, { } } `, - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessaryCatch", type: "TryStatement" - }] + }], + languageOptions: { ecmaVersion: 8 } } ] }); diff --git a/tests/lib/rules/no-useless-computed-key.js b/tests/lib/rules/no-useless-computed-key.js index 37f31118878..3a112d0de82 100644 --- a/tests/lib/rules/no-useless-computed-key.js +++ b/tests/lib/rules/no-useless-computed-key.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-computed-key"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("no-useless-computed-key", rule, { valid: [ @@ -52,7 +52,7 @@ ruleTester.run("no-useless-computed-key", rule, { */ { code: "({ [99999999999999999n]: 0 })", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } } ], invalid: [ @@ -131,12 +131,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async ['x']() {} })", output: "({ async 'x'() {} })", - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "'x'" }, type: "Property" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "({ get[.2]() {} })", output: "({ get.2() {} })", @@ -156,12 +156,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async[.2]() {} })", output: "({ async.2() {} })", - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: ".2" }, type: "Property" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "({ [2]() {} })", output: "({ 2() {} })", @@ -189,12 +189,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async [2]() {} })", output: "({ async 2() {} })", - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "Property" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "({ get[2]() {} })", output: "({ get 2() {} })", @@ -214,12 +214,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async[2]() {} })", output: "({ async 2() {} })", - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "Property" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "({ get['foo']() {} })", output: "({ get'foo'() {} })", @@ -327,12 +327,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async ['x']() {} }", output: "class Foo { async 'x'() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "'x'" }, type: "MethodDefinition" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "class Foo { get[.2]() {} }", output: "class Foo { get.2() {} }", @@ -355,12 +355,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async[.2]() {} }", output: "class Foo { async.2() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: ".2" }, type: "MethodDefinition" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "class Foo { [2]() {} }", output: "class Foo { 2() {} }", @@ -392,12 +392,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async [2]() {} }", output: "class Foo { async 2() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "MethodDefinition" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "class Foo { get[2]() {} }", output: "class Foo { get 2() {} }", @@ -420,12 +420,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async[2]() {} }", output: "class Foo { async 2() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "MethodDefinition" - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "class Foo { get['foo']() {} }", output: "class Foo { get'foo'() {} }", diff --git a/tests/lib/rules/no-useless-concat.js b/tests/lib/rules/no-useless-concat.js index f19a1965673..6b917dd7e1e 100644 --- a/tests/lib/rules/no-useless-concat.js +++ b/tests/lib/rules/no-useless-concat.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-concat"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ @@ -32,9 +32,9 @@ ruleTester.run("no-useless-concat", rule, { "var string = (number + 1) + 'px';", "'a' + 1", "1 + '1'", - { code: "1 + `1`", parserOptions: { ecmaVersion: 6 } }, - { code: "`1` + 1", parserOptions: { ecmaVersion: 6 } }, - { code: "(1 + +2) + `b`", parserOptions: { ecmaVersion: 6 } } + { code: "1 + `1`", languageOptions: { ecmaVersion: 6 } }, + { code: "`1` + 1", languageOptions: { ecmaVersion: 6 } }, + { code: "(1 + +2) + `b`", languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -96,24 +96,24 @@ ruleTester.run("no-useless-concat", rule, { }, { code: "`a` + 'b'", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "`a` + `b`", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo + `a` + `b`", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } - ] + ], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/no-useless-constructor.js b/tests/lib/rules/no-useless-constructor.js index e42a6b267e8..6602f8b49d3 100644 --- a/tests/lib/rules/no-useless-constructor.js +++ b/tests/lib/rules/no-useless-constructor.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-constructor"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); const error = { messageId: "noUselessConstructor", type: "MethodDefinition" }; ruleTester.run("no-useless-constructor", rule, { @@ -39,7 +39,9 @@ ruleTester.run("no-useless-constructor", rule, { "class A extends B { constructor(foo, bar) { super(bar); } }", { code: "declare class A { constructor(options: any); }", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/declare-class") + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/declare-class") + } } ], invalid: [ diff --git a/tests/lib/rules/no-useless-escape.js b/tests/lib/rules/no-useless-escape.js index 3130d52a0aa..c6d50a2a157 100644 --- a/tests/lib/rules/no-useless-escape.js +++ b/tests/lib/rules/no-useless-escape.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-escape"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-useless-escape", rule, { valid: [ @@ -50,42 +55,42 @@ ruleTester.run("no-useless-escape", rule, { "var foo = '\\f';", "var foo = '\\\n';", "var foo = '\\\r\n';", - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
Testing: \\
", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "
Testing: \
", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "<> Testing: \\ ", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "<> Testing: \ ", parserOptions: { ecmaFeatures: { jsx: true } } }, - { code: "var foo = `\\x123`", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\u00a9`", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `xs\\u2111`", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `foo \\\\ bar`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\t`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `foo \\b bar`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\n`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `foo \\r bar`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\v`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\f`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\\n`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\\r\n`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo} \\x123`", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo} \\u00a9`", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo} xs\\u2111`", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo} \\\\ ${bar}`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo} \\b ${bar}`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo}\\t`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo}\\n`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo}\\r`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo}\\v`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo}\\f`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo}\\\n`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `${foo}\\\r\n`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\``", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\`${foo}\\``", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\\${{${foo}`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `$\\{{${foo}`;", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = String.raw`\\.`", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = myFunc`\\.`", parserOptions: { ecmaVersion: 6 } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
Testing: \\
", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "
Testing: \
", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "<> Testing: \\ ", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "<> Testing: \ ", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo = `\\x123`", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\u00a9`", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `xs\\u2111`", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `foo \\\\ bar`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\t`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `foo \\b bar`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\n`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `foo \\r bar`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\v`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\f`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\\n`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\\r\n`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo} \\x123`", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo} \\u00a9`", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo} xs\\u2111`", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo} \\\\ ${bar}`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo} \\b ${bar}`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo}\\t`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo}\\n`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo}\\r`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo}\\v`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo}\\f`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo}\\\n`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `${foo}\\\r\n`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\``", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\`${foo}\\``", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\\${{${foo}`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `$\\{{${foo}`;", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = String.raw`\\.`", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = myFunc`\\.`", languageOptions: { ecmaVersion: 6 } }, String.raw`var foo = /[\d]/`, String.raw`var foo = /[a\-b]/`, @@ -116,76 +121,76 @@ ruleTester.run("no-useless-escape", rule, { // https://github.com/eslint/eslint/issues/7789 String.raw`/]/`, String.raw`/\]/`, - { code: String.raw`/\]/u`, parserOptions: { ecmaVersion: 6 } }, + { code: String.raw`/\]/u`, languageOptions: { ecmaVersion: 6 } }, String.raw`var foo = /foo\]/`, String.raw`var foo = /[[]\]/`, // A character class containing '[', followed by a ']' character String.raw`var foo = /\[foo\.bar\]/`, // ES2018 - { code: String.raw`var foo = /(?
)\k/`, parserOptions: { ecmaVersion: 2018 } }, - { code: String.raw`var foo = /(\\?)/`, parserOptions: { ecmaVersion: 2018 } }, - { code: String.raw`var foo = /\p{ASCII}/u`, parserOptions: { ecmaVersion: 2018 } }, - { code: String.raw`var foo = /\P{ASCII}/u`, parserOptions: { ecmaVersion: 2018 } }, - { code: String.raw`var foo = /[\p{ASCII}]/u`, parserOptions: { ecmaVersion: 2018 } }, - { code: String.raw`var foo = /[\P{ASCII}]/u`, parserOptions: { ecmaVersion: 2018 } }, + { code: String.raw`var foo = /(?)\k/`, languageOptions: { ecmaVersion: 2018 } }, + { code: String.raw`var foo = /(\\?)/`, languageOptions: { ecmaVersion: 2018 } }, + { code: String.raw`var foo = /\p{ASCII}/u`, languageOptions: { ecmaVersion: 2018 } }, + { code: String.raw`var foo = /\P{ASCII}/u`, languageOptions: { ecmaVersion: 2018 } }, + { code: String.raw`var foo = /[\p{ASCII}]/u`, languageOptions: { ecmaVersion: 2018 } }, + { code: String.raw`var foo = /[\P{ASCII}]/u`, languageOptions: { ecmaVersion: 2018 } }, // Carets String.raw`/[^^]/`, - { code: String.raw`/[^^]/u`, parserOptions: { ecmaVersion: 2015 } }, + { code: String.raw`/[^^]/u`, languageOptions: { ecmaVersion: 2015 } }, // ES2024 - { code: String.raw`/[\q{abc}]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\(]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\)]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\{]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\]]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\}]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\/]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\-]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\|]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\$$]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\&&]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\!!]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\##]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\%%]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\**]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\++]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\,,]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\..]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\::]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\;;]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\<<]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\==]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\>>]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\??]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\@@]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: "/[\\``]/v", parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\~~]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[^\^^]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[_\^^]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[$\$]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[&\&]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[!\!]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[#\#]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[%\%]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[*\*]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[+\+]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[,\,]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[.\.]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[:\:]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[;\;]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[<\<]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[=\=]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[>\>]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[?\?]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[@\@]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: "/[`\\`]/v", parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[~\~]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[^^\^]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[_^\^]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\&&&\&]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[[\-]\-]/v`, parserOptions: { ecmaVersion: 2024 } }, - { code: String.raw`/[\^]/v`, parserOptions: { ecmaVersion: 2024 } } + { code: String.raw`/[\q{abc}]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\(]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\)]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\{]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\]]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\}]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\/]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\-]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\|]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\$$]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\&&]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\!!]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\##]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\%%]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\**]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\++]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\,,]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\..]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\::]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\;;]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\<<]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\==]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\>>]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\??]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\@@]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: "/[\\``]/v", languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\~~]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[^\^^]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[_\^^]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[$\$]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[&\&]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[!\!]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[#\#]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[%\%]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[*\*]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[+\+]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[,\,]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[.\.]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[:\:]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[;\;]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[<\<]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[=\=]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[>\>]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[?\?]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[@\@]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: "/[`\\`]/v", languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[~\~]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[^^\^]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[_^\^]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\&&&\&]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[[\-]\-]/v`, languageOptions: { ecmaVersion: 2024 } }, + { code: String.raw`/[\^]/v`, languageOptions: { ecmaVersion: 2024 } } ], invalid: [ @@ -442,7 +447,6 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "", - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [{ line: 1, column: 13, @@ -456,7 +460,8 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "" }] - }] + }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var foo = '\\`';", @@ -477,7 +482,6 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\\"`;", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -491,11 +495,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\\"`;" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `\\'`;", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -509,11 +513,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\'`;" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `\\#`;", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -527,7 +531,8 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\#`;" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = '\\`foo\\`';", @@ -564,7 +569,6 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\\"${foo}\\\"`;", - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -594,11 +598,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\\"${foo}\\\\\"`;" }] } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `\\'${foo}\\'`;", - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -628,11 +632,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\'${foo}\\\\'`;" }] } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `\\#${foo}`;", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -646,11 +650,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\#${foo}`;" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let foo = '\\ ';", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -664,11 +668,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "let foo = '\\\\ ';" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let foo = /\\ /;", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -682,11 +686,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "let foo = /\\\\ /;" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `\\$\\{{${foo}`;", - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -702,11 +706,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\\\$\\{{${foo}`;" }] } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `\\$a${foo}`;", - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -722,11 +726,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\\\$a${foo}`;" }] } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `a\\{{${foo}`;", - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -742,7 +746,8 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `a\\\\{{${foo}`;" }] } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: String.raw`var foo = /[ab\-]/`, @@ -1001,7 +1006,6 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`multiline template\nliteral with useless \\escape`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 22, @@ -1015,11 +1019,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`multiline template\nliteral with useless \\\\escape`" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`multiline template\r\nliteral with useless \\escape`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 22, @@ -1033,11 +1037,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`multiline template\r\nliteral with useless \\\\escape`" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`template literal with line continuation \\\nand useless \\escape`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 13, @@ -1051,11 +1055,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with line continuation \\\nand useless \\\\escape`" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`template literal with line continuation \\\r\nand useless \\escape`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 13, @@ -1069,11 +1073,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with line continuation \\\r\nand useless \\\\escape`" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`template literal with mixed linebreaks \r\r\n\n\\and useless escape`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, @@ -1087,11 +1091,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with mixed linebreaks \r\r\n\n\\\\and useless escape`" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`template literal with mixed linebreaks in line continuations \\\n\\\r\\\r\n\\and useless escape`", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, @@ -1105,11 +1109,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with mixed linebreaks in line continuations \\\n\\\r\\\r\n\\\\and useless escape`" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "`\\a```", - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 2, @@ -1123,7 +1127,8 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`\\\\a```" }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/16988 @@ -1146,7 +1151,6 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`({ foo() { "foo"; "bar"; "ba\z" } })`, - parserOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 29, @@ -1160,7 +1164,8 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: String.raw`({ foo() { "foo"; "bar"; "ba\\z" } })` }] - }] + }], + languageOptions: { ecmaVersion: 6 } }, // Carets @@ -1185,7 +1190,6 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[^\^]/u`, - parserOptions: { ecmaVersion: 2015 }, errors: [{ line: 1, column: 4, @@ -1201,13 +1205,13 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[^\\^]/u` } ] - }] + }], + languageOptions: { ecmaVersion: 2015 } }, // ES2024 { code: String.raw`/[\$]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1224,11 +1228,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\$]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\&\&]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1244,11 +1248,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\&\&]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\!\!]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1264,11 +1268,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\!\!]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\#\#]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1284,11 +1288,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\#\#]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\%\%]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1304,11 +1308,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\%\%]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\*\*]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1324,11 +1328,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\*\*]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\+\+]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1344,11 +1348,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\+\+]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\,\,]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1364,11 +1368,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\,\,]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\.\.]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1384,11 +1388,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\.\.]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\:\:]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1404,11 +1408,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\:\:]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\;\;]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1424,11 +1428,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\;\;]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\<\<]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1444,11 +1448,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\<\<]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\=\=]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1464,11 +1468,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\=\=]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\>\>]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1484,11 +1488,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\>\>]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\?\?]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1504,11 +1508,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\?\?]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\@\@]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1524,11 +1528,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\@\@]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: "/[\\`\\`]/v", - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1544,11 +1548,11 @@ ruleTester.run("no-useless-escape", rule, { output: "/[\\\\`\\`]/v" } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\~\~]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1564,11 +1568,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\~\~]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[^\^\^]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1584,11 +1588,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[^\\^\^]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[_\^\^]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1604,11 +1608,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[_\\^\^]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\&\&&\&]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1624,11 +1628,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\&\&&\&]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\p{ASCII}--\.]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 14, @@ -1640,11 +1644,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\p{ASCII}--.]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\p{ASCII}&&\.]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 14, @@ -1656,11 +1660,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\p{ASCII}&&.]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\.--[.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1672,11 +1676,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[.--[.&]]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\.&&[.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1688,11 +1692,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[.&&[.&]]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\.--\.--\.]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1726,11 +1730,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\.--\.--.]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[\.&&\.&&\.]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1764,11 +1768,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\.&&\.&&.]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[[\.&]--[\.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1799,11 +1803,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[[\.&]--[\\.&]]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } }, { code: String.raw`/[[\.&]&&[\.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1834,7 +1838,8 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[[\.&]&&[\\.&]]/v` } ] - }] + }], + languageOptions: { ecmaVersion: 2024 } } ] }); diff --git a/tests/lib/rules/no-useless-rename.js b/tests/lib/rules/no-useless-rename.js index 262cf2cc5ac..de9608b3163 100644 --- a/tests/lib/rules/no-useless-rename.js +++ b/tests/lib/rules/no-useless-rename.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-rename"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, sourceType: "module" } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "module" } }); ruleTester.run("no-useless-rename", rule, { valid: [ @@ -49,7 +49,7 @@ ruleTester.run("no-useless-rename", rule, { "import {foo as bar, baz as qux} from 'foo';", { code: "import {'foo' as bar} from 'baz';", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, "export {foo} from 'foo';", "var foo = 0;export {foo as bar};", @@ -58,43 +58,43 @@ ruleTester.run("no-useless-rename", rule, { "export {foo as bar, baz as qux} from 'foo';", { code: "var foo = 0; export {foo as 'bar'};", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "export {foo as 'bar'} from 'baz';", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "export {'foo' as bar} from 'baz';", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "export {'foo' as 'bar'} from 'baz';", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "export {'' as ' '} from 'baz';", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "export {' ' as ''} from 'baz';", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "export {'foo'} from 'bar';", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "const {...stuff} = myObject;", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "const {foo, ...stuff} = myObject;", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "const {foo: bar, ...stuff} = myObject;", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // { ignoreDestructuring: true } @@ -157,7 +157,9 @@ ruleTester.run("no-useless-rename", rule, { */ { code: "const { ...foo } = bar;", - parser: require.resolve("../../fixtures/parsers/babel-eslint10/object-pattern-with-rest-element") + languageOptions: { + parser: require("../../fixtures/parsers/babel-eslint10/object-pattern-with-rest-element") + } } ], @@ -389,23 +391,23 @@ ruleTester.run("no-useless-rename", rule, { { code: "const {foo: foo, ...stuff} = myObject;", output: "const {foo, ...stuff} = myObject;", - parserOptions: { ecmaVersion: 2018 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }], + languageOptions: { ecmaVersion: 2018 } }, { code: "const {foo: foo, bar: baz, ...stuff} = myObject;", output: "const {foo, bar: baz, ...stuff} = myObject;", - parserOptions: { ecmaVersion: 2018 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }], + languageOptions: { ecmaVersion: 2018 } }, { code: "const {foo: foo, bar: bar, ...stuff} = myObject;", output: "const {foo, bar, ...stuff} = myObject;", - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "import {foo as foo} from 'foo';", @@ -415,8 +417,8 @@ ruleTester.run("no-useless-rename", rule, { { code: "import {'foo' as foo} from 'foo';", output: "import {foo} from 'foo';", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "import {\\u0061 as a} from 'foo';", @@ -459,38 +461,38 @@ ruleTester.run("no-useless-rename", rule, { { code: "var foo = 0; export {foo as 'foo'};", output: "var foo = 0; export {foo};", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "export {foo as 'foo'} from 'bar';", output: "export {foo} from 'bar';", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "export {'foo' as foo} from 'bar';", output: "export {'foo'} from 'bar';", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "export {'foo' as 'foo'} from 'bar';", output: "export {'foo'} from 'bar';", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "export {' 👍 ' as ' 👍 '} from 'bar';", output: "export {' 👍 '} from 'bar';", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: " 👍 " } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: " 👍 " } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "export {'' as ''} from 'bar';", output: "export {''} from 'bar';", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "" } }] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "" } }], + languageOptions: { ecmaVersion: 2022 } }, { code: "var a = 0; export {a as \\u0061};", diff --git a/tests/lib/rules/no-var.js b/tests/lib/rules/no-var.js index 26b0a8464f4..cabb2343050 100644 --- a/tests/lib/rules/no-var.js +++ b/tests/lib/rules/no-var.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-var"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "script" } }); ruleTester.run("no-var", rule, { valid: [ @@ -24,11 +24,11 @@ ruleTester.run("no-var", rule, { "let moo = 'car';", { code: "const JOE = 'schmoe';", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "let moo = 'car';", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } } ], @@ -36,222 +36,222 @@ ruleTester.run("no-var", rule, { { code: "var foo = bar;", output: "let foo = bar;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var foo = bar, toast = most;", output: "let foo = bar, toast = most;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var foo = bar; let toast = most;", output: "let foo = bar; let toast = most;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (var a of b) { console.log(a); }", output: "for (let a of b) { console.log(a); }", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (var a in b) { console.log(a); }", output: "for (let a in b) { console.log(a); }", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (let a of b) { var c = 1; console.log(c); }", output: "for (let a of b) { let c = 1; console.log(c); }", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (var i = 0; i < list.length; ++i) { foo(i) }", output: "for (let i = 0; i < list.length; ++i) { foo(i) }", - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (var i = 0, i = 0; false;);", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var i = 0; for (var i = 1; false;); console.log(i);", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" }, { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // Not fix if it's redeclared or it's used from outside of the scope or it's declared on a case chunk. { code: "var a, b, c; var a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a; if (b) { var a; }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "if (foo) { var a, b, c; } a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (var i = 0; i < 10; ++i) {} i;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (var a in obj) {} a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (var a of list) {} a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "switch (a) { case 0: var b = 1 }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // Don't fix if the variable is in a loop and the behavior might change. { code: "for (var a of b) { arr.push(() => a); }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "for (let a of b) { var c; console.log(c); c = 'hello'; }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // https://github.com/eslint/eslint/issues/7950 { code: "var a = a", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var {a = a} = {}", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var {a = b, b} = {}", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var {a, b = a} = {}", output: "let {a, b = a} = {}", - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a = b, b = 1", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a = b; var b = 1", output: "let a = b; var b = 1", - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, /* @@ -261,20 +261,20 @@ ruleTester.run("no-var", rule, { { code: "function foo() { a } var a = 1; foo()", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // https://github.com/eslint/eslint/issues/7961 { code: "if (foo) var bar = 1;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // https://github.com/eslint/eslint/issues/9520 @@ -296,17 +296,20 @@ ruleTester.run("no-var", rule, { { code: "var foo = 1", output: "let foo = 1", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // https://github.com/eslint/eslint/issues/11594 { code: "declare var foo = 2;", output: "declare let foo = 2;", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/declare-var"), - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { + ecmaVersion: 6, + sourceType: "module", + parser: require("../../fixtures/parsers/typescript-parsers/declare-var") + } }, // https://github.com/eslint/eslint/issues/11830 @@ -325,68 +328,68 @@ ruleTester.run("no-var", rule, { { code: "var fx = function (i = 0) { if (i < 5) { return fx(i + 1); } console.log(i); }; fx();", output: "let fx = function (i = 0) { if (i < 5) { return fx(i + 1); } console.log(i); }; fx();", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = function () { foo() };", output: "let foo = function () { foo() };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = () => foo();", output: "let foo = () => foo();", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = (function () { foo(); })();", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = bar(function () { foo(); });", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var bar = foo, foo = function () { foo(); };", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var bar = foo; var foo = function () { foo(); };", output: "let bar = foo; var foo = function () { foo(); };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var { foo = foo } = function () { foo(); };", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var { bar = foo, foo } = function () { foo(); };", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var bar = function () { foo(); }; var foo = function() {};", output: "let bar = function () { foo(); }; var foo = function() {};", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } } ] }); diff --git a/tests/lib/rules/no-void.js b/tests/lib/rules/no-void.js index 2a1ee1d9a4f..5d48c8a5c58 100644 --- a/tests/lib/rules/no-void.js +++ b/tests/lib/rules/no-void.js @@ -9,13 +9,17 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-void"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + sourceType: "script" + } +}); ruleTester.run("no-void", rule, { valid: [ diff --git a/tests/lib/rules/no-warning-comments.js b/tests/lib/rules/no-warning-comments.js index 74122456121..e7249fcf051 100644 --- a/tests/lib/rules/no-warning-comments.js +++ b/tests/lib/rules/no-warning-comments.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-warning-comments"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-whitespace-before-property.js b/tests/lib/rules/no-whitespace-before-property.js index 485588dc9d5..7b2feecfc49 100644 --- a/tests/lib/rules/no-whitespace-before-property.js +++ b/tests/lib/rules/no-whitespace-before-property.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-whitespace-before-property"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -104,39 +104,39 @@ ruleTester.run("no-whitespace-before-property", rule, { // Optional chaining { code: "obj?.prop", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "( obj )?.prop", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj\n ?.prop", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.\n prop", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.[key]", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "( obj )?.[ key ]", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj\n ?.[key]", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?.\n [key]", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "obj\n ?.\n [key]", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } } ], @@ -848,7 +848,8 @@ ruleTester.run("no-whitespace-before-property", rule, { errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }] + }], + languageOptions: { sourceType: "script" } }, { code: "0192 .toExponential()", @@ -856,25 +857,26 @@ ruleTester.run("no-whitespace-before-property", rule, { errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }] + }], + languageOptions: { sourceType: "script" } }, { code: "5_000 .toExponential()", output: null, // Not fixed, - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "5_000_00 .toExponential()", output: null, // Not fixed, - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "5. .toExponential()", @@ -895,11 +897,11 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "5.0_0 .toExponential()", output: "5.0_0.toExponential()", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "0x5 .toExponential()", @@ -912,11 +914,11 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "0x56_78 .toExponential()", output: "0x56_78.toExponential()", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "5e0 .toExponential()", @@ -948,57 +950,58 @@ ruleTester.run("no-whitespace-before-property", rule, { errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }] + }], + languageOptions: { sourceType: "script" } }, // Optional chaining { code: "obj?. prop", output: "obj?.prop", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj ?.prop", output: "obj?.prop", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj?. [key]", output: "obj?.[key]", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj ?.[key]", output: "obj?.[key]", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "5 ?. prop", output: "5?.prop", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "5 ?. [key]", output: "5?.[key]", - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj/* comment */?. prop", output: null, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "obj ?./* comment */prop", output: null, - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/no-with.js b/tests/lib/rules/no-with.js index 947686727ab..6a0383173a5 100644 --- a/tests/lib/rules/no-with.js +++ b/tests/lib/rules/no-with.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-with"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-with", rule, { valid: [ diff --git a/tests/lib/rules/nonblock-statement-body-position.js b/tests/lib/rules/nonblock-statement-body-position.js index b029d9316f8..82e0730ea38 100644 --- a/tests/lib/rules/nonblock-statement-body-position.js +++ b/tests/lib/rules/nonblock-statement-body-position.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/nonblock-statement-body-position"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const EXPECTED_LINEBREAK = { messageId: "expectLinebreak" }; const UNEXPECTED_LINEBREAK = { messageId: "expectNoLinebreak" }; @@ -18,7 +18,7 @@ const UNEXPECTED_LINEBREAK = { messageId: "expectNoLinebreak" }; // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("nonblock-statement-body-position", rule, { diff --git a/tests/lib/rules/object-curly-newline.js b/tests/lib/rules/object-curly-newline.js index 86e95609920..bc29cba3b2b 100644 --- a/tests/lib/rules/object-curly-newline.js +++ b/tests/lib/rules/object-curly-newline.js @@ -11,13 +11,13 @@ const resolvePath = require("path").resolve, rule = require("../../../lib/rules/object-curly-newline"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, sourceType: "module" } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "module" } }); ruleTester.run("object-curly-newline", rule, { valid: [ @@ -87,7 +87,9 @@ ruleTester.run("object-curly-newline", rule, { "} : MyType) {}" ].join("\n"), options: ["always"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline") + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline")) + } }, { code: [ @@ -97,7 +99,9 @@ ruleTester.run("object-curly-newline", rule, { "} : { a : string, b : string }) {}" ].join("\n"), options: ["always"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal") + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal")) + } }, // "never" ------------------------------------------------------------- @@ -137,12 +141,16 @@ ruleTester.run("object-curly-newline", rule, { { code: "function foo({ a, b } : MyType) {}", options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline") + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline")) + } }, { code: "function foo({ a, b } : { a : string, b : string }) {}", options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal") + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal")) + } }, // "multiline" --------------------------------------------------------- @@ -325,14 +333,14 @@ ruleTester.run("object-curly-newline", rule, { "let {} = {a: 1};" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "let {a} = {a: 1};" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -340,7 +348,7 @@ ruleTester.run("object-curly-newline", rule, { "} = {a: 1};" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -349,14 +357,14 @@ ruleTester.run("object-curly-newline", rule, { "} = {a: 1};" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "let {a, b} = {a: 1, b: 1};" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -365,14 +373,14 @@ ruleTester.run("object-curly-newline", rule, { "} = {a: 1, b: 1};" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ "let {k = function() {dosomething();}} = obj;" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -383,7 +391,7 @@ ruleTester.run("object-curly-newline", rule, { "} = obj;" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -398,7 +406,7 @@ ruleTester.run("object-curly-newline", rule, { "b} = {a: 1, b: 1};" ].join("\n"), options: [{ multiline: false, consistent: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // "consistent" and "minProperties" ------------------------------------------ @@ -423,7 +431,7 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ multiline: true, consistent: true, minProperties: 2 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -434,7 +442,7 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ multiline: true, consistent: true, minProperties: 2 }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // "ObjectExpression" and "ObjectPattern" --------------------------------------------- @@ -445,7 +453,7 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ ObjectExpression: "always", ObjectPattern: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // "ImportDeclaration" --------------------------------------------- @@ -682,11 +690,13 @@ ruleTester.run("object-curly-newline", rule, { "} : MyType) {}" ].join("\n"), options: ["always"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline"), errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline")) + } }, { code: "function foo({ a, b } : { a : string, b : string }) {}", @@ -696,11 +706,13 @@ ruleTester.run("object-curly-newline", rule, { "} : { a : string, b : string }) {}" ].join("\n"), options: ["always"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal"), errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal")) + } }, // "never" ------------------------------------------------------------ @@ -808,11 +820,13 @@ ruleTester.run("object-curly-newline", rule, { " b} : MyType) {}" ].join("\n"), options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline"), errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline")) + } }, { code: [ @@ -826,11 +840,13 @@ ruleTester.run("object-curly-newline", rule, { " b} : { a : string, b : string }) {}" ].join("\n"), options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal"), errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal")) + } }, // "multiline" --------------------------------------------------------- @@ -1316,10 +1332,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a} = {a: 1}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1330,10 +1346,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a} = {a: 1}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1344,10 +1360,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a, b} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1358,10 +1374,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a, b} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1375,11 +1391,11 @@ ruleTester.run("object-curly-newline", rule, { "} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 2, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1395,11 +1411,11 @@ ruleTester.run("object-curly-newline", rule, { "} = a;" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1442,10 +1458,10 @@ ruleTester.run("object-curly-newline", rule, { "b} = {a: 1, b: 2};" ].join("\n"), options: [{ multiline: false, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1458,10 +1474,10 @@ ruleTester.run("object-curly-newline", rule, { "b} = {a: 1, b: 2};" ].join("\n"), options: [{ multiline: false, consistent: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // "consistent" and "minProperties" ------------------------------------------ @@ -1494,11 +1510,11 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ multiline: true, consistent: true, minProperties: 2 }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 10, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // "ObjectExpression" and "ObjectPattern" --------------------------------------------- @@ -1514,13 +1530,13 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ ObjectExpression: "always", ObjectPattern: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" }, { line: 3, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 3, column: 16, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // "ImportDeclaration" --------------------------------------------- diff --git a/tests/lib/rules/object-curly-spacing.js b/tests/lib/rules/object-curly-spacing.js index f603832cb37..2e7a126f4ce 100644 --- a/tests/lib/rules/object-curly-spacing.js +++ b/tests/lib/rules/object-curly-spacing.js @@ -10,7 +10,7 @@ const resolvePath = require("path").resolve, rule = require("../../../lib/rules/object-curly-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -30,41 +30,41 @@ ruleTester.run("object-curly-spacing", rule, { { code: "var obj = { //\nfoo:bar };", options: ["always"] }, // always - destructuring - { code: "var { x } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { x, y } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { x,y } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {\nx,y } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {\nx,y\n} = z", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { /**/x/**/ } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { //\nx } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { x = 10, y } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { x: { z }, y } = y", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {\ny,\n} = x", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { y, } = x", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { y: x } = x", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "var { x } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { x, y } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { x,y } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {\nx,y } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {\nx,y\n} = z", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { /**/x/**/ } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { //\nx } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { x = 10, y } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { x: { z }, y } = y", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {\ny,\n} = x", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { y, } = x", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { y: x } = x", options: ["always"], languageOptions: { ecmaVersion: 6 } }, // always - import / export - { code: "import door from 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import * as door from 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { door } from 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {\ndoor } from 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { /**/door/**/ } from 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { //\ndoor } from 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { door } from 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { house, mouse } from 'caravan'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import house, { mouse } from 'caravan'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import door, { house, mouse } from 'caravan'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var door = 0;export { door }", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import 'room'", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { bar as x } from 'foo';", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { x, } from 'foo';", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {\nx,\n} from 'foo';", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { x, } from 'foo';", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {\nx,\n} from 'foo';", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { /**/x/**/ } from 'foo';", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { //\nx } from 'foo';", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var x = 1;\nexport { /**/x/**/ };", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var x = 1;\nexport { //\nx };", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import door from 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import * as door from 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { door } from 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {\ndoor } from 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { /**/door/**/ } from 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { //\ndoor } from 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { door } from 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { house, mouse } from 'caravan'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import house, { mouse } from 'caravan'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import door, { house, mouse } from 'caravan'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var door = 0;export { door }", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import 'room'", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { bar as x } from 'foo';", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { x, } from 'foo';", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {\nx,\n} from 'foo';", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { x, } from 'foo';", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {\nx,\n} from 'foo';", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { /**/x/**/ } from 'foo';", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { //\nx } from 'foo';", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var x = 1;\nexport { /**/x/**/ };", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var x = 1;\nexport { //\nx };", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // always - empty object { code: "var foo = {};", options: ["always"] }, @@ -72,7 +72,7 @@ ruleTester.run("object-curly-spacing", rule, { // always - objectsInObjects { code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", options: ["always", { objectsInObjects: false }] }, { code: "var a = { noop: function () {} };", options: ["always", { objectsInObjects: false }] }, - { code: "var { y: { z }} = x", options: ["always", { objectsInObjects: false }], parserOptions: { ecmaVersion: 6 } }, + { code: "var { y: { z }} = x", options: ["always", { objectsInObjects: false }], languageOptions: { ecmaVersion: 6 } }, // always - arraysInObjects { code: "var obj = { 'foo': [ 1, 2 ]};", options: ["always", { arraysInObjects: false }] }, @@ -100,50 +100,50 @@ ruleTester.run("object-curly-spacing", rule, { { code: "var obj = { // line comment exception\n foo: bar};", options: ["never"] }, // never - destructuring - { code: "var {x} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {x, y} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {x,y} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {\nx,y\n} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {x = 10} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {x = 10, y} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {x: {z}, y} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {\nx: {z\n}, y} = y", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {\ny,\n} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {y,} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {y:x} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {/* */ y} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {y /* */} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {//\n y} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var { // line comment exception\n y} = x", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "var {x} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {x, y} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {x,y} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {\nx,y\n} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {x = 10} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {x = 10, y} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {x: {z}, y} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {\nx: {z\n}, y} = y", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {\ny,\n} = x", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {y,} = x", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {y:x} = x", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {/* */ y} = x", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {y /* */} = x", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {//\n y} = x", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var { // line comment exception\n y} = x", options: ["never"], languageOptions: { ecmaVersion: 6 } }, // never - import / export - { code: "import door from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import * as door from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {/* */ door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {/* */ door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {door /* */} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {door /* */} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {//\n door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {//\n door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var door = foo;\nexport {//\n door}", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { // line comment exception\n door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { // line comment exception\n door} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var door = foo; export { // line comment exception\n door}", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {\ndoor} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {\ndoor\n} from 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {house,mouse} from 'caravan'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {house, mouse} from 'caravan'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var door = 0;export {door}", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import 'room'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import x, {bar} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import x, {bar, baz} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {bar as y} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {x,} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import {\nx,\n} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {x,} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {\nx,\n} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import door from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import * as door from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {/* */ door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {/* */ door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {door /* */} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {door /* */} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {//\n door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {//\n door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var door = foo;\nexport {//\n door}", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { // line comment exception\n door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { // line comment exception\n door} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var door = foo; export { // line comment exception\n door}", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {\ndoor} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {\ndoor\n} from 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {house,mouse} from 'caravan'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {house, mouse} from 'caravan'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var door = 0;export {door}", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import 'room'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import x, {bar} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import x, {bar, baz} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {bar as y} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {x,} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import {\nx,\n} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {x,} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {\nx,\n} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // never - empty object @@ -156,26 +156,28 @@ ruleTester.run("object-curly-spacing", rule, { * https://github.com/eslint/eslint/issues/3658 * Empty cases. */ - { code: "var {} = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var [] = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var {a: {}} = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "var {a: []} = foo;", parserOptions: { ecmaVersion: 6 } }, - { code: "import {} from 'foo';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {} from 'foo';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {};", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var {} = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var [] = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {a: {}} = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var {a: []} = foo;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "import {} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {} from 'foo';", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export {};", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var {} = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var [] = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var {a: {}} = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "var {a: []} = foo;", languageOptions: { ecmaVersion: 6 } }, + { code: "import {} from 'foo';", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {} from 'foo';", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {};", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var {} = foo;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var [] = foo;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {a: {}} = foo;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var {a: []} = foo;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "import {} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {} from 'foo';", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export {};", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // https://github.com/eslint/eslint/issues/6940 { code: "function foo ({a, b}: Props) {\n}", options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-valid") + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-valid")) + } } ], @@ -184,7 +186,6 @@ ruleTester.run("object-curly-spacing", rule, { code: "import {bar} from 'foo.js';", output: "import { bar } from 'foo.js';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -204,13 +205,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 13 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { bar as y} from 'foo.js';", output: "import { bar as y } from 'foo.js';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -221,13 +222,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 19 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {bar as y} from 'foo.js';", output: "import { bar as y } from 'foo.js';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -247,13 +248,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 18 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { bar} from 'foo.js';", output: "import { bar } from 'foo.js';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -264,13 +265,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 14 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import x, { bar} from 'foo';", output: "import x, { bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -282,13 +283,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 17 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import x, { bar/* */} from 'foo';", output: "import x, { bar/* */ } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -299,13 +300,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 22 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import x, {/* */bar } from 'foo';", output: "import x, { /* */bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -316,13 +317,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import x, {//\n bar } from 'foo';", output: "import x, { //\n bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -333,13 +334,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import x, { bar, baz} from 'foo';", output: "import x, { bar, baz } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -351,13 +352,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 22 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import x, {bar} from 'foo';", output: "import x, { bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -378,13 +379,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import x, {bar, baz} from 'foo';", output: "import x, { bar, baz } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -404,13 +405,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 21 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {bar,} from 'foo';", output: "import { bar, } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -431,13 +432,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 14 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { bar, } from 'foo';", output: "import {bar,} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -457,13 +458,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { /* */ bar, /* */ } from 'foo';", output: "import {/* */ bar, /* */} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -483,13 +484,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 27 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var bar = 0;\nexport {bar};", output: "var bar = 0;\nexport { bar };", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -507,13 +508,13 @@ ruleTester.run("object-curly-spacing", rule, { line: 2, column: 12 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var bar = 0;\nexport {/* */ bar /* */};", output: "var bar = 0;\nexport { /* */ bar /* */ };", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -533,13 +534,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 2, endColumn: 25 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var bar = 0;\nexport {//\n bar };", output: "var bar = 0;\nexport { //\n bar };", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -550,13 +551,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 2, endColumn: 9 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var bar = 0;\nexport { /* */ bar /* */ };", output: "var bar = 0;\nexport {/* */ bar /* */};", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -576,7 +577,8 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 2, endColumn: 26 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // always - arraysInObjects @@ -652,7 +654,6 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { a,} = x;", output: "var { a, } = x;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -663,13 +664,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a, } = x;", output: "var {a,} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -680,13 +681,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 9 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -697,13 +698,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 10 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -723,13 +724,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -749,13 +750,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 13 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -775,7 +776,8 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // never-objectsInObjects @@ -1134,7 +1136,6 @@ ruleTester.run("object-curly-spacing", rule, { code: "export const thing = {value: 1 };", output: "export const thing = { value: 1 };", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -1145,7 +1146,8 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 23 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // destructuring @@ -1153,7 +1155,6 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {x, y} = y", output: "var { x, y } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1173,13 +1174,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { x, y} = y", output: "var { x, y } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1190,13 +1191,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { x, y/* */} = y", output: "var { x, y/* */ } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1207,13 +1208,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 17 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {/* */x, y } = y", output: "var { /* */x, y } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1224,13 +1225,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 6 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {//\n x } = y", output: "var { //\n x } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1241,13 +1242,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 6 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { x, y } = y", output: "var {x, y} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1267,13 +1268,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {x, y } = y", output: "var {x, y} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1284,13 +1285,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {x, y/* */ } = y", output: "var {x, y/* */} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1301,13 +1302,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { /* */x, y} = y", output: "var {/* */x, y} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1318,13 +1319,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 7 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var { x=10} = y", output: "var { x=10 } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1335,13 +1336,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var {x=10 } = y", output: "var { x=10 } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1352,7 +1353,8 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 6 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // never - arraysInObjects @@ -1394,7 +1396,6 @@ ruleTester.run("object-curly-spacing", rule, { code: "function foo ({a, b }: Props) {\n}", output: "function foo ({a, b}: Props) {\n}", options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid"), errors: [ { messageId: "unexpectedSpaceBefore", @@ -1405,7 +1406,10 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 21 } - ] + ], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid")) + } } ] }); diff --git a/tests/lib/rules/object-property-newline.js b/tests/lib/rules/object-property-newline.js index e6499b9d7d7..0802956c984 100644 --- a/tests/lib/rules/object-property-newline.js +++ b/tests/lib/rules/object-property-newline.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/object-property-newline"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -30,19 +30,19 @@ ruleTester.run("object-property-newline", rule, { "var obj = { k1: 'val1' };", "var obj = {\nk1: 'val1'\n};", "var obj = {};", - { code: "var obj = {\n[bar]: 'baz',\nbaz\n};", parserOptions: { ecmaVersion: 6 } }, - { code: "var obj = {\nk1: 'val1',\nk2: 'val2',\n...{}\n};", parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = { k1: 'val1',\nk2: 'val2',\n...{} };", parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = { ...{} };", parserOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {\n[bar]: 'baz',\nbaz\n};", languageOptions: { ecmaVersion: 6 } }, + { code: "var obj = {\nk1: 'val1',\nk2: 'val2',\n...{}\n};", languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = { k1: 'val1',\nk2: 'val2',\n...{} };", languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = { ...{} };", languageOptions: { ecmaVersion: 2018 } }, "foo({ k1: 'val1',\nk2: 'val2' });", "foo({\nk1: 'val1',\nk2: 'val2'\n});", - { code: "foo({\na,\nb\n});", parserOptions: { ecmaVersion: 6 } }, - { code: "foo({\na,\nb,\n});", parserOptions: { ecmaVersion: 6 } }, - { code: "foo({\nbar() {},\nbaz\n});", parserOptions: { ecmaVersion: 6 } }, - { code: "foo({\n[bar]: 'baz',\nbaz \n})", parserOptions: { ecmaVersion: 6 } }, - { code: "foo({\nk1: 'val1',\nk2: 'val2',\n...{}\n});", parserOptions: { ecmaVersion: 2018 } }, - { code: "foo({ k1: 'val1',\nk2: 'val2',\n...{} });", parserOptions: { ecmaVersion: 2018 } }, - { code: "foo({ ...{} });", parserOptions: { ecmaVersion: 2018 } }, + { code: "foo({\na,\nb\n});", languageOptions: { ecmaVersion: 6 } }, + { code: "foo({\na,\nb,\n});", languageOptions: { ecmaVersion: 6 } }, + { code: "foo({\nbar() {},\nbaz\n});", languageOptions: { ecmaVersion: 6 } }, + { code: "foo({\n[bar]: 'baz',\nbaz \n})", languageOptions: { ecmaVersion: 6 } }, + { code: "foo({\nk1: 'val1',\nk2: 'val2',\n...{}\n});", languageOptions: { ecmaVersion: 2018 } }, + { code: "foo({ k1: 'val1',\nk2: 'val2',\n...{} });", languageOptions: { ecmaVersion: 2018 } }, + { code: "foo({ ...{} });", languageOptions: { ecmaVersion: 2018 } }, // allowAllPropertiesOnSameLine: true { code: "var obj = { k1: 'val1', k2: 'val2', k3: 'val3' };", options: [{ allowAllPropertiesOnSameLine: true }] }, @@ -50,15 +50,15 @@ ruleTester.run("object-property-newline", rule, { { code: "var obj = { k1: 'val1' };", options: [{ allowAllPropertiesOnSameLine: true }] }, { code: "var obj = {\nk1: 'val1'\n};", options: [{ allowAllPropertiesOnSameLine: true }] }, { code: "var obj = {};", options: [{ allowAllPropertiesOnSameLine: true }] }, - { code: "var obj = { 'k1': 'val1', k2: 'val2', ...{} };", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {\n'k1': 'val1', k2: 'val2', ...{}\n};", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } }, + { code: "var obj = { 'k1': 'val1', k2: 'val2', ...{} };", options: [{ allowAllPropertiesOnSameLine: true }], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {\n'k1': 'val1', k2: 'val2', ...{}\n};", options: [{ allowAllPropertiesOnSameLine: true }], languageOptions: { ecmaVersion: 2018 } }, { code: "foo({ k1: 'val1', k2: 'val2' });", options: [{ allowAllPropertiesOnSameLine: true }] }, { code: "foo({\nk1: 'val1', k2: 'val2'\n});", options: [{ allowAllPropertiesOnSameLine: true }] }, - { code: "foo({ a, b });", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "foo({ bar() {}, baz });", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "foo({ [bar]: 'baz', baz })", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "foo({ 'k1': 'val1', k2: 'val2', ...{} });", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } }, - { code: "foo({\n'k1': 'val1', k2: 'val2', ...{}\n});", options: [{ allowAllPropertiesOnSameLine: true }], parserOptions: { ecmaVersion: 2018 } }, + { code: "foo({ a, b });", options: [{ allowAllPropertiesOnSameLine: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo({ bar() {}, baz });", options: [{ allowAllPropertiesOnSameLine: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo({ [bar]: 'baz', baz })", options: [{ allowAllPropertiesOnSameLine: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo({ 'k1': 'val1', k2: 'val2', ...{} });", options: [{ allowAllPropertiesOnSameLine: true }], languageOptions: { ecmaVersion: 2018 } }, + { code: "foo({\n'k1': 'val1', k2: 'val2', ...{}\n});", options: [{ allowAllPropertiesOnSameLine: true }], languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {k1: ['foo', 'bar'], k2: 'val1', k3: 'val2'};", options: [{ allowAllPropertiesOnSameLine: true }] }, { code: "var obj = {\nk1: ['foo', 'bar'], k2: 'val1', k3: 'val2'\n};", options: [{ allowAllPropertiesOnSameLine: true }] }, { code: "var obj = {\nk1: 'val1', k2: {e1: 'foo', e2: 'bar'}, k3: 'val2'\n};", options: [{ allowAllPropertiesOnSameLine: true }] }, @@ -231,7 +231,6 @@ ruleTester.run("object-property-newline", rule, { { code: "var obj = { k1: 'val1', [\nk2]: 'val2' };", output: "var obj = { k1: 'val1',\n[\nk2]: 'val2' };", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -241,12 +240,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 26 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var obj = { k1: 'val1', ...{} };", output: "var obj = { k1: 'val1',\n...{} };", - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -256,12 +255,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 28 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {\nk1: 'val1', ...{}\n};", output: "var obj = {\nk1: 'val1',\n...{}\n};", - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -271,7 +270,8 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "foo({ k1: 'val1', k2: 'val2' });", @@ -304,7 +304,6 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({ a, b });", output: "foo({ a,\nb });", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -314,12 +313,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 11 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo({\na, b\n});", output: "foo({\na,\nb\n});", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -329,12 +328,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 5 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo({\nbar() {}, baz\n});", output: "foo({\nbar() {},\nbaz\n});", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -344,12 +343,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo({\n[bar]: 'baz', baz\n})", output: "foo({\n[bar]: 'baz',\nbaz\n})", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -359,12 +358,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 18 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo({ k1: 'val1', [\nk2]: 'val2' })", output: "foo({ k1: 'val1',\n[\nk2]: 'val2' })", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -374,12 +373,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 20 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo({ k1: 'val1', ...{} })", output: "foo({ k1: 'val1',\n...{} })", - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -389,12 +388,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 22 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "foo({\nk1: 'val1', ...{}\n})", output: "foo({\nk1: 'val1',\n...{}\n})", - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -404,7 +403,8 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {\na: {\nb: 1,\nc: 2\n}, d: 2\n};", @@ -560,7 +560,6 @@ ruleTester.run("object-property-newline", rule, { code: "var obj = { [\nk1]: 'val1', k2: 'val2' };", output: "var obj = { [\nk1]: 'val1',\nk2: 'val2' };", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -570,13 +569,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {\nk1: 'val1',\nk2: 'val2', ...{}\n};", output: "var obj = {\nk1: 'val1',\nk2: 'val2',\n...{}\n};", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -586,13 +585,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {\n...{},\nk1: 'val1', k2: 'val2'\n};", output: "var obj = {\n...{},\nk1: 'val1',\nk2: 'val2'\n};", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -602,13 +601,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "foo({ [\nk1]: 'val1', k2: 'val2' })", output: "foo({ [\nk1]: 'val1',\nk2: 'val2' })", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -618,13 +617,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "foo({\nk1: 'val1',\nk2: 'val2', ...{}\n})", output: "foo({\nk1: 'val1',\nk2: 'val2',\n...{}\n})", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -634,13 +633,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "foo({\n...{},\nk1: 'val1', k2: 'val2'\n})", output: "foo({\n...{},\nk1: 'val1',\nk2: 'val2'\n})", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -650,7 +649,8 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 15 } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // allowMultiplePropertiesPerLine: true (deprecated) diff --git a/tests/lib/rules/object-shorthand.js b/tests/lib/rules/object-shorthand.js index 58bb5708327..32cac815b7f 100644 --- a/tests/lib/rules/object-shorthand.js +++ b/tests/lib/rules/object-shorthand.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/object-shorthand"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const { unIndent } = require("../../_utils"); //------------------------------------------------------------------------------ @@ -25,7 +25,7 @@ const LONGFORM_METHOD_STRING_LITERAL_ERROR = { messageId: "expectedLiteralMethod const ALL_SHORTHAND_ERROR = { messageId: "expectedAllPropertiesShorthanded", type: "ObjectExpression" }; const MIXED_SHORTHAND_ERROR = { messageId: "unexpectedMix", type: "ObjectExpression" }; -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2018 } }); ruleTester.run("object-shorthand", rule, { valid: [ @@ -253,7 +253,7 @@ ruleTester.run("object-shorthand", rule, { { code: "var x = {foo: foo, bar: bar, ...baz}", options: ["never"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // consistent @@ -276,22 +276,22 @@ ruleTester.run("object-shorthand", rule, { { code: "var x = {...bar}", options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "var x = {foo, bar, ...baz}", options: ["consistent"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "var x = {bar: baz, ...qux}", options: ["consistent"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "var x = {...foo, bar: bar, baz: baz}", options: ["consistent"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // consistent-as-needed @@ -330,17 +330,17 @@ ruleTester.run("object-shorthand", rule, { { code: "var x = {bar, ...baz}", options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "var x = {bar: baz, ...qux}", options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "var x = {...foo, bar, baz}", options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // avoidExplicitReturnArrows @@ -579,20 +579,20 @@ ruleTester.run("object-shorthand", rule, { { code: "({ foo: async function () {} })", output: "({ async foo () {} })", - parserOptions: { ecmaVersion: 8 }, - errors: [METHOD_ERROR] + errors: [METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ 'foo': async function() {} })", output: "({ async 'foo'() {} })", - parserOptions: { ecmaVersion: 8 }, - errors: [METHOD_ERROR] + errors: [METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ [foo]: async function() {} })", output: "({ async [foo]() {} })", - parserOptions: { ecmaVersion: 8 }, - errors: [METHOD_ERROR] + errors: [METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ [foo.bar]: function*() {} })", @@ -607,8 +607,8 @@ ruleTester.run("object-shorthand", rule, { { code: "({ [ foo ]: async function() {} })", output: "({ async [ foo ]() {} })", - parserOptions: { ecmaVersion: 8 }, - errors: [METHOD_ERROR] + errors: [METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ foo: function *() {} })", @@ -659,8 +659,8 @@ ruleTester.run("object-shorthand", rule, { { code: "({ [(foo)]: async function() { return; } })", output: "({ async [(foo)]() { return; } })", - parserOptions: { ecmaVersion: 8 }, - errors: [METHOD_ERROR] + errors: [METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ [(((((((foo)))))))]: function() { return; } })", @@ -677,8 +677,8 @@ ruleTester.run("object-shorthand", rule, { code: "({ async [(foo)]() { return; } })", output: "({ [(foo)]: async function() { return; } })", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [LONGFORM_METHOD_ERROR] + errors: [LONGFORM_METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ *[((foo))]() { return; } })", @@ -708,15 +708,15 @@ ruleTester.run("object-shorthand", rule, { code: "({ async foo() { return; } })", output: "({ foo: async function() { return; } })", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [LONGFORM_METHOD_ERROR] + errors: [LONGFORM_METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ *['foo bar']() { return; } })", output: "({ ['foo bar']: function*() { return; } })", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [LONGFORM_METHOD_ERROR] + errors: [LONGFORM_METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "var x = {x: x}", @@ -776,15 +776,15 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {foo: foo, bar: baz, ...qux}", output: "var x = {foo, bar: baz, ...qux}", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, - errors: [PROPERTY_ERROR] + errors: [PROPERTY_ERROR], + languageOptions: { ecmaVersion: 2018 } }, { code: "var x = {foo, bar: baz, ...qux}", output: "var x = {foo: foo, bar: baz, ...qux}", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, - errors: [LONGFORM_PROPERTY_ERROR] + errors: [LONGFORM_PROPERTY_ERROR], + languageOptions: { ecmaVersion: 2018 } }, // ignoreConstructors @@ -920,8 +920,8 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {foo, bar: baz, ...qux}", output: null, options: ["consistent"], - parserOptions: { ecmaVersion: 2018 }, - errors: [MIXED_SHORTHAND_ERROR] + errors: [MIXED_SHORTHAND_ERROR], + languageOptions: { ecmaVersion: 2018 } }, // consistent-as-needed @@ -948,15 +948,15 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {a: a, b: b, ...baz}", output: null, options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 }, - errors: [ALL_SHORTHAND_ERROR] + errors: [ALL_SHORTHAND_ERROR], + languageOptions: { ecmaVersion: 2018 } }, { code: "var x = {foo, bar: bar, ...qux}", output: null, options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 }, - errors: [MIXED_SHORTHAND_ERROR] + errors: [MIXED_SHORTHAND_ERROR], + languageOptions: { ecmaVersion: 2018 } }, // avoidExplicitReturnArrows @@ -1084,15 +1084,15 @@ ruleTester.run("object-shorthand", rule, { code: "({ a: 1, foo: async (bar = 1) => { return; } })", output: "({ a: 1, async foo(bar = 1) { return; } })", options: ["always", { avoidExplicitReturnArrows: true }], - parserOptions: { ecmaVersion: 8 }, - errors: [METHOD_ERROR] + errors: [METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { code: "({ [ foo ]: async bar => { return; } })", output: "({ async [ foo ](bar) { return; } })", options: ["always", { avoidExplicitReturnArrows: true }], - parserOptions: { ecmaVersion: 8 }, - errors: [METHOD_ERROR] + errors: [METHOD_ERROR], + languageOptions: { ecmaVersion: 8 } }, { @@ -1263,8 +1263,10 @@ ruleTester.run("object-shorthand", rule, { } `, options: ["always", { avoidExplicitReturnArrows: true }], - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props"), - errors: Array(18).fill(METHOD_ERROR) + errors: Array(18).fill(METHOD_ERROR), + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props") + } } ] }); diff --git a/tests/lib/rules/one-var-declaration-per-line.js b/tests/lib/rules/one-var-declaration-per-line.js index 3103ef2d705..99c21642a68 100644 --- a/tests/lib/rules/one-var-declaration-per-line.js +++ b/tests/lib/rules/one-var-declaration-per-line.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/one-var-declaration-per-line"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Fixtures @@ -44,7 +44,7 @@ ruleTester.run("one-var-declaration-per-line", rule, { { code: "var a, b, c,\nd = 0;", options: ["initializations"] }, { code: "var a, b, c,\n\nd = 0;", options: ["initializations"] }, { code: "var a, b,\nc=0\nd = 0;", options: ["initializations"] }, - { code: "let a, b;", options: ["initializations"], parserOptions: { ecmaVersion: 6 } }, + { code: "let a, b;", options: ["initializations"], languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0; var b = 0;", options: ["initializations"] }, "var a, b,\nc=0\nd = 0;", @@ -54,28 +54,28 @@ ruleTester.run("one-var-declaration-per-line", rule, { { code: "var a; var b;", options: ["always"] }, { code: "for(var a = 0, b = 0;;){}", options: ["always"] }, - { code: "for(let a = 0, b = 0;;){}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "for(const a = 0, b = 0;;){}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "for(let a = 0, b = 0;;){}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "for(const a = 0, b = 0;;){}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, { code: "for(var a in obj){}", options: ["always"] }, - { code: "for(let a in obj){}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "for(const a in obj){}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "for(var a of arr){}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "for(let a of arr){}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "for(const a of arr){}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "for(let a in obj){}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "for(const a in obj){}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "for(var a of arr){}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "for(let a of arr){}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "for(const a of arr){}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, - { code: "export let a, b;", options: ["initializations"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export let a,\n b = 0;", options: ["initializations"], parserOptions: { ecmaVersion: 6, sourceType: "module" } } + { code: "export let a, b;", options: ["initializations"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export let a,\n b = 0;", options: ["initializations"], languageOptions: { ecmaVersion: 6, sourceType: "module" } } ], invalid: [ { code: "var foo, bar;", output: "var foo, \nbar;", options: ["always"], errors: [{ line: 1, column: 10, endLine: 1, endColumn: 13 }] }, { code: "var a, b;", output: "var a, \nb;", options: ["always"], errors: [errorAt(1, 8)] }, - { code: "let a, b;", output: "let a, \nb;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] }, + { code: "let a, b;", output: "let a, \nb;", options: ["always"], errors: [errorAt(1, 8)], languageOptions: { ecmaVersion: 6 } }, { code: "var a, b = 0;", output: "var a, \nb = 0;", options: ["always"], errors: [errorAt(1, 8)] }, { code: "var a = {\n foo: bar\n}, b;", output: "var a = {\n foo: bar\n}, \nb;", options: ["always"], errors: [errorAt(3, 4)] }, { code: "var a\n=0, b;", output: "var a\n=0, \nb;", options: ["always"], errors: [errorAt(2, 5)] }, - { code: "let a, b = 0;", output: "let a, \nb = 0;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] }, - { code: "const a = 0, b = 0;", output: "const a = 0, \nb = 0;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 14)] }, + { code: "let a, b = 0;", output: "let a, \nb = 0;", options: ["always"], errors: [errorAt(1, 8)], languageOptions: { ecmaVersion: 6 } }, + { code: "const a = 0, b = 0;", output: "const a = 0, \nb = 0;", options: ["always"], errors: [errorAt(1, 14)], languageOptions: { ecmaVersion: 6 } }, { code: "var foo, bar, baz = 0;", output: "var foo, bar, \nbaz = 0;", options: ["initializations"], errors: [{ line: 1, column: 15, endLine: 1, endColumn: 22 }] }, { code: "var a, b, c = 0;", output: "var a, b, \nc = 0;", options: ["initializations"], errors: [errorAt(1, 11)] }, @@ -85,7 +85,7 @@ ruleTester.run("one-var-declaration-per-line", rule, { { code: "var a = {\n foo: bar\n}, b;", output: "var a = {\n foo: bar\n}, \nb;", options: ["initializations"], errors: [errorAt(3, 4)] }, { code: "for(var a = 0, b = 0;;){\nvar c,d;}", output: "for(var a = 0, b = 0;;){\nvar c,\nd;}", options: ["always"], errors: [errorAt(2, 7)] }, - { code: "export let a, b;", output: "export let a, \nb;", options: ["always"], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [errorAt(1, 15)] }, - { code: "export let a, b = 0;", output: "export let a, \nb = 0;", options: ["initializations"], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [errorAt(1, 15)] } + { code: "export let a, b;", output: "export let a, \nb;", options: ["always"], errors: [errorAt(1, 15)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export let a, b = 0;", output: "export let a, \nb = 0;", options: ["initializations"], errors: [errorAt(1, 15)], languageOptions: { ecmaVersion: 6, sourceType: "module" } } ] }); diff --git a/tests/lib/rules/one-var.js b/tests/lib/rules/one-var.js index 935c464b3d0..da76d3dbfd8 100644 --- a/tests/lib/rules/one-var.js +++ b/tests/lib/rules/one-var.js @@ -10,9 +10,9 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/one-var"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "script" } }); //------------------------------------------------------------------------------ // Tests @@ -236,44 +236,44 @@ ruleTester.run("one-var", rule, { { code: "let a = 0, b, c;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0, b = 1, c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0, b = 1; foo(); let c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0, b = 1; foo(); const c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; var b = 1;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b = 1;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; const b = 1; var c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/10784 { code: "const foo = require('foo'); const bar = 'bar';", options: [{ const: "consecutive", separateRequires: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0, b = 1; var c, d;", @@ -286,22 +286,22 @@ ruleTester.run("one-var", rule, { { code: "let a = 0, b = 1; let c, d;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; let b, c; let d = 1;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0, b = 1; let c, d;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b, c; const d = 1;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0, b = 1; var c; var d;", @@ -314,22 +314,22 @@ ruleTester.run("one-var", rule, { { code: "let a = 0, b = 1; let c; let d;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; let b; let c; let d = 1;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0, b = 1; let c; let d;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b; let c; const d = 1;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a, b; var c = 0, d = 1;", @@ -342,22 +342,22 @@ ruleTester.run("one-var", rule, { { code: "let a, b; let c = 0, d = 1;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b = 0, c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a, b; const c = 0, d = 1;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0, c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a, b; var c = 0; var d = 1;", @@ -370,22 +370,22 @@ ruleTester.run("one-var", rule, { { code: "let a, b; let c = 0; let d = 1;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b = 0; let c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a, b; const c = 0; const d = 1;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0; const c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0, b = 1;", @@ -398,62 +398,62 @@ ruleTester.run("one-var", rule, { { code: "let a = 0, b = 1;", options: [{ let: "consecutive" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; foo; let b = 1;", options: [{ let: "consecutive" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0, b = 1;", options: [{ const: "consecutive" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; foo; const b = 1;", options: [{ const: "consecutive" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a, b; const c = 0, d = 1;", options: [{ let: "consecutive", const: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0, c = 1; let d;", options: [{ let: "consecutive", const: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a, b; const c = 0; const d = 1;", options: [{ let: "consecutive", const: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0; const c = 1; let d;", options: [{ let: "consecutive", const: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0, b = 1; let c, d;", options: [{ const: "consecutive", let: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b, c; const d = 1;", options: [{ const: "consecutive", let: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0, b = 1; let c; let d;", options: [{ const: "consecutive", let: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b; let c; const d = 1;", options: [{ const: "consecutive", let: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 1, b = 2; foo(); var c = 3, d = 4;", @@ -470,17 +470,17 @@ ruleTester.run("one-var", rule, { { code: "let a, b; var c; var d; let e;", options: [{ var: "never", let: "consecutive", const: "consecutive" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 1, b = 2; var d; var e; const f = 3;", options: [{ var: "never", let: "consecutive", const: "consecutive" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a, b; const c = 1; const d = 2; let e; let f; ", options: [{ var: "consecutive" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 1, b = 2; var c; var d; var e = 3, f = 4;", @@ -499,137 +499,137 @@ ruleTester.run("one-var", rule, { { code: "class C { static { var a; let b; const c = 0; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "const a = 0; class C { static { const b = 0; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { const b = 0; } } const a = 0; ", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "let a; class C { static { let b; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let b; } } let a;", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "var a; class C { static { var b; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var b; } } var a; ", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "var a; class C { static { if (foo) { var b; } } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (foo) { var b; } } } var a; ", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { const a = 0; if (foo) { const b = 0; } } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; if (foo) { let b; } } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { const a = 0; const b = 0; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; let b; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; var b; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; foo; let b; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; const b = 0; let c; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; foo; var b; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; let b; var c; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; if (foo) { let b; } } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (foo) { let b; } let a; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { const a = 0; if (foo) { const b = 0; } } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (foo) { const b = 0; } const a = 0; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; if (foo) var b; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (foo) var b; var a; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (foo) { var b; } var a; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; let b = 0; } }", options: [{ initialized: "consecutive" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a; var b = 0; } }", options: [{ initialized: "consecutive" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -986,14 +986,14 @@ ruleTester.run("one-var", rule, { { code: "var foo = () => { var bar = true; var baz = false; }", output: "var foo = () => { var bar = true, baz = false; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 35 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() { var bar = true; if (qux) { var baz = false; } }", @@ -1093,27 +1093,27 @@ ruleTester.run("one-var", rule, { code: "var {foo} = 1, [bar] = 2;", output: "var {foo} = 1; var [bar] = 2;", options: [{ initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const foo = 1,\n bar = 2;", output: "const foo = 1;\n const bar = 2;", options: [{ initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 1 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = 1,\n bar = 2;", @@ -1273,53 +1273,53 @@ ruleTester.run("one-var", rule, { code: "let a = 1, b; let c;", output: "let a = 1, b, c;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0, b = 1; let c = 2;", output: "let a = 0, b = 1, c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0, b = 1; const c = 2;", output: "const a = 0, b = 1, c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; var b = 1; var c = 2; const d = 3;", output: "const a = 0; var b = 1, c = 2; const d = 3;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = true; var b = false;", @@ -1337,27 +1337,27 @@ ruleTester.run("one-var", rule, { code: "const a = 0; let b = 1; let c = 2; const d = 3;", output: "const a = 0; let b = 1, c = 2; const d = 3;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; const b = 1; const c = 1; var d = 2;", output: "let a = 0; const b = 1, c = 1; var d = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 25 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0; var b; var c; var d = 1", @@ -1394,20 +1394,19 @@ ruleTester.run("one-var", rule, { code: "let a = 0; let b; let c; let d = 1;", output: "let a = 0; let b, c; let d = 1;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; let b = 1; let c; let d;", output: "let a = 0, b = 1; let c, d;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -1421,26 +1420,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 30 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b; let c; const d = 1;", output: "const a = 0; let b, c; const d = 1;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 21 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; const b = 1; let c; let d;", output: "const a = 0, b = 1; let c, d;", options: [{ initialized: "consecutive", uninitialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", type: "VariableDeclaration", @@ -1453,7 +1452,8 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 34 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0; var b = 1; var c, d;", @@ -1490,7 +1490,6 @@ ruleTester.run("one-var", rule, { code: "let a = 0; let b = 1; let c, d;", output: "let a = 0, b = 1; let c; let d;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -1504,26 +1503,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 23 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a = 0; let b, c; let d = 1;", output: "let a = 0; let b; let c; let d = 1;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; const b = 1; let c, d;", output: "const a = 0, b = 1; let c; let d;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "const" }, @@ -1537,20 +1536,21 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 27 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b, c; const d = 1;", output: "const a = 0; let b; let c; const d = 1;", options: [{ initialized: "consecutive", uninitialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 14 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a; var b; var c = 0; var d = 1;", @@ -1587,7 +1587,6 @@ ruleTester.run("one-var", rule, { code: "let a; let b; let c = 0; let d = 1;", output: "let a, b; let c = 0, d = 1;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1601,26 +1600,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 26 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b = 0; let c = 1; let d;", output: "let a; let b = 0, c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b; const c = 0; const d = 1;", output: "let a, b; const c = 0, d = 1;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1634,20 +1633,21 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0; const c = 1; let d;", output: "let a; const b = 0, c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a; var b; var c = 0, d = 1;", @@ -1684,7 +1684,6 @@ ruleTester.run("one-var", rule, { code: "let a; let b; let c = 0, d = 1;", output: "let a, b; let c = 0; let d = 1;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1698,26 +1697,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b = 0, c = 1; let d;", output: "let a; let b = 0; let c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b; const c = 0, d = 1;", output: "let a, b; const c = 0; const d = 1;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1731,20 +1730,21 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0, c = 1; let d;", output: "let a; const b = 0; const c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 8 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a = 0; var b = 1;", @@ -1762,33 +1762,32 @@ ruleTester.run("one-var", rule, { code: "let a = 0; let b = 1;", output: "let a = 0, b = 1;", options: [{ let: "consecutive" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; const b = 1;", output: "const a = 0, b = 1;", options: [{ const: "consecutive" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 14 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b; const c = 0; const d = 1;", output: "let a, b; const c = 0, d = 1;", options: [{ let: "consecutive", const: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1802,26 +1801,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 28 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0; const c = 1; let d;", output: "let a; const b = 0, c = 1; let d;", options: [{ let: "consecutive", const: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; let b; const c = 0, d = 1;", output: "let a, b; const c = 0; const d = 1;", options: [{ let: "consecutive", const: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1835,26 +1834,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "let a; const b = 0, c = 1; let d;", output: "let a; const b = 0; const c = 1; let d;", options: [{ let: "consecutive", const: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 8 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; const b = 1; let c; let d;", output: "const a = 0, b = 1; let c, d;", options: [{ const: "consecutive", let: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1868,26 +1867,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 34 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b; let c; const d = 1;", output: "const a = 0; let b, c; const d = 1;", options: [{ const: "consecutive", let: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 21 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; const b = 1; let c, d;", output: "const a = 0, b = 1; let c; let d;", options: [{ const: "consecutive", let: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1901,20 +1900,21 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 27 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "const a = 0; let b, c; const d = 1;", output: "const a = 0; let b; let c; const d = 1;", options: [{ const: "consecutive", let: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "split", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 14 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var bar; var baz;", @@ -1951,7 +1951,6 @@ ruleTester.run("one-var", rule, { code: "let a, b; let c; var d, e;", output: "let a, b, c; var d; var e;", options: [{ var: "never", let: "consecutive", const: "consecutive" }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1965,7 +1964,8 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 18 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var a; var b;", @@ -2040,89 +2040,89 @@ ruleTester.run("one-var", rule, { code: "export const foo=1, bar=2;", output: "export const foo=1; export const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, { code: "const foo=1,\n bar=2;", output: "const foo=1;\n const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, { code: "export const foo=1,\n bar=2;", output: "export const foo=1;\n export const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, { code: "export const foo=1\n, bar=2;", output: "export const foo=1\n; export const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, { code: "export const foo= a, bar=2;", output: "export const foo= a; export const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, { code: "export const foo=() => a, bar=2;", output: "export const foo=() => a; export const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, { code: "export const foo= a, bar=2, bar2=2;", output: "export const foo= a; export const bar=2; export const bar2=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, { code: "export const foo = 1,bar = 2;", output: "export const foo = 1; export const bar = 2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2021, sourceType: "module" } }, // "never" should not autofix declarations in a block position @@ -2262,122 +2262,122 @@ ruleTester.run("one-var", rule, { code: "class C { static { let x, y; } }", output: "class C { static { let x; let y; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "split", data: { type: "let" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var x, y; } }", output: "class C { static { var x; var y; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "split", data: { type: "var" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; let y; } }", output: "class C { static { let x, y; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var x; var y; } }", output: "class C { static { var x, y; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; foo; let y; } }", output: null, options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var x; foo; var y; } }", output: null, options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var x; if (foo) { var y; } } }", output: null, options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; let y; } }", output: "class C { static { let x, y; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var x; var y; } }", output: "class C { static { var x, y; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a = 0; let b = 1; } }", output: "class C { static { let a = 0, b = 1; } }", options: [{ initialized: "consecutive" }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { var a = 0; var b = 1; } }", output: "class C { static { var a = 0, b = 1; } }", options: [{ initialized: "consecutive" }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combineInitialized", data: { type: "var" }, type: "VariableDeclaration" - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/operator-assignment.js b/tests/lib/rules/operator-assignment.js index 50229af4903..3a6ee52059e 100644 --- a/tests/lib/rules/operator-assignment.js +++ b/tests/lib/rules/operator-assignment.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/operator-assignment"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("operator-assignment", rule, { diff --git a/tests/lib/rules/operator-linebreak.js b/tests/lib/rules/operator-linebreak.js index 8810c040776..39a0b6ba355 100644 --- a/tests/lib/rules/operator-linebreak.js +++ b/tests/lib/rules/operator-linebreak.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/operator-linebreak"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -63,88 +63,88 @@ ruleTester.run("operator-linebreak", rule, { { code: "a \n &&= b", options: ["after", { overrides: { "&&=": "ignore" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "a ??= \n b", options: ["before", { overrides: { "??=": "ignore" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "a ||= \n b", options: ["after", { overrides: { "=": "before" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "a \n &&= b", options: ["before", { overrides: { "&=": "after" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "a \n ||= b", options: ["before", { overrides: { "|=": "after" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "a &&= \n b", options: ["after", { overrides: { "&&": "before" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "a ||= \n b", options: ["after", { overrides: { "||": "before" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "a ??= \n b", options: ["after", { overrides: { "??": "before" } }], - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, // class fields { code: "class C { foo =\n0 }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n= 0 }", options: ["before"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo\n]= 0 }", options: ["before"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo]\n= 0 }", options: ["before"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo\n]\n= 0 }", options: ["before"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo\n]= 0 }", options: ["after"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo\n]=\n0 }", options: ["after"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo\n]= 0 }", options: ["none"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n=\n0 }", options: ["none", { overrides: { "=": "ignore" } }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -721,18 +721,17 @@ ruleTester.run("operator-linebreak", rule, { code: "foo ??\n bar", output: "foo\n ?? bar", options: ["after", { overrides: { "??": "before" } }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "??" } - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "a \n &&= b", output: "a &&= \n b", options: ["after"], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "&&=" }, @@ -741,13 +740,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 2, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a ||=\n b", output: "a\n ||= b", options: ["before"], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "||=" }, @@ -756,13 +755,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 1, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a ??=\n b", output: "a ??= b", options: ["none"], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLinebreak", data: { operator: "??=" }, @@ -771,13 +770,13 @@ ruleTester.run("operator-linebreak", rule, { column: 4, endLine: 1, endColumn: 7 - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a \n &&= b", output: "a &&= b", options: ["before", { overrides: { "&&=": "none" } }], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLinebreak", data: { operator: "&&=" }, @@ -786,13 +785,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 2, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a ||=\nb", output: "a\n||= b", options: ["after", { overrides: { "||=": "before" } }], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "||=" }, @@ -801,13 +800,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 1, endColumn: 6 - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a\n??=b", output: "a??=\nb", options: ["none", { overrides: { "??=": "after" } }], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "??=" }, @@ -816,7 +815,8 @@ ruleTester.run("operator-linebreak", rule, { column: 1, endLine: 2, endColumn: 4 - }] + }], + languageOptions: { ecmaVersion: 2021 } }, // class fields @@ -824,7 +824,6 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { a\n= 0; }", output: "class C { a =\n0; }", options: ["after"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "=" }, @@ -833,13 +832,13 @@ ruleTester.run("operator-linebreak", rule, { column: 1, endLine: 2, endColumn: 2 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { a =\n0; }", output: "class C { a\n= 0; }", options: ["before"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "=" }, @@ -848,13 +847,13 @@ ruleTester.run("operator-linebreak", rule, { column: 13, endLine: 1, endColumn: 14 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { a =\n0; }", output: "class C { a =0; }", options: ["none"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noLinebreak", data: { operator: "=" }, @@ -863,13 +862,13 @@ ruleTester.run("operator-linebreak", rule, { column: 13, endLine: 1, endColumn: 14 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [a]\n= 0; }", output: "class C { [a] =\n0; }", options: ["after"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "=" }, @@ -878,13 +877,13 @@ ruleTester.run("operator-linebreak", rule, { column: 1, endLine: 2, endColumn: 2 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [a] =\n0; }", output: "class C { [a]\n= 0; }", options: ["before"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "=" }, @@ -893,13 +892,13 @@ ruleTester.run("operator-linebreak", rule, { column: 15, endLine: 1, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [a]\n =0; }", output: "class C { [a] =0; }", options: ["none"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noLinebreak", data: { operator: "=" }, @@ -908,7 +907,8 @@ ruleTester.run("operator-linebreak", rule, { column: 2, endLine: 2, endColumn: 3 - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/padded-blocks.js b/tests/lib/rules/padded-blocks.js index 3dd0dc97e18..1eeee4aa408 100644 --- a/tests/lib/rules/padded-blocks.js +++ b/tests/lib/rules/padded-blocks.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/padded-blocks"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -43,11 +43,11 @@ ruleTester.run("padded-blocks", rule, { { code: "switch (a) {\n\n//comment\ncase 0: foo();//comment\n\n}", options: [{ switches: "always" }] }, { code: "switch (a) {//comment\n\ncase 0: foo();\ncase 1: bar();\n\n/* comment */}", options: [{ switches: "always" }] }, - { code: "class A{\n\nfoo(){}\n\n}", parserOptions: { ecmaVersion: 6 } }, - { code: "class A{\n\nfoo(){}\n\n}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "class A{}", options: [{ classes: "always" }], parserOptions: { ecmaVersion: 6 } }, - { code: "class A{\n\n}", options: [{ classes: "always" }], parserOptions: { ecmaVersion: 6 } }, - { code: "class A{\n\nfoo(){}\n\n}", options: [{ classes: "always" }], parserOptions: { ecmaVersion: 6 } }, + { code: "class A{\n\nfoo(){}\n\n}", languageOptions: { ecmaVersion: 6 } }, + { code: "class A{\n\nfoo(){}\n\n}", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "class A{}", options: [{ classes: "always" }], languageOptions: { ecmaVersion: 6 } }, + { code: "class A{\n\n}", options: [{ classes: "always" }], languageOptions: { ecmaVersion: 6 } }, + { code: "class A{\n\nfoo(){}\n\n}", options: [{ classes: "always" }], languageOptions: { ecmaVersion: 6 } }, { code: "{\na();\n}", options: ["never"] }, { code: "{\na();}", options: ["never"] }, @@ -71,11 +71,11 @@ ruleTester.run("padded-blocks", rule, { { code: "switch (a) {\ncase 0: foo();\n}", options: [{ switches: "never" }] }, - { code: "class A{\nfoo(){}\n}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "class A{\nfoo(){}\n}", options: [{ classes: "never" }], parserOptions: { ecmaVersion: 6 } }, + { code: "class A{\nfoo(){}\n}", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "class A{\nfoo(){}\n}", options: [{ classes: "never" }], languageOptions: { ecmaVersion: 6 } }, - { code: "class A{\n\nfoo;\n\n}", parserOptions: { ecmaVersion: 2022 } }, - { code: "class A{\nfoo;\n}", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, + { code: "class A{\n\nfoo;\n\n}", languageOptions: { ecmaVersion: 2022 } }, + { code: "class A{\nfoo;\n}", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, // Ignore block statements if not configured { code: "{\na();\n}", options: [{ switches: "always" }] }, @@ -87,109 +87,109 @@ ruleTester.run("padded-blocks", rule, { // Ignore class statements if not configured - { code: "class A{\nfoo(){}\n}", options: [{ blocks: "always" }], parserOptions: { ecmaVersion: 6 } }, - { code: "class A{\n\nfoo(){}\n\n}", options: [{ blocks: "never" }], parserOptions: { ecmaVersion: 6 } }, + { code: "class A{\nfoo(){}\n}", options: [{ blocks: "always" }], languageOptions: { ecmaVersion: 6 } }, + { code: "class A{\n\nfoo(){}\n\n}", options: [{ blocks: "never" }], languageOptions: { ecmaVersion: 6 } }, // class static blocks { code: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {// comment\n\nfoo;\n\n/* comment */} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\n\n// comment\nfoo;\n// comment\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\n\n// comment\n\nfoo;\n\n// comment\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static { foo; } \n\n}", options: ["always", { allowSingleLineBlocks: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static\n { foo; } \n\n}", options: ["always", { allowSingleLineBlocks: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {} static {\n} static {\n\n} \n\n}", // empty blocks are ignored options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static\n\n { foo; } \n\n}", options: ["always", { allowSingleLineBlocks: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n\nfoo;\n\n} \n}", options: [{ blocks: "always", classes: "never" }], // "blocks" applies to static blocks - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {foo;} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static\n {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static\n\n {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static\n\n {foo;} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {// comment\nfoo;\n/* comment */} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n// comment\nfoo;\n// comment\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {} static {\n} static {\n\n} \n}", // empty blocks are ignored options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\nfoo;\n} \n\n}", options: [{ blocks: "never", classes: "always" }], // "blocks" applies to static blocks - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\nfoo;\n} static {\n\nfoo;\n\n} \n\n}", options: [{ classes: "always" }], // if there's no "blocks" in the object option, static blocks are ignored - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\nfoo;\n} static {\n\nfoo;\n\n} \n}", options: [{ classes: "never" }], // if there's no "blocks" in the object option, static blocks are ignored - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -440,7 +440,6 @@ ruleTester.run("padded-blocks", rule, { code: "class A {\nconstructor(){}\n}", output: "class A {\n\nconstructor(){}\n\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "alwaysPadBlock", @@ -456,13 +455,13 @@ ruleTester.run("padded-blocks", rule, { endLine: 3, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A {\nconstructor(){}\n}", output: "class A {\n\nconstructor(){}\n\n}", options: [{ classes: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "alwaysPadBlock", @@ -478,7 +477,8 @@ ruleTester.run("padded-blocks", rule, { endLine: 3, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "{a();}", @@ -728,7 +728,6 @@ ruleTester.run("padded-blocks", rule, { code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", output: "class A {\nconstructor(){\nfoo();\n}\n}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -758,13 +757,13 @@ ruleTester.run("padded-blocks", rule, { endLine: 9, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", output: "class A {\nconstructor(){\n\nfoo();\n\n}\n}", options: [{ classes: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -780,13 +779,13 @@ ruleTester.run("padded-blocks", rule, { endLine: 9, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", output: "class A {\nconstructor(){\nfoo();\n}\n}", options: [{ blocks: "never", classes: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -816,7 +815,8 @@ ruleTester.run("padded-blocks", rule, { endLine: 9, endColumn: 1 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { // a\n\n b;\n}", @@ -857,15 +857,15 @@ ruleTester.run("padded-blocks", rule, { { code: "class A{\nfoo;\n}", output: "class A{\n\nfoo;\n\n}", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] + errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A{\n\nfoo;\n\n}", output: "class A{\nfoo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "neverPadBlock" }, { messageId: "neverPadBlock" }] + errors: [{ messageId: "neverPadBlock" }, { messageId: "neverPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, // class static blocks @@ -873,157 +873,157 @@ ruleTester.run("padded-blocks", rule, { code: "class C {\n\n static {\nfoo;\n\n} \n\n}", output: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "alwaysPadBlock" }] + errors: [{ messageId: "alwaysPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static\n {\nfoo;\n\n} \n\n}", output: "class C {\n\n static\n {\n\nfoo;\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "alwaysPadBlock" }] + errors: [{ messageId: "alwaysPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static\n\n {\nfoo;\n\n} \n\n}", output: "class C {\n\n static\n\n {\n\nfoo;\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "alwaysPadBlock" }] + errors: [{ messageId: "alwaysPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\n\nfoo;\n} \n\n}", output: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "alwaysPadBlock" }] + errors: [{ messageId: "alwaysPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {foo;} \n\n}", output: "class C {\n\n static {\nfoo;\n} \n\n}", // this is still not padded, the subsequent fix below will add another pair of `\n`. options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\nfoo;\n} \n\n}", output: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {// comment\nfoo;\n/* comment */} \n\n}", output: "class C {\n\n static {// comment\n\nfoo;\n\n/* comment */} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\n// comment\nfoo;\n// comment\n} \n\n}", output: "class C {\n\n static {\n\n// comment\nfoo;\n// comment\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\n// comment\n\nfoo;\n\n// comment\n} \n\n}", output: "class C {\n\n static {\n\n// comment\n\nfoo;\n\n// comment\n\n} \n\n}", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\nfoo;\n} \n}", output: "class C {\n static {\n\nfoo;\n\n} \n}", options: [{ blocks: "always", classes: "never" }], // "blocks" applies to static blocks - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n\nfoo;\n} \n}", output: "class C {\n static {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "neverPadBlock" }] + errors: [{ messageId: "neverPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static\n {\n\nfoo;\n} \n}", output: "class C {\n static\n {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "neverPadBlock" }] + errors: [{ messageId: "neverPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static\n\n {\n\nfoo;\n} \n}", output: "class C {\n static\n\n {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "neverPadBlock" }] + errors: [{ messageId: "neverPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\nfoo;\n\n} \n}", output: "class C {\n static {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "neverPadBlock" }] + errors: [{ messageId: "neverPadBlock" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n\nfoo;\n\n} \n}", output: "class C {\n static {\nfoo;\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {// comment\n\nfoo;\n\n/* comment */} \n}", output: "class C {\n static {// comment\nfoo;\n/* comment */} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n\n// comment\nfoo;\n// comment\n\n} \n}", output: "class C {\n static {\n// comment\nfoo;\n// comment\n} \n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", output: "class C {\n\n static {\nfoo;\n} \n\n}", options: [{ blocks: "never", classes: "always" }], // "blocks" applies to static blocks - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/padding-line-between-statements.js b/tests/lib/rules/padding-line-between-statements.js index 0d6e93c437a..d4e83ea7e38 100644 --- a/tests/lib/rules/padding-line-between-statements.js +++ b/tests/lib/rules/padding-line-between-statements.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/padding-line-between-statements"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2017 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2017, sourceType: "script" } }); ruleTester.run("padding-line-between-statements", rule, { valid: [ @@ -722,7 +722,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export let a=1\n\nfoo()", @@ -730,7 +730,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0; export {a}\n\nfoo()", @@ -738,7 +738,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "exports.foo=1\nfoo()", @@ -746,7 +746,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "module.exports={}\nfoo()", @@ -754,7 +754,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -888,7 +888,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import a from 'a'\n\nfoo()", @@ -896,7 +896,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as a from 'a'\n\nfoo()", @@ -904,7 +904,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {a} from 'a'\n\nfoo()", @@ -912,7 +912,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "const a=require('a')\nfoo()", @@ -920,7 +920,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -1672,7 +1672,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export let a = 1;\nexport let b = 2;", @@ -1680,7 +1680,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export var a = 1;\nexport var b = 2;", @@ -1688,7 +1688,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export var a = 1;\nexport var b = 2;", @@ -1696,7 +1696,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export const a = 1;\nexport const b = 2;", @@ -1704,7 +1704,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export const a = 1;\nexport const b = 2;", @@ -1712,7 +1712,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // should allow no blank line at end of block @@ -2244,35 +2244,35 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a;\n\nreturn;", options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "// comment\nreturn;", options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "/* comment */\nreturn;", options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "/* multi-line\ncomment */\nreturn;", options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, //---------------------------------------------------------------------- @@ -2541,7 +2541,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - parserOptions: { ecmaFeatures: { jsx: true } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "var i = 0;\nwhile (i < 100) {\nif(i % 2 === 0) {continue;}\n++i;\n}", @@ -2634,42 +2634,42 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "expression" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n }\n }", options: [ { blankLine: "never", prev: "let", next: "expression" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n }\n }", options: [ { blankLine: "always", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n }\n }", options: [ { blankLine: "never", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n const z = 1;\n }\n }", options: [ { blankLine: "always", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n const z = 1;\n }\n }", options: [ { blankLine: "never", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let a = 0;\n let b =0;\n\n bar();\n }\n }", @@ -2677,63 +2677,63 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; { let y; } let z; } }", options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { method() { let x; } static { let y; } }", options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let y; } method() { let x; } }", options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; } static { let y; } }", options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "let x; class C { static { let y; } }", options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; } } let y;", options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; } }", options: [ { blankLine: "always", prev: "class", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { 'use strict'; let x; } }", // 'use strict'; is "expression", because class static blocks don't have directives options: [ { blankLine: "always", prev: "directive", next: "let" } ], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -3534,8 +3534,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export let a=1\n\nfoo()", @@ -3543,8 +3543,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0;export {a}\n\nfoo()", @@ -3552,8 +3552,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default 1\nfoo()", @@ -3561,8 +3561,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export let a=1\nfoo()", @@ -3570,8 +3570,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var a = 0;export {a}\nfoo()", @@ -3579,8 +3579,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -3745,15 +3745,15 @@ ruleTester.run("padding-line-between-statements", rule, { code: "(function(){\n})?.()\nvar a = 2;", output: "(function(){\n})?.()\n\nvar a = 2;", options: [{ blankLine: "always", prev: "iife", next: "*" }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2020 } }, { code: "void (function(){\n})?.()\nvar a = 2;", output: "void (function(){\n})?.()\n\nvar a = 2;", options: [{ blankLine: "always", prev: "iife", next: "*" }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2020 } }, //---------------------------------------------------------------------- @@ -3766,8 +3766,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as a from 'a'\n\nfoo()", @@ -3775,8 +3775,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {a} from 'a'\n\nfoo()", @@ -3784,8 +3784,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import a from 'a'\nfoo()", @@ -3793,8 +3793,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as a from 'a'\nfoo()", @@ -3802,8 +3802,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import {a} from 'a'\nfoo()", @@ -3811,8 +3811,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, //---------------------------------------------------------------------- @@ -4692,8 +4692,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "var a; return;", @@ -4701,8 +4701,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "function a() {\n{\n//comment\n}\nreturn\n}", @@ -5093,8 +5093,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "expression" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n\n foo();\n }\n }", @@ -5102,8 +5102,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "let", next: "expression" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n }\n }", @@ -5111,8 +5111,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n }\n }", @@ -5120,8 +5120,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n const z = 1;\n }\n }", @@ -5129,8 +5129,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n const z = 1;\n }\n }", @@ -5138,8 +5138,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unexpectedBlankLine" }] + errors: [{ messageId: "unexpectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\n static {\n let a = 0;\n bar();\n }\n }", @@ -5148,8 +5148,8 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; { let y; let z; } let q; } }", @@ -5157,8 +5157,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { { let x; } let y; let z; } }", @@ -5166,8 +5166,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo(); if (bar) {} } }", @@ -5175,8 +5175,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "block-like" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let x; } } let y;", @@ -5184,8 +5184,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "class", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { 'use strict'; let x; } }", // 'use strict'; is "expression", because class static blocks don't have directives @@ -5193,8 +5193,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "expectedBlankLine" }] + errors: [{ messageId: "expectedBlankLine" }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/prefer-arrow-callback.js b/tests/lib/rules/prefer-arrow-callback.js index eba8c051140..0e0336e1cc7 100644 --- a/tests/lib/rules/prefer-arrow-callback.js +++ b/tests/lib/rules/prefer-arrow-callback.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-arrow-callback"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,7 +21,7 @@ const errors = [{ type: "FunctionExpression" }]; -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2020 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2020, sourceType: "script" } }); ruleTester.run("prefer-arrow-callback", rule, { valid: [ diff --git a/tests/lib/rules/prefer-const.js b/tests/lib/rules/prefer-const.js index bd00484c99f..341b78ca01c 100644 --- a/tests/lib/rules/prefer-const.js +++ b/tests/lib/rules/prefer-const.js @@ -11,24 +11,31 @@ const rule = require("../../../lib/rules/prefer-const"), fixtureParser = require("../../fixtures/fixture-parser"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ + plugins: { + custom: { + rules: { + "use-x": { + create(context) { + const sourceCode = context.sourceCode; -ruleTester.defineRule("use-x", { - create(context) { - const sourceCode = context.sourceCode; - - return { - VariableDeclaration(node) { - sourceCode.markVariableAsUsed("x", node); + return { + VariableDeclaration(node) { + sourceCode.markVariableAsUsed("x", node); + } + }; + } + } } - }; - } + } + }, + languageOptions: { ecmaVersion: 6, sourceType: "script" } }); ruleTester.run("prefer-const", rule, { @@ -115,60 +122,62 @@ ruleTester.run("prefer-const", rule, { { code: "let { name, ...otherStuff } = obj; otherStuff = {};", options: [{ destructuring: "all" }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", options: [{ destructuring: "all" }], - parser: fixtureParser("babel-eslint5/destructuring-object-spread") + languageOptions: { + parser: require(fixtureParser("babel-eslint5/destructuring-object-spread")) + } }, // https://github.com/eslint/eslint/issues/8308 { code: "let predicate; [typeNode.returnType, predicate] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [typeNode.returnType, ...predicate] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { // intentionally testing empty slot in destructuring assignment code: "let predicate; [typeNode.returnType,, predicate] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [typeNode.returnType=5, predicate] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [[typeNode.returnType=5], predicate] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [[typeNode.returnType, predicate]] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [typeNode.returnType, [predicate]] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [, [typeNode.returnType, predicate]] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [, {foo:typeNode.returnType, predicate}] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [, {foo:typeNode.returnType, ...predicate}] = foo();", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "let a; const b = {}; ({ a, c: b.c } = func());", - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, // ignoreReadBeforeAssign @@ -183,51 +192,51 @@ ruleTester.run("prefer-const", rule, { { code: "class C { static { let a = 1; a = 2; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; a = 1; a = 2; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "let a; class C { static { a = 1; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; if (foo) { a = 1; } } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; if (foo) a = 1; } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a, b; if (foo) { ({ a, b } = foo); } } }", output: null, - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a, b; if (foo) ({ a, b } = foo); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { a; } } let a = 1; ", options: [{ ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { () => a; let a = 1; } };", options: [{ ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -431,15 +440,17 @@ ruleTester.run("prefer-const", rule, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", output: null, options: [{ destructuring: "any" }], - parserOptions: { ecmaVersion: 2018 }, - errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }] + errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", output: null, options: [{ destructuring: "any" }], - parser: fixtureParser("babel-eslint5/destructuring-object-spread"), - errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }] + errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }], + languageOptions: { + parser: require(fixtureParser("babel-eslint5/destructuring-object-spread")) + } }, // Warnings are located at declaration if there are reading references before assignments. @@ -451,14 +462,14 @@ ruleTester.run("prefer-const", rule, { // https://github.com/eslint/eslint/issues/5837 { - code: "/*eslint use-x:error*/ let x = 1", - output: "/*eslint use-x:error*/ const x = 1", - parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }] + code: "/*eslint custom/use-x:error*/ let x = 1", + output: "/*eslint custom/use-x:error*/ const x = 1", + errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { - code: "/*eslint use-x:error*/ { let x = 1 }", - output: "/*eslint use-x:error*/ { const x = 1 }", + code: "/*eslint custom/use-x:error*/ { let x = 1 }", + output: "/*eslint custom/use-x:error*/ { const x = 1 }", errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }] }, { @@ -489,26 +500,26 @@ ruleTester.run("prefer-const", rule, { { code: "let predicate; [, {foo:returnType, predicate}] = foo();", output: null, - parserOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [, {foo:returnType, predicate}, ...bar ] = foo();", output: null, - parserOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "let predicate; [, {foo:returnType, ...predicate} ] = foo();", output: null, - parserOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "let x = 'x', y = 'y';", @@ -615,81 +626,81 @@ ruleTester.run("prefer-const", rule, { { code: "let a = 1; class C { static { a; } }", output: "const a = 1; class C { static { a; } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 } }, { // this is a TDZ error with either `let` or `const`, but that isn't a concern of this rule code: "class C { static { a; } } let a = 1;", output: "class C { static { a; } } const a = 1;", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a = 1; } }", output: "class C { static { const a = 1; } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (foo) { let a = 1; } } }", output: "class C { static { if (foo) { const a = 1; } } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a = 1; if (foo) { a; } } }", output: "class C { static { const a = 1; if (foo) { a; } } }", - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { if (foo) { let a; a = 1; } } }", output: null, - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; a = 1; } }", output: null, - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier", column: 27 }] + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier", column: 27 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let { a, b } = foo; } }", output: "class C { static { const { a, b } = foo; } }", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a, b; ({ a, b } = foo); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; let b; ({ a, b } = foo); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { let a; a = 0; console.log(a); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/issues/16266 @@ -703,12 +714,12 @@ ruleTester.run("prefer-const", rule, { `, output: null, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, { messageId: "useConst", data: { name: "obj" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -722,12 +733,12 @@ ruleTester.run("prefer-const", rule, { console.log(itemId, list, obj); `, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, { messageId: "useConst", data: { name: "obj" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -738,11 +749,11 @@ ruleTester.run("prefer-const", rule, { `, output: null, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -756,12 +767,12 @@ ruleTester.run("prefer-const", rule, { console.log(itemId, list, obj); `, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, { messageId: "useConst", data: { name: "obj" }, type: "Identifier" } - ] + ], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/prefer-destructuring.js b/tests/lib/rules/prefer-destructuring.js index 7f808a64218..c880b47d4b2 100644 --- a/tests/lib/rules/prefer-destructuring.js +++ b/tests/lib/rules/prefer-destructuring.js @@ -9,14 +9,14 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-destructuring"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("prefer-destructuring", rule, { valid: [ @@ -100,16 +100,16 @@ ruleTester.run("prefer-destructuring", rule, { "foo += array[0]", { code: "foo &&= array[0]", - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, "foo += bar.foo", { code: "foo ||= bar.foo", - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "foo ??= bar['foo']", - parserOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 } }, { code: "foo = object.foo;", diff --git a/tests/lib/rules/prefer-exponentiation-operator.js b/tests/lib/rules/prefer-exponentiation-operator.js index 8765330c00f..8b6b9adc3b4 100644 --- a/tests/lib/rules/prefer-exponentiation-operator.js +++ b/tests/lib/rules/prefer-exponentiation-operator.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-exponentiation-operator"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const parser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -41,7 +41,7 @@ function invalid(code, output) { // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("prefer-exponentiation-operator", rule, { valid: [ @@ -59,8 +59,8 @@ ruleTester.run("prefer-exponentiation-operator", rule, { "foo.Math.pow(a, b)", "new Math.pow(a, b)", "Math[pow](a, b)", - { code: "globalThis.Object.pow(a, b)", env: { es2020: true } }, - { code: "globalThis.Math.max(a, b)", env: { es2020: true } }, + { code: "globalThis.Object.pow(a, b)", languageOptions: { ecmaVersion: 2020 } }, + { code: "globalThis.Math.max(a, b)", languageOptions: { ecmaVersion: 2020 } }, // not the global Math "/* globals Math:off*/ Math.pow(a, b)", @@ -70,15 +70,15 @@ ruleTester.run("prefer-exponentiation-operator", rule, { "function foo(Math) { Math.pow(a, b); }", "function foo() { Math.pow(a, b); var Math; }", - "globalThis.Math.pow(a, b)", - { code: "globalThis.Math.pow(a, b)", env: { es6: true } }, - { code: "globalThis.Math.pow(a, b)", env: { es2017: true } }, + { code: "globalThis.Math.pow(a, b)", languageOptions: { ecmaVersion: 2019 } }, + { code: "globalThis.Math.pow(a, b)", languageOptions: { ecmaVersion: 6 } }, + { code: "globalThis.Math.pow(a, b)", languageOptions: { ecmaVersion: 2017 } }, { code: ` var globalThis = bar; globalThis.Math.pow(a, b) `, - env: { es2020: true } + languageOptions: { ecmaVersion: 2020 } }, "class C { #pow; foo() { Math.#pow(a, b); } }" @@ -94,7 +94,6 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "globalThis.Math.pow(a, b)", output: "a**b", - env: { es2020: true }, errors: [ { messageId: "useExponentiation", @@ -104,12 +103,12 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 26 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.Math['pow'](a, b)", output: "a**b", - env: { es2020: true }, errors: [ { messageId: "useExponentiation", @@ -119,7 +118,8 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 29 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, // able to catch some workarounds @@ -364,35 +364,41 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "Math.pow(a, b as any)", output: "a**(b as any)", - parser: parser("typescript-parsers/exponentiation-with-assertion-1"), errors: [ { messageId: "useExponentiation", type: "CallExpression" } - ] + ], + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-1")) + } }, { code: "Math.pow(a as any, b)", output: "(a as any)**b", - parser: parser("typescript-parsers/exponentiation-with-assertion-2"), errors: [ { messageId: "useExponentiation", type: "CallExpression" } - ] + ], + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-2")) + } }, { code: "Math.pow(a, b) as any", output: "(a**b) as any", - parser: parser("typescript-parsers/exponentiation-with-assertion-3"), errors: [ { messageId: "useExponentiation", type: "CallExpression" } - ] + ], + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-3")) + } } ] }); diff --git a/tests/lib/rules/prefer-named-capture-group.js b/tests/lib/rules/prefer-named-capture-group.js index 31dcc70f332..b1dc9042087 100644 --- a/tests/lib/rules/prefer-named-capture-group.js +++ b/tests/lib/rules/prefer-named-capture-group.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-named-capture-group"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2018 } }); ruleTester.run("prefer-named-capture-group", rule, { valid: [ @@ -37,30 +37,30 @@ ruleTester.run("prefer-named-capture-group", rule, { "new globalThis.RegExp('([0-9]{4})')", { code: "new globalThis.RegExp('([0-9]{4})')", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "new globalThis.RegExp('([0-9]{4})')", - env: { es2017: true } + languageOptions: { ecmaVersion: 2017 } }, { code: "new globalThis.RegExp()", - env: { es2020: true } + languageOptions: { ecmaVersion: 2020 } }, { code: "new globalThis.RegExp(foo)", - env: { es2020: true } + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.RegExp(foo)", - env: { es2020: true } + languageOptions: { ecmaVersion: 2020 } }, { code: ` var globalThis = bar; globalThis.RegExp(foo); `, - env: { es2020: true } + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -69,7 +69,7 @@ ruleTester.run("prefer-named-capture-group", rule, { new globalThis.RegExp(baz); } `, - env: { es2020: true } + languageOptions: { ecmaVersion: 2020 } }, // ES2024 @@ -529,7 +529,6 @@ ruleTester.run("prefer-named-capture-group", rule, { }, { code: "new globalThis.RegExp('([0-9]{4})')", - env: { es2020: true }, errors: [{ messageId: "required", type: "NewExpression", @@ -547,11 +546,11 @@ ruleTester.run("prefer-named-capture-group", rule, { output: "new globalThis.RegExp('(?:[0-9]{4})')" } ] - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.RegExp('([0-9]{4})')", - env: { es2020: true }, errors: [{ messageId: "required", type: "CallExpression", @@ -569,14 +568,14 @@ ruleTester.run("prefer-named-capture-group", rule, { output: "globalThis.RegExp('(?:[0-9]{4})')" } ] - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: ` function foo() { var globalThis = bar; } new globalThis.RegExp('([0-9]{4})'); `, - env: { es2020: true }, errors: [{ messageId: "required", type: "NewExpression", @@ -600,7 +599,8 @@ ruleTester.run("prefer-named-capture-group", rule, { ` } ] - }] + }], + languageOptions: { ecmaVersion: 2020 } }, // ES2024 diff --git a/tests/lib/rules/prefer-numeric-literals.js b/tests/lib/rules/prefer-numeric-literals.js index e3cacaa1318..dbbb42ac8f0 100644 --- a/tests/lib/rules/prefer-numeric-literals.js +++ b/tests/lib/rules/prefer-numeric-literals.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-numeric-literals"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2021 } }); ruleTester.run("prefer-numeric-literals", rule, { valid: [ @@ -41,27 +41,27 @@ ruleTester.run("prefer-numeric-literals", rule, { "parseInt(`11${foo}`, 2);", { code: "parseInt('11', 2n);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "Number.parseInt('11', 8n);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "parseInt('11', 16n);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "parseInt(`11`, 16n);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "parseInt(1n, 2);", - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "class C { #parseInt; foo() { Number.#parseInt(\"111110111\", 2); } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -178,38 +178,38 @@ ruleTester.run("prefer-numeric-literals", rule, { { code: "function *f(){ yield(Number).parseInt('11', 2) }", output: "function *f(){ yield 0b11 }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Use binary literals instead of (Number).parseInt()." }] + errors: [{ message: "Use binary literals instead of (Number).parseInt()." }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *f(){ yield(Number.parseInt)('67', 8) }", output: "function *f(){ yield 0o67 }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Use octal literals instead of Number.parseInt()." }] + errors: [{ message: "Use octal literals instead of Number.parseInt()." }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *f(){ yield(parseInt)('A', 16) }", output: "function *f(){ yield 0xA }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Use hexadecimal literals instead of parseInt()." }] + errors: [{ message: "Use hexadecimal literals instead of parseInt()." }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *f(){ yield Number.parseInt('11', 2) }", output: "function *f(){ yield 0b11 }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Use binary literals instead of Number.parseInt()." }] + errors: [{ message: "Use binary literals instead of Number.parseInt()." }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *f(){ yield/**/Number.parseInt('67', 8) }", output: "function *f(){ yield/**/0o67 }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Use octal literals instead of Number.parseInt()." }] + errors: [{ message: "Use octal literals instead of Number.parseInt()." }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *f(){ yield(parseInt('A', 16)) }", output: "function *f(){ yield(0xA) }", - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Use hexadecimal literals instead of parseInt()." }] + errors: [{ message: "Use hexadecimal literals instead of parseInt()." }], + languageOptions: { ecmaVersion: 6 } }, { code: "parseInt('11', 2)+5", diff --git a/tests/lib/rules/prefer-object-has-own.js b/tests/lib/rules/prefer-object-has-own.js index d58f7f5c211..d50606f34d6 100644 --- a/tests/lib/rules/prefer-object-has-own.js +++ b/tests/lib/rules/prefer-object-has-own.js @@ -11,17 +11,17 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-object-has-own"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const parserOptions = { +const languageOptions = { ecmaVersion: 2022 }; -const ruleTester = new RuleTester({ parserOptions }); +const ruleTester = new RuleTester({ languageOptions }); ruleTester.run("prefer-object-has-own", rule, { valid: [ diff --git a/tests/lib/rules/prefer-object-spread.js b/tests/lib/rules/prefer-object-spread.js index 8ecd37764c4..3ea4ed01275 100644 --- a/tests/lib/rules/prefer-object-spread.js +++ b/tests/lib/rules/prefer-object-spread.js @@ -10,18 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-object-spread"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const parserOptions = { +const languageOptions = { ecmaVersion: 2018, sourceType: "module" }; -const ruleTester = new RuleTester({ parserOptions }); +const ruleTester = new RuleTester({ languageOptions }); ruleTester.run("prefer-object-spread", rule, { valid: [ @@ -69,22 +69,22 @@ ruleTester.run("prefer-object-spread", rule, { "globalThis.Object.assign({}, foo)", { code: "globalThis.Object.assign({}, { foo: 'bar' })", - env: { es6: true } + languageOptions: { ecmaVersion: 6 } }, { code: "globalThis.Object.assign({}, baz, { foo: 'bar' })", - env: { es2017: true } + languageOptions: { ecmaVersion: 2017 } }, { code: ` var globalThis = foo; globalThis.Object.assign({}, foo) `, - env: { es2020: true } + languageOptions: { ecmaVersion: 2020 } }, { code: "class C { #assign; foo() { Object.#assign({}, foo); } }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // ignore Object.assign() with > 1 arguments if any of the arguments is an object expression with a getter/setter @@ -347,9 +347,6 @@ ruleTester.run("prefer-object-spread", rule, { baz: "cats" --> weird }`, - parserOptions: { - sourceType: "script" - }, errors: [ { messageId: "useSpreadMessage", @@ -357,7 +354,10 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 14 } - ] + ], + languageOptions: { + sourceType: "script" + } }, { @@ -899,7 +899,6 @@ ruleTester.run("prefer-object-spread", rule, { { code: "globalThis.Object.assign({ });", output: "({});", - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -907,12 +906,12 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.Object.assign({\n});", output: "({});", - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -920,7 +919,8 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -931,7 +931,6 @@ ruleTester.run("prefer-object-spread", rule, { function foo () { var globalThis = bar; } ({}); `, - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -939,7 +938,8 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: ` @@ -950,7 +950,6 @@ ruleTester.run("prefer-object-spread", rule, { const Foo = require('foo'); ({foo: Foo}); `, - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -958,7 +957,8 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, // report Object.assign() with getters/setters if the function call has only 1 argument @@ -979,7 +979,6 @@ ruleTester.run("prefer-object-spread", rule, { { code: "const obj = Object.assign<{}, Record>({}, getObject());", output: "const obj = { ...getObject()};", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1"), errors: [ { messageId: "useSpreadMessage", @@ -987,12 +986,14 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 13 } - ] + ], + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1") + } }, { code: "Object.assign<{}, A>({}, foo);", output: "({ ...foo});", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2"), errors: [ { messageId: "useSpreadMessage", @@ -1000,7 +1001,10 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ] + ], + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2") + } } ] }); diff --git a/tests/lib/rules/prefer-promise-reject-errors.js b/tests/lib/rules/prefer-promise-reject-errors.js index 40428d6fa24..9a9e1ea616d 100644 --- a/tests/lib/rules/prefer-promise-reject-errors.js +++ b/tests/lib/rules/prefer-promise-reject-errors.js @@ -9,13 +9,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-promise-reject-errors"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022, sourceType: "script" } }); ruleTester.run("prefer-promise-reject-errors", rule, { diff --git a/tests/lib/rules/prefer-reflect.js b/tests/lib/rules/prefer-reflect.js index 5da4261b9ca..0381f53d2dd 100644 --- a/tests/lib/rules/prefer-reflect.js +++ b/tests/lib/rules/prefer-reflect.js @@ -10,13 +10,18 @@ // Requirements //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-reflect"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("prefer-reflect", rule, { valid: [ diff --git a/tests/lib/rules/prefer-regex-literals.js b/tests/lib/rules/prefer-regex-literals.js index 11f23cac3d5..231483b6dc4 100644 --- a/tests/lib/rules/prefer-regex-literals.js +++ b/tests/lib/rules/prefer-regex-literals.js @@ -10,14 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-regex-literals"); -const { RuleTester } = require("../../../lib/rule-tester"), - FlatRuleTester = require("../../../lib/rule-tester/flat-rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 2022, + sourceType: "script" + } +}); ruleTester.run("prefer-regex-literals", rule, { valid: [ @@ -104,7 +108,9 @@ ruleTester.run("prefer-regex-literals", rule, { "/* globals String:off */ new RegExp(String.raw`a`);", { code: "RegExp('a', String.raw`g`);", - globals: { String: "off" } + languageOptions: { + globals: { String: "off" } + } }, // not RegExp @@ -120,21 +126,23 @@ ruleTester.run("prefer-regex-literals", rule, { "/* globals RegExp:off */ new RegExp('a');", { code: "RegExp('a');", - globals: { RegExp: "off" } + languageOptions: { + globals: { RegExp: "off" } + } }, - "new globalThis.RegExp('a');", { code: "new globalThis.RegExp('a');", - env: { es6: true } + languageOptions: { ecmaVersion: 5 } }, { code: "new globalThis.RegExp('a');", - env: { es2017: true } + languageOptions: { ecmaVersion: 2015 } }, { - code: "class C { #RegExp; foo() { globalThis.#RegExp('a'); } }", - env: { es2020: true } + code: "new globalThis.RegExp('a');", + languageOptions: { ecmaVersion: 2017 } }, + "class C { #RegExp; foo() { globalThis.#RegExp('a'); } }", // ES2024 "new RegExp('[[A--B]]' + a, 'v')" @@ -533,9 +541,6 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('a');", - env: { - es2020: true - }, errors: [ { messageId: "unexpectedRegExp", @@ -547,13 +552,11 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "globalThis.RegExp('a');", - env: { - es2020: true - }, errors: [ { messageId: "unexpectedRegExp", @@ -565,7 +568,8 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "new RegExp(/a/);", @@ -906,9 +910,6 @@ ruleTester.run("prefer-regex-literals", rule, { disallowRedundantWrapping: true } ], - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -917,7 +918,10 @@ ruleTester.run("prefer-regex-literals", rule, { column: 1, suggestions: null } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "(a)\nnew RegExp(/b/);", @@ -1077,33 +1081,31 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('abc', 'u');", - parserOptions: { - ecmaVersion: 3 - }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ] + ], + languageOptions: { + ecmaVersion: 3, + sourceType: "script" + } }, { code: "new RegExp('abc', 'd');", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "RegExp('abc', 'd');", - parserOptions: { - ecmaVersion: 2022 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1114,7 +1116,10 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2022 + } }, { code: "RegExp('\\\\\\\\', '');", @@ -1132,9 +1137,6 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('\\n', '');", - parserOptions: { - ecmaVersion: 2022 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1145,7 +1147,10 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2022 + } }, { code: "RegExp('\\n\\n', '');", @@ -1344,9 +1349,6 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('\\\\W', '');", - globals: { - globalThis: "readonly" - }, errors: [ { messageId: "unexpectedRegExp", @@ -1357,7 +1359,12 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + globals: { + globalThis: "readonly" + } + } }, { code: "RegExp('\\\\s', '');", @@ -1389,9 +1396,6 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "globalThis.RegExp('\\\\d', '');", - globals: { - globalThis: "readonly" - }, errors: [ { messageId: "unexpectedRegExp", @@ -1402,13 +1406,15 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + globals: { + globalThis: "readonly" + } + } }, { code: "globalThis.RegExp('\\\\D', '')", - globals: { - globalThis: "readonly" - }, errors: [ { messageId: "unexpectedRegExp", @@ -1419,13 +1425,15 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + globals: { + globalThis: "readonly" + } + } }, { code: "globalThis.RegExp('\\\\\\\\\\\\D', '')", - globals: { - globalThis: "readonly" - }, errors: [ { messageId: "unexpectedRegExp", @@ -1436,7 +1444,12 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + globals: { + globalThis: "readonly" + } + } }, { code: "new RegExp('\\\\D\\\\D', '')", @@ -1454,9 +1467,6 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('\\\\0\\\\0', '');", - globals: { - globalThis: "writable" - }, errors: [ { messageId: "unexpectedRegExp", @@ -1467,7 +1477,12 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + globals: { + globalThis: "writable" + } + } }, { code: "new RegExp('\\\\0\\\\0', '');", @@ -1508,9 +1523,6 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('\\\\78\\\\126\\\\5934', '')", - parserOptions: { - ecmaVersion: 2022 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1521,13 +1533,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2022 + } }, { code: "new window['RegExp']('\\\\x56\\\\x78\\\\x45', '');", - env: { - browser: true - }, errors: [ { messageId: "unexpectedRegExp", @@ -1538,7 +1550,12 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + globals: { + window: "readonly" + } + } }, { code: "a in(RegExp('abc'))", @@ -1748,16 +1765,16 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "async function abc(){await new RegExp(\"foo\")}", - parserOptions: { - ecmaVersion: 8, - sourceType: "module" - }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ] + ], + languageOptions: { + ecmaVersion: 8, + sourceType: "module" + } }, { code: "function* abc(){yield new RegExp(\"foo\")}", @@ -1886,9 +1903,6 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ == new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1899,13 +1913,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ === new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1916,13 +1930,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ != new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1933,13 +1947,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ !== new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1950,13 +1964,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ > new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1967,13 +1981,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ < new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -1984,13 +1998,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ >= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2001,13 +2015,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ <= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2018,13 +2032,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ << new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2035,13 +2049,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ >> new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2052,13 +2066,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ >>> new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2069,13 +2083,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ ^ new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2086,13 +2100,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ & new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2103,13 +2117,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n /abc/ | new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2120,13 +2134,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n null ?? new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2137,13 +2151,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc *= new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2154,13 +2168,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n console.log({a: new RegExp('sup')})\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2171,13 +2185,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n console.log(() => {new RegExp('sup')})\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2188,13 +2202,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n function abc() {new RegExp('sup')}\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2205,13 +2219,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n function abc() {return new RegExp('sup')}\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2222,13 +2236,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc <<= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2239,13 +2253,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc >>= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2256,13 +2270,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc >>>= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2273,13 +2287,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc ^= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2290,13 +2304,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc &= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2307,13 +2321,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc |= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2324,13 +2338,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc ??= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2341,13 +2355,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc &&= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2358,13 +2372,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc ||= new RegExp('cba');\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2375,13 +2389,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc **= new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2392,13 +2406,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc /= new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2409,13 +2423,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc += new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2426,13 +2440,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc -= new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2443,13 +2457,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n abc %= new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2460,13 +2474,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "\n () => new RegExp('blah')\n ", - parserOptions: { - ecmaVersion: 2021 - }, errors: [ { messageId: "unexpectedRegExp", @@ -2477,7 +2491,10 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { + ecmaVersion: 2021 + } }, { code: "a/RegExp(\"foo\")in b", @@ -2588,15 +2605,15 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "(async function(){for await (value of new RegExp('something being searched')) { console.log(value) }})()", - parserOptions: { - ecmaVersion: 2018 - }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ] + ], + languageOptions: { + ecmaVersion: 2018 + } }, { code: "for (value in new RegExp('something being searched')) { console.log(value) }", @@ -2816,7 +2833,6 @@ ruleTester.run("prefer-regex-literals", rule, { // ES2024 { code: "new RegExp('[[A--B]]', 'v')", - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", @@ -2827,42 +2843,42 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp('[[A--B]]', 'v')", - parserOptions: { ecmaVersion: 2023 }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ] + ], + languageOptions: { ecmaVersion: 2023 } }, { code: "new RegExp('[[A&&&]]', 'v')", - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp('a', 'uv')", - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp(/a/, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2876,23 +2892,23 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp(/a/, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2023 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", suggestions: null } - ] + ], + languageOptions: { ecmaVersion: 2023 } }, { code: "new RegExp(/a/g, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2913,12 +2929,12 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp(/[[A--B]]/v, 'g')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2934,12 +2950,12 @@ ruleTester.run("prefer-regex-literals", rule, { // suggestion with flags `g` would be invalid ] } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp(/a/u, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2955,12 +2971,12 @@ ruleTester.run("prefer-regex-literals", rule, { // suggestion with merged flags `uv` would be invalid ] } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp(/a/v, 'u')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2976,33 +2992,22 @@ ruleTester.run("prefer-regex-literals", rule, { // suggestion with merged flags `vu` would be invalid ] } - ] + ], + languageOptions: { ecmaVersion: 2024 } }, { code: "new RegExp(/[[A--B]]/v, 'u')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", suggestions: null } - ] - } - ] -}); - -const flatRuleTester = new FlatRuleTester(); - -flatRuleTester.run("prefer-regex-literals", rule, { - valid: [], - - invalid: [ + ], + languageOptions: { ecmaVersion: 2024 } + }, { code: "var regex = new RegExp('foo', 'u');", - languageOptions: { - ecmaVersion: 2015 - }, errors: [{ messageId: "unexpectedRegExp", suggestions: [ @@ -3011,7 +3016,11 @@ flatRuleTester.run("prefer-regex-literals", rule, { output: "var regex = /foo/u;" } ] - }] + }], + languageOptions: { + ecmaVersion: 2015 + } } + ] }); diff --git a/tests/lib/rules/prefer-rest-params.js b/tests/lib/rules/prefer-rest-params.js index c7040ea401d..328edff9f8e 100644 --- a/tests/lib/rules/prefer-rest-params.js +++ b/tests/lib/rules/prefer-rest-params.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-rest-params"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "script" } }); ruleTester.run("prefer-rest-params", rule, { valid: [ diff --git a/tests/lib/rules/prefer-spread.js b/tests/lib/rules/prefer-spread.js index 99c8c5fa41a..8683f88d9e9 100644 --- a/tests/lib/rules/prefer-spread.js +++ b/tests/lib/rules/prefer-spread.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-spread"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -18,7 +18,7 @@ const { RuleTester } = require("../../../lib/rule-tester"); const errors = [{ messageId: "preferSpread", type: "CallExpression" }]; -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } }); ruleTester.run("prefer-spread", rule, { valid: [ diff --git a/tests/lib/rules/prefer-template.js b/tests/lib/rules/prefer-template.js index a89a36a9de2..700cef91338 100644 --- a/tests/lib/rules/prefer-template.js +++ b/tests/lib/rules/prefer-template.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/prefer-template"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -21,7 +21,7 @@ const errors = [{ type: "BinaryExpression" }]; -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "script" } }); ruleTester.run("prefer-template", rule, { valid: [ diff --git a/tests/lib/rules/quote-props.js b/tests/lib/rules/quote-props.js index 10f35155f03..2aa08eb4361 100644 --- a/tests/lib/rules/quote-props.js +++ b/tests/lib/rules/quote-props.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/quote-props"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -29,14 +29,14 @@ ruleTester.run("quote-props", rule, { "({ 'if': 0 })", "({ '@': 0 })", - { code: "({ 'a': 0, b(){} })", parserOptions: { ecmaVersion: 6 } }, - { code: "({ [x]: 0 });", env: { es6: true } }, - { code: "({ x });", env: { es6: true } }, - { code: "({ a: 0, b(){} })", options: ["as-needed"], parserOptions: { ecmaVersion: 6 } }, - { code: "({ a: 0, [x]: 1 })", options: ["as-needed"], env: { es6: true } }, - { code: "({ a: 0, x })", options: ["as-needed"], env: { es6: true } }, - { code: "({ '@': 0, [x]: 1 })", options: ["as-needed"], env: { es6: true } }, - { code: "({ '@': 0, x })", options: ["as-needed"], env: { es6: true } }, + { code: "({ 'a': 0, b(){} })", languageOptions: { ecmaVersion: 6 } }, + { code: "({ [x]: 0 });", languageOptions: { ecmaVersion: 6 } }, + { code: "({ x });", languageOptions: { ecmaVersion: 6 } }, + { code: "({ a: 0, b(){} })", options: ["as-needed"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ a: 0, [x]: 1 })", options: ["as-needed"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ a: 0, x })", options: ["as-needed"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ '@': 0, [x]: 1 })", options: ["as-needed"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ '@': 0, x })", options: ["as-needed"], languageOptions: { ecmaVersion: 6 } }, { code: "({ a: 0, b: 0 })", options: ["as-needed"] }, { code: "({ a: 0, 0: 0 })", options: ["as-needed"] }, { code: "({ a: 0, true: 0 })", options: ["as-needed"] }, @@ -56,18 +56,18 @@ ruleTester.run("quote-props", rule, { { code: "({ 'true': 0, 'b': 0 })", options: ["consistent"] }, { code: "({ null: 0, a: 0 })", options: ["consistent"] }, { code: "({ a: 0, b: 0 })", options: ["consistent"] }, - { code: "({ 'a': 1, [x]: 0 });", options: ["consistent"], env: { es6: true } }, - { code: "({ 'a': 1, x });", options: ["consistent"], env: { es6: true } }, + { code: "({ 'a': 1, [x]: 0 });", options: ["consistent"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ 'a': 1, x });", options: ["consistent"], languageOptions: { ecmaVersion: 6 } }, { code: "({ a: 0, b: 0 })", options: ["consistent-as-needed"] }, { code: "({ a: 0, null: 0 })", options: ["consistent-as-needed"] }, { code: "({ 'a': 0, '-b': 0 })", options: ["consistent-as-needed"] }, { code: "({ '@': 0, 'B': 0 })", options: ["consistent-as-needed"] }, { code: "({ 'while': 0, 'B': 0 })", options: ["consistent-as-needed", { keywords: true }] }, { code: "({ '@': 0, 'B': 0 })", options: ["consistent-as-needed", { keywords: true }] }, - { code: "({ '@': 1, [x]: 0 });", options: ["consistent-as-needed"], env: { es6: true } }, - { code: "({ '@': 1, x });", options: ["consistent-as-needed"], env: { es6: true } }, - { code: "({ a: 1, [x]: 0 });", options: ["consistent-as-needed"], env: { es6: true } }, - { code: "({ a: 1, x });", options: ["consistent-as-needed"], env: { es6: true } }, + { code: "({ '@': 1, [x]: 0 });", options: ["consistent-as-needed"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ '@': 1, x });", options: ["consistent-as-needed"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ a: 1, [x]: 0 });", options: ["consistent-as-needed"], languageOptions: { ecmaVersion: 6 } }, + { code: "({ a: 1, x });", options: ["consistent-as-needed"], languageOptions: { ecmaVersion: 6 } }, { code: "({ a: 0, 'if': 0 })", options: ["as-needed", { keywords: true }] }, { code: "({ a: 0, 'while': 0 })", options: ["as-needed", { keywords: true }] }, { code: "({ a: 0, 'volatile': 0 })", options: ["as-needed", { keywords: true }] }, @@ -75,21 +75,21 @@ ruleTester.run("quote-props", rule, { { code: "({'1': 1})", options: ["as-needed", { numbers: true }] }, { code: "({1: 1, x: 2})", options: ["consistent", { numbers: true }] }, { code: "({1: 1, x: 2})", options: ["consistent-as-needed", { numbers: true }] }, - { code: "({ ...x })", options: ["as-needed"], parserOptions: { ecmaVersion: 2018 } }, - { code: "({ ...x })", options: ["consistent"], parserOptions: { ecmaVersion: 2018 } }, - { code: "({ ...x })", options: ["consistent-as-needed"], parserOptions: { ecmaVersion: 2018 } }, - { code: "({ 1n: 1 })", options: ["as-needed"], parserOptions: { ecmaVersion: 2020 } }, - { code: "({ 1n: 1 })", options: ["as-needed", { numbers: false }], parserOptions: { ecmaVersion: 2020 } }, - { code: "({ 1n: 1 })", options: ["consistent"], parserOptions: { ecmaVersion: 2020 } }, - { code: "({ 1n: 1 })", options: ["consistent-as-needed"], parserOptions: { ecmaVersion: 2020 } }, - { code: "({ '99999999999999999': 1 })", options: ["as-needed"], parserOptions: { ecmaVersion: 2020 } }, - { code: "({ '1n': 1 })", options: ["as-needed"], parserOptions: { ecmaVersion: 2020 } }, - { code: "({ 1_0: 1 })", options: ["as-needed"], parserOptions: { ecmaVersion: 2021 } }, - { code: "({ 1_0: 1 })", options: ["as-needed", { numbers: false }], parserOptions: { ecmaVersion: 2021 } }, - { code: "({ '1_0': 1 })", options: ["as-needed"], parserOptions: { ecmaVersion: 2021 } }, - { code: "({ '1_0': 1 })", options: ["as-needed", { numbers: false }], parserOptions: { ecmaVersion: 2021 } }, - { code: "({ '1_0': 1 })", options: ["as-needed", { numbers: true }], parserOptions: { ecmaVersion: 2021 } }, - { code: "({ 1_0: 1, 1: 1 })", options: ["consistent-as-needed"], parserOptions: { ecmaVersion: 2021 } } + { code: "({ ...x })", options: ["as-needed"], languageOptions: { ecmaVersion: 2018 } }, + { code: "({ ...x })", options: ["consistent"], languageOptions: { ecmaVersion: 2018 } }, + { code: "({ ...x })", options: ["consistent-as-needed"], languageOptions: { ecmaVersion: 2018 } }, + { code: "({ 1n: 1 })", options: ["as-needed"], languageOptions: { ecmaVersion: 2020 } }, + { code: "({ 1n: 1 })", options: ["as-needed", { numbers: false }], languageOptions: { ecmaVersion: 2020 } }, + { code: "({ 1n: 1 })", options: ["consistent"], languageOptions: { ecmaVersion: 2020 } }, + { code: "({ 1n: 1 })", options: ["consistent-as-needed"], languageOptions: { ecmaVersion: 2020 } }, + { code: "({ '99999999999999999': 1 })", options: ["as-needed"], languageOptions: { ecmaVersion: 2020 } }, + { code: "({ '1n': 1 })", options: ["as-needed"], languageOptions: { ecmaVersion: 2020 } }, + { code: "({ 1_0: 1 })", options: ["as-needed"], languageOptions: { ecmaVersion: 2021 } }, + { code: "({ 1_0: 1 })", options: ["as-needed", { numbers: false }], languageOptions: { ecmaVersion: 2021 } }, + { code: "({ '1_0': 1 })", options: ["as-needed"], languageOptions: { ecmaVersion: 2021 } }, + { code: "({ '1_0': 1 })", options: ["as-needed", { numbers: false }], languageOptions: { ecmaVersion: 2021 } }, + { code: "({ '1_0': 1 })", options: ["as-needed", { numbers: true }], languageOptions: { ecmaVersion: 2021 } }, + { code: "({ 1_0: 1, 1: 1 })", options: ["consistent-as-needed"], languageOptions: { ecmaVersion: 2021 } } ], invalid: [{ code: "({ a: 0 })", @@ -182,18 +182,18 @@ ruleTester.run("quote-props", rule, { code: "({ 'a': 0, [x]: 0 })", output: "({ a: 0, [x]: 0 })", options: ["consistent-as-needed"], - env: { es6: true }, errors: [ { messageId: "redundantQuoting", type: "Property" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "({ 'a': 0, x })", output: "({ a: 0, x })", options: ["consistent-as-needed"], - env: { es6: true }, errors: [{ messageId: "redundantQuoting", type: "Property" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "({ 'true': 0, 'null': 0 })", output: "({ true: 0, null: 0 })", @@ -375,56 +375,56 @@ ruleTester.run("quote-props", rule, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "1" } } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["as-needed", { numbers: true }], - parserOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unquotedNumericProperty", data: { property: "1" } - }] + }], + languageOptions: { ecmaVersion: 2020 } }, { code: "({ 1_0: 1 })", output: "({ \"10\": 1 })", options: ["as-needed", { numbers: true }], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedNumericProperty", data: { property: "10" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "({ 1_2.3_4e0_2: 1 })", output: "({ \"1234\": 1 })", options: ["always"], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "1234" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "({ 0b1_000: 1 })", output: "({ \"8\": 1 })", options: ["always"], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "8" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "({ 1_000: a, '1_000': b })", output: "({ \"1000\": a, '1_000': b })", options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "inconsistentlyQuotedProperty", data: { key: "1000" } - }] + }], + languageOptions: { ecmaVersion: 2021 } }] }); diff --git a/tests/lib/rules/quotes.js b/tests/lib/rules/quotes.js index 11ae90248b7..f3195e6aa94 100644 --- a/tests/lib/rules/quotes.js +++ b/tests/lib/rules/quotes.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/quotes"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("quotes", rule, { valid: [ @@ -27,71 +32,71 @@ ruleTester.run("quotes", rule, { { code: "var foo = 1;", options: ["double"] }, { code: "var foo = \"'\";", options: ["single", { avoidEscape: true }] }, { code: "var foo = '\"';", options: ["double", { avoidEscape: true }] }, - { code: "var foo = <>Hello world;", options: ["single"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo = <>Hello world;", options: ["double"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo = <>Hello world;", options: ["double", { avoidEscape: true }], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo = <>Hello world;", options: ["backtick"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo =
Hello world
;", options: ["single"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo =
;", options: ["single"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo =
Hello world
;", options: ["double"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo =
Hello world
;", options: ["double", { avoidEscape: true }], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo = `bar`;", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `bar 'baz'`;", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `bar \"baz\"`;", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = <>Hello world;", options: ["single"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo = <>Hello world;", options: ["double"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo = <>Hello world;", options: ["double", { avoidEscape: true }], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo = <>Hello world;", options: ["backtick"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo =
Hello world
;", options: ["single"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo =
;", options: ["single"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo =
Hello world
;", options: ["double"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo =
Hello world
;", options: ["double", { avoidEscape: true }], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo = `bar`;", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `bar 'baz'`;", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `bar \"baz\"`;", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, { code: "var foo = 1;", options: ["backtick"] }, { code: "var foo = \"a string containing `backtick` quotes\";", options: ["backtick", { avoidEscape: true }] }, - { code: "var foo =
;", options: ["backtick"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "var foo =
Hello world
;", options: ["backtick"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } }, - { code: "class C { \"f\"; \"m\"() {} }", options: ["double"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { 'f'; 'm'() {} }", options: ["single"], parserOptions: { ecmaVersion: 2022 } }, + { code: "var foo =
;", options: ["backtick"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "var foo =
Hello world
;", options: ["backtick"], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, + { code: "class C { \"f\"; \"m\"() {} }", options: ["double"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { 'f'; 'm'() {} }", options: ["single"], languageOptions: { ecmaVersion: 2022 } }, // Backticks are only okay if they have substitutions, contain a line break, or are tagged - { code: "var foo = `back\ntick`;", options: ["single"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `back\rtick`;", options: ["single"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `back\u2028tick`;", options: ["single"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `back\u2029tick`;", options: ["single"], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = `back\ntick`;", options: ["single"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `back\rtick`;", options: ["single"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `back\u2028tick`;", options: ["single"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `back\u2029tick`;", options: ["single"], languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `back\\\\\ntick`;", // 2 backslashes followed by a newline options: ["single"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, - { code: "var foo = `back\\\\\\\\\ntick`;", options: ["single"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `\n`;", options: ["single"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `back${x}tick`;", options: ["double"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = tag`backtick`;", options: ["double"], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = `back\\\\\\\\\ntick`;", options: ["single"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `\n`;", options: ["single"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `back${x}tick`;", options: ["double"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = tag`backtick`;", options: ["double"], languageOptions: { ecmaVersion: 6 } }, // Backticks are also okay if allowTemplateLiterals - { code: "var foo = `bar 'foo' baz` + 'bar';", options: ["single", { allowTemplateLiterals: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `bar 'foo' baz` + \"bar\";", options: ["double", { allowTemplateLiterals: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `bar 'foo' baz` + `bar`;", options: ["backtick", { allowTemplateLiterals: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = `bar 'foo' baz` + 'bar';", options: ["single", { allowTemplateLiterals: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `bar 'foo' baz` + \"bar\";", options: ["double", { allowTemplateLiterals: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `bar 'foo' baz` + `bar`;", options: ["backtick", { allowTemplateLiterals: true }], languageOptions: { ecmaVersion: 6 } }, // `backtick` should not warn the directive prologues. - { code: "\"use strict\"; var foo = `backtick`;", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "\"use strict\"; 'use strong'; \"use asm\"; var foo = `backtick`;", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "function foo() { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; }", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "(function() { 'use strict'; 'use strong'; 'use asm'; var foo = `backtick`; })();", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "(() => { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; })();", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, + { code: "\"use strict\"; var foo = `backtick`;", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "\"use strict\"; 'use strong'; \"use asm\"; var foo = `backtick`;", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; }", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "(function() { 'use strict'; 'use strong'; 'use asm'; var foo = `backtick`; })();", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "(() => { \"use strict\"; \"use strong\"; \"use asm\"; var foo = `backtick`; })();", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, // `backtick` should not warn import/export sources. - { code: "import \"a\"; import 'b';", options: ["backtick"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import a from \"a\"; import b from 'b';", options: ["backtick"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export * from \"a\"; export * from 'b';", options: ["backtick"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import \"a\"; import 'b';", options: ["backtick"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import a from \"a\"; import b from 'b';", options: ["backtick"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export * from \"a\"; export * from 'b';", options: ["backtick"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // `backtick` should not warn module export names. - { code: "import { \"a\" as b, 'c' as d } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "let a, c; export { a as \"b\", c as 'd' };", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { \"a\", 'b' } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { a as \"b\", c as 'd' } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { \"a\" as b, 'c' as d } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export { \"a\" as \"b\", 'c' as 'd' } from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export * as \"a\" from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "export * as 'a' from 'mod';", options: ["backtick"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "import { \"a\" as b, 'c' as d } from 'mod';", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "let a, c; export { a as \"b\", c as 'd' };", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { \"a\", 'b' } from 'mod';", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { a as \"b\", c as 'd' } from 'mod';", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { \"a\" as b, 'c' as d } from 'mod';", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export { \"a\" as \"b\", 'c' as 'd' } from 'mod';", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export * as \"a\" from 'mod';", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "export * as 'a' from 'mod';", options: ["backtick"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, // `backtick` should not warn property/method names (not computed). - { code: "var obj = {\"key0\": 0, 'key1': 1};", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "class Foo { 'bar'(){} }", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "class Foo { static ''(){} }", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }, - { code: "class C { \"double\"; 'single'; }", options: ["backtick"], parserOptions: { ecmaVersion: 2022 } } + { code: "var obj = {\"key0\": 0, 'key1': 1};", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "class Foo { 'bar'(){} }", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "class Foo { static ''(){} }", options: ["backtick"], languageOptions: { ecmaVersion: 6 } }, + { code: "class C { \"double\"; 'single'; }", options: ["backtick"], languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { @@ -117,14 +122,14 @@ ruleTester.run("quotes", rule, { code: "var foo = `bar`;", output: "var foo = 'bar';", options: ["single"], - parserOptions: { - ecmaVersion: 6 - }, errors: [{ messageId: "wrongQuotes", data: { description: "singlequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var foo = 'don\\'t';", @@ -168,14 +173,14 @@ ruleTester.run("quotes", rule, { code: "var foo = `bar`;", output: "var foo = \"bar\";", options: ["double"], - parserOptions: { - ecmaVersion: 6 - }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { + ecmaVersion: 6 + } }, { code: "var foo = \"bar\";", @@ -231,56 +236,56 @@ ruleTester.run("quotes", rule, { code: "var foo = 'bar';", output: "var foo = `bar`;", options: ["backtick"], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var foo = 'b${x}a$r';", output: "var foo = `b\\${x}a$r`;", options: ["backtick"], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var foo = \"bar\";", output: "var foo = `bar`;", options: ["backtick"], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var foo = \"bar\";", output: "var foo = `bar`;", options: ["backtick", { avoidEscape: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: "var foo = 'bar';", output: "var foo = `bar`;", options: ["backtick", { avoidEscape: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 2015 } }, // "use strict" is *not* a directive prologue in these statements so is subject to the rule @@ -288,34 +293,34 @@ ruleTester.run("quotes", rule, { code: "var foo = `backtick`; \"use strict\";", output: "var foo = `backtick`; `use strict`;", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "{ \"use strict\"; var foo = `backtick`; }", output: "{ `use strict`; var foo = `backtick`; }", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "if (1) { \"use strict\"; var foo = `backtick`; }", output: "if (1) { `use strict`; var foo = `backtick`; }", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 6 } }, // `backtick` should warn computed property names. @@ -323,7 +328,6 @@ ruleTester.run("quotes", rule, { code: "var obj = {[\"key0\"]: 0, ['key1']: 1};", output: "var obj = {[`key0`]: 0, [`key1`]: 1};", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -335,13 +339,13 @@ ruleTester.run("quotes", rule, { data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { ['a'](){} static ['b'](){} }", output: "class Foo { [`a`](){} static [`b`](){} }", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -353,7 +357,8 @@ ruleTester.run("quotes", rule, { data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7084 @@ -361,146 +366,146 @@ ruleTester.run("quotes", rule, { code: "
", output: "
", options: ["single"], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "wrongQuotes", data: { description: "singlequote" }, type: "Literal" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "
", output: "
", options: ["double"], - parserOptions: { ecmaFeatures: { jsx: true } }, errors: [ { messageId: "wrongQuotes", data: { description: "doublequote" }, type: "Literal" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, { code: "
", output: "
", options: ["backtick"], - parserOptions: { ecmaFeatures: { jsx: true }, ecmaVersion: 2015 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } }, ecmaVersion: 2015 } }, // https://github.com/eslint/eslint/issues/7610 { code: "`use strict`;", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { `use strict`; foo(); }", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo = function() { `use strict`; foo(); }", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "() => { `use strict`; foo(); }", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "() => { foo(); `use strict`; }", output: null, // no autofix - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo(); `use strict`;", output: null, // no autofix - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7646 { code: "var foo = `foo\\nbar`;", output: "var foo = \"foo\\nbar\";", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `foo\\\nbar`;", // 1 backslash followed by a newline output: "var foo = \"foo\\\nbar\";", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `foo\\\\\\\nbar`;", // 3 backslashes followed by a newline output: "var foo = \"foo\\\\\\\nbar\";", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "````", output: "\"\"``", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral", line: 1, column: 1 - }] + }], + languageOptions: { ecmaVersion: 6 } }, // Strings containing octal escape sequences. Don't autofix to backticks. @@ -532,118 +537,118 @@ ruleTester.run("quotes", rule, { code: "var notoctal = '\\0'", output: "var notoctal = `\\0`", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = '\\1'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = \"\\1\"", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = '\\01'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = '\\0\\1'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = '\\08'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = 'prefix \\33'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = 'prefix \\75 suffix'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var nonOctalDecimalEscape = '\\8'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, @@ -652,97 +657,96 @@ ruleTester.run("quotes", rule, { code: "class C { 'foo'; }", output: "class C { \"foo\"; }", options: ["double"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "doublequote" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { 'foo'() {} }", output: "class C { \"foo\"() {} }", options: ["double"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "doublequote" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { \"foo\"; }", output: "class C { 'foo'; }", options: ["single"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "singlequote" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { \"foo\"() {} }", output: "class C { 'foo'() {} }", options: ["single"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "singlequote" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [\"foo\"]; }", output: "class C { [`foo`]; }", options: ["backtick"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = \"foo\"; }", output: "class C { foo = `foo`; }", options: ["backtick"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, // https://github.com/eslint/eslint/pull/17022 { code: "() => { foo(); (`use strict`); }", output: "() => { foo(); (\"use strict\"); }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "('foo'); \"bar\";", output: "(`foo`); `bar`;", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -751,7 +755,8 @@ ruleTester.run("quotes", rule, { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "; 'use asm';", @@ -765,22 +770,22 @@ ruleTester.run("quotes", rule, { { code: "{ `foobar`; }", output: "{ \"foobar\"; }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo(() => `bar`);", output: "foo(() => \"bar\");", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }] + }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/radix.js b/tests/lib/rules/radix.js index 437d2465350..da90c460975 100644 --- a/tests/lib/rules/radix.js +++ b/tests/lib/rules/radix.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/radix"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -48,10 +48,10 @@ ruleTester.run("radix", rule, { "parseInt", "Number.foo();", "Number[parseInt]();", - { code: "class C { #parseInt; foo() { Number.#parseInt(); } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { #parseInt; foo() { Number.#parseInt(foo); } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { #parseInt; foo() { Number.#parseInt(foo, 'bar'); } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { #parseInt; foo() { Number.#parseInt(foo, 10); } }", options: ["as-needed"], parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { #parseInt; foo() { Number.#parseInt(); } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { #parseInt; foo() { Number.#parseInt(foo); } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { #parseInt; foo() { Number.#parseInt(foo, 'bar'); } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { #parseInt; foo() { Number.#parseInt(foo, 10); } }", options: ["as-needed"], languageOptions: { ecmaVersion: 2022 } }, // Ignores if it's shadowed or disabled. "var parseInt; parseInt();", @@ -61,7 +61,7 @@ ruleTester.run("radix", rule, { { code: "var Number; Number.parseInt(foo);", options: ["always"] }, { code: "var Number; Number.parseInt(foo, 10);", options: ["as-needed"] }, { code: "/* globals parseInt:off */ parseInt(foo);", options: ["always"] }, - { code: "Number.parseInt(foo, 10);", options: ["as-needed"], globals: { Number: "off" } } + { code: "Number.parseInt(foo, 10);", options: ["as-needed"], languageOptions: { globals: { Number: "off" } } } ], invalid: [ @@ -90,12 +90,12 @@ ruleTester.run("radix", rule, { }, { code: "parseInt(\"10\",);", // Function parameter with trailing comma - parserOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "parseInt(\"10\", 10,);" }] - }] + }], + languageOptions: { ecmaVersion: 2017 } }, { code: "parseInt((0, \"10\"));", // Sequence expression (no trailing comma). @@ -107,12 +107,12 @@ ruleTester.run("radix", rule, { }, { code: "parseInt((0, \"10\"),);", // Sequence expression (with trailing comma). - parserOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "parseInt((0, \"10\"), 10,);" }] - }] + }], + languageOptions: { ecmaVersion: 2017 } }, { code: "parseInt(\"10\", null);", @@ -226,47 +226,47 @@ ruleTester.run("radix", rule, { // Optional chaining { code: "parseInt?.(\"10\");", - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "parseInt?.(\"10\", 10);" }] } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "Number.parseInt?.(\"10\");", - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "Number.parseInt?.(\"10\", 10);" }] } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "Number?.parseInt(\"10\");", - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "Number?.parseInt(\"10\", 10);" }] } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "(Number?.parseInt)(\"10\");", - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "(Number?.parseInt)(\"10\", 10);" }] } - ] + ], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/require-atomic-updates.js b/tests/lib/rules/require-atomic-updates.js index 53d85b75289..37bd1dd1da0 100644 --- a/tests/lib/rules/require-atomic-updates.js +++ b/tests/lib/rules/require-atomic-updates.js @@ -9,13 +9,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/require-atomic-updates"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2022 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022, sourceType: "script" } }); const VARIABLE_ERROR = { messageId: "nonAtomicUpdate", @@ -365,7 +365,6 @@ ruleTester.run("require-atomic-updates", rule, { } }; `, - env: { node: true }, errors: [ { messageId: "nonAtomicObjectUpdate", @@ -379,7 +378,8 @@ ruleTester.run("require-atomic-updates", rule, { type: "AssignmentExpression", line: 8 } - ] + ], + languageOptions: { sourceType: "commonjs", globals: { process: "readonly" } } }, // allowProperties diff --git a/tests/lib/rules/require-await.js b/tests/lib/rules/require-await.js index 5ed2fe09367..37684c4dcf7 100644 --- a/tests/lib/rules/require-await.js +++ b/tests/lib/rules/require-await.js @@ -10,14 +10,14 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/require-await"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { + languageOptions: { ecmaVersion: 2018 } }); @@ -46,7 +46,9 @@ ruleTester.run("require-await", rule, { // global await { code: "await foo()", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/global-await") + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/global-await") + } }, { code: ` @@ -54,11 +56,13 @@ ruleTester.run("require-await", rule, { console.log(num); } `, - parser: require.resolve("../../fixtures/parsers/typescript-parsers/global-for-await-of") + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/global-for-await-of") + } }, { code: "async function* run() { yield * anotherAsyncGenerator() }", - parserOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 } }, { code: `async function* run() { @@ -67,23 +71,23 @@ ruleTester.run("require-await", rule, { console.log('World'); } `, - parserOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 } }, { code: "async function* run() { }", - parserOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 } }, { code: "const foo = async function *(){}", - parserOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 } }, { code: 'const foo = async function *(){ console.log("bar") }', - parserOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 } }, { code: 'async function* run() { console.log("bar") }', - parserOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 } } ], diff --git a/tests/lib/rules/require-jsdoc.js b/tests/lib/rules/require-jsdoc.js index f2f19da43ea..67414f84db4 100644 --- a/tests/lib/rules/require-jsdoc.js +++ b/tests/lib/rules/require-jsdoc.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/require-jsdoc"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -86,7 +86,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -108,7 +108,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: @@ -130,7 +130,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: @@ -152,7 +152,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: @@ -167,7 +167,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: false } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n Function doing something\n*/\nvar myFunction = () => {}", @@ -176,7 +176,7 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n Function doing something\n*/\nvar myFunction = () => () => {}", @@ -185,7 +185,7 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "setTimeout(() => {}, 10);", @@ -194,7 +194,7 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/**\nJSDoc Block\n*/\nvar foo = function() {}", @@ -211,7 +211,7 @@ ruleTester.run("require-jsdoc", rule, { FunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = {/**\nJSDoc Block\n*/\nbar: function() {}}", @@ -228,7 +228,7 @@ ruleTester.run("require-jsdoc", rule, { FunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -256,11 +256,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "FunctionExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -279,11 +279,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -302,11 +302,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: @@ -325,11 +325,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: @@ -348,11 +348,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var myFunction = () => {}", @@ -361,11 +361,11 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ArrowFunctionExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var myFunction = () => () => {}", @@ -374,11 +374,11 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ArrowFunctionExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() {}", @@ -399,11 +399,11 @@ ruleTester.run("require-jsdoc", rule, { FunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "FunctionExpression" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = {bar: function() {}}", diff --git a/tests/lib/rules/require-unicode-regexp.js b/tests/lib/rules/require-unicode-regexp.js index eab11b70fed..b53426b335d 100644 --- a/tests/lib/rules/require-unicode-regexp.js +++ b/tests/lib/rules/require-unicode-regexp.js @@ -10,14 +10,15 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/require-unicode-regexp"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); +const globals = require("globals"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const ruleTester = new RuleTester({ - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }); ruleTester.run("require-unicode-regexp", rule, { @@ -38,27 +39,27 @@ ruleTester.run("require-unicode-regexp", rule, { "function f(flags) { return new RegExp('', flags) }", "function f(RegExp) { return new RegExp('foo') }", "function f(patternAndFlags) { return new RegExp(...patternAndFlags) }", - { code: "new globalThis.RegExp('foo')", env: { es6: true } }, - { code: "new globalThis.RegExp('foo')", env: { es2017: true } }, - { code: "new globalThis.RegExp('foo', 'u')", env: { es2020: true } }, - { code: "globalThis.RegExp('foo', 'u')", env: { es2020: true } }, - { code: "const flags = 'u'; new globalThis.RegExp('', flags)", env: { es2020: true } }, - { code: "const flags = 'g'; new globalThis.RegExp('', flags + 'u')", env: { es2020: true } }, - { code: "const flags = 'gimu'; new globalThis.RegExp('foo', flags[3])", env: { es2020: true } }, - { code: "class C { #RegExp; foo() { new globalThis.#RegExp('foo') } }", parserOptions: { ecmaVersion: 2022 }, env: { es2020: true } }, + { code: "new globalThis.RegExp('foo')", languageOptions: { ecmaVersion: 6 } }, + { code: "new globalThis.RegExp('foo')", languageOptions: { ecmaVersion: 2017 } }, + { code: "new globalThis.RegExp('foo', 'u')", languageOptions: { ecmaVersion: 2020 } }, + { code: "globalThis.RegExp('foo', 'u')", languageOptions: { ecmaVersion: 2020 } }, + { code: "const flags = 'u'; new globalThis.RegExp('', flags)", languageOptions: { ecmaVersion: 2020 } }, + { code: "const flags = 'g'; new globalThis.RegExp('', flags + 'u')", languageOptions: { ecmaVersion: 2020 } }, + { code: "const flags = 'gimu'; new globalThis.RegExp('foo', flags[3])", languageOptions: { ecmaVersion: 2020 } }, + { code: "class C { #RegExp; foo() { new globalThis.#RegExp('foo') } }", languageOptions: { ecmaVersion: 2022 } }, // for v flag - { code: "/foo/v", parserOptions: { ecmaVersion: 2024 } }, - { code: "/foo/gimvy", parserOptions: { ecmaVersion: 2024 } }, - { code: "RegExp('', 'v')", parserOptions: { ecmaVersion: 2024 } }, - { code: "RegExp('', `v`)", parserOptions: { ecmaVersion: 2024 } }, - { code: "new RegExp('', 'v')", parserOptions: { ecmaVersion: 2024 } }, - { code: "RegExp('', 'gimvy')", parserOptions: { ecmaVersion: 2024 } }, - { code: "RegExp('', `gimvy`)", parserOptions: { ecmaVersion: 2024 } }, - { code: "new RegExp('', 'gimvy')", parserOptions: { ecmaVersion: 2024 } }, - { code: "const flags = 'v'; new RegExp('', flags)", parserOptions: { ecmaVersion: 2024 } }, - { code: "const flags = 'g'; new RegExp('', flags + 'v')", parserOptions: { ecmaVersion: 2024 } }, - { code: "const flags = 'gimv'; new RegExp('foo', flags[3])", parserOptions: { ecmaVersion: 2024 } } + { code: "/foo/v", languageOptions: { ecmaVersion: 2024 } }, + { code: "/foo/gimvy", languageOptions: { ecmaVersion: 2024 } }, + { code: "RegExp('', 'v')", languageOptions: { ecmaVersion: 2024 } }, + { code: "RegExp('', `v`)", languageOptions: { ecmaVersion: 2024 } }, + { code: "new RegExp('', 'v')", languageOptions: { ecmaVersion: 2024 } }, + { code: "RegExp('', 'gimvy')", languageOptions: { ecmaVersion: 2024 } }, + { code: "RegExp('', `gimvy`)", languageOptions: { ecmaVersion: 2024 } }, + { code: "new RegExp('', 'gimvy')", languageOptions: { ecmaVersion: 2024 } }, + { code: "const flags = 'v'; new RegExp('', flags)", languageOptions: { ecmaVersion: 2024 } }, + { code: "const flags = 'g'; new RegExp('', flags + 'v')", languageOptions: { ecmaVersion: 2024 } }, + { code: "const flags = 'gimv'; new RegExp('foo', flags[3])", languageOptions: { ecmaVersion: 2024 } } ], invalid: [ { @@ -265,7 +266,6 @@ ruleTester.run("require-unicode-regexp", rule, { }, { code: "new window.RegExp('foo')", - env: { browser: true }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -274,11 +274,11 @@ ruleTester.run("require-unicode-regexp", rule, { output: "new window.RegExp('foo', \"u\")" } ] - }] + }], + languageOptions: { globals: globals.browser } }, { code: "new global.RegExp('foo')", - env: { node: true }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -287,11 +287,11 @@ ruleTester.run("require-unicode-regexp", rule, { output: "new global.RegExp('foo', \"u\")" } ] - }] + }], + languageOptions: { sourceType: "commonjs" } }, { code: "new globalThis.RegExp('foo')", - env: { es2020: true }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -300,7 +300,8 @@ ruleTester.run("require-unicode-regexp", rule, { output: "new globalThis.RegExp('foo', \"u\")" } ] - }] + }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/require-yield.js b/tests/lib/rules/require-yield.js index c80f4246539..59c5c8b5ef4 100644 --- a/tests/lib/rules/require-yield.js +++ b/tests/lib/rules/require-yield.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/require-yield"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("require-yield", rule, { valid: [ diff --git a/tests/lib/rules/rest-spread-spacing.js b/tests/lib/rules/rest-spread-spacing.js index 73b4f3dd436..e36256c5483 100644 --- a/tests/lib/rules/rest-spread-spacing.js +++ b/tests/lib/rules/rest-spread-spacing.js @@ -10,14 +10,14 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/rest-spread-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("rest-spread-spacing", rule, { valid: [ @@ -40,18 +40,18 @@ ruleTester.run("rest-spread-spacing", rule, { { code: "let [a, b, ... arr] = [1, 2, 3, 4, 5];", options: ["always"] }, { code: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];", options: ["always"] }, { code: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];", options: ["always"] }, - { code: "let n = { x, y, ...z };", parserOptions: { ecmaVersion: 2018 } }, - { code: "let n = { x, y, ...(z) };", parserOptions: { ecmaVersion: 2018 } }, - { code: "let n = { x, y, ...( z ) };", parserOptions: { ecmaVersion: 2018 } }, - { code: "let n = { x, y, ...z };", options: ["never"], parserOptions: { ecmaVersion: 2018 } }, - { code: "let n = { x, y, ... z };", options: ["always"], parserOptions: { ecmaVersion: 2018 } }, - { code: "let n = { x, y, ...\tz };", options: ["always"], parserOptions: { ecmaVersion: 2018 } }, - { code: "let n = { x, y, ...\nz };", options: ["always"], parserOptions: { ecmaVersion: 2018 } }, - { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", parserOptions: { ecmaVersion: 2018 } }, - { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], parserOptions: { ecmaVersion: 2018 } }, - { code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], parserOptions: { ecmaVersion: 2018 } }, - { code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], parserOptions: { ecmaVersion: 2018 } }, - { code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], parserOptions: { ecmaVersion: 2018 } } + { code: "let n = { x, y, ...z };", languageOptions: { ecmaVersion: 2018 } }, + { code: "let n = { x, y, ...(z) };", languageOptions: { ecmaVersion: 2018 } }, + { code: "let n = { x, y, ...( z ) };", languageOptions: { ecmaVersion: 2018 } }, + { code: "let n = { x, y, ...z };", options: ["never"], languageOptions: { ecmaVersion: 2018 } }, + { code: "let n = { x, y, ... z };", options: ["always"], languageOptions: { ecmaVersion: 2018 } }, + { code: "let n = { x, y, ...\tz };", options: ["always"], languageOptions: { ecmaVersion: 2018 } }, + { code: "let n = { x, y, ...\nz };", options: ["always"], languageOptions: { ecmaVersion: 2018 } }, + { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", languageOptions: { ecmaVersion: 2018 } }, + { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], languageOptions: { ecmaVersion: 2018 } }, + { code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], languageOptions: { ecmaVersion: 2018 } }, + { code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], languageOptions: { ecmaVersion: 2018 } }, + { code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], languageOptions: { ecmaVersion: 2018 } } ], invalid: [ @@ -503,7 +503,6 @@ ruleTester.run("rest-spread-spacing", rule, { { code: "let n = { x, y, ... z };", output: "let n = { x, y, ...z };", - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -512,12 +511,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ...\tz };", output: "let n = { x, y, ...z };", - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -526,12 +525,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ...\nz };", output: "let n = { x, y, ...z };", - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -540,13 +539,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ... z };", output: "let n = { x, y, ...z };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -555,13 +554,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ...\tz };", output: "let n = { x, y, ...z };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -570,13 +569,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ...\nz };", output: "let n = { x, y, ...z };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -585,13 +584,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ...z };", output: "let n = { x, y, ... z };", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -600,13 +599,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ... (z) };", output: "let n = { x, y, ...(z) };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -615,13 +614,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ... ( z ) };", output: "let n = { x, y, ...( z ) };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -630,13 +629,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ...(z) };", output: "let n = { x, y, ... (z) };", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -645,13 +644,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let n = { x, y, ...( z ) };", output: "let n = { x, y, ... ( z ) };", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -660,12 +659,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -674,12 +673,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -688,12 +687,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -702,13 +701,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -717,13 +716,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -732,13 +731,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -747,13 +746,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } }, { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 13, @@ -762,7 +761,8 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }] + }], + languageOptions: { ecmaVersion: 2018 } } ] }); diff --git a/tests/lib/rules/semi-spacing.js b/tests/lib/rules/semi-spacing.js index ffd67854abc..f3377073511 100644 --- a/tests/lib/rules/semi-spacing.js +++ b/tests/lib/rules/semi-spacing.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/semi-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -62,18 +62,18 @@ ruleTester.run("semi-spacing", rule, { // Class fields { code: "class C { foo; bar; method() {} }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // Empty are ignored (`no-extra-semi` rule will remove those) "foo; ;;;;;;;;;", { code: "class C { foo; ;;;;;;;;;; }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -280,52 +280,51 @@ ruleTester.run("semi-spacing", rule, { code: "import Foo from 'bar' ;", output: "import Foo from 'bar';", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 22 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import * as foo from 'bar' ;", output: "import * as foo from 'bar';", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 27 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = 0; export {foo} ;", output: "var foo = 0; export {foo};", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportNamedDeclaration", line: 1, column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export * from 'foo' ;", output: "export * from 'foo';", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportAllDeclaration", line: 1, column: 20 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default foo ;", output: "export default foo;", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportDefaultDeclaration", line: 1, column: 19 } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "while(foo) {continue ;}", output: "while(foo) {continue;}", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -335,13 +334,13 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 24 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "if(foo) {throw new Error() ; }", output: "if(foo) {throw new Error(); }", options: [{ before: false, after: false }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -351,13 +350,13 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 30 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "for(a ; ; );", output: "for(a;; );", options: [{ before: false, after: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ type: "ForStatement", messageId: "unexpectedWhitespaceBefore", @@ -373,13 +372,13 @@ ruleTester.run("semi-spacing", rule, { column: 8, endLine: 1, endColumn: 9 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "for(a ; \n ; );", output: "for(a; \n ; );", options: [{ before: false, after: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ type: "ForStatement", messageId: "unexpectedWhitespaceBefore", @@ -388,7 +387,8 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 7 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "do {} while (true) ;", @@ -440,7 +440,6 @@ ruleTester.run("semi-spacing", rule, { { code: "class C { foo ;bar;}", output: "class C { foo; bar;}", - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -458,13 +457,13 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo; bar ; }", output: "class C { foo ;bar ; }", options: [{ before: true, after: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingWhitespaceBefore", @@ -482,12 +481,12 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 16 } - ] + ], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo;static {}}", output: "class C { foo; static {}}", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingWhitespaceAfter", type: "PropertyDefinition", @@ -495,7 +494,8 @@ ruleTester.run("semi-spacing", rule, { column: 14, endLine: 1, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/semi-style.js b/tests/lib/rules/semi-style.js index 7ab8f223fe8..a035d2ec550 100644 --- a/tests/lib/rules/semi-style.js +++ b/tests/lib/rules/semi-style.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/semi-style"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -33,8 +33,8 @@ ruleTester.run("semi-style", rule, { { code: "for(a;b;c);", options: ["last"] }, { code: "for(a;\nb;\nc);", options: ["last"] }, { code: "for((a\n);\n(b\n);\n(c));", options: ["last"] }, - { code: "class C { a; b; }", options: ["last"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C {\na;\nb;\n}", options: ["last"], parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { a; b; }", options: ["last"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C {\na;\nb;\n}", options: ["last"], languageOptions: { ecmaVersion: 2022 } }, { code: "if(a)foo;\nbar", options: ["last"] }, { code: ";", options: ["first"] }, { code: ";foo;bar;baz;", options: ["first"] }, @@ -42,8 +42,8 @@ ruleTester.run("semi-style", rule, { { code: "for(a;b;c);", options: ["first"] }, { code: "for(a;\nb;\nc);", options: ["first"] }, { code: "for((a\n);\n(b\n);\n(c));", options: ["first"] }, - { code: "class C { a ;b }", options: ["first"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C {\na\n;b\n}", options: ["first"], parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { a ;b }", options: ["first"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C {\na\n;b\n}", options: ["first"], languageOptions: { ecmaVersion: 2022 } }, // edge cases { @@ -137,7 +137,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["last"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -148,7 +148,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["last"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -160,7 +160,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["last"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -171,7 +171,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["last"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -182,7 +182,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["last"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -194,7 +194,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["last"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -207,7 +207,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["last"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -216,7 +216,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -227,7 +227,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -239,7 +239,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -250,7 +250,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -261,7 +261,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -272,7 +272,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -284,7 +284,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -296,7 +296,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -309,7 +309,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -322,7 +322,7 @@ ruleTester.run("semi-style", rule, { } `, options: ["first"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -591,25 +591,25 @@ ruleTester.run("semi-style", rule, { code: "class C { foo\n;bar }", output: "class C { foo;\nbar }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo;\nbar }", output: "class C { foo\n;bar }", options: ["first"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the beginning of the next line" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, // Class static blocks @@ -617,49 +617,49 @@ ruleTester.run("semi-style", rule, { code: "class C { static { foo\n; } }", output: "class C { static { foo;\n} }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo\n ;bar } }", output: "class C { static { foo;\nbar } }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo;\nbar\n ; } }", output: "class C { static { foo;\nbar;\n} }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo;\nbar } }", output: "class C { static { foo\n;bar } }", options: ["first"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the beginning of the next line" } - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/semi.js b/tests/lib/rules/semi.js index 1811e14ee7b..73527812621 100644 --- a/tests/lib/rules/semi.js +++ b/tests/lib/rules/semi.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/semi"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -45,43 +45,43 @@ ruleTester.run("semi", rule, { { code: ";-foo()", options: ["never"] }, { code: "a++\nb++", options: ["never"] }, { code: "a++; b++", options: ["never"] }, - { code: "for (let thing of {}) {\n console.log(thing);\n}", parserOptions: { ecmaVersion: 6 } }, + { code: "for (let thing of {}) {\n console.log(thing);\n}", languageOptions: { ecmaVersion: 6 } }, { code: "do{}while(true)", options: ["never"] }, { code: "do{}while(true);", options: ["always"] }, - { code: "class C { static {} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static {} }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo(); } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo(); } }", options: ["always"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo(); bar(); } }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo(); bar(); baz();} }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo() } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo()\nbar() } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo()\nbar()\nbaz() } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo(); bar() } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo();\n (a) } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo()\n ;(a) } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo();\n [a] } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo()\n ;[a] } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo();\n +a } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo()\n ;+a } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo();\n -a } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo()\n ;-a } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo();\n /a/ } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo()\n ;/a/} }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, + { code: "class C { static {} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static {} }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo(); } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo(); } }", options: ["always"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo(); bar(); } }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo(); bar(); baz();} }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo() } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo()\nbar() } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo()\nbar()\nbaz() } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo(); bar() } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo();\n (a) } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo()\n ;(a) } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo();\n [a] } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo()\n ;[a] } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo();\n +a } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo()\n ;+a } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo();\n -a } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo()\n ;-a } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo();\n /a/ } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo()\n ;/a/} }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo();\n (a) } }", options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { do ; while (foo)\n (a)} }", options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { do ; while (foo)\n ;(a)} }", options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // omitLastInOneLineBlock: true @@ -94,22 +94,22 @@ ruleTester.run("semi", rule, { { code: "function foo()\n{ bar(); baz() }", options: ["always", { omitLastInOneLineBlock: true }] }, { code: "function foo(){\n bar(); baz(); }", options: ["always", { omitLastInOneLineBlock: true }] }, { code: "function foo(){ bar(); baz(); \n}", options: ["always", { omitLastInOneLineBlock: true }] }, - { code: "() => { bar(); baz() };", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "() =>\n { bar(); baz() };", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "() => {\n bar(); baz(); };", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "() => { bar(); baz(); \n};", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const obj = { method() { bar(); baz() } };", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const obj = { method()\n { bar(); baz() } };", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const obj = { method() {\n bar(); baz(); } };", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "const obj = { method() { bar(); baz(); \n} };", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "class C {\n method() { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "class C {\n method()\n { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "class C {\n method() {\n bar(); baz(); } \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "class C {\n method() { bar(); baz(); \n} \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "class C {\n static { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C {\n static\n { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C {\n static {\n bar(); baz(); } \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C {\n static { bar(); baz(); \n} \n}", options: ["always", { omitLastInOneLineBlock: true }], parserOptions: { ecmaVersion: 2022 } }, + { code: "() => { bar(); baz() };", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "() =>\n { bar(); baz() };", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "() => {\n bar(); baz(); };", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "() => { bar(); baz(); \n};", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const obj = { method() { bar(); baz() } };", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const obj = { method()\n { bar(); baz() } };", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const obj = { method() {\n bar(); baz(); } };", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "const obj = { method() { bar(); baz(); \n} };", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "class C {\n method() { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "class C {\n method()\n { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "class C {\n method() {\n bar(); baz(); } \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "class C {\n method() { bar(); baz(); \n} \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 6 } }, + { code: "class C {\n static { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C {\n static\n { bar(); baz() } \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C {\n static {\n bar(); baz(); } \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C {\n static { bar(); baz(); \n} \n}", options: ["always", { omitLastInOneLineBlock: true }], languageOptions: { ecmaVersion: 2022 } }, // omitLastInOneLineClassBody: true { @@ -127,7 +127,7 @@ ruleTester.run("semi", rule, { export class Variant5 extends SomeClass{type=5} `, options: ["always", { omitLastInOneLineClassBody: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: ` @@ -141,7 +141,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1; anotherType=2} `, options: ["always", { omitLastInOneLineClassBody: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: ` @@ -158,83 +158,83 @@ ruleTester.run("semi", rule, { export class Variant5 extends SomeClass{type=5;} `, options: ["always", { omitLastInOneLineClassBody: false }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C {\nfoo;}", options: ["always", { omitLastInOneLineClassBody: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {foo;\n}", options: ["always", { omitLastInOneLineClassBody: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {foo;\nbar;}", options: ["always", { omitLastInOneLineClassBody: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "{ foo; }", options: ["always", { omitLastInOneLineClassBody: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C\n{ foo }", options: ["always", { omitLastInOneLineClassBody: true }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, // method definitions and static blocks don't have a semicolon. - { code: "class A { a() {} b() {} }", parserOptions: { ecmaVersion: 6 } }, - { code: "var A = class { a() {} b() {} };", parserOptions: { ecmaVersion: 6 } }, - { code: "class A { static {} }", parserOptions: { ecmaVersion: 2022 } }, + { code: "class A { a() {} b() {} }", languageOptions: { ecmaVersion: 6 } }, + { code: "var A = class { a() {} b() {} };", languageOptions: { ecmaVersion: 6 } }, + { code: "class A { static {} }", languageOptions: { ecmaVersion: 2022 } }, - { code: "import theDefault, { named1, named2 } from 'src/mylib';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import theDefault, { named1, named2 } from 'src/mylib'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import theDefault, { named1, named2 } from 'src/mylib';", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import theDefault, { named1, named2 } from 'src/mylib'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // exports, "always" - { code: "export * from 'foo';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { foo } from 'foo';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var foo = 0;export { foo };", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export var foo;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function foo () { }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function* foo () { }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export class Foo { }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export let foo;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export const FOO = 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default function() { }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default function* () { }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default class { }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default foo || bar;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default (foo) => foo.bar();", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default foo = 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default foo += 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export * from 'foo';", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { foo } from 'foo';", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var foo = 0;export { foo };", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export var foo;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function foo () { }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function* foo () { }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export class Foo { }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export let foo;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export const FOO = 42;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default function() { }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default function* () { }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default class { }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default foo || bar;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default (foo) => foo.bar();", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default foo = 42;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default foo += 42;", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // exports, "never" - { code: "export * from 'foo'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export { foo } from 'foo'", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "var foo = 0; export { foo }", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export var foo", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function foo () { }", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function* foo () { }", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export class Foo { }", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export let foo", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export const FOO = 42", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default function() { }", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default function* () { }", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default class { }", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default foo || bar", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default (foo) => foo.bar()", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default foo = 42", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export default foo += 42", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export * from 'foo'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export { foo } from 'foo'", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var foo = 0; export { foo }", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export var foo", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function foo () { }", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function* foo () { }", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export class Foo { }", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export let foo", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export const FOO = 42", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default function() { }", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default function* () { }", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default class { }", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default foo || bar", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default (foo) => foo.bar()", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default foo = 42", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default foo += 42", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "++\nfoo;", options: ["always"] }, { code: "var a = b;\n+ c", options: ["never"] }, // https://github.com/eslint/eslint/issues/7782 { code: "var a = b;\n/foo/.test(c)", options: ["never"] }, - { code: "var a = b;\n`foo`", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "var a = b;\n`foo`", options: ["never"], languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/9521 { @@ -257,7 +257,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -265,7 +265,7 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -275,7 +275,7 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: ` @@ -308,7 +308,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: ` @@ -316,7 +316,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -324,7 +324,7 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -334,7 +334,7 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: ` @@ -367,118 +367,118 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // Class fields { code: "class C { foo; }", - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = obj\n;[bar] }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo;\n[bar]; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n;[bar] }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n[bar] }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n;[bar] }", options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n[bar] }", options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = () => {}\n;[bar] }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = () => {}\n[bar] }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = () => {}\n;[bar] }", options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = () => {}\n[bar] }", options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo() {} }", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo() {}; }", // no-extra-semi reports it options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static {}; }", // no-extra-semi reports it options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { a=b;\n*foo() {} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { get;\nfoo() {} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { set;\nfoo() {} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static;\nfoo() {} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { a=b;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { a=b;\ninstanceof }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -494,7 +494,7 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: ` @@ -510,79 +510,78 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n[bar] }", options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = () => {}\n[bar] }", options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n;[bar] }", options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo = () => {}\n;[bar] }", options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo] = bar;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #foo = bar;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static static = bar;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [foo];\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [get];\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [get] = 5;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #get;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #set = 5;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static static;\nin }", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { code: "import * as utils from './utils'", output: "import * as utils from './utils';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -590,12 +589,12 @@ ruleTester.run("semi", rule, { column: 33, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { square, diag } from 'lib'", output: "import { square, diag } from 'lib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -603,12 +602,12 @@ ruleTester.run("semi", rule, { column: 35, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import { default as foo } from 'lib'", output: "import { default as foo } from 'lib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -616,12 +615,12 @@ ruleTester.run("semi", rule, { column: 37, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import 'src/mylib'", output: "import 'src/mylib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -629,12 +628,12 @@ ruleTester.run("semi", rule, { column: 19, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "import theDefault, { named1, named2 } from 'src/mylib'", output: "import theDefault, { named1, named2 } from 'src/mylib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -642,7 +641,8 @@ ruleTester.run("semi", rule, { column: 55, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "function foo() { return [] }", @@ -683,7 +683,6 @@ ruleTester.run("semi", rule, { { code: "let x = 5", output: "let x = 5;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -691,7 +690,8 @@ ruleTester.run("semi", rule, { column: 10, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = 5", @@ -975,7 +975,6 @@ ruleTester.run("semi", rule, { code: "let x = 5;", output: "let x = 5", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -983,7 +982,8 @@ ruleTester.run("semi", rule, { column: 10, endLine: 1, endColumn: 11 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var x = 5;", @@ -1106,7 +1106,6 @@ ruleTester.run("semi", rule, { code: "import theDefault, { named1, named2 } from 'src/mylib';", output: "import theDefault, { named1, named2 } from 'src/mylib'", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ImportDeclaration", @@ -1114,7 +1113,8 @@ ruleTester.run("semi", rule, { column: 55, endLine: 1, endColumn: 56 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "do{}while(true);", @@ -1132,7 +1132,6 @@ ruleTester.run("semi", rule, { { code: "class C { static { foo() } }", output: "class C { static { foo(); } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1140,13 +1139,13 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo() } }", output: "class C { static { foo(); } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1154,12 +1153,12 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo(); bar() } }", output: "class C { static { foo(); bar(); } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1167,12 +1166,12 @@ ruleTester.run("semi", rule, { column: 32, endLine: 1, endColumn: 33 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo()\nbar(); } }", output: "class C { static { foo();\nbar(); } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1180,12 +1179,12 @@ ruleTester.run("semi", rule, { column: 25, endLine: 2, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo(); bar()\nbaz(); } }", output: "class C { static { foo(); bar();\nbaz(); } }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1193,13 +1192,13 @@ ruleTester.run("semi", rule, { column: 32, endLine: 2, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo(); } }", output: "class C { static { foo() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1207,13 +1206,13 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo();\nbar() } }", output: "class C { static { foo()\nbar() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1221,13 +1220,13 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo()\nbar(); } }", output: "class C { static { foo()\nbar() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1235,13 +1234,13 @@ ruleTester.run("semi", rule, { column: 6, endLine: 2, endColumn: 7 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { foo()\nbar();\nbaz() } }", output: "class C { static { foo()\nbar()\nbaz() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1249,13 +1248,13 @@ ruleTester.run("semi", rule, { column: 6, endLine: 2, endColumn: 7 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { do ; while (foo)\n (a)} }", output: "class C { static { do ; while (foo);\n (a)} }", options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "DoWhileStatement", @@ -1263,13 +1262,13 @@ ruleTester.run("semi", rule, { column: 36, endLine: 2, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { do ; while (foo)\n ;(a)} }", output: "class C { static { do ; while (foo)\n (a)} }", options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "DoWhileStatement", @@ -1277,7 +1276,8 @@ ruleTester.run("semi", rule, { column: 2, endLine: 2, endColumn: 3 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, // omitLastInOneLineBlock: true @@ -1381,105 +1381,105 @@ ruleTester.run("semi", rule, { code: "class C {\nfoo() { bar(); baz(); }\n}", output: "class C {\nfoo() { bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", line: 2, column: 21, endLine: 2, endColumn: 22 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C {\nfoo() \n{ bar(); baz(); }\n}", output: "class C {\nfoo() \n{ bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", line: 3, column: 15, endLine: 3, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C {\nfoo() {\n bar(); baz() }\n}", output: "class C {\nfoo() {\n bar(); baz(); }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", line: 3, column: 14, endLine: 3, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C {\nfoo() { bar(); baz() \n}\n}", output: "class C {\nfoo() { bar(); baz(); \n}\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", line: 2, column: 21, endLine: 2, endColumn: 22 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "class C {\nstatic { bar(); baz(); }\n}", output: "class C {\nstatic { bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 2, column: 22, endLine: 2, endColumn: 23 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\nstatic \n{ bar(); baz(); }\n}", output: "class C {\nstatic \n{ bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 3, column: 15, endLine: 3, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\nstatic {\n bar(); baz() }\n}", output: "class C {\nstatic {\n bar(); baz(); }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 3, column: 14, endLine: 3, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C {\nfoo() { bar(); baz() \n}\n}", output: "class C {\nfoo() { bar(); baz(); \n}\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 2, column: 21, endLine: 2, endColumn: 22 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, @@ -1487,7 +1487,6 @@ ruleTester.run("semi", rule, { { code: "export * from 'foo'", output: "export * from 'foo';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportAllDeclaration", @@ -1495,12 +1494,12 @@ ruleTester.run("semi", rule, { column: 20, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo } from 'foo'", output: "export { foo } from 'foo';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportNamedDeclaration", @@ -1508,12 +1507,12 @@ ruleTester.run("semi", rule, { column: 26, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = 0;export { foo }", output: "var foo = 0;export { foo };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportNamedDeclaration", @@ -1521,12 +1520,12 @@ ruleTester.run("semi", rule, { column: 27, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export var foo", output: "export var foo;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1534,12 +1533,12 @@ ruleTester.run("semi", rule, { column: 15, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export let foo", output: "export let foo;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1547,12 +1546,12 @@ ruleTester.run("semi", rule, { column: 15, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export const FOO = 42", output: "export const FOO = 42;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1560,12 +1559,12 @@ ruleTester.run("semi", rule, { column: 22, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default foo || bar", output: "export default foo || bar;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1573,12 +1572,12 @@ ruleTester.run("semi", rule, { column: 26, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default (foo) => foo.bar()", output: "export default (foo) => foo.bar();", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1586,12 +1585,12 @@ ruleTester.run("semi", rule, { column: 34, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default foo = 42", output: "export default foo = 42;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1599,12 +1598,12 @@ ruleTester.run("semi", rule, { column: 24, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default foo += 42", output: "export default foo += 42;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1612,7 +1611,8 @@ ruleTester.run("semi", rule, { column: 25, endLine: void 0, endColumn: void 0 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // exports, "never" @@ -1620,7 +1620,6 @@ ruleTester.run("semi", rule, { code: "export * from 'foo';", output: "export * from 'foo'", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportAllDeclaration", @@ -1628,13 +1627,13 @@ ruleTester.run("semi", rule, { column: 20, endLine: 1, endColumn: 21 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export { foo } from 'foo';", output: "export { foo } from 'foo'", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportNamedDeclaration", @@ -1642,13 +1641,13 @@ ruleTester.run("semi", rule, { column: 26, endLine: 1, endColumn: 27 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = 0;export { foo };", output: "var foo = 0;export { foo }", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportNamedDeclaration", @@ -1656,13 +1655,13 @@ ruleTester.run("semi", rule, { column: 27, endLine: 1, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export var foo;", output: "export var foo", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1670,13 +1669,13 @@ ruleTester.run("semi", rule, { column: 15, endLine: 1, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export let foo;", output: "export let foo", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1684,13 +1683,13 @@ ruleTester.run("semi", rule, { column: 15, endLine: 1, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export const FOO = 42;", output: "export const FOO = 42", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1698,13 +1697,13 @@ ruleTester.run("semi", rule, { column: 22, endLine: 1, endColumn: 23 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default foo || bar;", output: "export default foo || bar", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1712,13 +1711,13 @@ ruleTester.run("semi", rule, { column: 26, endLine: 1, endColumn: 27 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default (foo) => foo.bar();", output: "export default (foo) => foo.bar()", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1726,13 +1725,13 @@ ruleTester.run("semi", rule, { column: 34, endLine: 1, endColumn: 35 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default foo = 42;", output: "export default foo = 42", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1740,13 +1739,13 @@ ruleTester.run("semi", rule, { column: 24, endLine: 1, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default foo += 42;", output: "export default foo += 42", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1754,7 +1753,8 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "a;\n++b", @@ -1811,14 +1811,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", line: 2, column: 34, endLine: 3, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -1830,14 +1830,14 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", line: 2, column: 38, endLine: 3, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -1853,14 +1853,14 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "missingSemi", line: 3, column: 27, endLine: 4, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: ` @@ -1934,14 +1934,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "missingSemi", line: 2, column: 35, endLine: 3, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: ` @@ -1953,14 +1953,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 2, column: 34, endLine: 2, endColumn: 35 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -1972,14 +1972,14 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 2, column: 38, endLine: 2, endColumn: 39 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -1995,14 +1995,14 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 3, column: 27, endLine: 3, endColumn: 28 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: ` @@ -2076,14 +2076,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 2, column: 35, endLine: 2, endColumn: 36 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, { code: ` @@ -2095,14 +2095,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 3, column: 17, endLine: 3, endColumn: 18 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -2114,14 +2114,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 3, column: 17, endLine: 3, endColumn: 18 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: ` @@ -2217,67 +2217,67 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 3, column: 17, endLine: 3, endColumn: 18 - }] + }], + languageOptions: { ecmaVersion: 2015 } }, // Class fields { code: "class C { foo }", output: "class C { foo; }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, column: 14, endLine: 1, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo }", output: "class C { foo; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, column: 14, endLine: 1, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo; }", output: "class C { foo }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 14, endLine: 1, endColumn: 15 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { foo\n[bar]; }", output: "class C { foo;\n[bar]; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, column: 14, endLine: 2, endColumn: 1 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, // class fields @@ -2285,105 +2285,105 @@ ruleTester.run("semi", rule, { code: "class C { [get];\nfoo\n}", output: "class C { [get]\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 16, endLine: 1, endColumn: 17 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [set];\nfoo\n}", output: "class C { [set]\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 16, endLine: 1, endColumn: 17 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #get;\nfoo\n}", output: "class C { #get\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 15, endLine: 1, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #set;\nfoo\n}", output: "class C { #set\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 15, endLine: 1, endColumn: 16 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { #static;\nfoo\n}", output: "class C { #static\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 18, endLine: 1, endColumn: 19 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { get=1;\nfoo\n}", output: "class C { get=1\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 16, endLine: 1, endColumn: 17 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static static;\nfoo\n}", output: "class C { static static\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 24, endLine: 1, endColumn: 25 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static;\n}", output: "class C { static\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 17, endLine: 1, endColumn: 18 - }] + }], + languageOptions: { ecmaVersion: 2022 } }, // omitLastInOneLineClassBody @@ -2407,7 +2407,6 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1;} `, options: ["always", { omitLastInOneLineClassBody: false }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2416,7 +2415,8 @@ ruleTester.run("semi", rule, { endLine: 8, endColumn: 64 } - ] + ], + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: ` @@ -2438,7 +2438,6 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1;} `, options: ["always", { omitLastInOneLineClassBody: false, omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2447,7 +2446,8 @@ ruleTester.run("semi", rule, { endLine: 8, endColumn: 64 } - ] + ], + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: ` @@ -2469,7 +2469,6 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1} `, options: ["always", { omitLastInOneLineClassBody: true, omitLastInOneLineBlock: false }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "extraSemi", @@ -2478,7 +2477,8 @@ ruleTester.run("semi", rule, { endLine: 8, endColumn: 64 } - ] + ], + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: ` @@ -2502,7 +2502,6 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1; anotherType=2;} `, options: ["always", { omitLastInOneLineClassBody: false, omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2511,7 +2510,8 @@ ruleTester.run("semi", rule, { endLine: 9, endColumn: 79 } - ] + ], + languageOptions: { ecmaVersion: 2022, sourceType: "module" } } ] }); diff --git a/tests/lib/rules/sort-imports.js b/tests/lib/rules/sort-imports.js index b5da5018919..e350b375721 100644 --- a/tests/lib/rules/sort-imports.js +++ b/tests/lib/rules/sort-imports.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/sort-imports"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, sourceType: "module" } }), +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6, sourceType: "module" } }), expectedError = { messageId: "sortImportsAlphabetically", type: "ImportDeclaration" diff --git a/tests/lib/rules/sort-keys.js b/tests/lib/rules/sort-keys.js index 5c9523ab68c..a8eda97ec04 100644 --- a/tests/lib/rules/sort-keys.js +++ b/tests/lib/rules/sort-keys.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/sort-keys"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -22,10 +22,10 @@ ruleTester.run("sort-keys", rule, { valid: [ // default (asc) - { code: "var obj = {'':1, [``]:2}", options: [], parserOptions: { ecmaVersion: 6 } }, - { code: "var obj = {[``]:1, '':2}", options: [], parserOptions: { ecmaVersion: 6 } }, + { code: "var obj = {'':1, [``]:2}", options: [], languageOptions: { ecmaVersion: 6 } }, + { code: "var obj = {[``]:1, '':2}", options: [], languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {'':1, a:2}", options: [] }, - { code: "var obj = {[``]:1, a:2}", options: [], parserOptions: { ecmaVersion: 6 } }, + { code: "var obj = {[``]:1, a:2}", options: [], languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {_:2, a:1, b:3} // default", options: [] }, { code: "var obj = {a:1, b:3, c:2}", options: [] }, { code: "var obj = {a:2, b:3, b_:1}", options: [] }, @@ -33,34 +33,34 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {$:1, A:3, _:2, a:4}", options: [] }, { code: "var obj = {1:1, '11':2, 2:4, A:3}", options: [] }, { code: "var obj = {'#':1, 'Z':2, À:3, è:4}", options: [] }, - { code: "var obj = { [/(?0)/]: 1, '/(?0)/': 2 }", options: [], parserOptions: { ecmaVersion: 2018 } }, + { code: "var obj = { [/(?0)/]: 1, '/(?0)/': 2 }", options: [], languageOptions: { ecmaVersion: 2018 } }, // ignore non-simple computed properties. - { code: "var obj = {a:1, b:3, [a + b]: -1, c:2}", options: [], parserOptions: { ecmaVersion: 6 } }, - { code: "var obj = {'':1, [f()]:2, a:3}", options: [], parserOptions: { ecmaVersion: 6 } }, - { code: "var obj = {a:1, [b++]:2, '':3}", options: ["desc"], parserOptions: { ecmaVersion: 6 } }, + { code: "var obj = {a:1, b:3, [a + b]: -1, c:2}", options: [], languageOptions: { ecmaVersion: 6 } }, + { code: "var obj = {'':1, [f()]:2, a:3}", options: [], languageOptions: { ecmaVersion: 6 } }, + { code: "var obj = {a:1, [b++]:2, '':3}", options: ["desc"], languageOptions: { ecmaVersion: 6 } }, // ignore properties separated by spread properties - { code: "var obj = {a:1, ...z, b:1}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {b:1, ...z, a:1}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {...a, b:1, ...c, d:1}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {...a, b:1, ...d, ...c, e:2, z:5}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {b:1, ...c, ...d, e:2}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {a:1, ...z, '':2}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {'':1, ...z, 'a':2}", options: ["desc"], parserOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {a:1, ...z, b:1}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {b:1, ...z, a:1}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {...a, b:1, ...c, d:1}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {...a, b:1, ...d, ...c, e:2, z:5}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {b:1, ...c, ...d, e:2}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {a:1, ...z, '':2}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {'':1, ...z, 'a':2}", options: ["desc"], languageOptions: { ecmaVersion: 2018 } }, // not ignore properties not separated by spread properties - { code: "var obj = {...z, a:1, b:1}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {...z, ...c, a:1, b:1}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {a:1, b:1, ...z}", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "var obj = {...z, ...x, a:1, ...c, ...d, f:5, e:4}", options: ["desc"], parserOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {...z, a:1, b:1}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {...z, ...c, a:1, b:1}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {a:1, b:1, ...z}", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "var obj = {...z, ...x, a:1, ...c, ...d, f:5, e:4}", options: ["desc"], languageOptions: { ecmaVersion: 2018 } }, // works when spread occurs somewhere other than an object literal - { code: "function fn(...args) { return [...args].length; }", options: [], parserOptions: { ecmaVersion: 2018 } }, - { code: "function g() {}; function f(...args) { return g(...args); }", options: [], parserOptions: { ecmaVersion: 2018 } }, + { code: "function fn(...args) { return [...args].length; }", options: [], languageOptions: { ecmaVersion: 2018 } }, + { code: "function g() {}; function f(...args) { return g(...args); }", options: [], languageOptions: { ecmaVersion: 2018 } }, // ignore destructuring patterns. - { code: "let {a, b} = {}", options: [], parserOptions: { ecmaVersion: 6 } }, + { code: "let {a, b} = {}", options: [], languageOptions: { ecmaVersion: 6 } }, // nested { code: "var obj = {a:1, b:{x:1, y:1}, c:1}", options: [] }, @@ -196,7 +196,7 @@ ruleTester.run("sort-keys", rule, { code: ` var obj = { b: 1 - + , // comment @@ -218,7 +218,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -234,7 +234,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -246,7 +246,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -270,7 +270,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -293,7 +293,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -306,7 +306,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -317,7 +317,7 @@ ruleTester.run("sort-keys", rule, { }; `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -330,7 +330,7 @@ ruleTester.run("sort-keys", rule, { }; `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -343,7 +343,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: ` @@ -357,7 +357,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } } ], invalid: [ @@ -380,7 +380,6 @@ ruleTester.run("sort-keys", rule, { }, { code: "var obj = {a:1, [``]:2} // default", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -392,7 +391,8 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {a:1, _:2, b:3} // default", @@ -501,7 +501,6 @@ ruleTester.run("sort-keys", rule, { }, { code: "var obj = { null: 1, [/(?0)/]: 2 }", - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -513,14 +512,14 @@ ruleTester.run("sort-keys", rule, { prevName: "null" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // not ignore properties not separated by spread properties { code: "var obj = {...z, c:1, b:1}", options: [], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -532,12 +531,12 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {...z, ...c, d:4, b:1, ...y, ...f, e:2, a:1}", options: [], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -559,12 +558,12 @@ ruleTester.run("sort-keys", rule, { prevName: "e" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {c:1, b:1, ...a}", options: [], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -576,12 +575,12 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {...z, ...a, c:1, b:1}", options: [], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -593,12 +592,12 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {...z, b:1, a:1, ...d, ...c}", options: [], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -610,12 +609,12 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {...z, a:2, b:0, ...x, ...c}", options: ["desc"], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -627,12 +626,12 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {...z, a:2, b:0, ...x}", options: ["desc"], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -644,12 +643,12 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "var obj = {...z, '':1, a:2}", options: ["desc"], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -661,13 +660,13 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, // ignore non-simple computed properties, but their position shouldn't affect other comparisons. { code: "var obj = {a:1, [b+c]:2, '':3}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -679,12 +678,12 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {'':1, [b+c]:2, a:3}", options: ["desc"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -696,12 +695,12 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {b:1, [f()]:2, '':3, a:4}", options: ["desc"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -713,13 +712,13 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // not ignore simple computed properties. { code: "var obj = {a:1, b:3, [a]: -1, c:2}", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -731,7 +730,8 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // nested @@ -1277,7 +1277,6 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {[``]:1, a:'2'} // desc", options: ["desc"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -1289,7 +1288,8 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var obj = {a:1, _:2, b:3} // desc", @@ -1990,7 +1990,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: false }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2002,7 +2001,8 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, // When allowLineSeparatedGroups option is true @@ -2017,7 +2017,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2029,7 +2028,8 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2044,7 +2044,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2056,7 +2055,8 @@ ruleTester.run("sort-keys", rule, { prevName: "z" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2069,7 +2069,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2081,7 +2080,8 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2092,7 +2092,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2104,7 +2103,8 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2119,7 +2119,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2131,7 +2130,8 @@ ruleTester.run("sort-keys", rule, { prevName: "d" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2153,7 +2153,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2175,7 +2174,8 @@ ruleTester.run("sort-keys", rule, { prevName: "f" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2207,7 +2207,6 @@ ruleTester.run("sort-keys", rule, { }; `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2219,7 +2218,8 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: ` @@ -2233,7 +2233,6 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -2245,7 +2244,8 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ] + ], + languageOptions: { ecmaVersion: 2018 } } ] }); diff --git a/tests/lib/rules/sort-vars.js b/tests/lib/rules/sort-vars.js index fb12b1fc33d..19c9315e3de 100644 --- a/tests/lib/rules/sort-vars.js +++ b/tests/lib/rules/sort-vars.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/sort-vars"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -35,61 +35,61 @@ ruleTester.run("sort-vars", rule, { { code: "var A, a;", options: ignoreCaseArgs }, { code: "var a, B, c;", options: ignoreCaseArgs }, { code: "var A, b, C;", options: ignoreCaseArgs }, - { code: "var {a, b, c} = x;", options: ignoreCaseArgs, parserOptions: { ecmaVersion: 6 } }, - { code: "var {A, b, C} = x;", options: ignoreCaseArgs, parserOptions: { ecmaVersion: 6 } }, - { code: "var test = [1,2,3];", parserOptions: { ecmaVersion: 6 } }, - { code: "var {a,b} = [1,2];", parserOptions: { ecmaVersion: 6 } }, + { code: "var {a, b, c} = x;", options: ignoreCaseArgs, languageOptions: { ecmaVersion: 6 } }, + { code: "var {A, b, C} = x;", options: ignoreCaseArgs, languageOptions: { ecmaVersion: 6 } }, + { code: "var test = [1,2,3];", languageOptions: { ecmaVersion: 6 } }, + { code: "var {a,b} = [1,2];", languageOptions: { ecmaVersion: 6 } }, { code: "var [a, B, c] = [1, 2, 3];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [A, B, c] = [1, 2, 3];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var [A, b, C] = [1, 2, 3];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, - { code: "let {a, b, c} = x;", parserOptions: { ecmaVersion: 6 } }, + { code: "let {a, b, c} = x;", languageOptions: { ecmaVersion: 6 } }, { code: "let [a, b, c] = [1, 2, 3];", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const {a, b, c} = {a: 1, b: true, c: \"Moo\"};", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const [a, b, c] = [1, true, \"Moo\"];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "const [c, a, b] = [1, true, \"Moo\"];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } - }, - { code: "var {a, x: {b, c}} = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var {c, x: {a, c}} = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var {a, x: [b, c]} = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, {b, c}] = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, {x: {b, c}}] = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var a = 42, {b, c } = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var b = 42, {a, c } = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var [b, {x: {a, c}}] = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var [b, d, a, c] = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var e, [a, c, d] = {};", parserOptions: { ecmaVersion: 6 } }, + languageOptions: { ecmaVersion: 6 } + }, + { code: "var {a, x: {b, c}} = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var {c, x: {a, c}} = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var {a, x: [b, c]} = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, {b, c}] = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var [a, {x: {b, c}}] = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var a = 42, {b, c } = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var b = 42, {a, c } = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var [b, {x: {a, c}}] = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var [b, d, a, c] = {};", languageOptions: { ecmaVersion: 6 } }, + { code: "var e, [a, c, d] = {};", languageOptions: { ecmaVersion: 6 } }, { code: "var a, [E, c, D] = [];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, - { code: "var a, f, [e, c, d] = [1,2,3];", parserOptions: { ecmaVersion: 6 } }, + { code: "var a, f, [e, c, d] = [1,2,3];", languageOptions: { ecmaVersion: 6 } }, { code: [ "export default class {", @@ -102,14 +102,13 @@ ruleTester.run("sort-vars", rule, { " }", "}" ].join("\n"), - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - env: { es6: true } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var {} = 1, a", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], invalid: [ @@ -190,22 +189,22 @@ ruleTester.run("sort-vars", rule, { code: "var d, a, [b, c] = {};", output: "var a, d, [b, c] = {};", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedError] + errors: [expectedError], + languageOptions: { ecmaVersion: 6 } }, { code: "var d, a, [b, {x: {c, e}}] = {};", output: "var a, d, [b, {x: {c, e}}] = {};", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedError] + errors: [expectedError], + languageOptions: { ecmaVersion: 6 } }, { code: "var {} = 1, b, a", output: "var {} = 1, a, b", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedError] + errors: [expectedError], + languageOptions: { ecmaVersion: 6 } }, { code: "var b=10, a=f();", @@ -220,14 +219,14 @@ ruleTester.run("sort-vars", rule, { { code: "var b = 0, a = `${b}`;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedError] + errors: [expectedError], + languageOptions: { ecmaVersion: 6 } }, { code: "var b = 0, a = `${f()}`", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedError] + errors: [expectedError], + languageOptions: { ecmaVersion: 6 } }, { code: "var b = 0, c = b, a;", @@ -247,8 +246,8 @@ ruleTester.run("sort-vars", rule, { { code: "var b = `${f()}`, c, d, a;", output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedError] + errors: [expectedError], + languageOptions: { ecmaVersion: 6 } }, { code: "var c, a = b = 0", diff --git a/tests/lib/rules/space-before-blocks.js b/tests/lib/rules/space-before-blocks.js index 49af9611650..952068e797a 100644 --- a/tests/lib/rules/space-before-blocks.js +++ b/tests/lib/rules/space-before-blocks.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/space-before-blocks"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), fixtureParser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -54,25 +54,25 @@ ruleTester.run("space-before-blocks", rule, { { code: "export default class{}", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default class {}", options: classesOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default function a() {}", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default function a(){}", options: keywordOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function a(){}", options: keywordOnlyArgs, parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function a() {}", options: functionsOnlyArgs, parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function a(){}", options: keywordOnlyArgs, languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export function a() {}", options: functionsOnlyArgs, languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "function a(){}", options: keywordOnlyArgs }, { code: "function a() {}", options: functionsOnlyArgs }, { code: "function a(){ if(b) {} }", options: keywordOnlyArgs }, @@ -106,36 +106,36 @@ ruleTester.run("space-before-blocks", rule, { { code: "class test { constructor() {} }", options: [{ functions: "always", keywords: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test { constructor(){} }", options: classesOnlyArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test{ constructor() {} }", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test {}", options: classesOnlyArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test{}", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test{}", options: neverArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test {}", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function a(){if(b) {}}", options: keywordAlwaysOthersOffArgs }, { code: "function a() {if(b) {}}", options: keywordAlwaysOthersOffArgs }, @@ -144,22 +144,22 @@ ruleTester.run("space-before-blocks", rule, { { code: "class test { constructor(){if(a){}} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test { constructor() {if(a){}} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test { constructor(){if(a) {}} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test { constructor() {if(a) {}} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function a(){if(b){}}", options: keywordNeverOthersOffArgs }, { code: "function a() {if(b){}}", options: keywordNeverOthersOffArgs }, @@ -168,33 +168,33 @@ ruleTester.run("space-before-blocks", rule, { { code: "class test{ constructor(){if(a){}} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test{ constructor() {if(a){}} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test{ constructor(){if(a) {}} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class test{ constructor() {if(a) {}} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/3769 - { code: "()=>{};", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "() => {};", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "()=>{};", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "() => {};", options: ["never"], languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/1338 "if(a) {}else{}", { code: "if(a){}else {}", options: neverArgs }, { code: "try {}catch(a){}", options: functionsOnlyArgs }, - { code: "export default class{}", options: classesOnlyArgs, parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "export default class{}", options: classesOnlyArgs, languageOptions: { ecmaVersion: 6, sourceType: "module" } }, // https://github.com/eslint/eslint/issues/15082 { code: "switch(x) { case 9:{ break; } }", options: alwaysArgs }, @@ -208,12 +208,12 @@ ruleTester.run("space-before-blocks", rule, { { code: "(class{ static{} })", options: ["always"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } }, { code: "(class { static {} })", options: ["never"], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -430,77 +430,77 @@ ruleTester.run("space-before-blocks", rule, { code: "export function a() { if(b) {} }", output: "export function a() { if(b){} }", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export function a(){ if(b){} }", output: "export function a(){ if(b) {} }", options: keywordOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export function a(){}", output: "export function a() {}", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export default function (a) {}", output: "export default function (a){}", options: keywordOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "export function a() {}", output: "export function a(){}", options: keywordOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "class test{}", output: "class test {}", - parserOptions: { ecmaVersion: 6 }, - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "class test{}", output: "class test {}", options: classesOnlyArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "class test{ constructor(){} }", output: "class test{ constructor() {} }", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "class test { constructor() {} }", output: "class test { constructor(){} }", options: classesOnlyArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "class test {}", output: "class test{}", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "class test {}", output: "class test{}", options: neverArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "if(a){ function a(){} }", @@ -530,15 +530,15 @@ ruleTester.run("space-before-blocks", rule, { code: "class test{ constructor(){} }", output: "class test { constructor(){} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "class test{ constructor() {} }", output: "class test { constructor() {} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "if(a){ function a() {} }", @@ -568,30 +568,34 @@ ruleTester.run("space-before-blocks", rule, { code: "class test { constructor(){} }", output: "class test{ constructor(){} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6 } }, { code: "class test { constructor() {} }", output: "class test{ constructor() {} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/13553 { code: "class A { foo(bar: string): void{} }", output: "class A { foo(bar: string): void {} }", - parser: fixtureParser("space-before-blocks", "return-type-keyword-1"), - errors: [expectedSpacingError] + errors: [expectedSpacingError], + languageOptions: { + parser: require(fixtureParser("space-before-blocks", "return-type-keyword-1")) + } }, { code: "function foo(): null {}", output: "function foo(): null{}", options: neverArgs, - parser: fixtureParser("space-before-blocks", "return-type-keyword-2"), - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + languageOptions: { + parser: require(fixtureParser("space-before-blocks", "return-type-keyword-2")) + } }, // https://github.com/eslint/eslint/issues/15082 regression tests (only blocks after switch case colons should be excluded) diff --git a/tests/lib/rules/space-before-function-paren.js b/tests/lib/rules/space-before-function-paren.js index 09187fad6d9..928450dbd51 100644 --- a/tests/lib/rules/space-before-function-paren.js +++ b/tests/lib/rules/space-before-function-paren.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/space-before-function-paren"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); const baseParser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -32,10 +32,10 @@ ruleTester.run("space-before-function-paren", rule, { "var obj = { get foo () {}, set foo (val) {} };", { code: "var obj = { foo () {} };", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, - { code: "function* foo () {}", parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = function *() {};", parserOptions: { ecmaVersion: 6 } }, + { code: "function* foo () {}", languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = function *() {};", languageOptions: { ecmaVersion: 6 } }, { code: "function foo() {}", options: ["never"] }, { code: "var foo = function() {}", options: ["never"] }, @@ -47,17 +47,17 @@ ruleTester.run("space-before-function-paren", rule, { { code: "var obj = { foo() {} };", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function* foo() {}", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function*() {};", options: ["never"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { @@ -69,7 +69,7 @@ ruleTester.run("space-before-function-paren", rule, { "var obj = { get foo() {}, set foo(val) {}, bar() {} };" ].join("\n"), options: [{ named: "never", anonymous: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -80,17 +80,17 @@ ruleTester.run("space-before-function-paren", rule, { "var obj = { get foo () {}, set foo (val) {}, bar () {} };" ].join("\n"), options: [{ named: "always", anonymous: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { constructor() {} *method() {} }", options: [{ named: "never", anonymous: "always" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { constructor () {} *method () {} }", options: [{ named: "always", anonymous: "never" }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() {}", @@ -110,21 +110,23 @@ ruleTester.run("space-before-function-paren", rule, { }, { code: "type TransformFunction = (el: ASTElement, code: string) => string;", - parser: baseParser("babel-eslint7", "function-type-annotation") + languageOptions: { + parser: require(baseParser("babel-eslint7", "function-type-annotation")) + } }, // Async arrow functions - { code: "() => 1", parserOptions: { ecmaVersion: 6 } }, - { code: "async a => a", parserOptions: { ecmaVersion: 8 } }, - { code: "async a => a", options: [{ asyncArrow: "always" }], parserOptions: { ecmaVersion: 8 } }, - { code: "async a => a", options: [{ asyncArrow: "never" }], parserOptions: { ecmaVersion: 8 } }, - { code: "async () => 1", options: [{ asyncArrow: "always" }], parserOptions: { ecmaVersion: 8 } }, - { code: "async() => 1", options: [{ asyncArrow: "never" }], parserOptions: { ecmaVersion: 8 } }, - { code: "async () => 1", options: [{ asyncArrow: "ignore" }], parserOptions: { ecmaVersion: 8 } }, - { code: "async() => 1", options: [{ asyncArrow: "ignore" }], parserOptions: { ecmaVersion: 8 } }, - { code: "async () => 1", parserOptions: { ecmaVersion: 8 } }, - { code: "async () => 1", options: ["always"], parserOptions: { ecmaVersion: 8 } }, - { code: "async() => 1", options: ["never"], parserOptions: { ecmaVersion: 8 } } + { code: "() => 1", languageOptions: { ecmaVersion: 6 } }, + { code: "async a => a", languageOptions: { ecmaVersion: 8 } }, + { code: "async a => a", options: [{ asyncArrow: "always" }], languageOptions: { ecmaVersion: 8 } }, + { code: "async a => a", options: [{ asyncArrow: "never" }], languageOptions: { ecmaVersion: 8 } }, + { code: "async () => 1", options: [{ asyncArrow: "always" }], languageOptions: { ecmaVersion: 8 } }, + { code: "async() => 1", options: [{ asyncArrow: "never" }], languageOptions: { ecmaVersion: 8 } }, + { code: "async () => 1", options: [{ asyncArrow: "ignore" }], languageOptions: { ecmaVersion: 8 } }, + { code: "async() => 1", options: [{ asyncArrow: "ignore" }], languageOptions: { ecmaVersion: 8 } }, + { code: "async () => 1", languageOptions: { ecmaVersion: 8 } }, + { code: "async () => 1", options: ["always"], languageOptions: { ecmaVersion: 8 } }, + { code: "async() => 1", options: ["never"], languageOptions: { ecmaVersion: 8 } } ], invalid: [ @@ -199,7 +201,6 @@ ruleTester.run("space-before-function-paren", rule, { { code: "var obj = { foo() {} };", output: "var obj = { foo () {} };", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -207,12 +208,12 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function* foo() {}", output: "function* foo () {}", - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -220,7 +221,8 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { @@ -381,7 +383,6 @@ ruleTester.run("space-before-function-paren", rule, { code: "var obj = { foo () {} };", output: "var obj = { foo() {} };", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -389,13 +390,13 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "function* foo () {}", output: "function* foo() {}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -403,7 +404,8 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 14 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { @@ -418,7 +420,6 @@ ruleTester.run("space-before-function-paren", rule, { "var obj = { get foo() {}, set foo(val) {}, bar() {} };" ].join("\n"), options: [{ named: "never", anonymous: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -450,13 +451,13 @@ ruleTester.run("space-before-function-paren", rule, { line: 3, column: 49 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "class Foo { constructor () {} *method () {} }", output: "class Foo { constructor() {} *method() {} }", options: [{ named: "never", anonymous: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -470,13 +471,13 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 38 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = { bar () {} }", output: "var foo = { bar() {} }", options: [{ named: "never", anonymous: "always" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -484,7 +485,8 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 16 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -498,7 +500,6 @@ ruleTester.run("space-before-function-paren", rule, { "var obj = { get foo () {}, set foo (val) {}, bar () {} };" ].join("\n"), options: [{ named: "always", anonymous: "never" }], - parserOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -530,7 +531,8 @@ ruleTester.run("space-before-function-paren", rule, { line: 3, column: 47 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() {}", @@ -590,35 +592,35 @@ ruleTester.run("space-before-function-paren", rule, { code: "async() => 1", output: "async () => 1", options: [{ asyncArrow: "always" }], - parserOptions: { ecmaVersion: 8 }, - errors: ["Missing space before function parentheses."] + errors: ["Missing space before function parentheses."], + languageOptions: { ecmaVersion: 8 } }, { code: "async () => 1", output: "async() => 1", options: [{ asyncArrow: "never" }], - parserOptions: { ecmaVersion: 8 }, - errors: ["Unexpected space before function parentheses."] + errors: ["Unexpected space before function parentheses."], + languageOptions: { ecmaVersion: 8 } }, { code: "async() => 1", output: "async () => 1", - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] + errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 8 } }, { code: "async() => 1", output: "async () => 1", options: ["always"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] + errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 8 } }, { code: "async () => 1", output: "async() => 1", options: ["never"], - parserOptions: { ecmaVersion: 8 }, - errors: [{ messageId: "unexpectedSpace", type: "ArrowFunctionExpression" }] + errors: [{ messageId: "unexpectedSpace", type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 8 } } ] }); diff --git a/tests/lib/rules/space-in-parens.js b/tests/lib/rules/space-in-parens.js index e304fb78858..5a65e77dc69 100644 --- a/tests/lib/rules/space-in-parens.js +++ b/tests/lib/rules/space-in-parens.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/space-in-parens"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -34,18 +34,18 @@ ruleTester.run("space-in-parens", rule, { { code: "var x = ( 1 + 2 ) * 3", options: ["always"] }, { code: "var x = 'foo(bar)'", options: ["always"] }, { code: "var x = 'bar( baz )'", options: ["always"] }, - { code: "var foo = `(bar)`;", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `(bar ${baz})`;", options: ["always"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `(bar ${( 1 + 2 )})`;", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = `(bar)`;", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `(bar ${baz})`;", options: ["always"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `(bar ${( 1 + 2 )})`;", options: ["always"], languageOptions: { ecmaVersion: 6 } }, { code: "bar(baz)", options: ["never"] }, { code: "var x = (4 + 5) * 6", options: ["never"] }, { code: "foo\n(\nbar\n)\n", options: ["never"] }, { code: "foo\n( \nbar\n )\n", options: ["never"] }, { code: "foo\n(\n bar \n)\n", options: ["never"] }, { code: "foo\n( \n bar \n )\n", options: ["never"] }, - { code: "var foo = `( bar )`;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `( bar ${baz} )`;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = `(bar ${(1 + 2)})`;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "var foo = `( bar )`;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `( bar ${baz} )`;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = `(bar ${(1 + 2)})`;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, // comments { code: "foo( /* bar */ )", options: ["always"] }, @@ -552,18 +552,18 @@ ruleTester.run("space-in-parens", rule, { code: "var foo = `(bar ${( 1 + 2 )})`;", output: "var foo = `(bar ${(1 + 2)})`;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "rejectedOpeningSpace", line: 1, column: 20 }, { messageId: "rejectedClosingSpace", line: 1, column: 26 } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = `(bar ${(1 + 2 )})`;", output: "var foo = `(bar ${( 1 + 2 )})`;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "missingOpeningSpace", line: 1, column: 19 }] + errors: [{ messageId: "missingOpeningSpace", line: 1, column: 19 }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/space-infix-ops.js b/tests/lib/rules/space-infix-ops.js index c2a5c554649..da84199b12d 100644 --- a/tests/lib/rules/space-infix-ops.js +++ b/tests/lib/rules/space-infix-ops.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/space-infix-ops"), - { RuleTester } = require("../../../lib/rule-tester"), + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"), parser = require("../../fixtures/fixture-parser"); //------------------------------------------------------------------------------ @@ -37,33 +37,33 @@ ruleTester.run("space-infix-ops", rule, { "a = b", "a ? b : c", "var a = b", - { code: "const my_object = {key: 'value'};", parserOptions: { ecmaVersion: 6 } }, - { code: "var {a = 0} = bar;", parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(a = 0) { }", parserOptions: { ecmaVersion: 6 } }, - { code: "a ** b", parserOptions: { ecmaVersion: 7 } }, + { code: "const my_object = {key: 'value'};", languageOptions: { ecmaVersion: 6 } }, + { code: "var {a = 0} = bar;", languageOptions: { ecmaVersion: 6 } }, + { code: "function foo(a = 0) { }", languageOptions: { ecmaVersion: 6 } }, + { code: "a ** b", languageOptions: { ecmaVersion: 7 } }, { code: "a|0", options: [{ int32Hint: true }] }, { code: "a |0", options: [{ int32Hint: true }] }, // Type Annotations - { code: "function foo(a: number = 0) { }", parser: parser("type-annotations/function-parameter-type-annotation"), parserOptions: { ecmaVersion: 6 } }, - { code: "function foo(): Bar { }", parser: parser("type-annotations/function-return-type-annotation"), parserOptions: { ecmaVersion: 6 } }, - { code: "var foo: Bar = '';", parser: parser("type-annotations/variable-declaration-init-type-annotation"), parserOptions: { ecmaVersion: 6 } }, - { code: "const foo = function(a: number = 0): Bar { };", parser: parser("type-annotations/function-expression-type-annotation"), parserOptions: { ecmaVersion: 6 } }, + { code: "function foo(a: number = 0) { }", languageOptions: { ecmaVersion: 6, parser: require(parser("type-annotations/function-parameter-type-annotation")) } }, + { code: "function foo(): Bar { }", languageOptions: { ecmaVersion: 6, parser: require(parser("type-annotations/function-return-type-annotation")) } }, + { code: "var foo: Bar = '';", languageOptions: { ecmaVersion: 6, parser: require(parser("type-annotations/variable-declaration-init-type-annotation")) } }, + { code: "const foo = function(a: number = 0): Bar { };", languageOptions: { ecmaVersion: 6, parser: require(parser("type-annotations/function-expression-type-annotation")) } }, // TypeScript Type Aliases - { code: "type Foo = T;", parser: parser("typescript-parsers/type-alias"), parserOptions: { ecmaVersion: 6 } }, + { code: "type Foo = T;", languageOptions: { ecmaVersion: 6, parser: require(parser("typescript-parsers/type-alias")) } }, // Logical Assignments - { code: "a &&= b", parserOptions: { ecmaVersion: 2021 } }, - { code: "a ||= b", parserOptions: { ecmaVersion: 2021 } }, - { code: "a ??= b", parserOptions: { ecmaVersion: 2021 } }, + { code: "a &&= b", languageOptions: { ecmaVersion: 2021 } }, + { code: "a ||= b", languageOptions: { ecmaVersion: 2021 } }, + { code: "a ??= b", languageOptions: { ecmaVersion: 2021 } }, // Class Fields - { code: "class C { a; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { a = b; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { 'a' = b; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { [a] = b; }", parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { #a = b; }", parserOptions: { ecmaVersion: 2022 } } + { code: "class C { a; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { a = b; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { 'a' = b; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { [a] = b; }", languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { #a = b; }", languageOptions: { ecmaVersion: 2022 } } ], invalid: [ { @@ -403,19 +403,18 @@ ruleTester.run("space-infix-ops", rule, { { code: "const my_object={key: 'value'}", output: "const my_object = {key: 'value'}", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 16 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "var {a=0}=bar;", output: "var {a = 0} = bar;", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -428,31 +427,32 @@ ruleTester.run("space-infix-ops", rule, { line: 1, column: 10, type: "VariableDeclarator" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a=0) { }", output: "function foo(a = 0) { }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, line: 1, column: 15, type: "AssignmentPattern" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "a**b", output: "a ** b", - parserOptions: { ecmaVersion: 7 }, errors: [{ messageId: "missingSpace", data: { operator: "**" }, line: 1, column: 2, type: "BinaryExpression" - }] + }], + languageOptions: { ecmaVersion: 7 } }, { code: "'foo'in{}", @@ -481,34 +481,37 @@ ruleTester.run("space-infix-ops", rule, { { code: "var a: Foo= b;", output: "var a: Foo = b;", - parser: parser("type-annotations/variable-declaration-init-type-annotation-no-space"), errors: [{ messageId: "missingSpace", data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 11 - }] + }], + languageOptions: { + parser: require(parser("type-annotations/variable-declaration-init-type-annotation-no-space")) + } }, { code: "function foo(a: number=0): Foo { }", output: "function foo(a: number = 0): Foo { }", - parser: parser("type-annotations/function-declaration-type-annotation-no-space"), - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, line: 1, column: 23, type: "AssignmentPattern" - }] + }], + languageOptions: { + ecmaVersion: 6, + parser: require(parser("type-annotations/function-declaration-type-annotation-no-space")) + } }, // Logical Assignments { code: "a&&=b", output: "a &&= b", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "&&=" }, @@ -517,12 +520,12 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 5, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a ||=b", output: "a ||= b", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "||=" }, @@ -531,12 +534,12 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 6, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, { code: "a??= b", output: "a ??= b", - parserOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "??=" }, @@ -545,14 +548,14 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 5, type: "AssignmentExpression" - }] + }], + languageOptions: { ecmaVersion: 2021 } }, // Class Fields { code: "class C { a=b; }", output: "class C { a = b; }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -561,12 +564,12 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 13, type: "PropertyDefinition" - }] + }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { [a ]= b; }", output: "class C { [a ] = b; }", - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -575,7 +578,8 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 16, type: "PropertyDefinition" - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/space-unary-ops.js b/tests/lib/rules/space-unary-ops.js index 9969bbc64e3..5b256bb05ad 100644 --- a/tests/lib/rules/space-unary-ops.js +++ b/tests/lib/rules/space-unary-ops.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/space-unary-ops"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -156,58 +156,58 @@ ruleTester.run("space-unary-ops", rule, { }, { code: "function *foo () { yield (0) }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield +1 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield* 0 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield * 0 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { (yield)*0 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { (yield) * 0 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield*0 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield *0 }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "async function foo() { await {foo: 1} }", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await {bar: 2} }", - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await{baz: 3} }", options: [{ words: false }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await {qux: 4} }", options: [{ words: false, overrides: { await: true } }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await{foo: 5} }", options: [{ words: true, overrides: { await: false } }], - parserOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 } }, { code: "foo++", @@ -244,17 +244,17 @@ ruleTester.run("space-unary-ops", rule, { { code: "function *foo () { yield(0) }", options: [{ words: true, overrides: { yield: false } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo () { yield(0) }", options: [{ words: false, overrides: { yield: false } }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class C { #x; *foo(bar) { yield#x in bar; } }", options: [{ words: false }], - parserOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 } } ], @@ -628,39 +628,39 @@ ruleTester.run("space-unary-ops", rule, { { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield (0) }", output: "function *foo() { yield(0) }", options: [{ words: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield+0 }", output: "function *foo() { yield +0 }", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "foo++", @@ -738,91 +738,91 @@ ruleTester.run("space-unary-ops", rule, { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", options: [{ words: true, overrides: { yield: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", options: [{ words: false, overrides: { yield: true } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "async function foo() { await{foo: 'bar'} }", output: "async function foo() { await {foo: 'bar'} }", - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "wordOperator", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await{baz: 'qux'} }", output: "async function foo() { await {baz: 'qux'} }", options: [{ words: false, overrides: { await: true } }], - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "wordOperator", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await {foo: 1} }", output: "async function foo() { await{foo: 1} }", options: [{ words: false }], - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "async function foo() { await {bar: 2} }", output: "async function foo() { await{bar: 2} }", options: [{ words: true, overrides: { await: false } }], - parserOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }] + }], + languageOptions: { ecmaVersion: 8 } }, { code: "class C { #x; *foo(bar) { yield #x in bar; } }", output: "class C { #x; *foo(bar) { yield#x in bar; } }", options: [{ words: false }], - parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 27 - }] + }], + languageOptions: { ecmaVersion: 2022 } } ] }); diff --git a/tests/lib/rules/spaced-comment.js b/tests/lib/rules/spaced-comment.js index 7ca6384364a..98a788348e3 100644 --- a/tests/lib/rules/spaced-comment.js +++ b/tests/lib/rules/spaced-comment.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/spaced-comment"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/strict.js b/tests/lib/rules/strict.js index 2798bc8cd53..469e7931a99 100644 --- a/tests/lib/rules/strict.js +++ b/tests/lib/rules/strict.js @@ -10,14 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/strict"), - { RuleTester } = require("../../../lib/rule-tester"), - FlatRuleTester = require("../../../lib/rule-tester/flat-rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("strict", rule, { valid: [ @@ -30,79 +34,92 @@ ruleTester.run("strict", rule, { { code: "function foo() { bar(); 'use strict'; return; }", options: ["never"] }, { code: "var foo = function() { { 'use strict'; } return; };", options: ["never"] }, { code: "(function() { bar('use strict'); return; }());", options: ["never"] }, - { code: "var fn = x => 1;", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "var fn = x => { return; };", options: ["never"], parserOptions: { ecmaVersion: 6 } }, - { code: "foo();", options: ["never"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function foo() { return; }", options: ["never"], parserOptions: { ecmaFeatures: { impliedStrict: true } } }, + { code: "var fn = x => 1;", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "var fn = x => { return; };", options: ["never"], languageOptions: { ecmaVersion: 6 } }, + { code: "foo();", options: ["never"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { return; }", options: ["never"], languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, // "global" mode { code: "// Intentionally empty", options: ["global"] }, { code: "\"use strict\"; foo();", options: ["global"] }, - { code: "foo();", options: ["global"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function foo() { return; }", options: ["global"], parserOptions: { ecmaFeatures: { impliedStrict: true } } }, + { code: "foo();", options: ["global"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { return; }", options: ["global"], languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "'use strict'; function foo() { return; }", options: ["global"] }, { code: "'use strict'; var foo = function() { return; };", options: ["global"] }, { code: "'use strict'; function foo() { bar(); 'use strict'; return; }", options: ["global"] }, { code: "'use strict'; var foo = function() { bar(); 'use strict'; return; };", options: ["global"] }, { code: "'use strict'; function foo() { return function() { bar(); 'use strict'; return; }; }", options: ["global"] }, - { code: "'use strict'; var foo = () => { return () => { bar(); 'use strict'; return; }; }", options: ["global"], parserOptions: { ecmaVersion: 6 } }, + { code: "'use strict'; var foo = () => { return () => { bar(); 'use strict'; return; }; }", options: ["global"], languageOptions: { ecmaVersion: 6 } }, // "function" mode { code: "function foo() { 'use strict'; return; }", options: ["function"] }, - { code: "function foo() { return; }", options: ["function"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function foo() { return; }", options: ["function"], parserOptions: { ecmaFeatures: { impliedStrict: true } } }, - { code: "var foo = function() { return; }", options: ["function"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { return; }", options: ["function"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { return; }", options: ["function"], languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, + { code: "var foo = function() { return; }", options: ["function"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "var foo = function() { 'use strict'; return; }", options: ["function"] }, { code: "function foo() { 'use strict'; return; } var bar = function() { 'use strict'; bar(); };", options: ["function"] }, { code: "var foo = function() { 'use strict'; function bar() { return; } bar(); };", options: ["function"] }, - { code: "var foo = () => { 'use strict'; var bar = () => 1; bar(); };", options: ["function"], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = () => { var bar = () => 1; bar(); };", options: ["function"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var foo = () => { 'use strict'; var bar = () => 1; bar(); };", options: ["function"], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => { var bar = () => 1; bar(); };", options: ["function"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "class A { constructor() { } }", options: ["function"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() { } }", options: ["function"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() { function bar() { } } }", options: ["function"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { 'use strict'; function foo(a = 0) { } }())", options: ["function"], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // "safe" mode corresponds to "global" if ecmaFeatures.globalReturn is true, otherwise "function" { code: "function foo() { 'use strict'; return; }", options: ["safe"] }, - { code: "'use strict'; function foo() { return; }", options: ["safe"], parserOptions: { ecmaFeatures: { globalReturn: true } } }, - { code: "function foo() { return; }", options: ["safe"], parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function foo() { return; }", options: ["safe"], parserOptions: { ecmaFeatures: { impliedStrict: true } } }, + { code: "'use strict'; function foo() { return; }", options: ["safe"], languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, + { code: "function foo() { return; }", options: ["safe"], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { return; }", options: ["safe"], languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, // defaults to "safe" mode "function foo() { 'use strict'; return; }", - { code: "'use strict'; function foo() { return; }", parserOptions: { ecmaFeatures: { globalReturn: true } } }, - { code: "function foo() { return; }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "function foo() { return; }", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, + { code: "'use strict'; function foo() { return; }", languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, + { code: "function foo() { return; }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "function foo() { return; }", languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, // class static blocks do not have directive prologues, therefore this rule should never require od disallow "use strict" statement in them. - { code: "'use strict'; class C { static { foo; } }", options: ["global"], parserOptions: { ecmaVersion: 2022 } }, - { code: "'use strict'; class C { static { 'use strict'; } }", options: ["global"], parserOptions: { ecmaVersion: 2022 } }, - { code: "'use strict'; class C { static { 'use strict'; 'use strict'; } }", options: ["global"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo; } }", options: ["function"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { 'use strict'; } }", options: ["function"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { 'use strict'; 'use strict'; } }", options: ["function"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { foo; } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { 'use strict'; } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { 'use strict'; 'use strict'; } }", options: ["never"], parserOptions: { ecmaVersion: 2022 } }, - { code: "class C { static { 'use strict'; } }", options: ["safe"], parserOptions: { ecmaVersion: 2022, sourceType: "module" } }, - { code: "class C { static { 'use strict'; } }", options: ["safe"], parserOptions: { ecmaVersion: 2022, ecmaFeatures: { impliedStrict: true } } } + { code: "'use strict'; class C { static { foo; } }", options: ["global"], languageOptions: { ecmaVersion: 2022 } }, + { code: "'use strict'; class C { static { 'use strict'; } }", options: ["global"], languageOptions: { ecmaVersion: 2022 } }, + { code: "'use strict'; class C { static { 'use strict'; 'use strict'; } }", options: ["global"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo; } }", options: ["function"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { 'use strict'; } }", options: ["function"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { 'use strict'; 'use strict'; } }", options: ["function"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { foo; } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { 'use strict'; } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { 'use strict'; 'use strict'; } }", options: ["never"], languageOptions: { ecmaVersion: 2022 } }, + { code: "class C { static { 'use strict'; } }", options: ["safe"], languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, + { code: "class C { static { 'use strict'; } }", options: ["safe"], languageOptions: { ecmaVersion: 2022, parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, + { + code: "'use strict'; module.exports = function identity (value) { return value; }", + languageOptions: { + sourceType: "commonjs" + } + }, + { + code: "'use strict'; module.exports = function identity (value) { return value; }", + options: ["safe"], + languageOptions: { + sourceType: "commonjs" + } + } ], invalid: [ @@ -148,28 +165,28 @@ ruleTester.run("strict", rule, { code: "\"use strict\"; foo();", output: " foo();", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["never"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, // "global" mode @@ -200,11 +217,11 @@ ruleTester.run("strict", rule, { code: "var foo = () => { 'use strict'; return () => 1; }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: null, @@ -230,28 +247,28 @@ ruleTester.run("strict", rule, { code: "'use strict'; foo();", output: " foo();", options: ["global"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["global"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["global"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, // "function" mode @@ -287,18 +304,18 @@ ruleTester.run("strict", rule, { code: "(() => { return true; })();", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "function", type: "ArrowFunctionExpression" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "(() => true)();", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "function", type: "ArrowFunctionExpression" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "var foo = function() { foo(); 'use strict'; return; }; function bar() { foo(); 'use strict'; }", output: null, @@ -325,28 +342,28 @@ ruleTester.run("strict", rule, { code: "var foo = function() { 'use strict'; return; }", output: "var foo = function() { return; }", options: ["function"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["function"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["function"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "function foo() { return function() { 'use strict'; return; }; }", output: null, @@ -396,8 +413,8 @@ ruleTester.run("strict", rule, { code: "var foo = () => { return; };", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "function", type: "ArrowFunctionExpression" }] + errors: [{ messageId: "function", type: "ArrowFunctionExpression" }], + languageOptions: { ecmaVersion: 6 } }, // Classes @@ -405,36 +422,36 @@ ruleTester.run("strict", rule, { code: "class A { constructor() { \"use strict\"; } }", output: "class A { constructor() { } }", options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() { \"use strict\"; } }", output: "class A { foo() { } }", options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { foo() { function bar() { \"use strict\"; } } }", output: "class A { foo() { function bar() { } } }", options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 6 } }, { code: "class A { field = () => { \"use strict\"; } }", output: "class A { field = () => { } }", options: ["function"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class A { field = function() { \"use strict\"; } }", output: "class A { field = function() { } }", options: ["function"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], + languageOptions: { ecmaVersion: 2022 } }, // "safe" mode corresponds to "global" if ecmaFeatures.globalReturn is true, otherwise "function" @@ -451,31 +468,31 @@ ruleTester.run("strict", rule, { code: "function foo() { 'use strict'; return; }", output: null, options: ["safe"], - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["safe"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["safe"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, // Default to "safe" mode @@ -495,29 +512,29 @@ ruleTester.run("strict", rule, { { code: "function foo() { 'use strict'; return; }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", - parserOptions: { ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ] + ], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ] + ], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, // Reports deprecated syntax: https://github.com/eslint/eslint/issues/6405 @@ -525,84 +542,84 @@ ruleTester.run("strict", rule, { code: "function foo(a = 0) { 'use strict' }", output: null, options: [], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "nonSimpleParameterList" }] + errors: [{ messageId: "nonSimpleParameterList" }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())", output: null, options: [], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "nonSimpleParameterList" }] + errors: [{ messageId: "nonSimpleParameterList" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: [], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } }, errors: [ "Use the global form of 'use strict'.", { messageId: "nonSimpleParameterList" } - ] + ], + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "'use strict'; function foo(a = 0) { 'use strict' }", output: null, options: [], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } }, - errors: [{ messageId: "nonSimpleParameterList" }] + errors: [{ messageId: "nonSimpleParameterList" }], + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["never"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "nonSimpleParameterList" }] + errors: [{ messageId: "nonSimpleParameterList" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 6 }, errors: [ "Use the global form of 'use strict'.", { messageId: "nonSimpleParameterList" } - ] + ], + languageOptions: { ecmaVersion: 6 } }, { code: "'use strict'; function foo(a = 0) { 'use strict' }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "nonSimpleParameterList" }] + errors: [{ messageId: "nonSimpleParameterList" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "nonSimpleParameterList" }] + errors: [{ messageId: "nonSimpleParameterList" }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "nonSimpleParameterList" }] + errors: [{ messageId: "nonSimpleParameterList" }], + languageOptions: { ecmaVersion: 6 } }, { code: "function foo(a = 0) { }", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "wrap", data: { name: "function 'foo'" } }] + errors: [{ messageId: "wrap", data: { name: "function 'foo'" } }], + languageOptions: { ecmaVersion: 6 } }, { code: "(function() { function foo(a = 0) { } }())", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, - errors: ["Use the function form of 'use strict'."] + errors: ["Use the function form of 'use strict'."], + languageOptions: { ecmaVersion: 6 } }, // functions inside class static blocks should be checked @@ -610,96 +627,74 @@ ruleTester.run("strict", rule, { code: "'use strict'; class C { static { function foo() { \n'use strict'; } } }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "global", line: 2 }] + errors: [{ messageId: "global", line: 2 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: null, options: ["never"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "never", line: 2 }] + errors: [{ messageId: "never", line: 2 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: "class C { static { function foo() { \n } } }", options: ["safe"], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, - errors: [{ messageId: "module", line: 2 }] + errors: [{ messageId: "module", line: 2 }], + languageOptions: { ecmaVersion: 2022, sourceType: "module" } }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: "class C { static { function foo() { \n } } }", options: ["safe"], - parserOptions: { ecmaVersion: 2022, ecmaFeatures: { impliedStrict: true } }, - errors: [{ messageId: "implied", line: 2 }] + errors: [{ messageId: "implied", line: 2 }], + languageOptions: { ecmaVersion: 2022, parserOptions: { ecmaFeatures: { impliedStrict: true } } } }, { code: "function foo() {'use strict'; class C { static { function foo() { \n'use strict'; } } } }", output: "function foo() {'use strict'; class C { static { function foo() { \n } } } }", options: ["function"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessary", line: 2 }] + errors: [{ messageId: "unnecessary", line: 2 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: "class C { static { function foo() { \n } } }", options: ["function"], - parserOptions: { ecmaVersion: 2022 }, - errors: [{ messageId: "unnecessaryInClasses", line: 2 }] + errors: [{ messageId: "unnecessaryInClasses", line: 2 }], + languageOptions: { ecmaVersion: 2022 } }, { code: "class C { static { function foo() { \n'use strict';\n'use strict'; } } }", output: "class C { static { function foo() { \n\n } } }", options: ["function"], - parserOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unnecessaryInClasses", line: 2 }, { messageId: "multiple", line: 3 } - ] - } - ] -}); - -const flatRuleTester = new FlatRuleTester(); - -// TODO: merge these tests into `ruleTester.run` once we switch to FlatRuleTester (when FlatRuleTester becomes RuleTester). -flatRuleTester.run("strict", rule, { - valid: [ - { - code: "'use strict'; module.exports = function identity (value) { return value; }", - languageOptions: { - sourceType: "commonjs" - } + ], + languageOptions: { ecmaVersion: 2022 } }, { - code: "'use strict'; module.exports = function identity (value) { return value; }", + code: "module.exports = function identity (value) { return value; }", + output: null, options: ["safe"], + errors: [ + { messageId: "global", line: 1 } + ], languageOptions: { sourceType: "commonjs" } - } - ], - - invalid: [ + }, { code: "module.exports = function identity (value) { return value; }", - options: ["safe"], - languageOptions: { - sourceType: "commonjs" - }, + output: null, errors: [ { messageId: "global", line: 1 } - ] - }, - { - code: "module.exports = function identity (value) { return value; }", + ], languageOptions: { sourceType: "commonjs" - }, - errors: [ - { messageId: "global", line: 1 } - ] + } } ] }); diff --git a/tests/lib/rules/switch-colon-spacing.js b/tests/lib/rules/switch-colon-spacing.js index 8ceb3bdf756..333fb026235 100644 --- a/tests/lib/rules/switch-colon-spacing.js +++ b/tests/lib/rules/switch-colon-spacing.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/switch-colon-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/symbol-description.js b/tests/lib/rules/symbol-description.js index 55cbbbc89c8..6f4c71d9be3 100644 --- a/tests/lib/rules/symbol-description.js +++ b/tests/lib/rules/symbol-description.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/symbol-description"); -const { RuleTester } = require("../../../lib/rule-tester"); +const RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ env: { es6: true } }); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 6, + sourceType: "script" + } +}); ruleTester.run("symbol-description", rule, { diff --git a/tests/lib/rules/template-curly-spacing.js b/tests/lib/rules/template-curly-spacing.js index ac672a5ec8c..c75634a72a9 100644 --- a/tests/lib/rules/template-curly-spacing.js +++ b/tests/lib/rules/template-curly-spacing.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/template-curly-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("template-curly-spacing", rule, { valid: [ diff --git a/tests/lib/rules/template-tag-spacing.js b/tests/lib/rules/template-tag-spacing.js index f01dbdce3a0..9f3d29f0ee8 100644 --- a/tests/lib/rules/template-tag-spacing.js +++ b/tests/lib/rules/template-tag-spacing.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/template-tag-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); ruleTester.run("template-tag-spacing", rule, { valid: [ diff --git a/tests/lib/rules/unicode-bom.js b/tests/lib/rules/unicode-bom.js index 62abee69870..45de6cf031f 100644 --- a/tests/lib/rules/unicode-bom.js +++ b/tests/lib/rules/unicode-bom.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/unicode-bom"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/use-isnan.js b/tests/lib/rules/use-isnan.js index a9bfe3a67d7..5307b34ab07 100644 --- a/tests/lib/rules/use-isnan.js +++ b/tests/lib/rules/use-isnan.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/use-isnan"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -266,7 +266,7 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf(...NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "foo.lastIndexOf(NaN())", @@ -339,7 +339,7 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf(...Number.NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "foo.lastIndexOf(Number.NaN())", @@ -477,8 +477,8 @@ ruleTester.run("use-isnan", rule, { }, { code: "x === Number?.NaN;", - parserOptions: { ecmaVersion: 2020 }, - errors: [comparisonError] + errors: [comparisonError], + languageOptions: { ecmaVersion: 2020 } }, { code: "x === Number['NaN'];", @@ -685,20 +685,20 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf?.(NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.indexOf(NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.indexOf)(NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo.indexOf(Number.NaN)", @@ -733,20 +733,20 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf?.(Number.NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "foo?.indexOf(Number.NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], + languageOptions: { ecmaVersion: 2020 } }, { code: "(foo?.indexOf)(Number.NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/utils/ast-utils.js b/tests/lib/rules/utils/ast-utils.js index bc03c7e47cd..7be295d22d8 100644 --- a/tests/lib/rules/utils/ast-utils.js +++ b/tests/lib/rules/utils/ast-utils.js @@ -145,7 +145,7 @@ describe("ast-utils", () => { })) }); - linter.verify("const a = 1; a = 2;", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); + linter.verify("const a = 1; a = 2;", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); }); it("should return false if reference is not assigned for const", () => { @@ -159,7 +159,7 @@ describe("ast-utils", () => { })) }); - linter.verify("const a = 1; c = 2;", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); + linter.verify("const a = 1; c = 2;", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); }); // class @@ -175,7 +175,7 @@ describe("ast-utils", () => { })) }); - linter.verify("class A { }\n A = 1;", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); + linter.verify("class A { }\n A = 1;", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); }); it("should return false if reference is not assigned for class", () => { @@ -189,7 +189,7 @@ describe("ast-utils", () => { })) }); - linter.verify("class A { } foo(A);", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); + linter.verify("class A { } foo(A);", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); }); }); @@ -393,7 +393,7 @@ describe("ast-utils", () => { }) })) }); - linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); + linter.verify(code, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); assert.lengthOf(results, 1); assert.strictEqual(results[0], expectedInLoop); @@ -924,7 +924,7 @@ describe("ast-utils", () => { })) }); - linter.verify(key, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 13 } }); + linter.verify(key, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 13 } }); }); }); }); @@ -1004,7 +1004,7 @@ describe("ast-utils", () => { })) }); - linter.verify(key, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 13 } }, "test.js", true); + linter.verify(key, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 13 } }, "test.js", true); }); }); }); @@ -1819,7 +1819,7 @@ describe("ast-utils", () => { })) }); - linter.verify("var foo = () => \"use strict\";", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 2022 } }); + linter.verify("var foo = () => \"use strict\";", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 2022 } }); }); const expectedResults = [ @@ -1853,7 +1853,7 @@ describe("ast-utils", () => { }) }); - linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 2022 } }); + linter.verify(code, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 2022 } }); }); }); }); @@ -1916,7 +1916,7 @@ describe("ast-utils", () => { }) }); - linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 2022 } }); + linter.verify(code, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 2022 } }); }); }); }); diff --git a/tests/lib/rules/valid-jsdoc.js b/tests/lib/rules/valid-jsdoc.js index 325064fc189..324efcd1036 100644 --- a/tests/lib/rules/valid-jsdoc.js +++ b/tests/lib/rules/valid-jsdoc.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/valid-jsdoc"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -88,12 +88,12 @@ ruleTester.run("valid-jsdoc", rule, { { code: "/**\n* Description\n* @param {string} p bar\n*/\nFoo.bar = (p) => {};", options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n* Description\n* @param {string} p bar\n*/\nFoo.bar = function({p}){};", options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n* Description\n* @param {string} p bar\n*/\nFoo.bar = function(p){};", @@ -136,24 +136,24 @@ ruleTester.run("valid-jsdoc", rule, { { code: "/**\n * Description for A.\n */\n class A {\n /**\n * Description for constructor.\n * @param {object[]} xs - xs\n */\n constructor(xs) {\n /**\n * Description for this.xs;\n * @type {object[]}\n */\n this.xs = xs.filter(x => x != null);\n }\n}", options: [{ requireReturn: false }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "/** @returns {object} foo */ var foo = () => bar();", options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/** @returns {object} foo */ var foo = () => { return bar(); };", options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/** foo */ var foo = () => { bar(); };", options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n* Start with caps and end with period.\n* @return {void} */\nfunction foo(){}", @@ -199,7 +199,7 @@ ruleTester.run("valid-jsdoc", rule, { " }\n" + "}", options: [{ requireReturn: true }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -218,7 +218,7 @@ ruleTester.run("valid-jsdoc", rule, { " }\n" + "}", options: [{ requireReturn: false }], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -246,7 +246,7 @@ ruleTester.run("valid-jsdoc", rule, { " }\n" + "}", options: [], - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -280,7 +280,7 @@ ruleTester.run("valid-jsdoc", rule, { " */\n" + "async function a() {}", options: [{ requireReturn: true }], - parserOptions: { + languageOptions: { ecmaVersion: 2017 } }, @@ -292,7 +292,7 @@ ruleTester.run("valid-jsdoc", rule, { " */\n" + "async function a() {}", options: [{ requireReturn: false }], - parserOptions: { + languageOptions: { ecmaVersion: 2017 } }, @@ -303,7 +303,7 @@ ruleTester.run("valid-jsdoc", rule, { " */\n" + "async function a() {}", options: [{ requireReturn: false }], - parserOptions: { + languageOptions: { ecmaVersion: 2017 } }, @@ -518,13 +518,13 @@ ruleTester.run("valid-jsdoc", rule, { }, { code: "/**\n* Description\n* @param {string} a bar\n* @returns {string} desc */\nfunction foo(a = 1){}", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n* Description\n* @param {string} b bar\n* @param {string} a bar\n* @returns {string} desc */\nfunction foo(b, a = 1){}", - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -1011,7 +1011,7 @@ ruleTester.run("valid-jsdoc", rule, { " // empty", "}" ].join("\n"), - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: [ @@ -1024,7 +1024,7 @@ ruleTester.run("valid-jsdoc", rule, { " // empty", "}" ].join("\n"), - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, // https://github.com/eslint/eslint/issues/7184 @@ -1188,7 +1188,6 @@ ruleTester.run("valid-jsdoc", rule, { code: "/** Foo \n@return {void} Foo\n */\nfoo.bar = () => {}", output: "/** Foo \n@returns {void} Foo\n */\nfoo.bar = () => {}", options: [{ prefer: { return: "returns" } }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1197,7 +1196,8 @@ ruleTester.run("valid-jsdoc", rule, { column: 1, endLine: 2, endColumn: 8 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "/** Foo \n@param {void Foo\n */\nfunction foo(){}", @@ -1311,9 +1311,6 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: true, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unsatisfiedDesc", @@ -1324,7 +1321,10 @@ ruleTester.run("valid-jsdoc", rule, { data: { returns: "returns" }, type: "Block" } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: "/**\n* Foo\n* @returns {string} \n*/\nfunction foo(){}", @@ -1346,17 +1346,16 @@ ruleTester.run("valid-jsdoc", rule, { { code: "/**\n* Foo\n* @returns {string} something \n*/\nvar foo = \nfunction foo(a = 1){}", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingParam", data: { name: "a" }, type: "Block" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n* Foo\n* @param {string} a Description \n* @param {string} b Description \n* @returns {string} something \n*/\nvar foo = \nfunction foo(b, a = 1){}", output: null, - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expected", data: { name: "b", jsdocName: "a" }, @@ -1374,7 +1373,8 @@ ruleTester.run("valid-jsdoc", rule, { column: 3, endLine: 4, endColumn: 32 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n* Foo\n* @param {string} p desc\n* @param {string} p desc \n*/\nfunction foo(){}", @@ -1470,7 +1470,6 @@ ruleTester.run("valid-jsdoc", rule, { code: "/**\n * Does something. \n* @param {string} a - this is a \n* @return {Array} The result of doing it \n*/\n export function doSomething(a) { }", output: "/**\n * Does something. \n* @param {string} a - this is a \n* @returns {Array} The result of doing it \n*/\n export function doSomething(a) { }", options: [{ prefer: { return: "returns" } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1479,13 +1478,13 @@ ruleTester.run("valid-jsdoc", rule, { column: 3, endLine: 4, endColumn: 10 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "/**\n * Does something. \n* @param {string} a - this is a \n* @return {Array} The result of doing it \n*/\n export default function doSomething(a) { }", output: "/**\n * Does something. \n* @param {string} a - this is a \n* @returns {Array} The result of doing it \n*/\n export default function doSomething(a) { }", options: [{ prefer: { return: "returns" } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1494,35 +1493,35 @@ ruleTester.run("valid-jsdoc", rule, { column: 3, endLine: 4, endColumn: 10 - }] + }], + languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: "/** foo */ var foo = () => bar();", output: null, options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, type: "Block" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "/** foo */ var foo = () => { return bar(); };", output: null, options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, type: "Block" - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "/** @returns {object} foo */ var foo = () => { bar(); };", output: null, options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedTag", data: { title: "returns" }, @@ -1531,7 +1530,8 @@ ruleTester.run("valid-jsdoc", rule, { column: 5, endLine: 1, endColumn: 26 - }] + }], + languageOptions: { ecmaVersion: 6 } }, { code: "/**\n* @param fields [Array]\n */\n function foo(){}", @@ -1611,9 +1611,6 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: false, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unsatisfiedDesc", @@ -1623,7 +1620,10 @@ ruleTester.run("valid-jsdoc", rule, { messageId: "unsatisfiedDesc", type: "Block" } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: @@ -1644,9 +1644,6 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: true, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "unsatisfiedDesc", @@ -1657,7 +1654,10 @@ ruleTester.run("valid-jsdoc", rule, { data: { returns: "returns" }, type: "Block" } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: @@ -1682,9 +1682,6 @@ ruleTester.run("valid-jsdoc", rule, { "}", output: null, options: [], - parserOptions: { - ecmaVersion: 6 - }, errors: [ { messageId: "missingReturn", @@ -1696,7 +1693,10 @@ ruleTester.run("valid-jsdoc", rule, { data: { name: "xs" }, type: "Block" } - ] + ], + languageOptions: { + ecmaVersion: 6 + } }, { code: @@ -1736,14 +1736,14 @@ ruleTester.run("valid-jsdoc", rule, { "async function a() {}", output: null, options: [{ requireReturn: true }], - parserOptions: { - ecmaVersion: 2017 - }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, type: "Block" - }] + }], + languageOptions: { + ecmaVersion: 2017 + } }, // type validations diff --git a/tests/lib/rules/valid-typeof.js b/tests/lib/rules/valid-typeof.js index 35a52f0a6c0..7298d3a6262 100644 --- a/tests/lib/rules/valid-typeof.js +++ b/tests/lib/rules/valid-typeof.js @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/valid-typeof"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -65,16 +65,16 @@ ruleTester.run("valid-typeof", rule, { { code: "typeof foo === `string`", options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "`object` === typeof foo", options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "typeof foo === `str${somethingElse}`", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } } ], @@ -129,8 +129,8 @@ ruleTester.run("valid-typeof", rule, { }, { code: "if (typeof bar === `umdefined`) {}", - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "invalidValue", type: "TemplateLiteral" }] + errors: [{ messageId: "invalidValue", type: "TemplateLiteral" }], + languageOptions: { ecmaVersion: 6 } }, { code: "typeof foo == 'invalid string'", @@ -208,14 +208,14 @@ ruleTester.run("valid-typeof", rule, { { code: "typeof foo === `undefined${foo}`", options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "notString", type: "TemplateLiteral" }] + errors: [{ messageId: "notString", type: "TemplateLiteral" }], + languageOptions: { ecmaVersion: 6 } }, { code: "typeof foo === `${string}`", options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "notString", type: "TemplateLiteral" }] + errors: [{ messageId: "notString", type: "TemplateLiteral" }], + languageOptions: { ecmaVersion: 6 } } ] }); diff --git a/tests/lib/rules/vars-on-top.js b/tests/lib/rules/vars-on-top.js index e2b1bb689c5..28892c7b0d7 100644 --- a/tests/lib/rules/vars-on-top.js +++ b/tests/lib/rules/vars-on-top.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/vars-on-top"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -143,7 +143,7 @@ ruleTester.run("vars-on-top", rule, { " i = i + 1;", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6 } }, @@ -151,21 +151,21 @@ ruleTester.run("vars-on-top", rule, { "'use strict'; 'directive'; var x; var y; f();", "function f() { 'use strict'; var x; f(); }", "function f() { 'use strict'; 'directive'; var x; var y; f(); }", - { code: "import React from 'react'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "'use strict'; import React from 'react'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import React from 'react'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import * as foo from 'mod.js'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { square, diag } from 'lib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import { default as foo } from 'lib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import 'src/mylib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "import theDefault, { named1, named2 } from 'src/mylib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import React from 'react'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "'use strict'; import React from 'react'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import React from 'react'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import * as foo from 'mod.js'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { square, diag } from 'lib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import { default as foo } from 'lib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import 'src/mylib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import theDefault, { named1, named2 } from 'src/mylib'; 'use strict'; var y; function f() { 'use strict'; var x; var y; f(); }", languageOptions: { ecmaVersion: 6, sourceType: "module" } }, { code: [ "export var x;", "var y;", "var z;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" } @@ -176,7 +176,7 @@ ruleTester.run("vars-on-top", rule, { "export var y;", "var z;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" } @@ -187,7 +187,7 @@ ruleTester.run("vars-on-top", rule, { "var y;", "export var z;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" } @@ -200,7 +200,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, @@ -213,7 +213,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, @@ -226,7 +226,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, @@ -240,7 +240,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, @@ -253,7 +253,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 } }, @@ -266,7 +266,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 } } @@ -430,8 +430,8 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { ecmaVersion: 6 }, - errors: [error] + errors: [error], + languageOptions: { ecmaVersion: 6 } }, { code: "'use strict'; 0; var x; f();", @@ -454,11 +454,11 @@ ruleTester.run("vars-on-top", rule, { "export function f() {}", "var x;" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 6, sourceType: "module" - }, - errors: [error] + } }, { code: [ @@ -466,11 +466,11 @@ ruleTester.run("vars-on-top", rule, { "export function f() {}", "var y;" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 6, sourceType: "module" - }, - errors: [error] + } }, { code: [ @@ -478,33 +478,33 @@ ruleTester.run("vars-on-top", rule, { "export {foo};", "var test = 1;" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 6, sourceType: "module" - }, - errors: [error] + } }, { code: [ "export {foo} from 'foo';", "var test = 1;" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 6, sourceType: "module" - }, - errors: [error] + } }, { code: [ "export * from 'foo';", "var test = 1;" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 6, sourceType: "module" - }, - errors: [error] + } }, { code: [ @@ -515,10 +515,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 2022 - }, - errors: [error] + } }, { code: [ @@ -529,10 +529,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 2022 - }, - errors: [error] + } }, { code: [ @@ -544,10 +544,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + errors: [{ ...error, line: 5 }], + languageOptions: { ecmaVersion: 2022 - }, - errors: [{ ...error, line: 5 }] + } }, { code: [ @@ -559,10 +559,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 2022 - }, - errors: [error] + } }, { code: [ @@ -573,10 +573,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + errors: [error], + languageOptions: { ecmaVersion: 2022 - }, - errors: [error] + } } ] }); diff --git a/tests/lib/rules/wrap-iife.js b/tests/lib/rules/wrap-iife.js index 642e29b26df..7087ff3403a 100644 --- a/tests/lib/rules/wrap-iife.js +++ b/tests/lib/rules/wrap-iife.js @@ -10,13 +10,18 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/wrap-iife"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); const wrapInvocationError = { messageId: "wrapInvocation", type: "CallExpression" }; const wrapExpressionError = { messageId: "wrapExpression", type: "CallExpression" }; @@ -107,7 +112,7 @@ ruleTester.run("wrap-iife", rule, { { code: "import(function (){}());", options: ["any"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if ((function (){})()) {}", @@ -148,7 +153,7 @@ ruleTester.run("wrap-iife", rule, { { code: "import(function (){}());", options: ["outside"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if ((function (){})()) {}", @@ -189,7 +194,7 @@ ruleTester.run("wrap-iife", rule, { { code: "import((function (){})());", options: ["inside"], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "while (((function (){})())) {}", @@ -286,7 +291,7 @@ ruleTester.run("wrap-iife", rule, { { code: "import(function (){}.call())", options: ["any", { functionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if ((function (){}).call()) {}", @@ -327,7 +332,7 @@ ruleTester.run("wrap-iife", rule, { { code: "import(function (){}.call())", options: ["outside", { functionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if ((function (){}).call()) {}", @@ -368,7 +373,7 @@ ruleTester.run("wrap-iife", rule, { { code: "import((function (){}).call())", options: ["inside", { functionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if (((function (){}).call())) {}", @@ -478,8 +483,8 @@ ruleTester.run("wrap-iife", rule, { code: "import(function (){}())", output: "import((function (){})())", // wrap function expression, but don't remove mandatory parens options: ["inside"], - parserOptions: { ecmaVersion: 2020 }, - errors: [wrapExpressionError] + errors: [wrapExpressionError], + languageOptions: { ecmaVersion: 2020 } }, { @@ -601,8 +606,8 @@ ruleTester.run("wrap-iife", rule, { code: "import(function (){}.call())", output: "import((function (){}).call())", // wrap function expression, but don't remove mandatory parens options: ["inside", { functionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [wrapExpressionError] + errors: [wrapExpressionError], + languageOptions: { ecmaVersion: 2020 } }, // Optional chaining @@ -610,29 +615,29 @@ ruleTester.run("wrap-iife", rule, { code: "window.bar = function() { return 3; }.call?.(this, arg1);", output: "window.bar = (function() { return 3; }).call?.(this, arg1);", options: ["inside", { functionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [wrapInvocationError] + errors: [wrapInvocationError], + languageOptions: { ecmaVersion: 2020 } }, { code: "window.bar = function() { return 3; }?.call(this, arg1);", output: "window.bar = (function() { return 3; })?.call(this, arg1);", options: ["inside", { functionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [wrapInvocationError] + errors: [wrapInvocationError], + languageOptions: { ecmaVersion: 2020 } }, { code: "window.bar = (function() { return 3; }?.call)(this, arg1);", output: "window.bar = ((function() { return 3; })?.call)(this, arg1);", options: ["inside", { functionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, - errors: [wrapInvocationError] + errors: [wrapInvocationError], + languageOptions: { ecmaVersion: 2020 } }, { code: "new (function () {} ?.());", output: "new ((function () {}) ?.());", options: ["inside"], - parserOptions: { ecmaVersion: 2020 }, - errors: [wrapExpressionError] + errors: [wrapExpressionError], + languageOptions: { ecmaVersion: 2020 } } ] }); diff --git a/tests/lib/rules/wrap-regex.js b/tests/lib/rules/wrap-regex.js index 6aea21118ad..9a7dfbed2ea 100644 --- a/tests/lib/rules/wrap-regex.js +++ b/tests/lib/rules/wrap-regex.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/wrap-regex"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/yield-star-spacing.js b/tests/lib/rules/yield-star-spacing.js index 9c8aaff952e..d3887d1fa33 100644 --- a/tests/lib/rules/yield-star-spacing.js +++ b/tests/lib/rules/yield-star-spacing.js @@ -10,13 +10,13 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/yield-star-spacing"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); +const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 6 } }); const missingBeforeError = { messageId: "missingBefore", type: "Punctuator" }; const missingAfterError = { messageId: "missingAfter", type: "Punctuator" }; diff --git a/tests/lib/rules/yoda.js b/tests/lib/rules/yoda.js index 7f88a829855..c7be95e9ec7 100644 --- a/tests/lib/rules/yoda.js +++ b/tests/lib/rules/yoda.js @@ -9,7 +9,7 @@ // Requirements //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/yoda"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests @@ -29,37 +29,37 @@ ruleTester.run("yoda", rule, { { code: "if (value === `red`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`red` === `red`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`${foo}` === `red`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (`${""}` === `red`) {}', options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (`${"red"}` === foo) {}', options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (b > `a` && b > `a`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (`b` > `a` && "b" > "a") {}', options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // "always" mode @@ -71,37 +71,37 @@ ruleTester.run("yoda", rule, { { code: "if (`red` === value) {}", options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`red` === `red`) {}", options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`red` === `${foo}`) {}", options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (`red` === `${""}`) {}', options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (foo === `${"red"}`) {}', options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`a` > b && `a` > b) {}", options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (`b` > `a` && "b" > "a") {}', options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, // Range exception @@ -120,7 +120,7 @@ ruleTester.run("yoda", rule, { { code: "if (x < `x` || `x` <= x) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 < x && x <= 1) {}", @@ -137,12 +137,12 @@ ruleTester.run("yoda", rule, { { code: "if (0 < x[``] && x[``] < 100) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 < x[''] && x[``] < 100) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: @@ -192,67 +192,67 @@ ruleTester.run("yoda", rule, { { code: "if (0 <= a.b && a[`b`] <= 100) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (-1n < x && x <= 1n) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if (-1n <= x && x < 1n) {}", options: ["always", { exceptRange: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if (x < `1` || `1` < x) {}", options: ["always", { exceptRange: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if (1 <= a['/(?0)/'] && a[/(?0)/] <= 100) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 } }, { code: "if (x <= `bar` || `foo` < x) {}", options: ["always", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if ('a' < x && x < MAX ) {}", options: ["always", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if ('a' < x && x < MAX ) {}", options: ["always"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (MIN < x && x < 'a' ) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (MIN < x && x < 'a' ) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`blue` < x.y && x.y < `green`) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 <= x[`y`] && x[`y`] <= 100) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (0 <= x[`y`] && x["y"] <= 100) {}', options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if ('a' <= x && x < 'b') {}", @@ -261,12 +261,12 @@ ruleTester.run("yoda", rule, { { code: "if (x < -1n || 1n <= x) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if (x < -1n || 1n <= x) {}", options: ["always", { exceptRange: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, { code: "if (1 < a && a <= 2) {}", @@ -291,7 +291,7 @@ ruleTester.run("yoda", rule, { { code: "if (0 <= obj?.a && obj?.a < 1) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 } }, // onlyEquality @@ -310,12 +310,12 @@ ruleTester.run("yoda", rule, { { code: "if (x !== `foo` && `foo` !== x) {}", options: ["never", { onlyEquality: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } }, { code: "if (x < `2` && x !== `-3`) {}", options: ["always", { onlyEquality: true }], - parserOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 } } ], invalid: [ @@ -371,14 +371,14 @@ ruleTester.run("yoda", rule, { code: "if (5n != value) {}", output: "if (value != 5n) {}", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "!=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: "if (null !== value) {}", @@ -408,40 +408,40 @@ ruleTester.run("yoda", rule, { code: "if (`red` <= value) {}", output: "if (value >= `red`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`red` <= `${foo}`) {}", output: "if (`${foo}` >= `red`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: 'if (`red` <= `${"red"}`) {}', output: 'if (`${"red"}` >= `red`) {}', options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (true >= value) {}", @@ -507,14 +507,14 @@ ruleTester.run("yoda", rule, { code: "if (value == `red`) {}", output: "if (`red` == value) {}", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "==" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (value === true) {}", @@ -532,27 +532,27 @@ ruleTester.run("yoda", rule, { code: "if (value === 5n) {}", output: "if (5n === value) {}", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "===" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2020 } }, { code: 'if (`${"red"}` <= `red`) {}', output: 'if (`red` >= `${"red"}`) {}', options: ["always"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (a < 0 && 0 <= b && b < 1) {}", @@ -642,27 +642,27 @@ ruleTester.run("yoda", rule, { code: "var a = (b < `0` && `0` <= b);", output: "var a = (`0` > b && `0` <= b);", options: ["always", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`green` < x.y && x.y < `blue`) {}", output: "if (x.y > `green` && x.y < `blue`) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 <= a[b] && a['b'] < 1) {}", @@ -680,27 +680,27 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a[b] && a[`b`] < 1) {}", output: "if (a[b] >= 0 && a[`b`] < 1) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (`0` <= a[b] && a[`b`] < `1`) {}", output: "if (a[b] >= `0` && a[`b`] < `1`) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 <= a[b] && a.b < 1) {}", @@ -754,14 +754,14 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a[``] && a[null] < 1) {}", output: "if (a[``] >= 0 && a[null] < 1) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 <= a[''] && a[b] < 1) {}", @@ -791,14 +791,14 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a[``] && a[b()] < 1) {}", output: "if (a[``] >= 0 && a[b()] < 1) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 <= a[b()] && a[b()] < 1) {}", @@ -816,14 +816,14 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a.null && a[/(?0)/] <= 1) {}", output: "if (a.null >= 0 && a[/(?0)/] <= 1) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2018 } }, { code: "if (3 == a) {}", @@ -865,14 +865,14 @@ ruleTester.run("yoda", rule, { code: "foo(a === `3`);", output: "foo(`3` === a);", options: ["always", { onlyEquality: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "===" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if (0 <= x && x < 1) {}", @@ -1001,79 +1001,79 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield(1) < a }", output: "function *foo() { yield a > (1) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield((1)) < a }", output: "function *foo() { yield a > ((1)) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield 1 < a }", output: "function *foo() { yield a > 1 }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield/**/1 < a }", output: "function *foo() { yield/**/a > 1 }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield(1) < ++a }", output: "function *foo() { yield++a > (1) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield(1) < (a) }", output: "function *foo() { yield(a) > (1) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "x=1 < a", @@ -1091,66 +1091,66 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield++a < 1 }", output: "function *foo() { yield 1 > ++a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield(a) < 1 }", output: "function *foo() { yield 1 > (a) }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield a < 1 }", output: "function *foo() { yield 1 > a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield/**/a < 1 }", output: "function *foo() { yield/**/1 > a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "function *foo() { yield++a < (1) }", output: "function *foo() { yield(1) > ++a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "x=a < 1", @@ -1312,14 +1312,14 @@ ruleTester.run("yoda", rule, { code: "if (`green` < x.y && x.y < `blue`) {}", output: "if (`green` < x.y && `blue` > x.y) {}", options: ["always", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ] + ], + languageOptions: { ecmaVersion: 2015 } }, { code: "if('a' <= x && x < 'b') {}", From ca35f9211cc66f06098975dfa6cc1b67eaa30341 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 6 Dec 2023 11:09:03 -0500 Subject: [PATCH 2/4] Fix ast-utils --- tests/lib/rules/utils/ast-utils.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/lib/rules/utils/ast-utils.js b/tests/lib/rules/utils/ast-utils.js index 7be295d22d8..bc03c7e47cd 100644 --- a/tests/lib/rules/utils/ast-utils.js +++ b/tests/lib/rules/utils/ast-utils.js @@ -145,7 +145,7 @@ describe("ast-utils", () => { })) }); - linter.verify("const a = 1; a = 2;", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); + linter.verify("const a = 1; a = 2;", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); }); it("should return false if reference is not assigned for const", () => { @@ -159,7 +159,7 @@ describe("ast-utils", () => { })) }); - linter.verify("const a = 1; c = 2;", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); + linter.verify("const a = 1; c = 2;", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); }); // class @@ -175,7 +175,7 @@ describe("ast-utils", () => { })) }); - linter.verify("class A { }\n A = 1;", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); + linter.verify("class A { }\n A = 1;", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); }); it("should return false if reference is not assigned for class", () => { @@ -189,7 +189,7 @@ describe("ast-utils", () => { })) }); - linter.verify("class A { } foo(A);", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); + linter.verify("class A { } foo(A);", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); }); }); @@ -393,7 +393,7 @@ describe("ast-utils", () => { }) })) }); - linter.verify(code, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 6 } }); + linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 6 } }); assert.lengthOf(results, 1); assert.strictEqual(results[0], expectedInLoop); @@ -924,7 +924,7 @@ describe("ast-utils", () => { })) }); - linter.verify(key, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 13 } }); + linter.verify(key, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 13 } }); }); }); }); @@ -1004,7 +1004,7 @@ describe("ast-utils", () => { })) }); - linter.verify(key, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 13 } }, "test.js", true); + linter.verify(key, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 13 } }, "test.js", true); }); }); }); @@ -1819,7 +1819,7 @@ describe("ast-utils", () => { })) }); - linter.verify("var foo = () => \"use strict\";", { rules: { checker: "error" }, languageOptions: { ecmaVersion: 2022 } }); + linter.verify("var foo = () => \"use strict\";", { rules: { checker: "error" }, parserOptions: { ecmaVersion: 2022 } }); }); const expectedResults = [ @@ -1853,7 +1853,7 @@ describe("ast-utils", () => { }) }); - linter.verify(code, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 2022 } }); + linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 2022 } }); }); }); }); @@ -1916,7 +1916,7 @@ describe("ast-utils", () => { }) }); - linter.verify(code, { rules: { checker: "error" }, languageOptions: { ecmaVersion: 2022 } }); + linter.verify(code, { rules: { checker: "error" }, parserOptions: { ecmaVersion: 2022 } }); }); }); }); From acb2c9537544d4154827d295bb3d51fd82c0c5f5 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Tue, 12 Dec 2023 11:02:24 -0500 Subject: [PATCH 3/4] Fix no-useless-return --- eslint.config.js | 13 ++++++++++++- tests/lib/rules/no-useless-return.js | 25 +++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 40ebe8c08f7..676fc87f226 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -135,7 +135,18 @@ module.exports = [ files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"], ...merge({}, eslintPluginTestsRecommendedConfig, { rules: { - "eslint-plugin/test-case-property-ordering": "error", + "eslint-plugin/test-case-property-ordering": [ + "error", + [ + "name", + "filename", + "code", + "output", + "options", + "languageOptions", + "errors" + ] + ], "eslint-plugin/test-case-shorthand-strings": "error" } }) diff --git a/tests/lib/rules/no-useless-return.js b/tests/lib/rules/no-useless-return.js index 5b090dbb365..c7907e3adf2 100644 --- a/tests/lib/rules/no-useless-return.js +++ b/tests/lib/rules/no-useless-return.js @@ -9,14 +9,19 @@ //------------------------------------------------------------------------------ const rule = require("../../../lib/rules/no-useless-return"), - { RuleTester } = require("../../../lib/rule-tester"); + RuleTester = require("../../../lib/rule-tester/flat-rule-tester"); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } +}); ruleTester.run("no-useless-return", rule, { valid: [ @@ -127,23 +132,23 @@ ruleTester.run("no-useless-return", rule, { for (var foo of bar) return; } `, - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => { if (foo) return; bar(); }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => 5", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "() => { return; doSomething(); }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "if (foo) { return; } doSomething();", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, // https://github.com/eslint/eslint/issues/7477 @@ -239,12 +244,12 @@ ruleTester.run("no-useless-return", rule, { { code: "foo(); return;", output: "foo(); ", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: "if (foo) { bar(); return; } else { baz(); }", output: "if (foo) { bar(); } else { baz(); }", - parserOptions: { ecmaFeatures: { globalReturn: true } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } }, { code: ` @@ -573,7 +578,7 @@ ruleTester.run("no-useless-return", rule, { { code: "() => { return; }", output: "() => { }", - parserOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 } }, { code: "function foo() { return; return; }", From 5d10e642dfb86a6eaed9dd6685bd4853a3d14522 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Tue, 12 Dec 2023 11:16:18 -0500 Subject: [PATCH 4/4] Fix test case ordering --- tests/lib/rules/accessor-pairs.js | 512 ++++++------ tests/lib/rules/array-bracket-newline.js | 60 +- tests/lib/rules/array-bracket-spacing.js | 64 +- tests/lib/rules/array-callback-return.js | 138 ++-- tests/lib/rules/array-element-newline.js | 28 +- tests/lib/rules/block-scoped-var.js | 20 +- tests/lib/rules/block-spacing.js | 84 +- tests/lib/rules/brace-style.js | 68 +- tests/lib/rules/callback-return.js | 24 +- tests/lib/rules/camelcase.js | 296 +++---- tests/lib/rules/class-methods-use-this.js | 88 +-- tests/lib/rules/comma-dangle.js | 368 ++++----- tests/lib/rules/comma-spacing.js | 16 +- tests/lib/rules/comma-style.js | 60 +- tests/lib/rules/complexity.js | 190 ++--- tests/lib/rules/computed-property-spacing.js | 160 ++-- tests/lib/rules/consistent-return.js | 36 +- tests/lib/rules/curly.js | 72 +- tests/lib/rules/dot-location.js | 40 +- tests/lib/rules/dot-notation.js | 36 +- tests/lib/rules/func-call-spacing.js | 56 +- tests/lib/rules/func-name-matching.js | 152 ++-- tests/lib/rules/func-names.js | 148 ++-- tests/lib/rules/func-style.js | 8 +- .../rules/function-call-argument-newline.js | 36 +- tests/lib/rules/function-paren-newline.js | 108 +-- tests/lib/rules/getter-return.js | 20 +- tests/lib/rules/grouped-accessor-pairs.js | 4 +- tests/lib/rules/handle-callback-err.js | 2 +- tests/lib/rules/id-blacklist.js | 248 +++--- tests/lib/rules/id-denylist.js | 256 +++--- tests/lib/rules/id-length.js | 286 +++---- tests/lib/rules/id-match.js | 128 +-- tests/lib/rules/implicit-arrow-linebreak.js | 12 +- tests/lib/rules/indent-legacy.js | 64 +- tests/lib/rules/indent.js | 232 +++--- tests/lib/rules/init-declarations.js | 56 +- tests/lib/rules/key-spacing.js | 76 +- tests/lib/rules/keyword-spacing.js | 740 +++++++++--------- tests/lib/rules/lines-around-comment.js | 112 +-- tests/lib/rules/lines-around-directive.js | 112 +-- .../lib/rules/logical-assignment-operators.js | 32 +- tests/lib/rules/max-depth.js | 20 +- tests/lib/rules/max-len.js | 88 +-- tests/lib/rules/max-nested-callbacks.js | 8 +- tests/lib/rules/max-params.js | 4 +- tests/lib/rules/max-statements-per-line.js | 20 +- tests/lib/rules/max-statements.js | 28 +- tests/lib/rules/new-cap.js | 24 +- tests/lib/rules/newline-after-var.js | 10 +- tests/lib/rules/newline-before-return.js | 12 +- tests/lib/rules/newline-per-chained-call.js | 24 +- tests/lib/rules/no-alert.js | 20 +- tests/lib/rules/no-case-declarations.js | 36 +- tests/lib/rules/no-console.js | 36 +- .../rules/no-constant-binary-expression.js | 4 +- tests/lib/rules/no-constant-condition.js | 18 +- tests/lib/rules/no-control-regex.js | 32 +- tests/lib/rules/no-dupe-class-members.js | 4 +- tests/lib/rules/no-dupe-keys.js | 20 +- tests/lib/rules/no-else-return.js | 208 ++--- tests/lib/rules/no-empty-character-class.js | 20 +- tests/lib/rules/no-empty-pattern.js | 76 +- tests/lib/rules/no-eval.js | 68 +- tests/lib/rules/no-ex-assign.js | 6 +- tests/lib/rules/no-extend-native.js | 44 +- tests/lib/rules/no-extra-bind.js | 36 +- tests/lib/rules/no-extra-boolean-cast.js | 92 +-- tests/lib/rules/no-extra-label.js | 4 +- tests/lib/rules/no-extra-parens.js | 64 +- tests/lib/rules/no-extra-semi.js | 52 +- tests/lib/rules/no-floating-decimal.js | 4 +- tests/lib/rules/no-func-assign.js | 16 +- tests/lib/rules/no-global-assign.js | 16 +- tests/lib/rules/no-implicit-coercion.js | 48 +- tests/lib/rules/no-implicit-globals.js | 228 +++--- tests/lib/rules/no-implied-eval.js | 80 +- tests/lib/rules/no-import-assign.js | 12 +- tests/lib/rules/no-inner-declarations.js | 20 +- tests/lib/rules/no-irregular-whitespace.js | 260 +++--- tests/lib/rules/no-iterator.js | 8 +- tests/lib/rules/no-lone-blocks.js | 68 +- tests/lib/rules/no-lonely-if.js | 4 +- tests/lib/rules/no-loop-func.js | 64 +- tests/lib/rules/no-loss-of-precision.js | 92 +-- tests/lib/rules/no-magic-numbers.js | 156 ++-- .../rules/no-misleading-character-class.js | 78 +- tests/lib/rules/no-mixed-operators.js | 4 +- tests/lib/rules/no-mixed-spaces-and-tabs.js | 8 +- tests/lib/rules/no-multi-assign.js | 28 +- tests/lib/rules/no-multi-spaces.js | 4 +- tests/lib/rules/no-multiple-empty-lines.js | 8 +- tests/lib/rules/no-native-reassign.js | 14 +- tests/lib/rules/no-new-func.js | 12 +- tests/lib/rules/no-new-object.js | 4 +- tests/lib/rules/no-new-wrappers.js | 4 +- tests/lib/rules/no-obj-calls.js | 132 ++-- tests/lib/rules/no-param-reassign.js | 96 +-- tests/lib/rules/no-promise-executor-return.js | 8 +- tests/lib/rules/no-proto.js | 4 +- tests/lib/rules/no-prototype-builtins.js | 48 +- tests/lib/rules/no-redeclare.js | 66 +- tests/lib/rules/no-regex-spaces.js | 12 +- tests/lib/rules/no-restricted-globals.js | 64 +- tests/lib/rules/no-restricted-modules.js | 8 +- tests/lib/rules/no-restricted-properties.js | 52 +- tests/lib/rules/no-restricted-syntax.js | 20 +- tests/lib/rules/no-return-assign.js | 12 +- tests/lib/rules/no-script-url.js | 8 +- tests/lib/rules/no-self-assign.js | 74 +- tests/lib/rules/no-self-compare.js | 4 +- tests/lib/rules/no-sequences.js | 4 +- tests/lib/rules/no-setter-return.js | 28 +- tests/lib/rules/no-shadow-restricted-names.js | 12 +- tests/lib/rules/no-shadow.js | 238 +++--- tests/lib/rules/no-this-before-super.js | 12 +- tests/lib/rules/no-throw-literal.js | 8 +- tests/lib/rules/no-trailing-spaces.js | 20 +- tests/lib/rules/no-undef-init.js | 68 +- tests/lib/rules/no-undef.js | 80 +- tests/lib/rules/no-undefined.js | 16 +- tests/lib/rules/no-underscore-dangle.js | 104 +-- tests/lib/rules/no-unexpected-multiline.js | 28 +- tests/lib/rules/no-unneeded-ternary.js | 56 +- tests/lib/rules/no-unreachable.js | 60 +- .../lib/rules/no-unsafe-optional-chaining.js | 16 +- tests/lib/rules/no-unused-expressions.js | 50 +- tests/lib/rules/no-unused-labels.js | 4 +- tests/lib/rules/no-unused-vars.js | 264 +++---- tests/lib/rules/no-use-before-define.js | 392 +++++----- tests/lib/rules/no-useless-call.js | 40 +- tests/lib/rules/no-useless-catch.js | 4 +- tests/lib/rules/no-useless-computed-key.js | 32 +- tests/lib/rules/no-useless-concat.js | 12 +- tests/lib/rules/no-useless-escape.js | 200 ++--- tests/lib/rules/no-useless-rename.js | 40 +- tests/lib/rules/no-var.js | 152 ++-- .../rules/no-whitespace-before-property.js | 60 +- tests/lib/rules/object-curly-newline.js | 72 +- tests/lib/rules/object-curly-spacing.js | 152 ++-- tests/lib/rules/object-property-newline.js | 64 +- tests/lib/rules/object-shorthand.js | 64 +- .../lib/rules/one-var-declaration-per-line.js | 10 +- tests/lib/rules/one-var.js | 220 +++--- tests/lib/rules/operator-linebreak.js | 52 +- tests/lib/rules/padded-blocks.js | 100 +-- .../rules/padding-line-between-statements.js | 112 +-- tests/lib/rules/prefer-const.js | 92 +-- .../rules/prefer-exponentiation-operator.js | 32 +- tests/lib/rules/prefer-named-capture-group.js | 12 +- tests/lib/rules/prefer-numeric-literals.js | 24 +- tests/lib/rules/prefer-object-spread.js | 40 +- tests/lib/rules/prefer-regex-literals.js | 476 +++++------ tests/lib/rules/quote-props.js | 32 +- tests/lib/rules/quotes.js | 184 ++--- tests/lib/rules/radix.js | 24 +- tests/lib/rules/require-atomic-updates.js | 4 +- tests/lib/rules/require-jsdoc.js | 32 +- tests/lib/rules/require-unicode-regexp.js | 12 +- tests/lib/rules/rest-spread-spacing.js | 72 +- tests/lib/rules/semi-spacing.js | 48 +- tests/lib/rules/semi-style.js | 24 +- tests/lib/rules/semi.js | 296 +++---- tests/lib/rules/sort-keys.js | 96 +-- tests/lib/rules/sort-vars.js | 24 +- tests/lib/rules/space-before-blocks.js | 68 +- .../lib/rules/space-before-function-paren.js | 52 +- tests/lib/rules/space-in-parens.js | 8 +- tests/lib/rules/space-infix-ops.js | 54 +- tests/lib/rules/space-unary-ops.js | 40 +- tests/lib/rules/strict.js | 184 ++--- tests/lib/rules/use-isnan.js | 28 +- tests/lib/rules/valid-jsdoc.js | 72 +- tests/lib/rules/valid-typeof.js | 12 +- tests/lib/rules/vars-on-top.js | 44 +- tests/lib/rules/wrap-iife.js | 24 +- tests/lib/rules/yoda.js | 108 +-- 177 files changed, 6619 insertions(+), 6619 deletions(-) diff --git a/tests/lib/rules/accessor-pairs.js b/tests/lib/rules/accessor-pairs.js index 556dba7af2e..f9154fd1b63 100644 --- a/tests/lib/rules/accessor-pairs.js +++ b/tests/lib/rules/accessor-pairs.js @@ -668,38 +668,38 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get ['abc']() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }] }, { code: "var o = { get [`abc`]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter 'abc'.", type: "Property" }] }, { code: "var o = { get [123]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter '123'.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter '123'.", type: "Property" }] }, { code: "var o = { get [abc]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter.", type: "Property" }] }, { code: "var o = { get [f(abc)]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter.", type: "Property" }] }, { code: "var o = { get [a + b]() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter.", type: "Property" }] }, // Various kinds of the setter's key @@ -726,38 +726,38 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { set ['abc'](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }] }, { code: "var o = { set [`abc`](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter 'abc'.", type: "Property" }] }, { code: "var o = { set [123](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter '123'.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter '123'.", type: "Property" }] }, { code: "var o = { set [abc](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter.", type: "Property" }] }, { code: "var o = { set [f(abc)](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter.", type: "Property" }] }, { code: "var o = { set [a + b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter.", type: "Property" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter.", type: "Property" }] }, // Different keys @@ -828,56 +828,56 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get [`a`]() {}, set b(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }, { message: "Getter is not present for setter 'b'.", type: "Property", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var o = { get [a]() {}, set [b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 25 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var o = { get [a]() {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter 'a'.", type: "Property", column: 25 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var o = { get a() {}, set [a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 23 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var o = { get [a + b]() {}, set [a - b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 29 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var o = { get [`${0} `]() {}, set [`${0}`](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter.", type: "Property", column: 11 }, { message: "Getter is not present for setter.", type: "Property", column: 31 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Multiple invalid of same and different kinds @@ -970,79 +970,79 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get a() {}, get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }, { message: "Setter is not present for getter 'a'.", type: "Property", column: 23 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var o = { set a(foo) {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }, { message: "Getter is not present for setter 'a'.", type: "Property", column: 26 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Other elements or even value property duplicates in the same literal do not affect this rule { code: "var o = { a, get b() {}, c };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter 'b'.", type: "Property", column: 14 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter 'b'.", type: "Property", column: 14 }] }, { code: "var o = { a, get b() {}, c, set d(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'b'.", type: "Property", column: 14 }, { message: "Getter is not present for setter 'd'.", type: "Property", column: 29 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var o = { get a() {}, a:1 };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }] }, { code: "var o = { a, get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 14 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 14 }] }, { code: "var o = { set a(foo) {}, a:1 };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }] }, { code: "var o = { a, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 14 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 14 }] }, { code: "var o = { get a() {}, ...b };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }] }, { code: "var o = { get a() {}, ...a };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [{ message: "Setter is not present for getter 'a'.", type: "Property", column: 11 }] }, { code: "var o = { set a(foo) {}, ...a };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }] }, // Full location tests @@ -1061,6 +1061,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = {\n set [\n a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: "Getter is not present for setter.", type: "Property", @@ -1068,8 +1069,7 @@ ruleTester.run("accessor-pairs", rule, { column: 3, endLine: 3, endColumn: 4 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, //------------------------------------------------------------------------------ @@ -1094,43 +1094,43 @@ ruleTester.run("accessor-pairs", rule, { }, { code: "var o = {d: 1};\n Object?.defineProperty(o, 'c', \n{set: function(value) {\n val = value; \n} \n});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "Reflect?.defineProperty(obj, 'foo', {set: function(value) {}});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "Object?.defineProperties(obj, {foo: {set: function(value) {}}});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "Object?.create(null, {foo: {set: function(value) {}}});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "var o = {d: 1};\n (Object?.defineProperty)(o, 'c', \n{set: function(value) {\n val = value; \n} \n});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "(Reflect?.defineProperty)(obj, 'foo', {set: function(value) {}});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "(Object?.defineProperties)(obj, {foo: {set: function(value) {}}});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "(Object?.create)(null, {foo: {set: function(value) {}}});", - errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, //------------------------------------------------------------------------------ @@ -1140,673 +1140,674 @@ ruleTester.run("accessor-pairs", rule, { // Test default settings { code: "class A { set a(foo) {} }", - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] }, { code: "class A { get a() {} set b(foo) {} }", options: [{}], - errors: [{ message: "Getter is not present for class setter 'b'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'b'.", type: "MethodDefinition" }] }, { code: "class A { get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] }, { code: "class A { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] }, { code: "class A { static get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }] }, { code: "class A { static set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] }, { code: "A = class { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] }, { code: "A = class { get a() {} set b(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { set a(value) {} }", options: [{ enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] }, { code: "class A { static set a(value) {} }", options: [{ enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] }, { code: "A = class { set a(value) {} };", options: [{ enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] }, { code: "(class A { static set a(value) {} });", options: [{ enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] }, { code: "class A { set '#a'(foo) {} }", - errors: [{ message: "Getter is not present for class setter '#a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Getter is not present for class setter '#a'.", type: "MethodDefinition" }] }, { code: "class A { set #a(foo) {} }", - errors: [{ message: "Getter is not present for class private setter #a.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Getter is not present for class private setter #a.", type: "MethodDefinition" }] }, { code: "class A { static set '#a'(foo) {} }", - errors: [{ message: "Getter is not present for class static setter '#a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Getter is not present for class static setter '#a'.", type: "MethodDefinition" }] }, { code: "class A { static set #a(foo) {} }", - errors: [{ message: "Getter is not present for class static private setter #a.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Getter is not present for class static private setter #a.", type: "MethodDefinition" }] }, // Test that the accessor kind options do not affect each other { code: "class A { set a(value) {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition" }] }, { code: "A = class { static set a(value) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] }, { code: "let foo = class A { get a() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] }, { code: "class A { static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition" }] }, { code: "(class { get a() {} });", options: [{ getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition" }] }, { code: "class A { get '#a'() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter '#a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Setter is not present for class getter '#a'.", type: "MethodDefinition" }] }, { code: "class A { get #a() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class private getter #a.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Setter is not present for class private getter #a.", type: "MethodDefinition" }] }, { code: "class A { static get '#a'() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static getter '#a'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Setter is not present for class static getter '#a'.", type: "MethodDefinition" }] }, { code: "class A { static get #a() {} };", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static private getter #a.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 13 } + languageOptions: { ecmaVersion: 13 }, + errors: [{ message: "Setter is not present for class static private getter #a.", type: "MethodDefinition" }] }, // Various kinds of keys { code: "class A { get abc() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }] }, { code: "A = class { static set 'abc'(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class static setter 'abc'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class static setter 'abc'.", type: "MethodDefinition" }] }, { code: "(class { get 123() {} });", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter '123'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter '123'.", type: "MethodDefinition" }] }, { code: "class A { static get 1e2() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static getter '100'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class static getter '100'.", type: "MethodDefinition" }] }, { code: "A = class { get ['abc']() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'abc'.", type: "MethodDefinition" }] }, { code: "class A { set [`abc`](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class setter 'abc'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'abc'.", type: "MethodDefinition" }] }, { code: "class A { static get [123]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static getter '123'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class static getter '123'.", type: "MethodDefinition" }] }, { code: "class A { get [abc]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter.", type: "MethodDefinition" }] }, { code: "class A { static get [f(abc)]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static getter.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class static getter.", type: "MethodDefinition" }] }, { code: "A = class { set [a + b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class setter.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter.", type: "MethodDefinition" }] }, { code: "class A { get ['constructor']() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter 'constructor'.", type: "MethodDefinition" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'constructor'.", type: "MethodDefinition" }] }, // Different keys { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { set a(foo) {} get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { static get a() {} static set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class static setter 'b'.", type: "MethodDefinition", column: 31 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get 'a '() {} set 'a'(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a '.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 25 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get 'a'() {} set 1(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter '1'.", type: "MethodDefinition", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get 1() {} set 2(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter '1'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter '2'.", type: "MethodDefinition", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get ''() {} set null(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter ''.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'null'.", type: "MethodDefinition", column: 23 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get a() {} set [a](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get [a]() {} set [b](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get [a]() {} set [a++](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get [a + b]() {} set [a - b](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 28 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get #a() {} set '#a'(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 13 }, errors: [ { message: "Setter is not present for class private getter #a.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter '#a'.", type: "MethodDefinition", column: 23 } - ], - languageOptions: { ecmaVersion: 13 } + ] }, { code: "class A { get '#a'() {} set #a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 13 }, errors: [ { message: "Setter is not present for class getter '#a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class private setter #a.", type: "MethodDefinition", column: 25 } - ], - languageOptions: { ecmaVersion: 13 } + ] }, // Prototype and static accessors with same keys { code: "class A { get a() {} static set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { static get a() {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 31 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { set [a](foo) {} static get [a]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class static getter.", type: "MethodDefinition", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { static set [a](foo) {} get [a]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 34 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Multiple invalid of same and different kinds { code: "class A { get a() {} get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { get a() {} get [b]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get [a]() {} get [b]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { set a(foo) {} set b(bar) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { static get a() {} static get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class static getter 'b'.", type: "MethodDefinition", column: 29 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { static set a(foo) {} static set b(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class static setter 'b'.", type: "MethodDefinition", column: 34 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { static get a() {} set b(foo) {} static set c(bar) {} get d() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 29 }, { message: "Getter is not present for class static setter 'c'.", type: "MethodDefinition", column: 43 }, { message: "Setter is not present for class getter 'd'.", type: "MethodDefinition", column: 64 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Checks per class { code: "class A { get a() {} } class B { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 34 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { set a(foo) {} }, class { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 38 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { get a() {} }, { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for setter 'a'.", type: "Property", column: 29 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = { get a() {} }, class { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for getter 'a'.", type: "Property", column: 7 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 29 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Combinations or valid and invalid { code: "class A { get a() {} get b() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }] }, { code: "A = class { get b() {} get a() {} set b(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 24 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 24 }] }, { code: "class A { set b(foo) {} get b() {} set a(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 36 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 36 }] }, { code: "A = class { static get b() {} set a(foo) {} static set b(bar) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 31 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 31 }] }, { code: "class A { static set a(foo) {} get b() {} set b(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 11 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 11 }] }, { code: "class A { get b() {} static get a() {} set b(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 22 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 22 }] }, { code: "class A { static set b(foo) {} static get a() {} static get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 32 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 32 }] }, { code: "class A { get [v1](){} static set i1(foo){} static set v2(bar){} get [i2](){} static get i3(){} set [v1](baz){} static get v2(){} set i4(quux){} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'i1'.", type: "MethodDefinition", column: 24 }, { message: "Setter is not present for class getter.", type: "MethodDefinition", column: 66 }, { message: "Setter is not present for class static getter 'i3'.", type: "MethodDefinition", column: 79 }, { message: "Getter is not present for class setter 'i4'.", type: "MethodDefinition", column: 131 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // In the case of duplicates which don't have the other kind, all nodes are reported { code: "class A { get a() {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { set a(foo) {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { static get a() {} static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 13 }, { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 31 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { set a(foo) {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 11 }, { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 25 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Other elements or even method duplicates in the same class do not affect this rule { code: "class A { a() {} get b() {} c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { a() {} get b() {} c() {} set d(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 20 }, { message: "Getter is not present for class setter 'd'.", type: "MethodDefinition", column: 38 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { static a() {} get b() {} static c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 25 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { a() {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { static a() {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { a() {} static get b() {} c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'b'.", type: "MethodDefinition", column: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { static a() {} static set b(foo) {} static c() {} d() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'b'.", type: "MethodDefinition", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { a() {} static get a() {} a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { static set a(foo) {} static a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Full location tests { code: "class A { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", @@ -1814,12 +1815,12 @@ ruleTester.run("accessor-pairs", rule, { column: 11, endLine: 1, endColumn: 16 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "A = class {\n set [\n a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Getter is not present for class setter.", type: "MethodDefinition", @@ -1827,12 +1828,12 @@ ruleTester.run("accessor-pairs", rule, { column: 3, endLine: 3, endColumn: 4 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class A { static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", @@ -1840,8 +1841,7 @@ ruleTester.run("accessor-pairs", rule, { column: 11, endLine: 1, endColumn: 23 - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/array-bracket-newline.js b/tests/lib/rules/array-bracket-newline.js index 7d02fbb354c..74f1ac3076c 100644 --- a/tests/lib/rules/array-bracket-newline.js +++ b/tests/lib/rules/array-bracket-newline.js @@ -1736,6 +1736,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [] = foo;", output: "var [\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1749,13 +1750,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 6 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a] = foo;", output: "var [\na\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1769,13 +1770,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 7 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [ // any comment\na] = foo;", output: "var [ // any comment\na\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1783,13 +1784,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [ /* any comment */\na] = foo;", output: "var [ /* any comment */\na\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1797,13 +1798,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a, b] = foo;", output: "var [\na, b\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1817,13 +1818,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a, b // any comment\n] = foo;", output: "var [\na, b // any comment\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1831,13 +1832,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 5 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a, b /* any comment */] = foo;", output: "var [\na, b /* any comment */\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1851,13 +1852,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 28 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a,\nb] = foo;", output: "var [\na,\nb\n] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1871,8 +1872,7 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // "consistent" @@ -1880,6 +1880,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [\na] = foo", output: "var [\na\n] = foo", options: ["consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1889,13 +1890,13 @@ ruleTester.run("array-bracket-newline", rule, { endLine: 2, endColumn: 3 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a\n] = foo", output: "var [a] = foo", options: ["consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedClosingLinebreak", @@ -1905,13 +1906,13 @@ ruleTester.run("array-bracket-newline", rule, { endLine: 2, endColumn: 2 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [//\na] = foo", output: "var [//\na\n] = foo", options: ["consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1921,8 +1922,7 @@ ruleTester.run("array-bracket-newline", rule, { endLine: 2, endColumn: 3 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // { minItems: 2 } @@ -1930,6 +1930,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [\n] = foo;", output: "var [] = foo;", options: [{ minItems: 2 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedOpeningLinebreak", @@ -1943,13 +1944,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [\na\n] = foo;", output: "var [a] = foo;", options: [{ minItems: 2 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedOpeningLinebreak", @@ -1963,13 +1964,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 3, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a, b] = foo;", output: "var [\na, b\n] = foo;", options: [{ minItems: 2 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1983,13 +1984,13 @@ ruleTester.run("array-bracket-newline", rule, { line: 1, column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a,\nb] = foo;", output: "var [\na,\nb\n] = foo;", options: [{ minItems: 2 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -2003,8 +2004,7 @@ ruleTester.run("array-bracket-newline", rule, { line: 2, column: 2 } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/array-bracket-spacing.js b/tests/lib/rules/array-bracket-spacing.js index 44027f1c80f..2120833114a 100644 --- a/tests/lib/rules/array-bracket-spacing.js +++ b/tests/lib/rules/array-bracket-spacing.js @@ -472,6 +472,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [x,y] = y", output: "var [ x,y ] = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -493,13 +494,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 9, endLine: 1, endColumn: 10 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [x,y ] = y", output: "var [ x,y ] = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -510,13 +511,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 5, endLine: 1, endColumn: 6 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [,,,x,,] = y", output: "var [ ,,,x,, ] = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -538,13 +539,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 12, endLine: 1, endColumn: 13 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [ ,,,x,,] = y", output: "var [ ,,,x,, ] = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceBefore", data: { @@ -555,13 +556,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 13, endLine: 1, endColumn: 14 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [...horse] = y", output: "var [ ...horse ] = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -583,13 +584,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 14, endLine: 1, endColumn: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [...horse ] = y", output: "var [ ...horse ] = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -600,13 +601,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 5, endLine: 1, endColumn: 6 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [ [ x, y ], z ] = arr;", output: "var [[ x, y ], z ] = arr;", options: ["always", { arraysInArrays: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceAfter", data: { @@ -617,13 +618,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 6, endLine: 1, endColumn: 7 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "[ { x, y }, z ] = arr;", output: "[{ x, y }, z ] = arr;", options: ["always", { objectsInArrays: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceAfter", data: { @@ -634,13 +635,13 @@ ruleTester.run("array-bracket-spacing", rule, { column: 2, endLine: 1, endColumn: 3 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "[ x, { y, z } ] = arr;", output: "[ x, { y, z }] = arr;", options: ["always", { objectsInArrays: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceBefore", data: { @@ -651,8 +652,7 @@ ruleTester.run("array-bracket-spacing", rule, { column: 14, endLine: 1, endColumn: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, // never - arraysInArrays @@ -921,6 +921,10 @@ ruleTester.run("array-bracket-spacing", rule, { code: "([ a, b ]: Array) => {}", output: "([a, b]: Array) => {}", options: ["never"], + languageOptions: { + ecmaVersion: 6, + parser: parser("flow-destructuring-1") + }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -944,16 +948,16 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 9 } - ], - languageOptions: { - ecmaVersion: 6, - parser: parser("flow-destructuring-1") - } + ] }, { code: "([a, b]: Array< any >) => {}", output: "([ a, b ]: Array< any >) => {}", options: ["always"], + languageOptions: { + parser: parser("flow-destructuring-2"), + ecmaVersion: 6 + }, errors: [ { messageId: "missingSpaceAfter", @@ -977,11 +981,7 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 8 } - ], - languageOptions: { - parser: parser("flow-destructuring-2"), - ecmaVersion: 6 - } + ] }, // multiple spaces @@ -1018,6 +1018,9 @@ ruleTester.run("array-bracket-spacing", rule, { code: "function f( [ a, b ] ) {}", output: "function f( [a, b] ) {}", options: ["never"], + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1041,10 +1044,7 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 23 } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, { code: "var arr = [ 1,\n 2 ];", diff --git a/tests/lib/rules/array-callback-return.js b/tests/lib/rules/array-callback-return.js index 1b649bc216e..6c78cb8025e 100644 --- a/tests/lib/rules/array-callback-return.js +++ b/tests/lib/rules/array-callback-return.js @@ -168,9 +168,9 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.bar.baz.every(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }] }, { code: "foo[\"every\"](function() {})", errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, { code: "foo[\"every\"](function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }] }, - { code: "foo[`every`](function() {})", errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "foo[`every`](function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "foo.every(() => {})", errors: [{ message: "Array.prototype.every() expects a return value from arrow function.", column: 14 }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo[`every`](function() {})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, + { code: "foo[`every`](function foo() {})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.every" } }] }, + { code: "foo.every(() => {})", languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expects a return value from arrow function.", column: 14 }] }, { code: "foo.every(function() { if (a) return true; })", errors: [{ message: "Array.prototype.every() expects a value to be returned at the end of function.", column: 11 }] }, { code: "foo.every(function cb() { if (a) return true; })", errors: [{ message: "Array.prototype.every() expects a value to be returned at the end of function 'cb'.", column: 11 }] }, { code: "foo.every(function() { switch (a) { case 0: break; default: return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, @@ -189,8 +189,8 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.every(a ? function foo() {} : function bar() {})", errors: ["Array.prototype.every() expects a return value from function 'foo'.", "Array.prototype.every() expects a return value from function 'bar'."] }, { code: "foo.every(function(){ return function() {}; }())", errors: [{ message: "Array.prototype.every() expects a return value from function.", column: 30 }] }, { code: "foo.every(function(){ return function foo() {}; }())", errors: [{ message: "Array.prototype.every() expects a return value from function 'foo'.", column: 30 }] }, - { code: "foo.every(() => {})", options: [{ allowImplicit: false }], errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }], languageOptions: { ecmaVersion: 6 } }, - { code: "foo.every(() => {})", options: [{ allowImplicit: true }], errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.every(() => {})", options: [{ allowImplicit: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }] }, + { code: "foo.every(() => {})", options: [{ allowImplicit: true }], languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Array.prototype.every() expects a return value from arrow function." }] }, // options: { allowImplicit: true } { code: "Array.from(x, function() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.from" } }] }, @@ -204,7 +204,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.every(cb || function() {})", options: allowImplicitOptions, errors: ["Array.prototype.every() expects a return value from function."] }, { code: "[\"foo\",\"bar\"].sort(function foo() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.sort" } }] }, { code: "[\"foo\",\"bar\"].toSorted(function foo() {})", options: allowImplicitOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.toSorted" } }] }, - { code: "foo.forEach(x => x)", options: allowImplicitCheckForEach, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach(x => x)", options: allowImplicitCheckForEach, languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "foo.forEach(function(x) { if (a == b) {return x;}})", options: allowImplicitCheckForEach, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "foo.forEach(function bar(x) { return x;})", options: allowImplicitCheckForEach, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function 'bar'", arrayMethodName: "Array.prototype.forEach" } }] }, @@ -212,62 +212,62 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(x => x)", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach(x => {x})", messageId: "wrapBraces" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach(x => (x))", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach(x => {(x)})", messageId: "wrapBraces" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach(val => y += val)", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach(val => {y += val})", messageId: "wrapBraces" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "[\"foo\",\"bar\"].forEach(x => ++x)", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "[\"foo\",\"bar\"].forEach(x => {++x})", messageId: "wrapBraces" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.bar().forEach(x => x === y)", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.bar().forEach(x => {x === y})", messageId: "wrapBraces" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach(function() {return function() { if (a == b) { return a; }}}())", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "foo.forEach(function(x) { if (a == b) {return x;}})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function", arrayMethodName: "Array.prototype.forEach" } }] }, @@ -276,22 +276,23 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(function bar(x) { return x;})", options: checkForEachOptions, errors: ["Array.prototype.forEach() expects no useless return value from function 'bar'."] }, { code: "foo.bar().forEach(function bar(x) { return x;})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function 'bar'", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "[\"foo\",\"bar\"].forEach(function bar(x) { return x;})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "function 'bar'", arrayMethodName: "Array.prototype.forEach" } }] }, - { code: "foo.forEach((x) => { return x;})", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => { return x;})", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, { code: "Array.from(x, function() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.from" } }] }, { code: "foo.every(function() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function", arrayMethodName: "Array.prototype.every" } }] }, { code: "foo.filter(function foo() {})", options: checkForEachOptions, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.filter" } }] }, { code: "foo.filter(function foo() { return; })", options: checkForEachOptions, errors: [{ messageId: "expectedReturnValue", data: { name: "function 'foo'", arrayMethodName: "Array.prototype.filter" } }] }, { code: "foo.every(cb || function() {})", options: checkForEachOptions, errors: ["Array.prototype.every() expects a return value from function."] }, - { code: "foo.forEach((x) => void x)", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach((x) => void bar(x))", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach((x) => { return void bar(x); })", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "foo.forEach((x) => { if (a === b) { return void a; } bar(x) })", options: checkForEachOptions, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "foo.forEach((x) => void x)", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { code: "foo.forEach((x) => void bar(x))", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { code: "foo.forEach((x) => { return void bar(x); })", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { code: "foo.forEach((x) => { if (a === b) { return void a; } bar(x) })", options: checkForEachOptions, languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, // options: { checkForEach: true, allowVoid: true } { code: "foo.forEach(x => x)", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -299,12 +300,12 @@ ruleTester.run("array-callback-return", rule, { { output: "foo.forEach(x => {x})", messageId: "wrapBraces" }, { output: "foo.forEach(x => void x)", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach(x => !x)", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -312,12 +313,12 @@ ruleTester.run("array-callback-return", rule, { { output: "foo.forEach(x => {!x})", messageId: "wrapBraces" }, { output: "foo.forEach(x => void !x)", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach(x => (x))", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -325,97 +326,97 @@ ruleTester.run("array-callback-return", rule, { { output: "foo.forEach(x => {(x)})", messageId: "wrapBraces" }, { output: "foo.forEach(x => void (x))", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((x) => { return x; })", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void x; })", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((x) => { return !x; })", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void !x; })", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((x) => { return(x); })", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void (x); })", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((x) => { return (x + 1); })", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { return void (x + 1); })", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((x) => { if (a === b) { return x; } })", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { if (a === b) { return void x; } })", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((x) => { if (a === b) { return !x; } })", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { if (a === b) { return void !x; } })", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((x) => { if (a === b) { return (x + a); } })", options: checkForEachAllowVoid, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, suggestions: [ { output: "foo.forEach((x) => { if (a === b) { return void (x + a); } })", messageId: "prependVoid" } ] - }], - languageOptions: { ecmaVersion: 6 } + }] }, // full location tests { code: "foo.filter(bar => { baz(); } )", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -424,11 +425,11 @@ ruleTester.run("array-callback-return", rule, { column: 16, endLine: 1, endColumn: 18 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.filter(\n() => {} )", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -437,11 +438,11 @@ ruleTester.run("array-callback-return", rule, { column: 4, endLine: 2, endColumn: 6 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.filter(bar || ((baz) => {}) )", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -450,11 +451,11 @@ ruleTester.run("array-callback-return", rule, { column: 26, endLine: 1, endColumn: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.filter(bar => { return; })", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -463,11 +464,11 @@ ruleTester.run("array-callback-return", rule, { column: 21, endLine: 1, endColumn: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "Array.from(foo, bar => { bar })", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" }, @@ -476,12 +477,12 @@ ruleTester.run("array-callback-return", rule, { column: 21, endLine: 1, endColumn: 23 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach(bar => bar)", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -490,12 +491,12 @@ ruleTester.run("array-callback-return", rule, { column: 17, endLine: 1, endColumn: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((function () { return (bar) => bar; })())", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -504,12 +505,12 @@ ruleTester.run("array-callback-return", rule, { column: 41, endLine: 1, endColumn: 43 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((() => {\n return bar => bar; })())", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -518,12 +519,12 @@ ruleTester.run("array-callback-return", rule, { column: 13, endLine: 2, endColumn: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.forEach((bar) => { if (bar) { return; } else { return bar ; } })", options: checkForEachOptions, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -532,8 +533,7 @@ ruleTester.run("array-callback-return", rule, { column: 52, endLine: 1, endColumn: 64 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.filter(function(){})", @@ -660,28 +660,28 @@ ruleTester.run("array-callback-return", rule, { // Optional chaining { code: "foo?.filter(() => { console.log('hello') })", - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] }, { code: "(foo?.filter)(() => { console.log('hello') })", - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] }, { code: "Array?.from([], () => { console.log('hello') })", - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }] }, { code: "(Array?.from)([], () => { console.log('hello') })", - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }] }, { code: "foo?.filter((function() { return () => { console.log('hello') } })?.())", - errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] } ] }); diff --git a/tests/lib/rules/array-element-newline.js b/tests/lib/rules/array-element-newline.js index 01221907a57..a66ac252499 100644 --- a/tests/lib/rules/array-element-newline.js +++ b/tests/lib/rules/array-element-newline.js @@ -859,19 +859,20 @@ ruleTester.run("array-element-newline", rule, { code: "var [a, b] = foo;", output: "var [a,\nb] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", line: 1, column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a, b, c] = foo;", output: "var [a,\nb,\nc] = foo;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -883,8 +884,7 @@ ruleTester.run("array-element-newline", rule, { line: 1, column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // { minItems: 3 } @@ -892,19 +892,20 @@ ruleTester.run("array-element-newline", rule, { code: "var [a,\nb] = foo;", output: "var [a, b] = foo;", options: [{ minItems: 3 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", line: 1, column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a, b, c] = foo;", output: "var [a,\nb,\nc] = foo;", options: [{ minItems: 3 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -916,8 +917,7 @@ ruleTester.run("array-element-newline", rule, { line: 1, column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, /* @@ -928,6 +928,7 @@ ruleTester.run("array-element-newline", rule, { code: "var [a,\nb] = [1, 2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -939,34 +940,33 @@ ruleTester.run("array-element-newline", rule, { line: 2, column: 9 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a, b] = [1, 2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", line: 1, column: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [a,\nb] = [1,\n2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", line: 1, column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] diff --git a/tests/lib/rules/block-scoped-var.js b/tests/lib/rules/block-scoped-var.js index 5ebaebd3616..4fd45661660 100644 --- a/tests/lib/rules/block-scoped-var.js +++ b/tests/lib/rules/block-scoped-var.js @@ -195,6 +195,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "function a() { for(var b of {}) { var c = b; } c; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -205,8 +206,7 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 48, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function f(){ switch(2) { case 1: var b = 2; b; break; default: b; break;} b; }", @@ -252,6 +252,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "for (var a of []) {} a;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -262,11 +263,11 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 22, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ var a = 0; } a;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "outOfScope", data: { @@ -277,8 +278,7 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 16, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "if (true) { var a; } a;", @@ -350,6 +350,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "class C { static { if (bar) { var foo; } foo; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "outOfScope", data: { @@ -360,8 +361,7 @@ ruleTester.run("block-scoped-var", rule, { line: 1, column: 42, type: "Identifier" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "{ var foo,\n bar; } bar;", @@ -379,6 +379,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "{ var { foo,\n bar } = baz; } bar;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -389,8 +390,7 @@ ruleTester.run("block-scoped-var", rule, { line: 2, column: 18, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "if (foo) { var a = 1; } else if (bar) { var a = 2; } else { var a = 3; }", diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index b89a4e0e70f..4ec40f87bec 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -181,11 +181,11 @@ ruleTester.run("block-spacing", rule, { { code: "for (var a of b) {foo();}", output: "for (var a of b) { foo(); }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", line: 1, column: 18, messageId: "missing", data: { location: "after", token: "{" } }, { type: "BlockStatement", line: 1, column: 25, messageId: "missing", data: { location: "before", token: "}" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "try {foo();} catch (e) {foo();} finally {foo();}", @@ -266,24 +266,25 @@ ruleTester.run("block-spacing", rule, { { code: "(() => {bar();});", output: "(() => { bar(); });", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }, { type: "BlockStatement", line: 1, column: 15, messageId: "missing", data: { location: "before", token: "}" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (a) {/* comment */ foo(); /* comment */}", output: "if (a) { /* comment */ foo(); /* comment */ }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }, { type: "BlockStatement", line: 1, column: 43, messageId: "missing", data: { location: "before", token: "}" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (a) {//comment\n foo(); }", output: "if (a) { //comment\n foo(); }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -297,14 +298,14 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 9 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // class static blocks { code: "class C { static {foo; } }", output: "class C { static { foo; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -318,12 +319,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 19 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { foo;} }", output: "class C { static { foo; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -337,12 +338,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 25 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static {foo;} }", output: "class C { static { foo; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -368,12 +369,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 24 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static {/* comment */} }", output: "class C { static { /* comment */ } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -399,12 +400,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 33 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static {/* comment 1 */ foo; /* comment 2 */} }", output: "class C { static { /* comment 1 */ foo; /* comment 2 */ } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -430,12 +431,12 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 56 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n static {foo()\nbar()} }", output: "class C {\n static { foo()\nbar() } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -461,8 +462,7 @@ ruleTester.run("block-spacing", rule, { endLine: 3, endColumn: 7 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, //---------------------------------------------------------------------- @@ -747,6 +747,7 @@ ruleTester.run("block-spacing", rule, { code: "for (var a of b) { foo(); }", output: "for (var a of b) {foo();}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -766,8 +767,7 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "try { foo(); } catch (e) { foo(); } finally { foo(); }", @@ -884,6 +884,7 @@ ruleTester.run("block-spacing", rule, { code: "(() => { bar(); });", output: "(() => {bar();});", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -903,8 +904,7 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (a) { /* comment */ foo(); /* comment */ }", @@ -935,6 +935,7 @@ ruleTester.run("block-spacing", rule, { code: "(() => { bar();});", output: "(() => {bar();});", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -945,13 +946,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "(() => {bar(); });", output: "(() => {bar();});", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -962,13 +963,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "(() => { bar(); });", output: "(() => {bar();});", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -988,8 +989,7 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 21 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // class static blocks @@ -997,6 +997,7 @@ ruleTester.run("block-spacing", rule, { code: "class C { static { foo;} }", output: "class C { static {foo;} }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1010,13 +1011,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 20 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static {foo; } }", output: "class C { static {foo;} }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1030,13 +1031,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 24 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { foo; } }", output: "class C { static {foo;} }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1062,13 +1063,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 25 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { /* comment */ } }", output: "class C { static {/* comment */} }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1094,13 +1095,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 34 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { /* comment 1 */ foo; /* comment 2 */ } }", output: "class C { static {/* comment 1 */ foo; /* comment 2 */} }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1126,13 +1127,13 @@ ruleTester.run("block-spacing", rule, { endLine: 1, endColumn: 57 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static\n{ foo()\nbar() } }", output: "class C { static\n{foo()\nbar()} }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1158,8 +1159,7 @@ ruleTester.run("block-spacing", rule, { endLine: 3, endColumn: 8 } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/brace-style.js b/tests/lib/rules/brace-style.js index f213820c3e9..e2b47c54705 100644 --- a/tests/lib/rules/brace-style.js +++ b/tests/lib/rules/brace-style.js @@ -335,8 +335,8 @@ ruleTester.run("brace-style", rule, { { code: "var foo = () => { return; }", output: "var foo = () => {\n return; \n}", - errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "function foo() { return; }", @@ -411,8 +411,8 @@ ruleTester.run("brace-style", rule, { { code: "for (foo of bar) \n { \n baz(); \n }", output: "for (foo of bar) { \n baz(); \n }", - errors: [{ messageId: "nextLineOpen", type: "Punctuator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "try { \n bar(); \n }\ncatch (e) {\n}", @@ -809,10 +809,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -829,10 +829,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -849,10 +849,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -869,12 +869,12 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -889,10 +889,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -911,10 +911,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -931,10 +931,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -951,10 +951,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -971,12 +971,12 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -991,10 +991,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1015,10 +1015,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1039,10 +1039,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1063,10 +1063,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1085,12 +1085,12 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1107,10 +1107,10 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/callback-return.js b/tests/lib/rules/callback-return.js index 34186a6ccd6..32d136e818d 100644 --- a/tests/lib/rules/callback-return.js +++ b/tests/lib/rules/callback-return.js @@ -191,23 +191,23 @@ ruleTester.run("callback-return", rule, { }, { code: "var x = (err) => { if (err) { callback (err); } }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 31, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var x = { x(err) { if (err) { callback (err); } } }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 31, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function x(err) { if (err) {\n log();\n callback(err); } }", @@ -220,13 +220,13 @@ ruleTester.run("callback-return", rule, { }, { code: "var x = { x(err) { if (err) { callback && callback (err); } } }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 43, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function a(err) { callback (err); callback(); }", @@ -257,13 +257,13 @@ ruleTester.run("callback-return", rule, { }, { code: "var a = (err) => { callback (err); callback(); }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 20, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function a(err) { if (err) { callback (err); } else if (x) { callback(err); return; } }", @@ -286,13 +286,13 @@ ruleTester.run("callback-return", rule, { }, { code: "class x { horse() { if (err) { callback(); } callback(); } } ", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, column: 32, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, @@ -324,6 +324,7 @@ ruleTester.run("callback-return", rule, { }, { code: "() => { if (x) { callback(); } }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -331,8 +332,7 @@ ruleTester.run("callback-return", rule, { column: 18, type: "CallExpression" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function b() { switch(x) { case 'horse': callback(); } }", diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index 2c56f09e43d..10bc1f61356 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -571,351 +571,352 @@ ruleTester.run("camelcase", rule, { }, { code: "var { category_id: category_alias } = query;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_alias" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { category_id: category_alias } = query;", options: [{ ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_alias" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { [category_id]: categoryId } = query;", options: [{ ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { [category_id]: categoryId } = query;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { category_id: categoryId, ...other_props } = query;", options: [{ ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "notCamelCase", data: { name: "other_props" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var { category_id } = query;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { category_id: category_id } = query;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { category_id = 1 } = query;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "category_id" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "import no_camelcased from \"external-module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import * as no_camelcased from \"external-module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { no_camelcased } from \"external-module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { no_camelcased as no_camel_cased } from \"external module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camel_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { camelCased as no_camel_cased } from \"external module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camel_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { 'snake_cased' as snake_cased } from 'mod'", + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + ] }, { code: "import { 'snake_cased' as another_snake_cased } from 'mod'", options: [{ ignoreImports: true }], + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "another_snake_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + ] }, { code: "import { camelCased, no_camelcased } from \"external-module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "another_no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import camelCased, { no_camelcased } from \"external-module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import snake_cased from 'mod'", options: [{ ignoreImports: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import * as snake_cased from 'mod'", options: [{ ignoreImports: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import snake_cased from 'mod'", options: [{ ignoreImports: false }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import * as snake_cased from 'mod'", options: [{ ignoreImports: false }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var camelCased = snake_cased", options: [{ ignoreGlobals: false }], + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "a_global_variable.foo()", options: [{ ignoreGlobals: false }], + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "a_global_variable[undefined]", options: [{ ignoreGlobals: false }], + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "var camelCased = snake_cased", + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "var camelCased = snake_cased", options: [{}], + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { globals: { snake_cased: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "foo.a_global_variable = bar", options: [{ ignoreGlobals: true }], + languageOptions: { globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "var foo = { a_global_variable: bar }", options: [{ ignoreGlobals: true }], + languageOptions: { globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "var foo = { a_global_variable: a_global_variable }", options: [{ ignoreGlobals: true }], + languageOptions: { globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -923,48 +924,48 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 13 } - ], - languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "var foo = { a_global_variable() {} }", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "class Foo { a_global_variable() {} }", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "a_global_variable: for (;;);", options: [{ ignoreGlobals: true }], + languageOptions: { globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "if (foo) { let a_global_variable; a_global_variable = bar; }", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -978,12 +979,12 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 35 } - ], - languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "function foo(a_global_variable) { foo = a_global_variable; }", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -997,36 +998,36 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 41 } - ], - languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "var a_global_variable", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function a_global_variable () {}", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const a_global_variable = foo; bar = a_global_variable", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1040,12 +1041,12 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 38 } - ], - languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "bar = a_global_variable; var a_global_variable;", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1059,20 +1060,19 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 30 } - ], - languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "var foo = { a_global_variable }", options: [{ ignoreGlobals: true }], + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "readonly" } } // eslint-disable-line camelcase -- Testing non-CamelCase + ] }, { code: "undefined_variable;", @@ -1098,39 +1098,40 @@ ruleTester.run("camelcase", rule, { }, { code: "export * as snake_cased from 'mod'", + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + ] }, { code: "function foo({ no_camelcased }) {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ no_camelcased = 'default value' }) {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1142,74 +1143,73 @@ ruleTester.run("camelcase", rule, { data: { name: "camelcased_value" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { bar: no_camelcased } = foo;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ value_1: my_default }) {}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "my_default" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ isCamelcased: no_camelcased }) {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { foo: bar_baz = 1 } = quz;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "bar_baz" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { no_camelcased = false } = bar;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { no_camelcased = foo_bar } = bar;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "not_ignored_foo = 0;", @@ -1236,205 +1236,205 @@ ruleTester.run("camelcase", rule, { { code: "foo = { [computed_bar]: 0 };", options: [{ ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "computed_bar" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ a: obj.fo_o } = bar);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ a: obj.fo_o } = bar);", options: [{ ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ a: obj.fo_o.b_ar } = baz);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "b_ar" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ a: { b: { c: obj.fo_o } } } = bar);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "b_ar" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "([obj.fo_o] = bar);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "([obj.fo_o] = bar);", options: [{ ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "([obj.fo_o = 1] = bar);", options: [{ properties: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ a: [obj.fo_o] } = bar);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ a: { b: [obj.fo_o] } } = bar);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "([obj.fo_o.ba_r] = baz);", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", data: { name: "ba_r" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({...obj.fo_o} = baz);", + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 9 } + ] }, { code: "({...obj.fo_o.ba_r} = baz);", + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", data: { name: "ba_r" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 9 } + ] }, { code: "({c: {...obj.fo_o }} = baz);", + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", data: { name: "fo_o" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 9 } + ] }, // Optional chaining. { code: "obj.o_k.non_camelcase = 0", options: [{ properties: "always" }], - errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }] }, { code: "(obj?.o_k).non_camelcase = 0", options: [{ properties: "always" }], - errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }] }, // class public/private fields, private methods. { code: "class C { snake_case; }", options: [{ properties: "always" }], - errors: [{ messageId: "notCamelCase", data: { name: "snake_case" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "notCamelCase", data: { name: "snake_case" } }] }, { code: "class C { #snake_case; foo() { this.#snake_case; } }", options: [{ properties: "always" }], - errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" }, column: 11 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" }, column: 11 }] }, { code: "class C { #snake_case() {} }", options: [{ properties: "always" }], - errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }] }, // Combinations of `properties` and `ignoreDestructuring` @@ -1444,6 +1444,7 @@ ruleTester.run("camelcase", rule, { doSomething({ some_property }); `, options: [{ properties: "always", ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1451,8 +1452,7 @@ ruleTester.run("camelcase", rule, { line: 3, column: 27 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: ` @@ -1461,6 +1461,7 @@ ruleTester.run("camelcase", rule, { doSomething({ [some_property]: "bar" }); `, options: [{ properties: "never", ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1468,8 +1469,7 @@ ruleTester.run("camelcase", rule, { line: 4, column: 28 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: ` @@ -1486,6 +1486,7 @@ ruleTester.run("camelcase", rule, { }; `, options: [{ properties: "always", ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1505,8 +1506,7 @@ ruleTester.run("camelcase", rule, { line: 8, column: 27 } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/class-methods-use-this.js b/tests/lib/rules/class-methods-use-this.js index 8ae661bef62..7d2619f6f4b 100644 --- a/tests/lib/rules/class-methods-use-this.js +++ b/tests/lib/rules/class-methods-use-this.js @@ -47,88 +47,89 @@ ruleTester.run("class-methods-use-this", rule, { invalid: [ { code: "class A { foo() {} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() {/**this**/} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() {var a = function () {this};} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() {var a = function () {var b = function(){this}};} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() {window.this} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() {that.this = 'this';} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() { () => undefined; } }", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() {} bar() {} }", options: [{ exceptMethods: ["bar"] }], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo() {} hasOwnProperty() {} }", options: [{ exceptMethods: ["foo"] }], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 20, messageId: "missingThis", data: { name: "method 'hasOwnProperty'" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { [foo]() {} }", options: [{ exceptMethods: ["foo"] }], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { #foo() { } foo() {} #bar() {} }", options: [{ exceptMethods: ["#foo"] }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "FunctionExpression", line: 1, column: 22, messageId: "missingThis", data: { name: "method 'foo'" } }, { type: "FunctionExpression", line: 1, column: 31, messageId: "missingThis", data: { name: "private method #bar" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { foo(){} 'bar'(){} 123(){} [`baz`](){} [a](){} [f(a)](){} get quux(){} set[a](b){} *quuux(){} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, type: "FunctionExpression", column: 11 }, { messageId: "missingThis", data: { name: "method 'bar'" }, type: "FunctionExpression", column: 19 }, @@ -139,78 +140,77 @@ ruleTester.run("class-methods-use-this", rule, { { messageId: "missingThis", data: { name: "getter 'quux'" }, type: "FunctionExpression", column: 68 }, { messageId: "missingThis", data: { name: "setter" }, type: "FunctionExpression", column: 81 }, { messageId: "missingThis", data: { name: "generator method 'quuux'" }, type: "FunctionExpression", column: 93 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { foo = function() {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 25 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { foo = () => {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 17 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { #foo = function() {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 26 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { #foo = () => {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 18 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { #foo() {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { get #foo() {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private getter #foo" }, column: 11, endColumn: 19 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { set #foo(x) {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private setter #foo" }, column: 11, endColumn: 19 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { foo () { return class { foo = this }; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { foo () { return function () { foo = this }; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class A { foo () { return class { static { this; } } } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/comma-dangle.js b/tests/lib/rules/comma-dangle.js index e0ab1a60f6b..d7917a8f516 100644 --- a/tests/lib/rules/comma-dangle.js +++ b/tests/lib/rules/comma-dangle.js @@ -1090,6 +1090,7 @@ ruleTester.run("comma-dangle", rule, { code: "var { a, b, } = foo;", output: "var { a, b } = foo;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1097,13 +1098,13 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a, b, } = foo;", output: "var { a, b } = foo;", options: ["only-multiline"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1111,13 +1112,13 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [ a, b, ] = foo;", output: "var [ a, b ] = foo;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1125,13 +1126,13 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [ a, b, ] = foo;", output: "var [ a, b ] = foo;", options: ["only-multiline"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1139,8 +1140,7 @@ ruleTester.run("comma-dangle", rule, { line: 1, column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "[(1),]", @@ -1200,92 +1200,92 @@ ruleTester.run("comma-dangle", rule, { code: "import {foo} from 'foo';", output: "import {foo,} from 'foo';", options: ["always"], - errors: [{ messageId: "missing", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "missing", type: "ImportSpecifier" }] }, { code: "import foo, {abc} from 'foo';", output: "import foo, {abc,} from 'foo';", options: ["always"], - errors: [{ messageId: "missing", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "missing", type: "ImportSpecifier" }] }, { code: "export {foo} from 'foo';", output: "export {foo,} from 'foo';", options: ["always"], - errors: [{ messageId: "missing", type: "ExportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "missing", type: "ExportSpecifier" }] }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["never"], - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["only-multiline"], - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "import foo, {abc,} from 'foo';", output: "import foo, {abc} from 'foo';", options: ["never"], - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "import foo, {abc,} from 'foo';", output: "import foo, {abc} from 'foo';", options: ["only-multiline"], - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["never"], - errors: [{ messageId: "unexpected", type: "ExportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["only-multiline"], - errors: [{ messageId: "unexpected", type: "ExportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["always-multiline"], - errors: [{ messageId: "unexpected", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["always-multiline"], - errors: [{ messageId: "unexpected", type: "ExportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] }, { code: "import {\n foo\n} from 'foo';", output: "import {\n foo,\n} from 'foo';", options: ["always-multiline"], - errors: [{ messageId: "missing", type: "ImportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "missing", type: "ImportSpecifier" }] }, { code: "export {\n foo\n} from 'foo';", output: "export {\n foo,\n} from 'foo';", options: ["always-multiline"], - errors: [{ messageId: "missing", type: "ExportSpecifier" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "missing", type: "ExportSpecifier" }] }, // https://github.com/eslint/eslint/issues/6233 @@ -1313,395 +1313,395 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => a", output: "(a) => a", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => (a)", output: "(a) => (a)", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "({foo(a,) {}})", output: "({foo(a) {}})", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "class A {foo(a,) {}}", output: "class A {foo(a) {}}", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(a) {}", output: "function foo(a,) {}", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(function foo(a) {})", output: "(function foo(a,) {})", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => a", output: "(a,) => a", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => (a)", output: "(a,) => (a)", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "({foo(a) {}})", output: "({foo(a,) {}})", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "class A {foo(a) {}}", output: "class A {foo(a,) {}}", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(a)", output: "foo(a,)", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(...a)", output: "foo(...a,)", options: [{ functions: "always" }], - errors: [{ messageId: "missing", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "SpreadElement" }] }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "always-multiline" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "always-multiline" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "always-multiline" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "always-multiline" }], - errors: [{ messageId: "unexpected", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(\na,\nb\n) {}", output: "function foo(\na,\nb,\n) {}", options: [{ functions: "always-multiline" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\na,\nb\n)", output: "foo(\na,\nb,\n)", options: [{ functions: "always-multiline" }], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\n...a,\n...b\n)", output: "foo(\n...a,\n...b,\n)", options: [{ functions: "always-multiline" }], - errors: [{ messageId: "missing", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "SpreadElement" }] }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "only-multiline" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "only-multiline" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "only-multiline" }], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "only-multiline" }], - errors: [{ messageId: "unexpected", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["never"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["never"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => a", output: "(a) => a", options: ["never"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => (a)", output: "(a) => (a)", options: ["never"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "({foo(a,) {}})", output: "({foo(a) {}})", options: ["never"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "class A {foo(a,) {}}", output: "class A {foo(a) {}}", options: ["never"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: ["never"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: ["never"], - errors: [{ messageId: "unexpected", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(a) {}", output: "function foo(a,) {}", options: ["always"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(function foo(a) {})", output: "(function foo(a,) {})", options: ["always"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => a", output: "(a,) => a", options: ["always"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => (a)", output: "(a,) => (a)", options: ["always"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "({foo(a) {}})", output: "({foo(a,) {},})", options: ["always"], + languageOptions: { ecmaVersion: 8 }, errors: [ { messageId: "missing", type: "Identifier" }, { messageId: "missing", type: "Property" } - ], - languageOptions: { ecmaVersion: 8 } + ] }, { code: "class A {foo(a) {}}", output: "class A {foo(a,) {}}", options: ["always"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(a)", output: "foo(a,)", options: ["always"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(...a)", output: "foo(...a,)", options: ["always"], - errors: [{ messageId: "missing", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "SpreadElement" }] }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["always-multiline"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["always-multiline"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: ["always-multiline"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: ["always-multiline"], - errors: [{ messageId: "unexpected", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(\na,\nb\n) {}", output: "function foo(\na,\nb,\n) {}", options: ["always-multiline"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\na,\nb\n)", output: "foo(\na,\nb,\n)", options: ["always-multiline"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\n...a,\n...b\n)", output: "foo(\n...a,\n...b,\n)", options: ["always-multiline"], - errors: [{ messageId: "missing", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missing", type: "SpreadElement" }] }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["only-multiline"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["only-multiline"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: ["only-multiline"], - errors: [{ messageId: "unexpected", type: "Identifier" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: ["only-multiline"], - errors: [{ messageId: "unexpected", type: "SpreadElement" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(a) {}", output: "function foo(a,) {}", options: ["always"], - errors: [{ messageId: "missing", type: "Identifier" }], - languageOptions: { ecmaVersion: 9 } + languageOptions: { ecmaVersion: 9 }, + errors: [{ messageId: "missing", type: "Identifier" }] }, // separated options @@ -1723,11 +1723,11 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 1 }, { messageId: "unexpected", line: 1 } - ], - languageOptions: { ecmaVersion: 8, sourceType: "module" } + ] }, { code: `let {a,} = {a: 1,}; @@ -1747,11 +1747,11 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 2 }, { messageId: "unexpected", line: 2 } - ], - languageOptions: { ecmaVersion: 8, sourceType: "module" } + ] }, { code: `let {a,} = {a: 1,}; @@ -1771,10 +1771,10 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 3 } - ], - languageOptions: { ecmaVersion: 8, sourceType: "module" } + ] }, { code: `let {a,} = {a: 1,}; @@ -1794,10 +1794,10 @@ let d = 0;export {d}; exports: "never", functions: "ignore" }], + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 4 } - ], - languageOptions: { ecmaVersion: 8, sourceType: "module" } + ] }, { code: `let {a,} = {a: 1,}; @@ -1817,11 +1817,11 @@ let d = 0;export {d,}; exports: "ignore", functions: "never" }], + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 5 }, { messageId: "unexpected", line: 5 } - ], - languageOptions: { ecmaVersion: 8, sourceType: "module" } + ] }, // https://github.com/eslint/eslint/issues/7370 @@ -1829,45 +1829,45 @@ let d = 0;export {d,}; code: "function foo({a}: {a: string,}) {}", output: "function foo({a,}: {a: string,}) {}", options: ["always"], - errors: [{ messageId: "missing" }], languageOptions: { parser: parser("object-pattern-1") - } + }, + errors: [{ messageId: "missing" }] }, { code: "function foo({a,}: {a: string}) {}", output: "function foo({a}: {a: string}) {}", options: ["never"], - errors: [{ messageId: "unexpected" }], languageOptions: { parser: parser("object-pattern-2") - } + }, + errors: [{ messageId: "unexpected" }] }, { code: "function foo(a): {b: boolean,} {}", output: "function foo(a,): {b: boolean,} {}", options: [{ functions: "always" }], - errors: [{ messageId: "missing" }], languageOptions: { parser: parser("return-type-1") - } + }, + errors: [{ messageId: "missing" }] }, { code: "function foo(a,): {b: boolean} {}", output: "function foo(a): {b: boolean} {}", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected" }], languageOptions: { parser: parser("return-type-2") - } + }, + errors: [{ messageId: "unexpected" }] }, // https://github.com/eslint/eslint/issues/11502 { code: "foo(a,)", output: "foo(a)", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpected" }] }, // https://github.com/eslint/eslint/issues/15660 @@ -1897,8 +1897,8 @@ let d = 0;export {d,}; } from 'react-native'; `, options: [{ imports: "always-multiline" }], - errors: 2, - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: 2 }, { code: unIndent` @@ -1926,8 +1926,8 @@ let d = 0;export {d,}; } from 'react-native'; `, options: [{ imports: "never" }], - errors: 2, - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: 2 }, // https://github.com/eslint/eslint/issues/16442 @@ -1935,57 +1935,57 @@ let d = 0;export {d,}; code: "function f(\n a,\n b\n) {}", output: "function f(\n a,\n b,\n) {}", options: ["always-multiline"], + languageOptions: { + ecmaVersion: 2017 + }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }], - languageOptions: { - ecmaVersion: 2017 - } + }] }, { code: "f(\n a,\n b\n);", output: "f(\n a,\n b,\n);", options: ["always-multiline"], + languageOptions: { + ecmaVersion: 2017 + }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }], - languageOptions: { - ecmaVersion: 2017 - } + }] }, { code: "function f(\n a,\n b\n) {}", output: "function f(\n a,\n b,\n) {}", options: ["always-multiline"], + languageOptions: { + ecmaVersion: "latest" + }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }], - languageOptions: { - ecmaVersion: "latest" - } + }] }, { code: "f(\n a,\n b\n);", output: "f(\n a,\n b,\n);", options: ["always-multiline"], + languageOptions: { + ecmaVersion: "latest" + }, errors: [{ messageId: "missing", type: "Identifier", line: 3, column: 3 - }], - languageOptions: { - ecmaVersion: "latest" - } + }] } ] }); diff --git a/tests/lib/rules/comma-spacing.js b/tests/lib/rules/comma-spacing.js index b4d17f08452..4b73d15da1b 100644 --- a/tests/lib/rules/comma-spacing.js +++ b/tests/lib/rules/comma-spacing.js @@ -441,6 +441,7 @@ ruleTester.run("comma-spacing", rule, { code: "var foo = (a,b) => {}", output: "var foo = (a , b) => {}", options: [{ before: true, after: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missing", @@ -452,13 +453,13 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = (a = 1,b) => {}", output: "var foo = (a = 1 , b) => {}", options: [{ before: true, after: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missing", @@ -470,13 +471,13 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(a = 1 ,b = 2) {}", output: "function foo(a = 1, b = 2) {}", options: [{ before: false, after: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "There should be no space before ','.", @@ -487,12 +488,12 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "{foo(1 ,2)}", output: "{foo(1, 2)}", + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { message: "There should be no space before ','.", @@ -503,8 +504,7 @@ ruleTester.run("comma-spacing", rule, { data: { loc: "after" }, type: "Punctuator" } - ], - languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "myfunc(404, true/* bla bla bla */ , 'hello');", diff --git a/tests/lib/rules/comma-style.js b/tests/lib/rules/comma-style.js index e055ed88cbe..e8835bb6e83 100644 --- a/tests/lib/rules/comma-style.js +++ b/tests/lib/rules/comma-style.js @@ -375,13 +375,13 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], + languageOptions: { + ecmaVersion: 6 + }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }], - languageOptions: { - ecmaVersion: 6 - } + }] }, { code: "f(1\n, 2);", @@ -417,14 +417,14 @@ ruleTester.run("comma-style", rule, { FunctionExpression: false } }], - errors: [{ - messageId: "expectedCommaLast", - type: "Identifier" - }], languageOptions: { ecmaVersion: 6, sourceType: "module" - } + }, + errors: [{ + messageId: "expectedCommaLast", + type: "Identifier" + }] }, { code: "function foo([a\n, b]) { return a + b; }", @@ -434,13 +434,13 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], + languageOptions: { + ecmaVersion: 6 + }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }], - languageOptions: { - ecmaVersion: 6 - } + }] }, { code: "const foo = (a\n, b) => { return a + b; }", @@ -450,13 +450,13 @@ ruleTester.run("comma-style", rule, { ArrowFunctionExpression: false } }], + languageOptions: { + ecmaVersion: 6 + }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }], - languageOptions: { - ecmaVersion: 6 - } + }] }, { code: "const foo = ([a\n, b]) => { return a + b; }", @@ -466,13 +466,13 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], + languageOptions: { + ecmaVersion: 6 + }, errors: [{ messageId: "expectedCommaLast", type: "Identifier" - }], - languageOptions: { - ecmaVersion: 6 - } + }] }, { code: "import { a\n, b } from './source';", @@ -482,14 +482,14 @@ ruleTester.run("comma-style", rule, { ImportDeclaration: false } }], - errors: [{ - messageId: "expectedCommaLast", - type: "ImportSpecifier" - }], languageOptions: { ecmaVersion: 6, sourceType: "module" - } + }, + errors: [{ + messageId: "expectedCommaLast", + type: "ImportSpecifier" + }] }, { code: "var {foo\n, bar} = {foo:'apples', bar:'oranges'};", @@ -499,13 +499,13 @@ ruleTester.run("comma-style", rule, { ObjectPattern: false } }], + languageOptions: { + ecmaVersion: 6 + }, errors: [{ messageId: "expectedCommaLast", type: "Property" - }], - languageOptions: { - ecmaVersion: 6 - } + }] }, { code: "var foo = 1,\nbar = 2;", diff --git a/tests/lib/rules/complexity.js b/tests/lib/rules/complexity.js index cb11eed566b..3f26629fa45 100644 --- a/tests/lib/rules/complexity.js +++ b/tests/lib/rules/complexity.js @@ -129,15 +129,15 @@ ruleTester.run("complexity", rule, { invalid: [ { code: "function a(x) {}", options: [0], errors: [makeError("Function 'a'", 1, 0)] }, { code: "var func = function () {}", options: [0], errors: [makeError("Function", 1, 0)] }, - { code: "var obj = { a(x) {} }", options: [0], errors: [makeError("Method 'a'", 1, 0)], languageOptions: { ecmaVersion: 6 } }, - { code: "class Test { a(x) {} }", options: [0], errors: [makeError("Method 'a'", 1, 0)], languageOptions: { ecmaVersion: 6 } }, - { code: "var a = (x) => {if (true) {return x;}}", options: [1], errors: 1, languageOptions: { ecmaVersion: 6 } }, + { code: "var obj = { a(x) {} }", options: [0], languageOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 1, 0)] }, + { code: "class Test { a(x) {} }", options: [0], languageOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 1, 0)] }, + { code: "var a = (x) => {if (true) {return x;}}", options: [1], languageOptions: { ecmaVersion: 6 }, errors: 1 }, { code: "function a(x) {if (true) {return x;}}", options: [1], errors: 1 }, { code: "function a(x) {if (true) {return x;} else {return x+1;}}", options: [1], errors: 1 }, { code: "function a(x) {if (true) {return x;} else if (false) {return x+1;} else {return 4;}}", options: [2], errors: 1 }, { code: "function a(x) {for(var i = 0; i < 5; i ++) {x ++;} return x;}", options: [1], errors: 1 }, { code: "function a(obj) {for(var i in obj) {obj[i] = 3;}}", options: [1], errors: 1 }, - { code: "function a(obj) {for(var i of obj) {obj[i] = 3;}}", options: [1], errors: 1, languageOptions: { ecmaVersion: 6 } }, + { code: "function a(obj) {for(var i of obj) {obj[i] = 3;}}", options: [1], languageOptions: { ecmaVersion: 6 }, errors: 1 }, { code: "function a(x) {for(var i = 0; i < 5; i ++) {if(i % 2 === 0) {x ++;}} return x;}", options: [2], errors: 1 }, { code: "function a(obj) {if(obj){ for(var x in obj) {try {x.getThis();} catch (e) {x.getThat();}}} else {return false;}}", options: [3], errors: 1 }, { code: "function a(x) {try {x.getThis();} catch (e) {x.getThat();}}", options: [1], errors: 1 }, @@ -155,7 +155,7 @@ ruleTester.run("complexity", rule, { { code: "function a(x) {do {'foo';} while (true)}", options: [1], errors: 1 }, { code: "function a(x) {(function() {while(true){'foo';}})(); (function() {while(true){'bar';}})();}", options: [1], errors: 2 }, { code: "function a(x) {(function() {while(true){'foo';}})(); (function() {'bar';})();}", options: [1], errors: 1 }, - { code: "var obj = { a(x) { return x ? 0 : 1; } };", options: [1], errors: [makeError("Method 'a'", 2, 1)], languageOptions: { ecmaVersion: 6 } }, + { code: "var obj = { a(x) { return x ? 0 : 1; } };", options: [1], languageOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 2, 1)] }, { code: "var obj = { a: function b(x) { return x ? 0 : 1; } };", options: [1], errors: [makeError("Method 'a'", 2, 1)] }, { code: createComplexity(21), @@ -171,120 +171,121 @@ ruleTester.run("complexity", rule, { { code: "function foo () { a || b; class C { x; } c || d; }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { x = c; } d || e; }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { [x || y]; } }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { [x || y] = c; } }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y]; } a || b; }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y] = a; } b || c; }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y]; [z || q]; } }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y] = a; [z || q] = b; } }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { x = c || d; } e || f; }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "class C { x(){ a || b; } y = c || d || e; z() { f || g; } }", options: [2], - errors: [makeError("Class field initializer", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class field initializer", 3, 2)] }, { code: "class C { x = a || b; y() { c || d || e; } z = f || g; }", options: [2], - errors: [makeError("Method 'y'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Method 'y'", 3, 2)] }, { code: "class C { x; y() { c || d || e; } z; }", options: [2], - errors: [makeError("Method 'y'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Method 'y'", 3, 2)] }, { code: "class C { x = a || b; }", options: [1], - errors: [makeError("Class field initializer", 2, 1)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class field initializer", 2, 1)] }, { code: "(class { x = a || b; })", options: [1], - errors: [makeError("Class field initializer", 2, 1)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class field initializer", 2, 1)] }, { code: "class C { static x = a || b; }", options: [1], - errors: [makeError("Class field initializer", 2, 1)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class field initializer", 2, 1)] }, { code: "(class { x = a ? b : c; })", options: [1], - errors: [makeError("Class field initializer", 2, 1)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class field initializer", 2, 1)] }, { code: "class C { x = a || b || c; }", options: [2], - errors: [makeError("Class field initializer", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class field initializer", 3, 2)] }, { code: "class C { x = a || b; y = b || c || d; z = e || f; }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class field initializer", 3, 2), line: 1, column: 27, endLine: 1, endColumn: 38 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { x = a || b || c; y = d || e; z = f || g || h; }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 3, 2), @@ -300,30 +301,30 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 55 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { x = () => a || b || c; }", options: [2], - errors: [makeError("Method 'x'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Method 'x'", 3, 2)] }, { code: "class C { x = (() => a || b || c) || d; }", options: [2], - errors: [makeError("Arrow function", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Arrow function", 3, 2)] }, { code: "class C { x = () => a || b || c; y = d || e; }", options: [2], - errors: [makeError("Method 'x'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Method 'x'", 3, 2)] }, { code: "class C { x = () => a || b || c; y = d || e || f; }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [ makeError("Method 'x'", 3, 2), { @@ -333,21 +334,21 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 49 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { x = function () { a || b }; y = function () { c || d }; }", options: [1], + languageOptions: { ecmaVersion: 2022 }, errors: [ makeError("Method 'x'", 2, 1), makeError("Method 'y'", 2, 1) - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { x = class { [y || z]; }; }", options: [1], + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -356,12 +357,12 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 34 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { x = class { [y || z] = a; }; }", options: [1], + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -370,12 +371,12 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 38 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { x = class { y = a || b; }; }", options: [1], + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -384,128 +385,128 @@ ruleTester.run("complexity", rule, { endLine: 1, endColumn: 33 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // class static blocks { code: "function foo () { a || b; class C { static {} } c || d; }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { static { c || d; } } e || f; }", options: [2], - errors: [makeError("Function 'foo'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Function 'foo'", 3, 2)] }, { code: "class C { static { a || b; } }", options: [1], - errors: [makeError("Class static block", 2, 1)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 2, 1)] }, { code: "class C { static { a || b || c; } }", options: [2], - errors: [makeError("Class static block", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 3, 2)] }, { code: "class C { static { a || b; c || d; } }", options: [2], - errors: [makeError("Class static block", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 3, 2)] }, { code: "class C { static { a || b; c || d; e || f; } }", options: [3], - errors: [makeError("Class static block", 4, 3)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 4, 3)] }, { code: "class C { static { a || b; c || d; { e || f; } } }", options: [3], - errors: [makeError("Class static block", 4, 3)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 4, 3)] }, { code: "class C { static { if (a || b) c = d || e; } }", options: [3], - errors: [makeError("Class static block", 4, 3)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 4, 3)] }, { code: "class C { static { if (a || b) c = (d => e || f)() || (g => h || i)(); } }", options: [3], - errors: [makeError("Class static block", 4, 3)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 4, 3)] }, { code: "class C { x(){ a || b; } static { c || d || e; } z() { f || g; } }", options: [2], - errors: [makeError("Class static block", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 3, 2)] }, { code: "class C { x = a || b; static { c || d || e; } y = f || g; }", options: [2], - errors: [makeError("Class static block", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 3, 2)] }, { code: "class C { static x = a || b; static { c || d || e; } static y = f || g; }", options: [2], - errors: [makeError("Class static block", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Class static block", 3, 2)] }, { code: "class C { static { a || b; } static(){ c || d || e; } static { f || g; } }", options: [2], - errors: [makeError("Method 'static'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Method 'static'", 3, 2)] }, { code: "class C { static { a || b; } static static(){ c || d || e; } static { f || g; } }", options: [2], - errors: [makeError("Static method 'static'", 3, 2)], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [makeError("Static method 'static'", 3, 2)] }, { code: "class C { static { a || b; } static x = c || d || e; static { f || g; } }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class field initializer", 3, 2), column: 41, endColumn: 52 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { a || b || c || d; } static { e || f || g; } }", options: [3], + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class static block", 4, 3), column: 11, endColumn: 39 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { a || b || c; } static { d || e || f || g; } }", options: [3], + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class static block", 4, 3), column: 35, endColumn: 63 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { a || b || c || d; } static { e || f || g || h; } }", options: [3], + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class static block", 4, 3), @@ -517,8 +518,7 @@ ruleTester.run("complexity", rule, { column: 40, endColumn: 68 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // object property options diff --git a/tests/lib/rules/computed-property-spacing.js b/tests/lib/rules/computed-property-spacing.js index 89d26b222e3..9a51e2f9dda 100644 --- a/tests/lib/rules/computed-property-spacing.js +++ b/tests/lib/rules/computed-property-spacing.js @@ -554,6 +554,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[a]: b}", output: "var x = {[ a ]: b}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -573,13 +574,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 13 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var x = {[a ]: b}", output: "var x = {[ a ]: b}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -590,13 +591,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var x = {[ a]: b}", output: "var x = {[ a ]: b}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceBefore", @@ -607,8 +608,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // never - objectLiteralComputedProperties @@ -616,6 +616,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[ a ]: b}", output: "var x = {[a]: b}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -635,13 +636,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var x = {[a ]: b}", output: "var x = {[a]: b}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -652,13 +653,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 13 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var x = {[ a]: b}", output: "var x = {[a]: b}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -669,13 +670,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var x = {[ a\n]: b}", output: "var x = {[a\n]: b}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -686,14 +687,14 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // test default settings for classes { code: "class A { [ a ](){} }", output: "class A { [a](){} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -713,13 +714,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", output: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -829,13 +830,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 105 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", options: ["never", {}], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -945,13 +946,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 107 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { [a](){} }", output: "A = class { [ a ](){} }", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -971,13 +972,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1087,13 +1088,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 96 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", output: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["always", {}], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1203,8 +1204,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 94 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // never - classes @@ -1212,6 +1212,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "class A { [ a](){} }", output: "class A { [a](){} }", options: ["never", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1222,13 +1223,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 13 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { [a](){} b(){} static [c ](){} static [d](){}}", output: "A = class { [a](){} b(){} static [c](){} static [d](){}}", options: ["never", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1239,13 +1240,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 37 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }", output: "class A { get [a](){} set [a](foo){} get b(){} static set b(bar){} static get [a](){} static set [a](baz){} }", options: ["never", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1283,13 +1284,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 104 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", options: ["never", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1399,13 +1400,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 107 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { [ a]; [b ]; [ c ]; [ a] = 0; [b ] = 0; [ c ] = 0; }", output: "class A { [a]; [b]; [c]; [a] = 0; [b] = 0; [c] = 0; }", options: ["never", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1455,8 +1456,7 @@ ruleTester.run("computed-property-spacing", rule, { column: 53, endColumn: 54 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // always - classes @@ -1464,6 +1464,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "class A { [ a](){} }", output: "class A { [ a ](){} }", options: ["always", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceBefore", @@ -1474,13 +1475,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { [ a ](){} b(){} static [c ](){} static [ d ](){}}", output: "A = class { [ a ](){} b(){} static [ c ](){} static [ d ](){}}", options: ["always", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1491,13 +1492,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 37 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }", output: "class A { get [ a ](){} set [ a ](foo){} get b(){} static set b(bar){} static get [ a ](){} static set [ a ](baz){} }", options: ["always", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1535,13 +1536,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 102 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", options: ["always", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1651,13 +1652,13 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 1, endColumn: 96 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { [ a]; [b ]; [c]; [ a] = 0; [b ] = 0; [c] = 0; }", output: "class A { [ a ]; [ b ]; [ c ]; [ a ] = 0; [ b ] = 0; [ c ] = 0; }", options: ["always", { enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceBefore", @@ -1699,8 +1700,7 @@ ruleTester.run("computed-property-spacing", rule, { column: 50, endColumn: 51 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // handling of parens and comments @@ -1716,6 +1716,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1735,8 +1736,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1750,6 +1750,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1769,8 +1770,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1784,6 +1784,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1803,8 +1804,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1818,6 +1818,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1837,8 +1838,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1852,6 +1852,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1871,8 +1872,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1886,6 +1886,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1923,8 +1924,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 9 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1938,6 +1938,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1975,8 +1976,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1990,6 +1990,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -2018,8 +2019,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 19 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -2033,6 +2033,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -2061,8 +2062,7 @@ ruleTester.run("computed-property-spacing", rule, { endLine: 2, endColumn: 19 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Optional chaining @@ -2070,21 +2070,21 @@ ruleTester.run("computed-property-spacing", rule, { code: "obj?.[1];", output: "obj?.[ 1 ];", options: ["always"], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "obj?.[ 1 ];", output: "obj?.[1];", options: ["never"], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, // Destructuring Assignment @@ -2092,59 +2092,59 @@ ruleTester.run("computed-property-spacing", rule, { code: "const { [ a]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "const { [a ]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "const { [ a ]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "({ [ a ]: someProp } = obj);", output: "({ [a]: someProp } = obj);", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "const { [a]: someProp } = obj;", output: "const { [ a ]: someProp } = obj;", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "({ [a]: someProp } = obj);", output: "({ [ a ]: someProp } = obj);", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/consistent-return.js b/tests/lib/rules/consistent-return.js index 6903b630d86..2e01eef6fd3 100644 --- a/tests/lib/rules/consistent-return.js +++ b/tests/lib/rules/consistent-return.js @@ -67,6 +67,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "var foo = () => { if (true) return true; else return; }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturnValue", @@ -77,8 +78,7 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 54 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { if (true) return; else return false; }", @@ -124,6 +124,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "f(a => { if (true) return; else return false; })", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedReturnValue", @@ -134,8 +135,7 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 46 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { if (true) return true; return undefined; }", @@ -199,6 +199,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "if (true) { return 1; } return;", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "missingReturnValue", @@ -209,8 +210,7 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 32 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "function foo() { if (a) return true; }", @@ -270,6 +270,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "f(() => { if (a) return true; });", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -280,11 +281,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var obj = {foo() { if (a) return true; }};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -295,11 +296,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A {foo() { if (a) return true; }};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -310,11 +311,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 13 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (a) return true;", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "missingReturn", @@ -325,11 +326,11 @@ ruleTester.run("consistent-return", rule, { endLine: void 0, endColumn: void 0 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "class A { CapitalizedFunction() { if (a) return true; } }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -340,11 +341,11 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 30 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ constructor() { if (a) return true; } });", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -355,8 +356,7 @@ ruleTester.run("consistent-return", rule, { endLine: 1, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/curly.js b/tests/lib/rules/curly.js index 6c0867d3e88..db23378917b 100644 --- a/tests/lib/rules/curly.js +++ b/tests/lib/rules/curly.js @@ -564,6 +564,7 @@ ruleTester.run("curly", rule, { { code: "for (var foo of bar) console.log(foo)", output: "for (var foo of bar) {console.log(foo)}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -574,12 +575,12 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 38 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for (var foo of bar) \n console.log(foo)", output: "for (var foo of bar) \n {console.log(foo)}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -590,12 +591,12 @@ ruleTester.run("curly", rule, { endLine: 2, endColumn: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for (a;;) console.log(foo)", output: "for (a;;) {console.log(foo)}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", @@ -606,12 +607,12 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for (a;;) \n console.log(foo)", output: "for (a;;) \n {console.log(foo)}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", @@ -622,13 +623,13 @@ ruleTester.run("curly", rule, { endLine: 2, endColumn: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for (var foo of bar) {console.log(foo)}", output: "for (var foo of bar) console.log(foo)", options: ["multi"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -639,13 +640,13 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 40 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "do{foo();} while(bar);", output: "do foo(); while(bar);", options: ["multi"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -656,8 +657,7 @@ ruleTester.run("curly", rule, { endLine: 1, endColumn: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for (;foo;) { bar() }", @@ -854,14 +854,14 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) { console.log(foo) }", output: "for (var foo of bar) console.log(foo) ", options: ["multi"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (foo) \n baz()", @@ -1018,6 +1018,7 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) \n console.log(foo)", output: "for (var foo of bar) \n {console.log(foo)}", options: ["multi-line"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -1028,21 +1029,20 @@ ruleTester.run("curly", rule, { endLine: 2, endColumn: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for (var foo of bar) \n console.log(1); \n console.log(2)", output: "for (var foo of bar) \n {console.log(1);} \n console.log(2)", options: ["multi-line"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (foo) \n quz = { \n bar: baz, \n qux: foo \n };", @@ -1096,27 +1096,27 @@ ruleTester.run("curly", rule, { code: "if (foo) { let bar; } else baz();", output: "if (foo) { let bar; } else {baz();}", options: ["multi", "consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", data: { name: "else" }, type: "IfStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (foo) bar(); else { const baz = 'quux' }", output: "if (foo) {bar();} else { const baz = 'quux' }", options: ["multi", "consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (foo) { \n var bar = 'baz'; \n }", @@ -1224,27 +1224,27 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) \n if (foo) console.log(1); \n else console.log(2);", output: "for (var foo of bar) \n {if (foo) console.log(1); \n else console.log(2);}", options: ["multi-or-nest"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for (var foo of bar) { if (foo) console.log(1) }", output: "for (var foo of bar) if (foo) console.log(1) ", options: ["multi-or-nest"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if (true) foo(); \n else { \n bar(); \n baz(); \n }", @@ -1463,8 +1463,8 @@ ruleTester.run("curly", rule, { code: "if (foo) { bar }\n/regex/.test('foo');", output: null, options: ["multi"], - errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { bar }\nBaz();", @@ -1500,8 +1500,8 @@ ruleTester.run("curly", rule, { code: "if (foo) { var foo = () => {} } else {}", output: null, options: ["multi"], - errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { var foo = function() {} } else {}", @@ -1513,8 +1513,8 @@ ruleTester.run("curly", rule, { code: "if (foo) { var foo = function*() {} } else {}", output: null, options: ["multi"], - errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (true)\nfoo()\n;[1, 2, 3].bar()", @@ -1558,8 +1558,8 @@ ruleTester.run("curly", rule, { code: "for (var foo of bar) {\ndoSomething()\n;\n}", output: "for (var foo of bar) \ndoSomething()\n;\n", options: ["multi-or-nest"], - errors: [{ messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" }] }, { code: "while (foo) {\ndoSomething()\n;\n}", @@ -1835,6 +1835,7 @@ ruleTester.run("curly", rule, { { code: "for(var i of \n z)\nfoo()\n", output: "for(var i of \n z)\n{foo()}\n", + languageOptions: { ecmaVersion: 6 }, errors: [{ data: { name: "for-of" }, type: "ForOfStatement", @@ -1843,8 +1844,7 @@ ruleTester.run("curly", rule, { column: 1, endLine: 3, endColumn: 6 - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/dot-location.js b/tests/lib/rules/dot-location.js index 67d55ce4671..d84fa00626b 100644 --- a/tests/lib/rules/dot-location.js +++ b/tests/lib/rules/dot-location.js @@ -270,29 +270,29 @@ ruleTester.run("dot-location", rule, { code: "5_000\n.toExponential()", output: "5_000 .\ntoExponential()", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { code: "5_000_00\n.toExponential()", output: "5_000_00 .\ntoExponential()", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { code: "5.000_000\n.toExponential()", output: "5.000_000.\ntoExponential()", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { code: "0b1010_1010\n.toExponential()", output: "0b1010_1010.\ntoExponential()", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { code: "foo /* a */ . /* b */ \n /* c */ bar", @@ -316,8 +316,8 @@ ruleTester.run("dot-location", rule, { code: "`\n`\n.prop", output: "`\n`.\nprop", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }] }, // https://github.com/eslint/eslint/issues/11868 (also in valid) @@ -387,22 +387,22 @@ ruleTester.run("dot-location", rule, { code: "obj\n?.prop", output: "obj?.\nprop", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedDotAfterObject" }] }, { code: "10\n?.prop", output: "10?.\nprop", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedDotAfterObject" }] }, { code: "obj?.\nprop", output: "obj\n?.prop", options: ["property"], - errors: [{ messageId: "expectedDotBeforeProperty" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedDotBeforeProperty" }] }, // Private properties @@ -410,15 +410,15 @@ ruleTester.run("dot-location", rule, { code: "class C { #a; foo() { this\n.#a; } }", output: "class C { #a; foo() { this.\n#a; } }", options: ["object"], - errors: [{ messageId: "expectedDotAfterObject" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedDotAfterObject" }] }, { code: "class C { #a; foo() { this.\n#a; } }", output: "class C { #a; foo() { this\n.#a; } }", options: ["property"], - errors: [{ messageId: "expectedDotBeforeProperty" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedDotBeforeProperty" }] } ] }); diff --git a/tests/lib/rules/dot-notation.js b/tests/lib/rules/dot-notation.js index 0ee0925b64c..c03cdc73ee9 100644 --- a/tests/lib/rules/dot-notation.js +++ b/tests/lib/rules/dot-notation.js @@ -90,8 +90,8 @@ ruleTester.run("dot-notation", rule, { { code: "a[`time`];", output: "a.time;", - errors: [{ messageId: "useDot", data: { key: "`time`" } }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "useDot", data: { key: "`time`" } }] }, { code: "a[null];", @@ -272,54 +272,54 @@ ruleTester.run("dot-notation", rule, { { code: "5_000['prop']", output: "5_000 .prop", - errors: [{ messageId: "useDot", data: { key: q("prop") } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "5_000_00['prop']", output: "5_000_00 .prop", - errors: [{ messageId: "useDot", data: { key: q("prop") } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "5.000_000['prop']", output: "5.000_000.prop", - errors: [{ messageId: "useDot", data: { key: q("prop") } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "0b1010_1010['prop']", output: "0b1010_1010.prop", - errors: [{ messageId: "useDot", data: { key: q("prop") } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, // Optional chaining { code: "obj?.['prop']", output: "obj?.prop", - errors: [{ messageId: "useDot", data: { key: q("prop") } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "0?.['prop']", output: "0?.prop", - errors: [{ messageId: "useDot", data: { key: q("prop") } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "obj?.true", output: "obj?.[\"true\"]", options: [{ allowKeywords: false }], - errors: [{ messageId: "useBrackets", data: { key: "true" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "useBrackets", data: { key: "true" } }] }, { code: "let?.true", output: "let?.[\"true\"]", options: [{ allowKeywords: false }], - errors: [{ messageId: "useBrackets", data: { key: "true" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "useBrackets", data: { key: "true" } }] } ] }); diff --git a/tests/lib/rules/func-call-spacing.js b/tests/lib/rules/func-call-spacing.js index 8455ec380a4..e4c7c0c1372 100644 --- a/tests/lib/rules/func-call-spacing.js +++ b/tests/lib/rules/func-call-spacing.js @@ -324,8 +324,8 @@ ruleTester.run("func-call-spacing", rule, { { code: "import (source);", output: "import(source);", - errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] }, // https://github.com/eslint/eslint/issues/7787 @@ -357,8 +357,8 @@ ruleTester.run("func-call-spacing", rule, { { code: "import\n(source);", output: null, - errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] }, // "never" @@ -453,8 +453,8 @@ ruleTester.run("func-call-spacing", rule, { code: "import (source);", output: "import(source);", options: ["never"], - errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] }, // https://github.com/eslint/eslint/issues/7787 @@ -704,8 +704,8 @@ ruleTester.run("func-call-spacing", rule, { code: "import(source);", output: "import (source);", options: ["always"], - errors: [{ messageId: "missing", type: "ImportExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "missing", type: "ImportExpression" }] }, { code: "f();\n t();", @@ -900,71 +900,71 @@ ruleTester.run("func-call-spacing", rule, { code: "func ?.()", output: "func?.()", options: ["never"], - errors: [{ messageId: "unexpectedWhitespace" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func?. ()", output: "func?.()", options: ["never"], - errors: [{ messageId: "unexpectedWhitespace" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func ?. ()", output: "func?.()", options: ["never"], - errors: [{ messageId: "unexpectedWhitespace" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func\n?.()", output: "func?.()", options: ["never"], - errors: [{ messageId: "unexpectedWhitespace" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func\n//comment\n?.()", output: null, // Don't remove comments options: ["never"], - errors: [{ messageId: "unexpectedWhitespace" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func?.()", output: null, // Not sure inserting a space into either before/after `?.`. options: ["always"], - errors: [{ messageId: "missing" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "missing" }] }, { code: "func\n ?.()", output: "func ?.()", options: ["always"], - errors: [{ messageId: "unexpectedNewline" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] }, { code: "func?.\n ()", output: "func?. ()", options: ["always"], - errors: [{ messageId: "unexpectedNewline" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] }, { code: "func ?.\n ()", output: "func ?. ()", options: ["always"], - errors: [{ messageId: "unexpectedNewline" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] }, { code: "func\n /*comment*/ ?.()", output: null, // Don't remove comments options: ["always"], - errors: [{ messageId: "unexpectedNewline" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedNewline" }] } ] }); diff --git a/tests/lib/rules/func-name-matching.js b/tests/lib/rules/func-name-matching.js index d7ec8be3d58..14b0d72ed8f 100644 --- a/tests/lib/rules/func-name-matching.js +++ b/tests/lib/rules/func-name-matching.js @@ -518,135 +518,135 @@ ruleTester.run("func-name-matching", rule, { { code: "let foo = function bar() {};", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let foo = function bar() {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo = function bar() {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo &&= function bar() {};", + languageOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 2021 } + ] }, { code: "obj.foo ||= function bar() {};", + languageOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 2021 } + ] }, { code: "obj['foo'] ??= function bar() {};", + languageOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 2021 } + ] }, { code: "obj.foo = function bar() {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "obj.bar.foo = function bar() {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "obj['foo'] = function bar() {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let obj = {foo: function bar() {}};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let obj = {'foo': function bar() {}};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({['foo']: function bar() {}})", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "module.exports = function foo(name) {};", options: [{ includeCommonJSModuleExports: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "module.exports = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "module.exports = function exports(name) {};", options: ["never", { includeCommonJSModuleExports: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "exports", name: "exports" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "module['exports'] = function foo(name) {};", options: [{ includeCommonJSModuleExports: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "module['exports'] = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "module['exports'] = function exports(name) {};", options: ["never", { includeCommonJSModuleExports: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "exports", name: "exports" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = function foo(name) {};", @@ -736,163 +736,163 @@ ruleTester.run("func-name-matching", rule, { // Optional chaining { code: "(obj?.aaa).foo = function bar() {};", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "Object?.defineProperty(foo, 'bar', { value: function baz() {} })", options: ["always", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(Object?.defineProperty)(foo, 'bar', { value: function baz() {} })", options: ["always", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "Object?.defineProperty(foo, 'bar', { value: function bar() {} })", options: ["never", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(Object?.defineProperty)(foo, 'bar', { value: function bar() {} })", options: ["never", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "Object?.defineProperties(foo, { bar: { value: function baz() {} } })", options: ["always", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(Object?.defineProperties)(foo, { bar: { value: function baz() {} } })", options: ["always", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "Object?.defineProperties(foo, { bar: { value: function bar() {} } })", options: ["never", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(Object?.defineProperties)(foo, { bar: { value: function bar() {} } })", options: ["never", { considerPropertyDescriptor: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, // class fields { code: "class C { x = function y() {}; }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { x = function x() {}; }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { 'x' = function y() {}; }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { 'x' = function x() {}; }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { ['x'] = function y() {}; }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { ['x'] = function x() {}; }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static x = function y() {}; }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static x = function x() {}; }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "(class { x = function y() {}; })", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "(class { x = function x() {}; })", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "var obj = { '\\u1885': function foo() {} };", // valid identifier in es2015 + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "\u1885" } } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/func-names.js b/tests/lib/rules/func-names.js index e03f454de29..c296c61eb0d 100644 --- a/tests/lib/rules/func-names.js +++ b/tests/lib/rules/func-names.js @@ -400,62 +400,62 @@ ruleTester.run("func-names", rule, { { code: "var {foo} = function(){};", options: ["as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 13, endColumn: 21 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "({ a: obj.prop = function(){} } = foo);", options: ["as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 18, endColumn: 26 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "[obj.prop = function(){}] = foo;", options: ["as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 13, endColumn: 21 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var { a: [b] = function(){} } = foo;", options: ["as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 16, endColumn: 24 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo({ a } = function(){}) {};", options: ["as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 22, endColumn: 30 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var x = function foo() {};", @@ -498,282 +498,283 @@ ruleTester.run("func-names", rule, { { code: "export default function() {}", options: ["always"], + languageOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionDeclaration", column: 16, endColumn: 24 - }], - languageOptions: { sourceType: "module", ecmaVersion: 6 } + }] }, { code: "export default function() {}", options: ["as-needed"], + languageOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionDeclaration", column: 16, endColumn: 24 - }], - languageOptions: { sourceType: "module", ecmaVersion: 6 } + }] }, { code: "export default (function(){});", options: ["as-needed"], + languageOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", column: 17, endColumn: 25 - }], - languageOptions: { sourceType: "module", ecmaVersion: 6 } + }] }, // generators { code: "var foo = bar(function *() {});", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function*() {};", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *() {});", options: ["always", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function*() {};", options: ["always", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["always", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *() {});", options: ["always", { generators: "as-needed" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["always", { generators: "as-needed" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *() {});", options: ["as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *() {});", options: ["as-needed", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function*() {};", options: ["as-needed", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["as-needed", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *() {});", options: ["as-needed", { generators: "as-needed" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["as-needed", { generators: "as-needed" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *() {});", options: ["never", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function*() {};", options: ["never", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 11, endColumn: 20 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["never", { generators: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *() {});", options: ["never", { generators: "as-needed" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 15, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function*() {}())", options: ["never", { generators: "as-needed" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", line: 1, column: 2, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *baz() {});", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -781,12 +782,12 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *baz() {});", options: ["never", { generators: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -794,12 +795,12 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *baz() {});", options: ["always", { generators: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -807,12 +808,12 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = bar(function *baz() {});", options: ["as-needed", { generators: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -820,65 +821,64 @@ ruleTester.run("func-names", rule, { line: 1, column: 15, endColumn: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, // class fields { code: "class C { foo = function() {} }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "method 'foo'" }, column: 11, endColumn: 25 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [foo] = function() {} }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "method" }, column: 11, endColumn: 27 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { #foo = function() {} }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "private method #foo" }, column: 11, endColumn: 26 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { foo = bar(function() {}) }", options: ["as-needed"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "function" }, column: 21, endColumn: 29 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { foo = function bar() {} }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "named", data: { name: "method 'foo'" }, column: 11, endColumn: 29 - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/func-style.js b/tests/lib/rules/func-style.js index 1e5823f5c63..8ee8b481f78 100644 --- a/tests/lib/rules/func-style.js +++ b/tests/lib/rules/func-style.js @@ -98,24 +98,24 @@ ruleTester.run("func-style", rule, { { code: "var foo = () => {};", options: ["declaration"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "declaration", type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = () => { function foo() { this; } };", options: ["declaration"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "declaration", type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(){}", diff --git a/tests/lib/rules/function-call-argument-newline.js b/tests/lib/rules/function-call-argument-newline.js index f67d97a1e23..2e09ae63c29 100644 --- a/tests/lib/rules/function-call-argument-newline.js +++ b/tests/lib/rules/function-call-argument-newline.js @@ -192,6 +192,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(a, b, x => {\n\tx()\n})", output: "fn(a,\nb,\nx => {\n\tx()\n})", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -207,8 +208,7 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 1, endColumn: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "fn({\n\ta: 1\n}, b)", @@ -228,6 +228,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`, b)", output: "fn(`\n`,\nb)", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -236,8 +237,7 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 2, endColumn: 4 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, /* "never" */ @@ -343,6 +343,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(a,\n\tb,\n\tx => {\n\t\tx()\n})", output: "fn(a, b, x => {\n\t\tx()\n})", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -358,8 +359,7 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 2 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "fn({\n\ta: 1\n},\nb)", @@ -379,6 +379,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`,\nb)", output: "fn(`\n`, b)", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -387,13 +388,13 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "fn(a,/* comment */\nb)", output: "fn(a,/* comment */ b)", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -402,8 +403,7 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 2, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, /* "consistent" */ @@ -495,6 +495,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`,\nb, c)", output: "fn(`\n`,\nb,\nc)", options: ["consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -503,13 +504,13 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 4 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "fn(`\n`, b,\nc)", output: "fn(`\n`, b, c)", options: ["consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -518,13 +519,13 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "fn(a,// comment\n{b, c})", output: null, options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -533,8 +534,7 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 2, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "fn(a, // comment\nb)", @@ -554,6 +554,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`, b, // comment\nc)", output: null, options: ["consistent"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -562,8 +563,7 @@ ruleTester.run("function-call-argument-newline", rule, { endLine: 3, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/function-paren-newline.js b/tests/lib/rules/function-paren-newline.js index 16ea5f2e929..322dcab87c7 100644 --- a/tests/lib/rules/function-paren-newline.js +++ b/tests/lib/rules/function-paren-newline.js @@ -738,8 +738,8 @@ ruleTester.run("function-paren-newline", rule, { output: ` async (foo, bar) => {}; `, - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { code: ` @@ -749,8 +749,8 @@ ruleTester.run("function-paren-newline", rule, { output: ` async (foo, bar) => {}; `, - errors: [RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [RIGHT_UNEXPECTED_ERROR] }, { code: ` @@ -761,8 +761,8 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar\n) => {}; `, - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { code: ` @@ -775,14 +775,14 @@ ruleTester.run("function-paren-newline", rule, { foo, bar\n) => {}; `, - errors: [RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [RIGHT_MISSING_ERROR] }, { code: "import(\n source\n)", output: "import(source)", - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, // multiline-arguments @@ -980,8 +980,8 @@ ruleTester.run("function-paren-newline", rule, { async (foo, bar) => {}; `, options: ["multiline-arguments"], - errors: [RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [RIGHT_UNEXPECTED_ERROR] }, { code: ` @@ -993,8 +993,8 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["multiline-arguments"], - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { code: ` @@ -1008,22 +1008,22 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["multiline-arguments"], - errors: [RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [RIGHT_MISSING_ERROR] }, { code: "import(source\n)", output: "import(source)", options: ["multiline-arguments"], - errors: [RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [RIGHT_UNEXPECTED_ERROR] }, { code: "import(\n source)", output: "import(\n source\n)", options: ["multiline-arguments"], - errors: [RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [RIGHT_MISSING_ERROR] }, // always option @@ -1111,8 +1111,8 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar\n) => {}; `, options: ["always"], - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { code: ` @@ -1124,8 +1124,8 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["always"], - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { code: ` @@ -1139,15 +1139,15 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["always"], - errors: [RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [RIGHT_MISSING_ERROR] }, { code: "import(source)", output: "import(\nsource\n)", options: ["always"], - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, // never option @@ -1282,8 +1282,8 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["never"], - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { code: ` @@ -1296,15 +1296,15 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["never"], - errors: [LEFT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_UNEXPECTED_ERROR] }, { code: "import(\n source\n)", output: "import(source)", options: ["never"], - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, // minItems option @@ -1358,8 +1358,8 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: [{ minItems: 3 }], - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { code: ` @@ -1372,8 +1372,8 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: [{ minItems: 3 }], - errors: [LEFT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_UNEXPECTED_ERROR] }, { code: ` @@ -1383,22 +1383,22 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar, baz\n) => {}; `, options: [{ minItems: 3 }], - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { code: "import(\n source\n)", output: "import(source)", options: [{ minItems: 3 }], - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { code: "import(source)", output: "import(\nsource\n)", options: [{ minItems: 1 }], - errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, // consistent option @@ -1441,8 +1441,8 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["consistent"], - errors: [RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [RIGHT_MISSING_ERROR] }, { code: ` @@ -1455,22 +1455,22 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["consistent"], - errors: [RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [RIGHT_UNEXPECTED_ERROR] }, { code: "import(source\n)", output: "import(source)", options: ["consistent"], - errors: [RIGHT_UNEXPECTED_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [RIGHT_UNEXPECTED_ERROR] }, { code: "import(\n source)", output: "import(\n source\n)", options: ["consistent"], - errors: [RIGHT_MISSING_ERROR], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [RIGHT_MISSING_ERROR] }, // https://github.com/eslint/eslint/issues/15091#issuecomment-975605821 @@ -1494,10 +1494,10 @@ ruleTester.run("function-paren-newline", rule, { method6(3, () => {}); `, options: ["never"], - errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR], languageOptions: { parser: require(fixtureParser("function-paren-newline", "arrow-function-return-type")) - } + }, + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] } ] }); diff --git a/tests/lib/rules/getter-return.js b/tests/lib/rules/getter-return.js index 474d3d81056..189a9f87073 100644 --- a/tests/lib/rules/getter-return.js +++ b/tests/lib/rules/getter-return.js @@ -304,31 +304,31 @@ ruleTester.run("getter-return", rule, { // Optional chaining { code: "Object?.defineProperty(foo, 'bar', { get: function (){} });", - errors: [{ messageId: "expected", data: { name: "method 'get'" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "(Object?.defineProperty)(foo, 'bar', { get: function (){} });", - errors: [{ messageId: "expected", data: { name: "method 'get'" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "Object?.defineProperty(foo, 'bar', { get: function (){} });", options, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "(Object?.defineProperty)(foo, 'bar', { get: function (){} });", options, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "(Object?.create)(foo, { bar: { get: function (){} } });", options, - errors: [{ messageId: "expected", data: { name: "method 'get'" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expected", data: { name: "method 'get'" } }] } ] }); diff --git a/tests/lib/rules/grouped-accessor-pairs.js b/tests/lib/rules/grouped-accessor-pairs.js index 24db32842f9..be7ce392351 100644 --- a/tests/lib/rules/grouped-accessor-pairs.js +++ b/tests/lib/rules/grouped-accessor-pairs.js @@ -438,8 +438,8 @@ ruleTester.run("grouped-accessor-pairs", rule, { }, { code: "class A { get a(){} a; set a(foo){} }", - errors: [{ messageId: "notGrouped", data: { formerName: "getter 'a'", latterName: "setter 'a'" }, type: "MethodDefinition", column: 24 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "notGrouped", data: { formerName: "getter 'a'", latterName: "setter 'a'" }, type: "MethodDefinition", column: 24 }] }, // full location tests diff --git a/tests/lib/rules/handle-callback-err.js b/tests/lib/rules/handle-callback-err.js index c073cd3c8ee..cf2620db210 100644 --- a/tests/lib/rules/handle-callback-err.js +++ b/tests/lib/rules/handle-callback-err.js @@ -57,7 +57,7 @@ ruleTester.run("handle-callback-err", rule, { { code: "function test(err) {errorLookingWord();}", errors: [expectedFunctionDeclarationError] }, { code: "function test(err) {try{} catch(err) {}}", errors: [expectedFunctionDeclarationError] }, { code: "function test(err, callback) { foo(function(err, callback) {}); }", errors: [expectedFunctionDeclarationError, expectedFunctionExpressionError] }, - { code: "var test = (err) => {};", errors: [{ messageId: "expected" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var test = (err) => {};", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expected" }] }, { code: "var test = function(err) {};", errors: [expectedFunctionExpressionError] }, { code: "var test = function test(err, data) {};", errors: [expectedFunctionExpressionError] }, { code: "var test = function test(err) {/* if(err){} */};", errors: [expectedFunctionExpressionError] }, diff --git a/tests/lib/rules/id-blacklist.js b/tests/lib/rules/id-blacklist.js index ce61242313b..f29afcc6765 100644 --- a/tests/lib/rules/id-blacklist.js +++ b/tests/lib/rules/id-blacklist.js @@ -251,115 +251,116 @@ ruleTester.run("id-blacklist", rule, { { code: "import foo from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import * as foo from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export * as foo from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + ] }, { code: "import { foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { foo as bar } from 'mod'", options: ["bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo as bar } from 'mod'", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo as foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo, foo as bar } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo as bar, foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import foo, { foo as bar } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 8 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var foo; export { foo as bar };", options: ["bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 26 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var foo; export { foo };", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -373,12 +374,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo; export { foo as bar };", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -394,12 +395,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo; export { foo as foo };", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -419,12 +420,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 26 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo; export { foo as bar };", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -444,71 +445,70 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 26 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export { foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export { foo as bar } from 'mod'", options: ["bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo as bar } from 'mod'", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo as foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo, foo as bar } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo as bar, foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "foo.bar()", @@ -643,6 +643,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const {foo} = baz", options: ["foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -650,12 +651,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {foo: bar} = baz", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -663,12 +664,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 13 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {[foo]: bar} = baz", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -682,12 +683,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 15 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -695,12 +696,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {foo: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -714,12 +715,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 21 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {[foo]: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -739,12 +740,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 23 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ bar: baz }) {}", options: ["bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -752,12 +753,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 21 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz", "qux"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -765,12 +766,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: obj.bar} = baz);", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -778,12 +779,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -791,12 +792,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({[foo]: obj.bar} = baz);", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -810,12 +811,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: { a: obj.bar }} = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -823,12 +824,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: obj.bar = baz} = qux);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -836,12 +837,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: obj.bar.bar.baz = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -849,12 +850,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: obj[bar] = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -862,12 +863,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: [obj.bar] = baz} = qux);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -875,12 +876,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: { a: obj.bar = baz}} = qux);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -888,12 +889,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: { [a]: obj.bar }} = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -901,12 +902,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({...obj.bar} = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "restricted", @@ -914,12 +915,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 9 } + ] }, { code: "([obj.bar] = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -927,12 +928,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 7 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const [bar] = baz;", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -940,8 +941,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // not a reference to a global variable, because it isn't a reference to a variable @@ -982,30 +982,33 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = { Number() {} };", options: ["Number"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class Foo { Number() {} }", options: ["Number"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1019,16 +1022,14 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 30 } - ], - languageOptions: { - globals: { myGlobal: "readonly" } - } + ] }, // globals declared in the given source code are not excluded from consideration { code: "const foo = 1; bar = foo;", options: ["foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1042,12 +1043,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let foo; foo = bar;", options: ["foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1061,8 +1062,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "bar = foo; var foo;", @@ -1103,6 +1103,7 @@ ruleTester.run("id-blacklist", rule, { { code: "class Foo {} var bar = Foo;", options: ["Foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1116,14 +1117,14 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // redeclared globals are not excluded from consideration { code: "let undefined; undefined = 1;", options: ["undefined"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1137,8 +1138,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo = undefined; var undefined;", @@ -1179,6 +1179,7 @@ ruleTester.run("id-blacklist", rule, { { code: "class Number {} x = Number.NaN;", options: ["Number"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1192,8 +1193,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 21 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, /* @@ -1203,6 +1203,11 @@ ruleTester.run("id-blacklist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], + languageOptions: { + globals: { + window: "readonly" + } + }, errors: [ { messageId: "restricted", @@ -1210,28 +1215,23 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 31 } - ], - languageOptions: { - globals: { - window: "readonly" - } - } + ] }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], + languageOptions: { + globals: { undefined: "off" } + }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ], - languageOptions: { - globals: { undefined: "off" } - } + ] }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1260,6 +1260,7 @@ ruleTester.run("id-blacklist", rule, { { code: "if (foo) { let undefined; bar = undefined; }", options: ["undefined"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1273,8 +1274,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 33 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(Number) { var x = Number.NaN; }", @@ -1297,6 +1297,9 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1310,14 +1313,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 36 } - ], - languageOptions: { - globals: { myGlobal: "readonly" } - } + ] }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", options: ["Number"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1331,12 +1332,12 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 58 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import Number from 'myNumber'; const foo = Number.parseInt(bar);", options: ["Number"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1350,8 +1351,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 44 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo = function undefined() {};", @@ -1369,14 +1369,14 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = { undefined }", options: ["undefined"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/id-denylist.js b/tests/lib/rules/id-denylist.js index 04c5602ee85..4ffab3ea07a 100644 --- a/tests/lib/rules/id-denylist.js +++ b/tests/lib/rules/id-denylist.js @@ -265,115 +265,116 @@ ruleTester.run("id-denylist", rule, { { code: "import foo from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import * as foo from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export * as foo from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + ] }, { code: "import { foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { foo as bar } from 'mod'", options: ["bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo as bar } from 'mod'", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo as foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo, foo as bar } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { foo as bar, foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import foo, { foo as bar } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 8 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var foo; export { foo as bar };", options: ["bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 26 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var foo; export { foo };", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -387,12 +388,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo; export { foo as bar };", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -408,12 +409,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo; export { foo as foo };", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -433,12 +434,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 26 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo; export { foo as bar };", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -458,71 +459,70 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 26 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export { foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export { foo as bar } from 'mod'", options: ["bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo as bar } from 'mod'", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo as foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 17 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo, foo as bar } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 10 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo as bar, foo } from 'mod'", options: ["foo"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, type: "Identifier", column: 22 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "foo.bar()", @@ -657,6 +657,7 @@ ruleTester.run("id-denylist", rule, { { code: "const {foo} = baz", options: ["foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -664,12 +665,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {foo: bar} = baz", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -677,12 +678,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 13 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {[foo]: bar} = baz", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -696,12 +697,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 15 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -709,12 +710,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {foo: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -728,12 +729,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 21 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const {[foo]: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -753,12 +754,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 23 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ bar: baz }) {}", options: ["bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -766,12 +767,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 21 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz", "qux"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -779,12 +780,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 27 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: obj.bar} = baz);", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -792,12 +793,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar", "baz"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -805,12 +806,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({[foo]: obj.bar} = baz);", options: ["foo", "bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -824,12 +825,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: { a: obj.bar }} = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -837,12 +838,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: obj.bar = baz} = qux);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -850,12 +851,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: obj.bar.bar.baz = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -863,12 +864,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: obj[bar] = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -876,12 +877,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({a: [obj.bar] = baz} = qux);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -889,12 +890,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: { a: obj.bar = baz}} = qux);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -902,12 +903,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({foo: { [a]: obj.bar }} = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -915,12 +916,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 19 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({...obj.bar} = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "restricted", @@ -928,12 +929,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 9 } + ] }, { code: "([obj.bar] = baz);", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -941,12 +942,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 7 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const [bar] = baz;", options: ["bar"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -954,8 +955,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // not a reference to a global variable, because it isn't a reference to a variable @@ -996,30 +996,33 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = { Number() {} };", options: ["Number"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class Foo { Number() {} }", options: ["Number"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "Number" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1033,16 +1036,14 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 30 } - ], - languageOptions: { - globals: { myGlobal: "readonly" } - } + ] }, // globals declared in the given source code are not excluded from consideration { code: "const foo = 1; bar = foo;", options: ["foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1056,12 +1057,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let foo; foo = bar;", options: ["foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1075,8 +1076,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "bar = foo; var foo;", @@ -1117,6 +1117,7 @@ ruleTester.run("id-denylist", rule, { { code: "class Foo {} var bar = Foo;", options: ["Foo"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1130,14 +1131,14 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // redeclared globals are not excluded from consideration { code: "let undefined; undefined = 1;", options: ["undefined"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1151,8 +1152,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo = undefined; var undefined;", @@ -1193,6 +1193,7 @@ ruleTester.run("id-denylist", rule, { { code: "class Number {} x = Number.NaN;", options: ["Number"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1206,8 +1207,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 21 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, /* @@ -1217,6 +1217,11 @@ ruleTester.run("id-denylist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], + languageOptions: { + globals: { + window: "readonly" + } + }, errors: [ { messageId: "restricted", @@ -1224,28 +1229,23 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 31 } - ], - languageOptions: { - globals: { - window: "readonly" - } - } + ] }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], + languageOptions: { + globals: { undefined: "off" } + }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ], - languageOptions: { - globals: { undefined: "off" } - } + ] }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1274,6 +1274,7 @@ ruleTester.run("id-denylist", rule, { { code: "if (foo) { let undefined; bar = undefined; }", options: ["undefined"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1287,8 +1288,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 33 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(Number) { var x = Number.NaN; }", @@ -1311,6 +1311,9 @@ ruleTester.run("id-denylist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1324,14 +1327,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 36 } - ], - languageOptions: { - globals: { myGlobal: "readonly" } - } + ] }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", options: ["Number"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1345,12 +1346,12 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 58 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import Number from 'myNumber'; const foo = Number.parseInt(bar);", options: ["Number"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1364,8 +1365,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 44 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo = function undefined() {};", @@ -1383,20 +1383,21 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = { undefined }", options: ["undefined"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Class fields { code: "class C { camelCase; #camelCase; #camelCase2() {} }", options: ["camelCase"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "restricted", @@ -1408,13 +1409,13 @@ ruleTester.run("id-denylist", rule, { data: { name: "camelCase" }, type: "PrivateIdentifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { snake_case; #snake_case() {}; #snake_case2() {} }", options: ["snake_case"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "restricted", @@ -1426,8 +1427,7 @@ ruleTester.run("id-denylist", rule, { data: { name: "snake_case" }, type: "PrivateIdentifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] diff --git a/tests/lib/rules/id-length.js b/tests/lib/rules/id-length.js index a38e84862fa..5dfcb226d54 100644 --- a/tests/lib/rules/id-length.js +++ b/tests/lib/rules/id-length.js @@ -243,9 +243,9 @@ ruleTester.run("id-length", rule, { { code: "var handler = function (e) {};", errors: [tooShortError] }, { code: "for (var i=0; i < 10; i++) { console.log(i); }", errors: [tooShortError] }, { code: "var j=0; while (j > -10) { console.log(--j); }", errors: [tooShortError] }, - { code: "var [i] = arr;", errors: [tooShortError], languageOptions: { ecmaVersion: 6 } }, - { code: "var [,i,a] = arr;", errors: [tooShortError, tooShortError], languageOptions: { ecmaVersion: 6 } }, - { code: "function foo([a]) {}", errors: [tooShortError], languageOptions: { ecmaVersion: 6 } }, + { code: "var [i] = arr;", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError] }, + { code: "var [,i,a] = arr;", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError, tooShortError] }, + { code: "function foo([a]) {}", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError] }, { code: "var _$xt_$ = Foo(42)", options: [{ min: 2, max: 4 }], @@ -269,83 +269,84 @@ ruleTester.run("id-length", rule, { }, { code: "(a) => { a * a };", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(x = 0) { }", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class x { }", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class Foo { x() {} }", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(...x) { }", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({x}) { }", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({x: a}) { }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", data: { name: "a", min: 2 }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({x: a, longName}) { }", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ longName: a }) {}", options: [{ min: 3, max: 5 }], + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ prop: longName }) {};", options: [{ min: 3, max: 5 }], + languageOptions: { ecmaVersion: 6 }, errors: [ tooLongError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ a: b }) {};", options: [{ exceptions: ["a"] }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -354,8 +355,7 @@ ruleTester.run("id-length", rule, { column: 19, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var hasOwnProperty;", @@ -372,6 +372,7 @@ ruleTester.run("id-length", rule, { }, { code: "function foo({ a: { b: { c: d, e } } }) { }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -387,66 +388,66 @@ ruleTester.run("id-length", rule, { column: 32, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { x} = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { x: a} = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", data: { name: "a", min: 2 }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a: a} = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { prop: a } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { longName: a } = {};", options: [{ min: 3, max: 5 }], + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { prop: [x] } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { prop: [[x]] } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { prop: longName } = {};", options: [{ min: 3, max: 5 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooLong", @@ -455,12 +456,12 @@ ruleTester.run("id-length", rule, { column: 13, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { x: a} = {};", options: [{ exceptions: ["x"] }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -469,11 +470,11 @@ ruleTester.run("id-length", rule, { column: 10, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a: { b: { c: d } } } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -482,11 +483,11 @@ ruleTester.run("id-length", rule, { column: 20, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a: { b: { c: d, e } } } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -502,11 +503,11 @@ ruleTester.run("id-length", rule, { column: 23, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a: { b: { c, e: longName } } } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -515,11 +516,11 @@ ruleTester.run("id-length", rule, { column: 17, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a: { b: { c: d, e: longName } } } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -528,11 +529,11 @@ ruleTester.run("id-length", rule, { column: 20, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a, b: { c: d, e: longName } } = {};", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -548,25 +549,25 @@ ruleTester.run("id-length", rule, { column: 18, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "import x from 'y';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export var x = 0;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "({ a: obj.x.y.z } = {});", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -575,11 +576,11 @@ ruleTester.run("id-length", rule, { column: 15, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ prop: obj.x } = {});", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -588,13 +589,13 @@ ruleTester.run("id-length", rule, { column: 14, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var x = 1;", options: [{ properties: "never" }], errors: [tooShortError] }, { code: "var {prop: x} = foo;", options: [{ properties: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -603,16 +604,15 @@ ruleTester.run("id-length", rule, { column: 12, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = {x: prop};", options: [{ properties: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function BEFORE_send() {};", @@ -639,199 +639,199 @@ ruleTester.run("id-length", rule, { // Class Fields { code: "class Foo { #x() {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ tooShortErrorPrivate - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class Foo { x = 1 }", + languageOptions: { ecmaVersion: 2022 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class Foo { #x = 1 }", + languageOptions: { ecmaVersion: 2022 }, errors: [ tooShortErrorPrivate - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class Foo { #abcdefg() {} }", options: [{ max: 3 }], + languageOptions: { ecmaVersion: 2022 }, errors: [ tooLongErrorPrivate - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class Foo { abcdefg = 1 }", options: [{ max: 3 }], + languageOptions: { ecmaVersion: 2022 }, errors: [ tooLongError - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class Foo { #abcdefg = 1 }", options: [{ max: 3 }], + languageOptions: { ecmaVersion: 2022 }, errors: [ tooLongErrorPrivate - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // Identifier consisting of two code units { code: "var 𠮟 = 2", + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var 葛󠄀 = 2", // 2 code points but only 1 grapheme + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var myObj = { 𐌘: 1 };", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "(𐌘) => { 𐌘 * 𐌘 };", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "class 𠮟 { }", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "class Foo { 𐌘() {} }", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "class Foo1 { #𐌘() {} }", - errors: [ - tooShortErrorPrivate - ], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [ + tooShortErrorPrivate + ] }, { code: "class Foo2 { 𐌘 = 1 }", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [ + tooShortError + ] }, { code: "class Foo3 { #𐌘 = 1 }", - errors: [ - tooShortErrorPrivate - ], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [ + tooShortErrorPrivate + ] }, { code: "function foo1(...𐌘) { }", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "function foo([𐌘]) { }", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "var [ 𐌘 ] = arr;", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "var { prop: [𐌘]} = {};", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "function foo({𐌘}) { }", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "var { 𐌘 } = {};", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "var { prop: 𐌘} = {};", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] }, { code: "({ prop: obj.𐌘 } = {});", - errors: [ - tooShortError - ], languageOptions: { ecmaVersion: 6 - } + }, + errors: [ + tooShortError + ] } ] }); diff --git a/tests/lib/rules/id-match.js b/tests/lib/rules/id-match.js index 036b24c03c7..7d4cec1b851 100644 --- a/tests/lib/rules/id-match.js +++ b/tests/lib/rules/id-match.js @@ -407,13 +407,13 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_alias' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { category_id: category_alias } = query;", @@ -421,13 +421,13 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_alias' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { category_id: categoryId, ...other_props } = query;", @@ -435,199 +435,200 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "Identifier 'other_props' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var { category_id } = query;", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_id' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { category_id = 1 } = query;", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_id' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "import no_camelcased from \"external-module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import * as no_camelcased from \"external-module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export * as no_camelcased from \"external-module\";", options: ["^[^_]+$"], + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + ] }, { code: "import { no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { no_camelcased as no_camel_cased } from \"external module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camel_cased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { camelCased as no_camel_cased } from \"external module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camel_cased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { camelCased, no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'another_no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import camelCased, { no_camelcased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "function foo({ no_camelcased }) {};", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ no_camelcased = 'default value' }) {};", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased }) {}", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -637,73 +638,72 @@ ruleTester.run("id-match", rule, { message: "Identifier 'camelcased_value' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { bar: no_camelcased } = foo;", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ value_1: my_default }) {}", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'my_default' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo({ isCamelcased: no_camelcased }) {};", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { foo: bar_baz = 1 } = quz;", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'bar_baz' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { no_camelcased = false } = bar;", options: ["^[^_]+$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // https://github.com/eslint/eslint/issues/15395 @@ -723,6 +723,7 @@ ruleTester.run("id-match", rule, { options: ["^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$", { properties: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'foo_variable' does not match the pattern '^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$'.", @@ -772,32 +773,31 @@ ruleTester.run("id-match", rule, { line: 11, column: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Class Methods { code: "class x { _foo() {} }", options: ["^[^_]+$"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '_foo' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class x { #_foo() {} }", options: ["^[^_]+$"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '#_foo' does not match the pattern '^[^_]+$'.", type: "PrivateIdentifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // Class Fields @@ -806,26 +806,26 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { classFields: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '_foo' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class x { #_foo = 1; }", options: ["^[^_]+$", { classFields: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '#_foo' does not match the pattern '^[^_]+$'.", type: "PrivateIdentifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // https://github.com/eslint/eslint/issues/15123 @@ -841,6 +841,7 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.", @@ -850,8 +851,7 @@ ruleTester.run("id-match", rule, { message: "Identifier 'bar_one' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: ` @@ -865,6 +865,7 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.", @@ -874,8 +875,7 @@ ruleTester.run("id-match", rule, { message: "Identifier 'bar_one' does not match the pattern '^[^_]+$'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: ` @@ -887,13 +887,13 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'a' does not match the pattern '^[^a]'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // https://github.com/eslint/eslint/issues/15443 @@ -907,13 +907,13 @@ ruleTester.run("id-match", rule, { properties: false, onlyDeclarations: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'a' does not match the pattern '^[^a]'.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/implicit-arrow-linebreak.js b/tests/lib/rules/implicit-arrow-linebreak.js index e92000dc873..7f081197853 100644 --- a/tests/lib/rules/implicit-arrow-linebreak.js +++ b/tests/lib/rules/implicit-arrow-linebreak.js @@ -399,8 +399,8 @@ ruleTester.run("implicit-arrow-linebreak", rule, { 'string' `, output: null, - errors: [UNEXPECTED_LINEBREAK], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [UNEXPECTED_LINEBREAK] }, { code: unIndent` async foo => @@ -409,8 +409,8 @@ ruleTester.run("implicit-arrow-linebreak", rule, { bar; `, output: null, - errors: [UNEXPECTED_LINEBREAK], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [UNEXPECTED_LINEBREAK] }, { code: unIndent` async (foo) => @@ -418,8 +418,8 @@ ruleTester.run("implicit-arrow-linebreak", rule, { 'string' `, output: null, - errors: [UNEXPECTED_LINEBREAK], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [UNEXPECTED_LINEBREAK] }, { code: unIndent` const foo = 1, diff --git a/tests/lib/rules/indent-legacy.js b/tests/lib/rules/indent-legacy.js index d60ad53e5f7..923d3e08399 100644 --- a/tests/lib/rules/indent-legacy.js +++ b/tests/lib/rules/indent-legacy.js @@ -2281,10 +2281,10 @@ ruleTester.run("indent-legacy", rule, { " .bar\n" + "}", options: [4, { MemberExpression: 2 }], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors( [3, 12, 13, "Punctuator"] - ), - languageOptions: { ecmaVersion: 6 } + ) }, { code: @@ -2302,12 +2302,12 @@ ruleTester.run("indent-legacy", rule, { " });\n" + "};", options: [2, { MemberExpression: 1 }], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors( [ [3, 4, 6, "Punctuator"] ] - ), - languageOptions: { ecmaVersion: 6 } + ) }, { code: @@ -2437,11 +2437,11 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + "});\n", options: [4], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 2, "ExpressionStatement"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: @@ -2454,11 +2454,11 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 2, "ReturnStatement"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: @@ -2471,8 +2471,8 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - errors: expectedErrors([[2, 4, 0, "Identifier"]]), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedErrors([[2, 4, 0, "Identifier"]]) }, { code: @@ -2484,10 +2484,10 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + "});\n", options: [4], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "ExpressionStatement"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: @@ -2499,10 +2499,10 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "ReturnStatement"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: @@ -2576,13 +2576,13 @@ ruleTester.run("indent-legacy", rule, { " 'c'\n" + "];", options: [4], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 9, "Literal"], [3, 4, 9, "Literal"], [4, 4, 9, "Literal"], [5, 0, 2, "ArrayExpression"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: "while (1 < 2)\nconsole.log('foo')\n console.log('bar')", @@ -2698,10 +2698,10 @@ ruleTester.run("indent-legacy", rule, { "let geometry,\n" + " rotate;", options: [2, { VariableDeclarator: 2 }], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "VariableDeclarator"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: @@ -2765,11 +2765,11 @@ ruleTester.run("indent-legacy", rule, { " b\n" + "]", options: [2, { VariableDeclarator: { let: 2 }, SwitchCase: 1 }], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 2, 4, "Identifier"], [3, 2, 4, "Identifier"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: @@ -2808,12 +2808,12 @@ ruleTester.run("indent-legacy", rule, { " }),\n" + " d = 4;\n", options: [2, { VariableDeclarator: { var: 2 } }], + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [6, 4, 6, "Property"], [7, 2, 4, "ObjectExpression"], [8, 2, 4, "VariableDeclarator"] - ]), - languageOptions: { ecmaVersion: 6 } + ]) }, { code: @@ -2902,8 +2902,8 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "}", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - errors: expectedErrors([[2, 4, 2, "MethodDefinition"]]), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedErrors([[2, 4, 2, "MethodDefinition"]]) }, { code: @@ -2919,8 +2919,8 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "};", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - errors: expectedErrors([[2, 4, 2, "MethodDefinition"], [4, 4, 2, "MethodDefinition"]]), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedErrors([[2, 4, 2, "MethodDefinition"], [4, 4, 2, "MethodDefinition"]]) }, { code: @@ -2938,8 +2938,8 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + " };", options: [2, { VariableDeclarator: 2, SwitchCase: 1 }], - errors: expectedErrors([[3, 6, 4, "MethodDefinition"]]), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedErrors([[3, 6, 4, "MethodDefinition"]]) }, { code: @@ -3686,8 +3686,8 @@ ruleTester.run("indent-legacy", rule, { "return (\n" + " foo\n" + ");", - errors: expectedErrors([3, 0, 4, "ReturnStatement"]), - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: expectedErrors([3, 0, 4, "ReturnStatement"]) }, { code: @@ -3698,8 +3698,8 @@ ruleTester.run("indent-legacy", rule, { "return (\n" + " foo\n" + ")", - errors: expectedErrors([3, 0, 4, "ReturnStatement"]), - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: expectedErrors([3, 0, 4, "ReturnStatement"]) }, // https://github.com/eslint/eslint/issues/7604 diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index c9a05485197..6f5ca1fae38 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -8816,8 +8816,8 @@ ruleTester.run("indent", rule, { foo ); `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { code: unIndent` @@ -8830,8 +8830,8 @@ ruleTester.run("indent", rule, { foo ) `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, // https://github.com/eslint/eslint/issues/7604 @@ -9309,8 +9309,8 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 2, "Identifier"]]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 2, "Identifier"]]) }, { code: unIndent` @@ -9326,8 +9326,8 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [4, { ImportDeclaration: "first" }], - errors: expectedErrors([[3, 9, 10, "Identifier"]]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([[3, 9, 10, "Identifier"]]) }, { code: unIndent` @@ -9343,8 +9343,8 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [2, { ImportDeclaration: 2 }], - errors: expectedErrors([[3, 4, 5, "Identifier"]]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([[3, 4, 5, "Identifier"]]) }, { code: unIndent` @@ -9363,8 +9363,8 @@ ruleTester.run("indent", rule, { baz }; `, - errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]) }, { code: unIndent` @@ -9383,8 +9383,8 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]) }, { @@ -9821,8 +9821,8 @@ ruleTester.run("indent", rule, { baz } `, - errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 8, "Identifier"], [5, 4, 2, "Identifier"]]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 8, "Identifier"], [5, 4, 2, "Identifier"]]) }, { code: unIndent` @@ -10193,8 +10193,8 @@ ruleTester.run("indent", rule, { import {foo} from 'bar'; `, - errors: expectedErrors([2, 4, 0, "Identifier"]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([2, 4, 0, "Identifier"]) }, { code: unIndent` @@ -10205,8 +10205,8 @@ ruleTester.run("indent", rule, { export {foo} from 'bar'; `, - errors: expectedErrors([2, 4, 0, "Identifier"]), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedErrors([2, 4, 0, "Identifier"]) }, { code: unIndent` @@ -10423,8 +10423,8 @@ ruleTester.run("indent", rule, { } } `, - errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]), - languageOptions: { parser: require(parser("unknown-nodes/namespace-invalid")) } + languageOptions: { parser: require(parser("unknown-nodes/namespace-invalid")) }, + errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]) }, { code: unIndent` @@ -10455,8 +10455,8 @@ ruleTester.run("indent", rule, { } } `, - errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]), - languageOptions: { parser: require(parser("unknown-nodes/abstract-class-invalid")) } + languageOptions: { parser: require(parser("unknown-nodes/abstract-class-invalid")) }, + errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]) }, { code: unIndent` @@ -10485,14 +10485,14 @@ ruleTester.run("indent", rule, { } } `, + languageOptions: { parser: require(parser("unknown-nodes/functions-with-abstract-class-invalid")) }, errors: expectedErrors([ [4, 12, 8, "Keyword"], [5, 16, 8, "Keyword"], [6, 20, 8, "Identifier"], [7, 16, 8, "Punctuator"], [8, 12, 8, "Punctuator"] - ]), - languageOptions: { parser: require(parser("unknown-nodes/functions-with-abstract-class-invalid")) } + ]) }, { code: unIndent` @@ -10525,11 +10525,11 @@ ruleTester.run("indent", rule, { } } `, + languageOptions: { parser: require(parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid")) }, errors: expectedErrors([ [3, 8, 4, "Keyword"], [7, 24, 20, "Identifier"] - ]), - languageOptions: { parser: require(parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid")) } + ]) }, //---------------------------------------------------------------------- @@ -11330,8 +11330,8 @@ ruleTester.run("indent", rule, { foo }: bar) => baz `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation") } + languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation") }, + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { code: unIndent` @@ -11344,8 +11344,8 @@ ruleTester.run("indent", rule, { foo ]: bar) => baz `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation") } + languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation") }, + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { code: unIndent` @@ -11358,8 +11358,8 @@ ruleTester.run("indent", rule, { foo }: {}) => baz `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation") } + languageOptions: { parser: require("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation") }, + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { code: unIndent` @@ -11852,11 +11852,11 @@ ruleTester.run("indent", rule, { source ) `, + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 0, 4, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2020 } + ]) }, // https://github.com/eslint/eslint/issues/12122 @@ -11883,10 +11883,10 @@ ruleTester.run("indent", rule, { }); }); `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 4, "Identifier"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -11911,12 +11911,12 @@ ruleTester.run("indent", rule, { }); } `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 8, "Identifier"], [7, 8, 12, "Identifier"], [8, 4, 8, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -11957,12 +11957,12 @@ ruleTester.run("indent", rule, { }); }); `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 12, "Identifier"], [15, 8, 12, "Identifier"], [16, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12003,12 +12003,12 @@ ruleTester.run("indent", rule, { }); } `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 12, "Identifier"], [15, 8, 12, "Identifier"], [16, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12043,11 +12043,11 @@ ruleTester.run("indent", rule, { }); }); `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 4, 0, "Identifier"], [11, 8, 4, "Identifier"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12076,12 +12076,12 @@ ruleTester.run("indent", rule, { }) }); `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [4, 4, 8, "Identifier"], [5, 4, 0, "Identifier"], [9, 8, 0, "Identifier"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12094,10 +12094,10 @@ ruleTester.run("indent", rule, { baz(); }) `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 8, "Identifier"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12110,11 +12110,11 @@ ruleTester.run("indent", rule, { baz(); }) `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 0, 4, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12131,10 +12131,10 @@ ruleTester.run("indent", rule, { baz(); }) `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12153,10 +12153,10 @@ ruleTester.run("indent", rule, { bar(); }) `, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 8, 0, "Identifier"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, { code: unIndent` @@ -12176,12 +12176,12 @@ ruleTester.run("indent", rule, { }) `, options: [4, { MemberExpression: 0 }], + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 0, 4, "Punctuator"], [5, 4, 0, "Identifier"], [6, 0, 4, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2015 } + ]) }, // Optional chaining @@ -12201,13 +12201,13 @@ ruleTester.run("indent", rule, { [key] `, options: [4], + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 4, 0, "Punctuator"], [4, 4, 0, "Punctuator"], [5, 8, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2020 } + ]) }, { code: unIndent` @@ -12229,11 +12229,11 @@ ruleTester.run("indent", rule, { ?.[key] `, options: [4], + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [6, 4, 0, "Punctuator"], [7, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2020 } + ]) }, { code: unIndent` @@ -12249,12 +12249,12 @@ ruleTester.run("indent", rule, { (arg) `, options: [4], + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 4, 0, "Punctuator"], [4, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2020 } + ]) }, { code: unIndent` @@ -12276,11 +12276,11 @@ ruleTester.run("indent", rule, { ?.(arg) `, options: [4], + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [6, 4, 0, "Punctuator"], [7, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2020 } + ]) }, { code: unIndent` @@ -12298,10 +12298,10 @@ ruleTester.run("indent", rule, { } `, options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }], + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 19, 20, "Identifier"] - ]), - languageOptions: { ecmaVersion: 2020 } + ]) }, { code: unIndent` @@ -12331,11 +12331,11 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 0, "Keyword"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12365,6 +12365,7 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 8, 0, "Punctuator"], @@ -12375,8 +12376,7 @@ ruleTester.run("indent", rule, { [8, 12, 0, "Punctuator"], [9, 16, 0, "Numeric"], [10, 16, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12426,6 +12426,7 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 8, 0, "Identifier"], @@ -12446,8 +12447,7 @@ ruleTester.run("indent", rule, { [18, 8, 0, "Numeric"], [19, 4, 0, "Punctuator"], [20, 8, 0, "Numeric"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12467,12 +12467,12 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 8, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12492,13 +12492,13 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "PrivateIdentifier"], [3, 4, 0, "Identifier"], [4, 8, 0, "Keyword"], [5, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12518,13 +12518,13 @@ ruleTester.run("indent", rule, { } `, options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 2, 0, "Keyword"], [3, 4, 0, "Identifier"], [4, 4, 0, "Identifier"], [5, 2, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12544,13 +12544,13 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Identifier"], [4, 8, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12570,13 +12570,13 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 8, "Keyword"], [3, 8, 4, "Identifier"], [4, 8, 0, "Identifier"], [5, 4, 8, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12596,13 +12596,13 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 2 } }], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 12, 0, "Identifier"], [4, 12, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12622,13 +12622,13 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 0 } }], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Identifier"], [4, 4, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12648,13 +12648,13 @@ ruleTester.run("indent", rule, { } `, options: ["tab"], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors("tab", [ [2, 1, 0, "Keyword"], [3, 2, 0, "Identifier"], [4, 2, 0, "Identifier"], [5, 1, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12674,13 +12674,13 @@ ruleTester.run("indent", rule, { } `, options: ["tab", { StaticBlock: { body: 2 } }], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors("tab", [ [2, 1, 0, "Keyword"], [3, 3, 0, "Identifier"], [4, 3, 0, "Identifier"], [5, 1, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12702,14 +12702,14 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Punctuator"], [4, 8, 0, "Identifier"], [5, 8, 0, "Identifier"], [6, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12731,11 +12731,11 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 8, "Punctuator"], [6, 4, 8, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12755,13 +12755,13 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], [4, 12, 0, "Identifier"], [5, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12783,14 +12783,14 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Punctuator"], [4, 8, 0, "Keyword"], [5, 12, 0, "Identifier"], [6, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12812,14 +12812,14 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], [4, 12, 0, "Identifier"], [5, 8, 0, "Punctuator"], [6, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12841,14 +12841,14 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Punctuator"], [4, 12, 0, "Identifier"], [5, 8, 0, "Punctuator"], [6, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12876,6 +12876,7 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [4, 4, 0, "Keyword"], @@ -12883,8 +12884,7 @@ ruleTester.run("indent", rule, { [7, 4, 0, "Keyword"], [8, 4, 0, "Punctuator"], [9, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12914,6 +12914,7 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Keyword"], [4, 8, 4, "Identifier"], @@ -12921,8 +12922,7 @@ ruleTester.run("indent", rule, { [7, 4, 0, "Keyword"], [8, 8, 4, "Identifier"], [9, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12952,14 +12952,14 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Identifier"], [5, 4, 0, "Keyword"], [6, 8, 4, "Identifier"], [7, 4, 0, "Punctuator"], [9, 4, 0, "Identifier"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -12997,6 +12997,7 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Identifier"], [4, 8, 4, "Identifier"], @@ -13007,8 +13008,7 @@ ruleTester.run("indent", rule, { [11, 4, 0, "Identifier"], [12, 8, 4, "Identifier"], [13, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -13032,6 +13032,7 @@ ruleTester.run("indent", rule, { } `, options: [4], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], @@ -13039,8 +13040,7 @@ ruleTester.run("indent", rule, { [5, 12, 0, "Identifier"], [6, 8, 0, "Punctuator"], [7, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, { code: unIndent` @@ -13064,6 +13064,7 @@ ruleTester.run("indent", rule, { } `, options: [4, { FunctionExpression: { body: 2 }, StaticBlock: { body: 2 } }], + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 12, 0, "Identifier"], @@ -13071,8 +13072,7 @@ ruleTester.run("indent", rule, { [5, 4, 0, "Keyword"], [6, 12, 0, "Identifier"], [7, 4, 0, "Punctuator"] - ]), - languageOptions: { ecmaVersion: 2022 } + ]) }, // https://github.com/eslint/eslint/issues/15930 diff --git a/tests/lib/rules/init-declarations.js b/tests/lib/rules/init-declarations.js index 2c860ddb9a2..40e30269056 100644 --- a/tests/lib/rules/init-declarations.js +++ b/tests/lib/rules/init-declarations.js @@ -134,6 +134,7 @@ ruleTester.run("init-declarations", rule, { { code: "var foo, bar = false, baz;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -145,60 +146,60 @@ ruleTester.run("init-declarations", rule, { data: { idName: "baz" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { var foo = 0; var bar; }", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "bar" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { var foo; var bar = foo; }", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let a;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "a" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { let a = 1, b; if (a) { let c = 3, d = null; } }", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", data: { idName: "b" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { let a; const b = false; var c; }", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -210,36 +211,36 @@ ruleTester.run("init-declarations", rule, { data: { idName: "c" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = bar = 2;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = true;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo, bar = 5, baz = 3;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -251,12 +252,12 @@ ruleTester.run("init-declarations", rule, { data: { idName: "baz" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { var foo; var bar = foo; }", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -264,44 +265,43 @@ ruleTester.run("init-declarations", rule, { type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let a = 1;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "a" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { let a = 'foo', b; if (a) { let c, d; } }", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "a" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { let a; const b = false; var c = 1; }", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "c" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for(var i = 0; i < 1; i++){}", @@ -328,14 +328,14 @@ ruleTester.run("init-declarations", rule, { { code: "for (var foo of []) {}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", data: { idName: "foo" }, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/key-spacing.js b/tests/lib/rules/key-spacing.js index e25064842ab..e841a069552 100644 --- a/tests/lib/rules/key-spacing.js +++ b/tests/lib/rules/key-spacing.js @@ -587,8 +587,8 @@ ruleTester.run("key-spacing", rule, { afterColon: false } }], - errors: [], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [] }, { code: [ "({", @@ -1191,8 +1191,8 @@ ruleTester.run("key-spacing", rule, { code: "var obj = { [ (a + b) ]:value };", output: "var obj = { [ (a + b) ]: value };", options: [{}], - errors: [{ messageId: "missingValue", data: { computed: "computed ", key: "a + b" }, type: "Identifier", line: 1, column: 25 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "missingValue", data: { computed: "computed ", key: "a + b" }, type: "Identifier", line: 1, column: 25 }] }, { code: "fn({ foo:bar, 'key' :value });", output: "fn({ foo:bar, 'key':value });", @@ -1310,13 +1310,13 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "a" }, type: "CallExpression", line: 2, column: 6 }, { messageId: "extraKey", data: { computed: "", key: "b" }, type: "Literal", line: 3, column: 8 }, { messageId: "missingValue", data: { computed: "", key: "foo" }, type: "Identifier", line: 4, column: 9 }, { messageId: "extraKey", data: { computed: "computed ", key: "a" }, type: "Identifier", line: 6, column: 8 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "foo = {", @@ -1506,10 +1506,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "var obj = {", @@ -1526,10 +1526,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 11, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "var obj = {", @@ -1546,10 +1546,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "var obj = {", @@ -1566,10 +1566,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 11, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "var obj = {", @@ -1594,10 +1594,10 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "baz" }, line: 6, column: 8, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "var obj = {", @@ -1742,11 +1742,11 @@ ruleTester.run("key-spacing", rule, { "})" ].join("\n"), options: [{ align: "colon" }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 5, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "f" }, line: 12, column: 6, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // https://github.com/eslint/eslint/issues/4792 @@ -1960,11 +1960,11 @@ ruleTester.run("key-spacing", rule, { code: "({ a:b, ...object, c : d })", output: "({ a: b, ...object, c: d })", options: [{ align: "colon" }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "a" }, line: 1, column: 6, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "c" }, line: 1, column: 21, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // https://github.com/eslint/eslint/issues/5613 @@ -1991,13 +1991,13 @@ ruleTester.run("key-spacing", rule, { mode: "strict" } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingKey", data: { computed: "", key: "longName" }, line: 2, column: 5, type: "Identifier" }, { messageId: "missingValue", data: { computed: "", key: "longName" }, line: 2, column: 14, type: "Literal" }, { messageId: "missingValue", data: { computed: "", key: "small" }, line: 3, column: 15, type: "Literal" }, { messageId: "missingKey", data: { computed: "", key: "xs" }, line: 4, column: 5, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "({", @@ -2039,14 +2039,14 @@ ruleTester.run("key-spacing", rule, { mode: "strict" } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "func" }, line: 2, column: 10, type: "FunctionExpression" }, { messageId: "missingKey", data: { computed: "", key: "longName" }, line: 5, column: 5, type: "Identifier" }, { messageId: "missingKey", data: { computed: "", key: "small" }, line: 6, column: 5, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "xs" }, line: 7, column: 7, type: "Identifier" }, { messageId: "extraKey", data: { computed: "", key: "singleLine" }, line: 11, column: 15, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "({", @@ -2088,6 +2088,7 @@ ruleTester.run("key-spacing", rule, { } } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "func" }, line: 2, column: 10, type: "FunctionExpression" }, { messageId: "missingKey", data: { computed: "", key: "small" }, line: 6, column: 5, type: "Identifier" }, @@ -2095,8 +2096,7 @@ ruleTester.run("key-spacing", rule, { { messageId: "extraValue", data: { computed: "", key: "xs" }, line: 7, column: 19, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "func2" }, line: 8, column: 14, type: "FunctionExpression" }, { messageId: "extraKey", data: { computed: "", key: "singleLine" }, line: 11, column: 15, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "var obj = {", @@ -2130,11 +2130,11 @@ ruleTester.run("key-spacing", rule, { } } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "key2" }, line: 4, column: 9, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "key3" }, line: 5, column: 9, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ "var obj = {", @@ -2168,11 +2168,11 @@ ruleTester.run("key-spacing", rule, { on: "colon" } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "key2" }, line: 4, column: 9, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "key3" }, line: 5, column: 9, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { // https://github.com/eslint/eslint/issues/7603 @@ -2413,10 +2413,10 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "a" }, line: 3, column: 22, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2436,10 +2436,10 @@ ruleTester.run("key-spacing", rule, { on: "colon" } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 17, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2459,10 +2459,10 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "a" }, line: 3, column: 20, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2518,12 +2518,12 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "id" }, line: 4, column: 19, type: "Literal" }, { messageId: "extraValue", data: { computed: "", key: "code" }, line: 5, column: 21, type: "Literal" }, { messageId: "extraValue", data: { computed: "computed ", key: "n" }, line: 6, column: 20, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js index df33ef87dee..c179a8b22cc 100644 --- a/tests/lib/rules/keyword-spacing.js +++ b/tests/lib/rules/keyword-spacing.js @@ -1527,118 +1527,119 @@ ruleTester.run("keyword-spacing", rule, { { code: "import { \"a\"as b } from \"foo\"", output: "import { \"a\" as b } from \"foo\"", - errors: expectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBefore("as") }, { code: "import{ \"a\" as b }from\"foo\"", output: "import{ \"a\"as b }from\"foo\"", options: [NEITHER], - errors: unexpectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBefore("as") }, { code: "import{ \"a\"as b }from\"foo\"", output: "import{ \"a\" as b }from\"foo\"", options: [override("as", BOTH)], - errors: expectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBefore("as") }, { code: "import { \"a\" as b } from \"foo\"", output: "import { \"a\"as b } from \"foo\"", options: [override("as", NEITHER)], - errors: unexpectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBefore("as") }, // export { a as b } { code: "let a; export { a as\"b\" };", output: "let a; export { a as \"b\" };", - errors: expectedAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedAfter("as") }, { code: "export { \"a\"as b } from \"foo\";", output: "export { \"a\" as b } from \"foo\";", - errors: expectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBefore("as") }, { code: "export { \"a\"as\"b\" } from \"foo\";", output: "export { \"a\" as \"b\" } from \"foo\";", - errors: expectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBeforeAndAfter("as") }, { code: "let a; export{ a as \"b\" };", output: "let a; export{ a as\"b\" };", options: [NEITHER], - errors: unexpectedAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedAfter("as") }, { code: "export{ \"a\" as b }from\"foo\";", output: "export{ \"a\"as b }from\"foo\";", options: [NEITHER], - errors: unexpectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBefore("as") }, { code: "export{ \"a\" as \"b\" }from\"foo\";", output: "export{ \"a\"as\"b\" }from\"foo\";", options: [NEITHER], - errors: unexpectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("as") }, { code: "let a; export{ a as\"b\" };", output: "let a; export{ a as \"b\" };", options: [override("as", BOTH)], - errors: expectedAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedAfter("as") }, { code: "export{ \"a\"as b }from\"foo\";", output: "export{ \"a\" as b }from\"foo\";", options: [override("as", BOTH)], - errors: expectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBefore("as") }, { code: "export{ \"a\"as\"b\" }from\"foo\";", output: "export{ \"a\" as \"b\" }from\"foo\";", options: [override("as", BOTH)], - errors: expectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBeforeAndAfter("as") }, { code: "let a; export { a as \"b\" };", output: "let a; export { a as\"b\" };", options: [override("as", NEITHER)], - errors: unexpectedAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedAfter("as") }, { code: "export { \"a\" as b } from \"foo\";", output: "export { \"a\"as b } from \"foo\";", options: [override("as", NEITHER)], - errors: unexpectedBefore("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBefore("as") }, { code: "export { \"a\" as \"b\" } from \"foo\";", output: "export { \"a\"as\"b\" } from \"foo\";", options: [override("as", NEITHER)], - errors: unexpectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("as") }, // import * as a { code: "import *as a from \"foo\"", output: "import * as a from \"foo\"", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBefore", data: { value: "as" }, @@ -1646,13 +1647,13 @@ ruleTester.run("keyword-spacing", rule, { column: 9, endLine: 1, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import* as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBefore", data: { value: "as" }, @@ -1660,13 +1661,13 @@ ruleTester.run("keyword-spacing", rule, { column: 8, endLine: 1, endColumn: 9 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import* as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBefore", data: { value: "as" }, @@ -1674,78 +1675,77 @@ ruleTester.run("keyword-spacing", rule, { column: 8, endLine: 1, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import*as a from\"foo\"", output: "import* as a from\"foo\"", options: [override("as", BOTH)], - errors: expectedBefore("as"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBefore("as") }, { code: "import * as a from \"foo\"", output: "import *as a from \"foo\"", options: [override("as", NEITHER)], - errors: unexpectedBefore("as"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBefore("as") }, // export * as a { code: "export *as a from \"foo\"", output: "export * as a from \"foo\"", - errors: expectedBefore("as"), - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, + errors: expectedBefore("as") }, { code: "export *as\"a\" from \"foo\"", output: "export * as \"a\" from \"foo\"", - errors: expectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBeforeAndAfter("as") }, { code: "export* as a from\"foo\"", output: "export*as a from\"foo\"", options: [NEITHER], - errors: unexpectedBefore("as"), - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, + errors: unexpectedBefore("as") }, { code: "export* as \"a\"from\"foo\"", output: "export*as\"a\"from\"foo\"", options: [NEITHER], - errors: unexpectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("as") }, { code: "export*as a from\"foo\"", output: "export* as a from\"foo\"", options: [override("as", BOTH)], - errors: expectedBefore("as"), - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, + errors: expectedBefore("as") }, { code: "export*as\"a\"from\"foo\"", output: "export* as \"a\"from\"foo\"", options: [override("as", BOTH)], - errors: expectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBeforeAndAfter("as") }, { code: "export * as a from \"foo\"", output: "export *as a from \"foo\"", options: [override("as", NEITHER)], - errors: unexpectedBefore("as"), - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, + errors: unexpectedBefore("as") }, { code: "export * as \"a\" from \"foo\"", output: "export *as\"a\" from \"foo\"", options: [override("as", NEITHER)], - errors: unexpectedBeforeAndAfter("as"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("as") }, //---------------------------------------------------------------------- @@ -1755,110 +1755,110 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}async function foo() {}", output: "{} async function foo() {}", - errors: expectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBefore("async") }, { code: "{} async function foo() {}", output: "{}async function foo() {}", options: [NEITHER], - errors: unexpectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore("async") }, { code: "{}async function foo() {}", output: "{} async function foo() {}", options: [override("async", BOTH)], - errors: expectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBefore("async") }, { code: "{} async function foo() {}", output: "{}async function foo() {}", options: [override("async", NEITHER)], - errors: unexpectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore("async") }, { code: "{}async () => {}", output: "{} async () => {}", - errors: expectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBefore("async") }, { code: "{} async () => {}", output: "{}async () => {}", options: [NEITHER], - errors: unexpectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore("async") }, { code: "{}async () => {}", output: "{} async () => {}", options: [override("async", BOTH)], - errors: expectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBefore("async") }, { code: "{} async () => {}", output: "{}async () => {}", options: [override("async", NEITHER)], - errors: unexpectedBefore("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore("async") }, { code: "({async[b]() {}})", output: "({async [b]() {}})", - errors: expectedAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedAfter("async") }, { code: "({async [b]() {}})", output: "({async[b]() {}})", options: [NEITHER], - errors: unexpectedAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedAfter("async") }, { code: "({async[b]() {}})", output: "({async [b]() {}})", options: [override("async", BOTH)], - errors: expectedAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedAfter("async") }, { code: "({async [b]() {}})", output: "({async[b]() {}})", options: [override("async", NEITHER)], - errors: unexpectedAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedAfter("async") }, { code: "class A {a(){}async[b]() {}}", output: "class A {a(){} async [b]() {}}", - errors: expectedBeforeAndAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBeforeAndAfter("async") }, { code: "class A {a(){} async [b]() {}}", output: "class A {a(){}async[b]() {}}", options: [NEITHER], - errors: unexpectedBeforeAndAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBeforeAndAfter("async") }, { code: "class A {a(){}async[b]() {}}", output: "class A {a(){} async [b]() {}}", options: [override("async", BOTH)], - errors: expectedBeforeAndAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBeforeAndAfter("async") }, { code: "class A {a(){} async [b]() {}}", output: "class A {a(){}async[b]() {}}", options: [override("async", NEITHER)], - errors: unexpectedBeforeAndAfter("async"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBeforeAndAfter("async") }, //---------------------------------------------------------------------- @@ -1868,57 +1868,57 @@ ruleTester.run("keyword-spacing", rule, { { code: "async function wrap() { {}await a }", output: "async function wrap() { {} await a }", - errors: expectedBefore("await"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBefore("await") }, { code: "async function wrap() { {} await a }", output: "async function wrap() { {}await a }", options: [NEITHER], - errors: unexpectedBefore("await"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore("await") }, { code: "async function wrap() { {}await a }", output: "async function wrap() { {} await a }", options: [override("await", BOTH)], - errors: expectedBefore("await"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: expectedBefore("await") }, { code: "async function wrap() { {} await a }", output: "async function wrap() { {}await a }", options: [override("await", NEITHER)], - errors: unexpectedBefore("await"), - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: unexpectedBefore("await") }, { code: "async function wrap() { for await(x of xs); }", output: "async function wrap() { for await (x of xs); }", - errors: expectedAfter("await"), - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: expectedAfter("await") }, { code: "async function wrap() { for await (x of xs); }", output: "async function wrap() { for await(x of xs); }", options: [NEITHER], - errors: unexpectedAfter("await"), - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: unexpectedAfter("await") }, { code: "async function wrap() { for await(x of xs); }", output: "async function wrap() { for await (x of xs); }", options: [override("await", BOTH)], - errors: expectedAfter("await"), - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: expectedAfter("await") }, { code: "async function wrap() { for await (x of xs); }", output: "async function wrap() { for await(x of xs); }", options: [override("await", NEITHER)], - errors: unexpectedAfter("await"), - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: unexpectedAfter("await") }, //---------------------------------------------------------------------- @@ -2023,42 +2023,42 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}class Bar {}", output: "{} class Bar {}", - errors: expectedBefore("class"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBefore("class") }, { code: "(class{})", output: "(class {})", - errors: expectedAfter("class"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("class") }, { code: "{} class Bar {}", output: "{}class Bar {}", options: [NEITHER], - errors: unexpectedBefore("class"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore("class") }, { code: "(class {})", output: "(class{})", options: [NEITHER], - errors: unexpectedAfter("class"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("class") }, { code: "{}class Bar {}", output: "{} class Bar {}", options: [override("class", BOTH)], - errors: expectedBefore("class"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBefore("class") }, { code: "{} class Bar {}", output: "{}class Bar {}", options: [override("class", NEITHER)], - errors: unexpectedBefore("class"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore("class") }, //---------------------------------------------------------------------- @@ -2068,56 +2068,56 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}const[a] = b", output: "{} const [a] = b", - errors: expectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("const") }, { code: "{}const{a} = b", output: "{} const {a} = b", - errors: expectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("const") }, { code: "{} const [a] = b", output: "{}const[a] = b", options: [NEITHER], - errors: unexpectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("const") }, { code: "{} const {a} = b", output: "{}const{a} = b", options: [NEITHER], - errors: unexpectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("const") }, { code: "{}const[a] = b", output: "{} const [a] = b", options: [override("const", BOTH)], - errors: expectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("const") }, { code: "{}const{a} = b", output: "{} const {a} = b", options: [override("const", BOTH)], - errors: expectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("const") }, { code: "{} const [a] = b", output: "{}const[a] = b", options: [override("const", NEITHER)], - errors: unexpectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("const") }, { code: "{} const {a} = b", output: "{}const{a} = b", options: [override("const", NEITHER)], - errors: unexpectedBeforeAndAfter("const"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("const") }, //---------------------------------------------------------------------- @@ -2373,47 +2373,47 @@ ruleTester.run("keyword-spacing", rule, { { code: "var a = 0; {}export{a}", output: "var a = 0; {} export {a}", - errors: expectedBeforeAndAfter("export"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("export") }, { code: "var a = 0; {}export default a", output: "var a = 0; {} export default a", - errors: expectedBefore("export"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBefore("export") }, { code: "var a = 0; export default{a}", output: "var a = 0; export default {a}", - errors: expectedAfter("default"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedAfter("default") }, { code: "{}export* from \"a\"", output: "{} export * from \"a\"", - errors: expectedBeforeAndAfter("export"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("export") }, { code: "var a = 0; {} export {a}", output: "var a = 0; {}export{a}", options: [NEITHER], - errors: unexpectedBeforeAndAfter("export"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("export") }, { code: "var a = 0; {}export{a}", output: "var a = 0; {} export {a}", options: [override("export", BOTH)], - errors: expectedBeforeAndAfter("export"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("export") }, { code: "var a = 0; {} export {a}", output: "var a = 0; {}export{a}", options: [override("export", NEITHER)], - errors: unexpectedBeforeAndAfter("export"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("export") }, //---------------------------------------------------------------------- @@ -2423,48 +2423,48 @@ ruleTester.run("keyword-spacing", rule, { { code: "class Bar extends[] {}", output: "class Bar extends [] {}", - errors: expectedAfter("extends"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("extends") }, { code: "(class extends[] {})", output: "(class extends [] {})", - errors: expectedAfter("extends"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("extends") }, { code: "class Bar extends [] {}", output: "class Bar extends[] {}", options: [NEITHER], - errors: unexpectedAfter("extends"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("extends") }, { code: "(class extends [] {})", output: "(class extends[] {})", options: [NEITHER], - errors: unexpectedAfter("extends"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("extends") }, { code: "class Bar extends[] {}", output: "class Bar extends [] {}", options: [override("extends", BOTH)], - errors: expectedAfter("extends"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("extends") }, { code: "class Bar extends [] {}", output: "class Bar extends[] {}", options: [override("extends", NEITHER)], - errors: unexpectedAfter("extends"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("extends") }, { code: "class Bar extends`}` {}", output: "class Bar extends `}` {}", - errors: expectedAfter("extends"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("extends") }, //---------------------------------------------------------------------- @@ -2512,8 +2512,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}for(var foo of list) {}", output: "{} for (var foo of list) {}", - errors: expectedBeforeAndAfter("for"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("for") }, { code: "{} for (;;) {}", @@ -2531,8 +2531,8 @@ ruleTester.run("keyword-spacing", rule, { code: "{} for (var foo of list) {}", output: "{}for(var foo of list) {}", options: [NEITHER], - errors: unexpectedBeforeAndAfter("for"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("for") }, { code: "{}for(;;) {}", @@ -2550,8 +2550,8 @@ ruleTester.run("keyword-spacing", rule, { code: "{}for(var foo of list) {}", output: "{} for (var foo of list) {}", options: [override("for", BOTH)], - errors: expectedBeforeAndAfter("for"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("for") }, { code: "{} for (;;) {}", @@ -2569,8 +2569,8 @@ ruleTester.run("keyword-spacing", rule, { code: "{} for (var foo of list) {}", output: "{}for(var foo of list) {}", options: [override("for", NEITHER)], - errors: unexpectedBeforeAndAfter("for"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("for") }, //---------------------------------------------------------------------- @@ -2580,124 +2580,124 @@ ruleTester.run("keyword-spacing", rule, { { code: "import {foo}from\"foo\"", output: "import {foo} from \"foo\"", - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "export {foo}from\"foo\"", output: "export {foo} from \"foo\"", - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "export *from\"foo\"", output: "export * from \"foo\"", - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "export * as \"a\"from\"foo\"", output: "export * as \"a\" from \"foo\"", - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "import{foo} from \"foo\"", output: "import{foo}from\"foo\"", options: [NEITHER], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, { code: "export{foo} from \"foo\"", output: "export{foo}from\"foo\"", options: [NEITHER], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, { code: "export* from \"foo\"", output: "export*from\"foo\"", options: [NEITHER], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, { code: "export*as x from \"foo\"", output: "export*as x from\"foo\"", options: [NEITHER], - errors: unexpectedAfter("from"), - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, + errors: unexpectedAfter("from") }, { code: "export*as\"x\" from \"foo\"", output: "export*as\"x\"from\"foo\"", options: [NEITHER], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, { code: "import{foo}from\"foo\"", output: "import{foo} from \"foo\"", options: [override("from", BOTH)], - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "export{foo}from\"foo\"", output: "export{foo} from \"foo\"", options: [override("from", BOTH)], - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "export*from\"foo\"", output: "export* from \"foo\"", options: [override("from", BOTH)], - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "export*as\"x\"from\"foo\"", output: "export*as\"x\" from \"foo\"", options: [override("from", BOTH)], - errors: expectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: expectedBeforeAndAfter("from") }, { code: "import {foo} from \"foo\"", output: "import {foo}from\"foo\"", options: [override("from", NEITHER)], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, { code: "export {foo} from \"foo\"", output: "export {foo}from\"foo\"", options: [override("from", NEITHER)], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, { code: "export * from \"foo\"", output: "export *from\"foo\"", options: [override("from", NEITHER)], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, { code: "export * as x from \"foo\"", output: "export * as x from\"foo\"", options: [override("from", NEITHER)], - errors: unexpectedAfter("from"), - languageOptions: { ecmaVersion: 2020, sourceType: "module" } + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, + errors: unexpectedAfter("from") }, { code: "export * as \"x\" from \"foo\"", output: "export * as \"x\"from\"foo\"", options: [override("from", NEITHER)], - errors: unexpectedBeforeAndAfter("from"), - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("from") }, //---------------------------------------------------------------------- @@ -2735,82 +2735,82 @@ ruleTester.run("keyword-spacing", rule, { { code: "({ get[b]() {} })", output: "({ get [b]() {} })", - errors: expectedAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("get") }, { code: "class A { a() {}get[b]() {} }", output: "class A { a() {} get [b]() {} }", - errors: expectedBeforeAndAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("get") }, { code: "class A { a() {} static get[b]() {} }", output: "class A { a() {} static get [b]() {} }", - errors: expectedAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("get") }, { code: "({ get [b]() {} })", output: "({ get[b]() {} })", options: [NEITHER], - errors: unexpectedAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("get") }, { code: "class A { a() {} get [b]() {} }", output: "class A { a() {}get[b]() {} }", options: [NEITHER], - errors: unexpectedBeforeAndAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("get") }, { code: "class A { a() {}static get [b]() {} }", output: "class A { a() {}static get[b]() {} }", options: [NEITHER], - errors: unexpectedAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("get") }, { code: "({ get[b]() {} })", output: "({ get [b]() {} })", options: [override("get", BOTH)], - errors: expectedAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("get") }, { code: "class A { a() {}get[b]() {} }", output: "class A { a() {} get [b]() {} }", options: [override("get", BOTH)], - errors: expectedBeforeAndAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("get") }, { code: "({ get [b]() {} })", output: "({ get[b]() {} })", options: [override("get", NEITHER)], - errors: unexpectedAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("get") }, { code: "class A { a() {} get [b]() {} }", output: "class A { a() {}get[b]() {} }", options: [override("get", NEITHER)], - errors: unexpectedBeforeAndAfter("get"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("get") }, { code: "class A { a;get#b() {} }", output: "class A { a;get #b() {} }", - errors: expectedAfter("get"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedAfter("get") }, { code: "class A { a; get #b() {} }", output: "class A { a; get#b() {} }", options: [NEITHER], - errors: unexpectedAfter("get"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedAfter("get") }, //---------------------------------------------------------------------- @@ -2871,6 +2871,7 @@ ruleTester.run("keyword-spacing", rule, { { code: "import* as a from \"foo\"", output: "import * as a from \"foo\"", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedAfter", data: { value: "import" }, @@ -2878,13 +2879,13 @@ ruleTester.run("keyword-spacing", rule, { column: 1, endLine: 1, endColumn: 7 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import *as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedAfter", data: { value: "import" }, @@ -2892,13 +2893,13 @@ ruleTester.run("keyword-spacing", rule, { column: 7, endLine: 1, endColumn: 8 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import *as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedAfter", data: { value: "import" }, @@ -2906,68 +2907,67 @@ ruleTester.run("keyword-spacing", rule, { column: 7, endLine: 1, endColumn: 10 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "{}import{a} from \"foo\"", output: "{} import {a} from \"foo\"", - errors: expectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("import") }, { code: "{}import a from \"foo\"", output: "{} import a from \"foo\"", - errors: expectedBefore("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBefore("import") }, { code: "{}import* as a from \"a\"", output: "{} import * as a from \"a\"", - errors: expectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("import") }, { code: "{} import {a}from\"foo\"", output: "{}import{a}from\"foo\"", options: [NEITHER], - errors: unexpectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("import") }, { code: "{} import *as a from\"foo\"", output: "{}import*as a from\"foo\"", options: [NEITHER], - errors: unexpectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("import") }, { code: "{}import{a}from\"foo\"", output: "{} import {a}from\"foo\"", options: [override("import", BOTH)], - errors: expectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("import") }, { code: "{}import*as a from\"foo\"", output: "{} import *as a from\"foo\"", options: [override("import", BOTH)], - errors: expectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: expectedBeforeAndAfter("import") }, { code: "{} import {a} from \"foo\"", output: "{}import{a} from \"foo\"", options: [override("import", NEITHER)], - errors: unexpectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("import") }, { code: "{} import * as a from \"foo\"", output: "{}import* as a from \"foo\"", options: [override("import", NEITHER)], - errors: unexpectedBeforeAndAfter("import"), - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: unexpectedBeforeAndAfter("import") }, //---------------------------------------------------------------------- @@ -2977,29 +2977,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "for ([foo]in{foo: 0}) {}", output: "for ([foo] in {foo: 0}) {}", - errors: expectedBeforeAndAfter("in"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("in") }, { code: "for([foo] in {foo: 0}) {}", output: "for([foo]in{foo: 0}) {}", options: [NEITHER], - errors: unexpectedBeforeAndAfter("in"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("in") }, { code: "for([foo]in{foo: 0}) {}", output: "for([foo] in {foo: 0}) {}", options: [override("in", BOTH)], - errors: expectedBeforeAndAfter("in"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("in") }, { code: "for ([foo] in {foo: 0}) {}", output: "for ([foo]in{foo: 0}) {}", options: [override("in", NEITHER)], - errors: unexpectedBeforeAndAfter("in"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("in") }, //---------------------------------------------------------------------- @@ -3015,29 +3015,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}let[a] = b", output: "{} let [a] = b", - errors: expectedBeforeAndAfter("let"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("let") }, { code: "{} let [a] = b", output: "{}let[a] = b", options: [NEITHER], - errors: unexpectedBeforeAndAfter("let"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("let") }, { code: "{}let[a] = b", output: "{} let [a] = b", options: [override("let", BOTH)], - errors: expectedBeforeAndAfter("let"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("let") }, { code: "{} let [a] = b", output: "{}let[a] = b", options: [override("let", NEITHER)], - errors: unexpectedBeforeAndAfter("let"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("let") }, //---------------------------------------------------------------------- @@ -3075,29 +3075,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "for ([foo]of{foo: 0}) {}", output: "for ([foo] of {foo: 0}) {}", - errors: expectedBeforeAndAfter("of"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("of") }, { code: "for([foo] of {foo: 0}) {}", output: "for([foo]of{foo: 0}) {}", options: [NEITHER], - errors: unexpectedBeforeAndAfter("of"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("of") }, { code: "for([foo]of{foo: 0}) {}", output: "for([foo] of {foo: 0}) {}", options: [override("of", BOTH)], - errors: expectedBeforeAndAfter("of"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("of") }, { code: "for ([foo] of {foo: 0}) {}", output: "for ([foo]of{foo: 0}) {}", options: [override("of", NEITHER)], - errors: unexpectedBeforeAndAfter("of"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("of") }, //---------------------------------------------------------------------- @@ -3112,8 +3112,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "function foo() { return

; }", output: "function foo() { return

; }", - errors: expectedAfter("return"), - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, + errors: expectedAfter("return") }, { code: "function foo() { {} return +a }", @@ -3125,8 +3125,8 @@ ruleTester.run("keyword-spacing", rule, { code: "function foo() { return

; }", output: "function foo() { return

; }", options: [{ after: false }], - errors: unexpectedAfter("return"), - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, + errors: unexpectedAfter("return") }, { code: "function foo() { {}return+a }", @@ -3148,75 +3148,75 @@ ruleTester.run("keyword-spacing", rule, { { code: "({ set[b](value) {} })", output: "({ set [b](value) {} })", - errors: expectedAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("set") }, { code: "class A { a() {}set[b](value) {} }", output: "class A { a() {} set [b](value) {} }", - errors: expectedBeforeAndAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("set") }, { code: "class A { a() {} static set[b](value) {} }", output: "class A { a() {} static set [b](value) {} }", - errors: expectedAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("set") }, { code: "({ set [b](value) {} })", output: "({ set[b](value) {} })", options: [NEITHER], - errors: unexpectedAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("set") }, { code: "class A { a() {} set [b](value) {} }", output: "class A { a() {}set[b](value) {} }", options: [NEITHER], - errors: unexpectedBeforeAndAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("set") }, { code: "({ set[b](value) {} })", output: "({ set [b](value) {} })", options: [override("set", BOTH)], - errors: expectedAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedAfter("set") }, { code: "class A { a() {}set[b](value) {} }", output: "class A { a() {} set [b](value) {} }", options: [override("set", BOTH)], - errors: expectedBeforeAndAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("set") }, { code: "({ set [b](value) {} })", output: "({ set[b](value) {} })", options: [override("set", NEITHER)], - errors: unexpectedAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedAfter("set") }, { code: "class A { a() {} set [b](value) {} }", output: "class A { a() {}set[b](value) {} }", options: [override("set", NEITHER)], - errors: unexpectedBeforeAndAfter("set"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("set") }, { code: "class A { a;set#b(x) {} }", output: "class A { a;set #b(x) {} }", - errors: expectedAfter("set"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedAfter("set") }, { code: "class A { a; set #b(x) {} }", output: "class A { a; set#b(x) {} }", options: [NEITHER], - errors: unexpectedAfter("set"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedAfter("set") }, //---------------------------------------------------------------------- @@ -3226,121 +3226,121 @@ ruleTester.run("keyword-spacing", rule, { { code: "class A { a() {}static[b]() {} }", output: "class A { a() {} static [b]() {} }", - errors: expectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {}static get [b]() {} }", output: "class A { a() {} static get [b]() {} }", - errors: expectedBefore("static"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBefore("static") }, { code: "class A { a() {} static [b]() {} }", output: "class A { a() {}static[b]() {} }", options: [NEITHER], - errors: unexpectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a() {} static get[b]() {} }", output: "class A { a() {}static get[b]() {} }", options: [NEITHER], - errors: unexpectedBefore("static"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore("static") }, { code: "class A { a() {}static[b]() {} }", output: "class A { a() {} static [b]() {} }", options: [override("static", BOTH)], - errors: expectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {} static [b]() {} }", output: "class A { a() {}static[b]() {} }", options: [override("static", NEITHER)], - errors: unexpectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a;static[b]; }", output: "class A { a;static [b]; }", - errors: expectedAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedAfter("static") }, { code: "class A { a; static [b]; }", output: "class A { a; static[b]; }", options: [NEITHER], - errors: unexpectedAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedAfter("static") }, { code: "class A { a;static#b; }", output: "class A { a;static #b; }", - errors: expectedAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedAfter("static") }, { code: "class A { a; static #b; }", output: "class A { a; static#b; }", options: [NEITHER], - errors: unexpectedAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedAfter("static") }, { code: "class A { a() {}static{} }", output: "class A { a() {} static {} }", - errors: expectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {}static{} }", output: "class A { a() {} static {} }", options: [override("static", BOTH)], - errors: expectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {}static {} }", output: "class A { a() {} static {} }", - errors: expectedBefore("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedBefore("static") }, { code: "class A { a() {} static{} }", output: "class A { a() {} static {} }", - errors: expectedAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: expectedAfter("static") }, { code: "class A { a() {} static {} }", output: "class A { a() {}static{} }", options: [NEITHER], - errors: unexpectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a() {} static {} }", output: "class A { a() {}static{} }", options: [override("static", NEITHER)], - errors: unexpectedBeforeAndAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a() {} static{} }", output: "class A { a() {}static{} }", options: [NEITHER], - errors: unexpectedBefore("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedBefore("static") }, { code: "class A { a() {}static {} }", output: "class A { a() {}static{} }", options: [NEITHER], - errors: unexpectedAfter("static"), - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: unexpectedAfter("static") }, //---------------------------------------------------------------------- @@ -3350,29 +3350,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "class A { a() { {}super[b]; } }", output: "class A { a() { {} super[b]; } }", - errors: expectedBefore("super"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBefore("super") }, { code: "class A { a() { {} super[b]; } }", output: "class A { a() { {}super[b]; } }", options: [NEITHER], - errors: unexpectedBefore("super"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore("super") }, { code: "class A { a() { {}super[b]; } }", output: "class A { a() { {} super[b]; } }", options: [override("super", BOTH)], - errors: expectedBefore("super"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBefore("super") }, { code: "class A { a() { {} super[b]; } }", output: "class A { a() { {}super[b]; } }", options: [override("super", NEITHER)], - errors: unexpectedBefore("super"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore("super") }, //---------------------------------------------------------------------- @@ -3434,18 +3434,18 @@ ruleTester.run("keyword-spacing", rule, { code: " this.blah", output: "this.blah", options: [override("this", { before: false })], - errors: unexpectedBefore("this"), languageOptions: { parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-space")) - } + }, + errors: unexpectedBefore("this") }, { code: "this.blah", output: " this.blah", - errors: expectedBefore("this"), languageOptions: { parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-no-space")) - } + }, + errors: expectedBefore("this") }, //---------------------------------------------------------------------- @@ -3539,29 +3539,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}var[a] = b", output: "{} var [a] = b", - errors: expectedBeforeAndAfter("var"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("var") }, { code: "{} var [a] = b", output: "{}var[a] = b", options: [NEITHER], - errors: unexpectedBeforeAndAfter("var"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("var") }, { code: "{}var[a] = b", output: "{} var [a] = b", options: [override("var", BOTH)], - errors: expectedBeforeAndAfter("var"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBeforeAndAfter("var") }, { code: "{} var [a] = b", output: "{}var[a] = b", options: [override("var", NEITHER)], - errors: unexpectedBeforeAndAfter("var"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBeforeAndAfter("var") }, //---------------------------------------------------------------------- @@ -3678,29 +3678,29 @@ ruleTester.run("keyword-spacing", rule, { { code: "function* foo() { {}yield foo }", output: "function* foo() { {} yield foo }", - errors: expectedBefore("yield"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBefore("yield") }, { code: "function* foo() { {} yield foo }", output: "function* foo() { {}yield foo }", options: [NEITHER], - errors: unexpectedBefore("yield"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore("yield") }, { code: "function* foo() { {}yield foo }", output: "function* foo() { {} yield foo }", options: [override("yield", BOTH)], - errors: expectedBefore("yield"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: expectedBefore("yield") }, { code: "function* foo() { {} yield foo }", output: "function* foo() { {}yield foo }", options: [override("yield", NEITHER)], - errors: unexpectedBefore("yield"), - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: unexpectedBefore("yield") }, //---------------------------------------------------------------------- @@ -3711,8 +3711,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }", output: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }", - errors: expectedAfter("async"), - languageOptions: { parser: require(parser("typescript-parsers/decorator-with-keywords-class-method")) } + languageOptions: { parser: require(parser("typescript-parsers/decorator-with-keywords-class-method")) }, + errors: expectedAfter("async") } ] diff --git a/tests/lib/rules/lines-around-comment.js b/tests/lib/rules/lines-around-comment.js index 4c3b8bea786..8a6cd28e96a 100644 --- a/tests/lib/rules/lines-around-comment.js +++ b/tests/lib/rules/lines-around-comment.js @@ -1221,8 +1221,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - errors: [{ messageId: "before", type: "Line", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Line", line: 2 }] }, { code: "class A {\n// line at class start\nconstructor() {}\n}", @@ -1232,8 +1232,8 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: false, beforeLineComment: true }], - errors: [{ messageId: "before", type: "Line", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Line", line: 2 }] }, { code: "class B {\nconstructor() {}\n\n// line at class end\n}", @@ -1241,8 +1241,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - errors: [{ messageId: "after", type: "Line", line: 4 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Line", line: 4 }] }, { code: "class B {\nconstructor() {}\n\n// line at class end\n}", @@ -1252,8 +1252,8 @@ ruleTester.run("lines-around-comment", rule, { allowBlockEnd: true, allowClassEnd: false }], - errors: [{ messageId: "after", type: "Line", line: 4 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Line", line: 4 }] }, { code: "switch ('foo'){\ncase 'foo':\nvar g = 1;\n\n// line at switch case end\n}", @@ -1291,10 +1291,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Line", line: 2 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1318,10 +1318,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Block", line: 2 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1346,11 +1346,11 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 3 }, { messageId: "after", type: "Line", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1377,11 +1377,11 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 3 }, { messageId: "after", type: "Block", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1405,10 +1405,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Line", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1434,10 +1434,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Block", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1461,10 +1461,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 4 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1490,10 +1490,10 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 4 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1520,11 +1520,11 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 4 }, { messageId: "after", type: "Line", line: 4 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1553,11 +1553,11 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 4 }, { messageId: "after", type: "Block", line: 4 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1579,10 +1579,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: unIndent` @@ -1606,10 +1606,10 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // object start comments @@ -1712,8 +1712,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - errors: [{ messageId: "before", type: "Line", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Line", line: 2 }] }, { code: @@ -1730,8 +1730,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - errors: [{ messageId: "before", type: "Line", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Line", line: 2 }] }, { code: @@ -1748,8 +1748,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - errors: [{ messageId: "before", type: "Block", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Block", line: 2 }] }, { code: @@ -1766,8 +1766,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - errors: [{ messageId: "before", type: "Block", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Block", line: 2 }] }, // object end comments @@ -1874,8 +1874,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - errors: [{ messageId: "after", type: "Line", line: 3 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Line", line: 3 }] }, { code: @@ -1892,8 +1892,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - errors: [{ messageId: "after", type: "Line", line: 3 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Line", line: 3 }] }, { code: @@ -1912,8 +1912,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - errors: [{ messageId: "after", type: "Block", line: 4 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Block", line: 4 }] }, { code: @@ -1932,8 +1932,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - errors: [{ messageId: "after", type: "Block", line: 4 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Block", line: 4 }] }, // array start comments @@ -1986,8 +1986,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - errors: [{ messageId: "before", type: "Line", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Line", line: 2 }] }, { code: @@ -2004,8 +2004,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - errors: [{ messageId: "before", type: "Block", line: 2 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "before", type: "Block", line: 2 }] }, // array end comments @@ -2060,8 +2060,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - errors: [{ messageId: "after", type: "Line", line: 3 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Line", line: 3 }] }, { code: @@ -2080,8 +2080,8 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - errors: [{ messageId: "after", type: "Block", line: 4 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "after", type: "Block", line: 4 }] }, // ignorePattern diff --git a/tests/lib/rules/lines-around-directive.js b/tests/lib/rules/lines-around-directive.js index e4b600b0f2a..ff2e7afaa28 100644 --- a/tests/lib/rules/lines-around-directive.js +++ b/tests/lib/rules/lines-around-directive.js @@ -841,8 +841,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\nvar foo;\n}", output: "() => {\n'use strict';\n\nvar foo;\n}", options: ["always"], - errors: [expectedAfterStrictError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedAfterStrictError] }, // multiple directives @@ -856,8 +856,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], - errors: [expectedAfterAsmError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedAfterAsmError] }, /* @@ -886,21 +886,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\n\nvar foo;\n}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n\nvar foo;\n}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, // multiple directives @@ -926,21 +926,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, /* @@ -1080,8 +1080,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n\nvar foo;\n}", output: "() => {\n'use strict';\nvar foo;\n}", options: ["never"], - errors: [unexpectedAfterStrictError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [unexpectedAfterStrictError] }, // multiple directives @@ -1095,8 +1095,8 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], - errors: [unexpectedAfterAsmError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [unexpectedAfterAsmError] }, /* @@ -1125,21 +1125,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\n\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\nvar foo;\n}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\nvar foo;\n}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, // multiple directives @@ -1165,21 +1165,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\nvar foo;\n}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, @@ -1308,15 +1308,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\nvar foo;\n}", output: "() => {\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - errors: [expectedAfterStrictError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedAfterStrictError] }, { code: "() => {\n\n'use strict';\nvar foo;\n}", output: "() => {\n\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - errors: [expectedAfterStrictError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedAfterStrictError] }, // multiple directives @@ -1336,15 +1336,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - errors: [expectedAfterAsmError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedAfterAsmError] }, { code: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], - errors: [expectedAfterAsmError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedAfterAsmError] }, /* @@ -1373,21 +1373,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, // multiple directives @@ -1413,21 +1413,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n//comment\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\n\nvar foo;\n}", options: [{ before: "never", after: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, /* @@ -1555,15 +1555,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n\nvar foo;\n}", output: "() => {\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - errors: [unexpectedAfterStrictError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [unexpectedAfterStrictError] }, { code: "() => {\n\n'use strict';\n\nvar foo;\n}", output: "() => {\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - errors: [unexpectedAfterStrictError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [unexpectedAfterStrictError] }, // multiple directives @@ -1583,15 +1583,15 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - errors: [unexpectedAfterAsmError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [unexpectedAfterAsmError] }, { code: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], - errors: [unexpectedAfterAsmError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [unexpectedAfterAsmError] }, /* @@ -1620,21 +1620,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\n\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\nvar foo;\n}", options: [{ before: "always", after: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterStrictError - ], - languageOptions: { ecmaVersion: 6 } + ] }, // multiple directives @@ -1660,21 +1660,21 @@ ruleTester.run("lines-around-directive", rule, { code: "() => {\n//comment\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n//comment\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "() => {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\n\nvar foo;\n}", output: "() => {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\nvar foo;\n}", options: [{ before: "always", after: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterAsmError - ], - languageOptions: { ecmaVersion: 6 } + ] }, // https://github.com/eslint/eslint/issues/7450 diff --git a/tests/lib/rules/logical-assignment-operators.js b/tests/lib/rules/logical-assignment-operators.js index 4afa51584e9..9fdf7278b83 100644 --- a/tests/lib/rules/logical-assignment-operators.js +++ b/tests/lib/rules/logical-assignment-operators.js @@ -756,8 +756,8 @@ ruleTester.run("logical-assignment-operators", rule, { }, { code: "class Class { #prop; constructor() { this.#prop || (this.#prop = value) } }", output: "class Class { #prop; constructor() { this.#prop ||= value } }", - errors: [{ messageId: "logical", type: "LogicalExpression", data: { operator: "||=" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "logical", type: "LogicalExpression", data: { operator: "||=" } }] }, { code: "a['b'] || (a['b'] = c)", output: "a['b'] ||= c", @@ -1491,14 +1491,17 @@ ruleTester.run("logical-assignment-operators", rule, { code: "a ||= b as number;", output: "a = a || (b as number);", options: ["never"], - errors: [{ messageId: "unexpected", type: "AssignmentExpression", data: { operator: "||=" } }], languageOptions: { parser: require(parser("typescript-parsers/logical-assignment-with-assertion")) - } + }, + errors: [{ messageId: "unexpected", type: "AssignmentExpression", data: { operator: "||=" } }] }, { code: "a.b.c || (a.b.c = d as number)", output: null, + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-1")) + }, errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1508,14 +1511,14 @@ ruleTester.run("logical-assignment-operators", rule, { data: { operator: "||=" }, output: "a.b.c ||= d as number" }] - }], - languageOptions: { - parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-1")) - } + }] }, { code: "a.b.c || (a.b.c = (d as number))", output: null, + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-2")) + }, errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1525,14 +1528,14 @@ ruleTester.run("logical-assignment-operators", rule, { data: { operator: "||=" }, output: "a.b.c ||= (d as number)" }] - }], - languageOptions: { - parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-2")) - } + }] }, { code: "(a.b.c || (a.b.c = d)) as number", output: null, + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-3")) + }, errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1542,10 +1545,7 @@ ruleTester.run("logical-assignment-operators", rule, { data: { operator: "||=" }, output: "(a.b.c ||= d) as number" }] - }], - languageOptions: { - parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-3")) - } + }] }, // 3 or more operands diff --git a/tests/lib/rules/max-depth.js b/tests/lib/rules/max-depth.js index 6253f04c5c1..0d50184d0f5 100644 --- a/tests/lib/rules/max-depth.js +++ b/tests/lib/rules/max-depth.js @@ -41,10 +41,10 @@ ruleTester.run("max-depth", rule, { ], invalid: [ { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [2], errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }] }, - { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [2], errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [2], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, type: "IfStatement" }] }, { code: "function foo() { if (true) {} else { for(;;) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "ForStatement" }] }, { code: "function foo() { while (true) { if (true) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }] }, - { code: "function foo() { for (let x of foo) { if (true) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }], languageOptions: { ecmaVersion: 6 } }, + { code: "function foo() { for (let x of foo) { if (true) {} } }", options: [1], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }] }, { code: "function foo() { while (true) { if (true) { if (false) { } } } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2, maxDepth: 1 }, type: "IfStatement" }, { messageId: "tooDeeply", data: { depth: 3, maxDepth: 1 }, type: "IfStatement" }] }, { code: "function foo() { if (true) { if (false) { if (true) { if (false) { if (true) { } } } } } }", errors: [{ messageId: "tooDeeply", data: { depth: 5, maxDepth: 4 }, type: "IfStatement" }] }, @@ -57,46 +57,46 @@ ruleTester.run("max-depth", rule, { { code: "class C { static { if (1) { if (2) { if (3) {} } } } }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 38 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 47 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "function foo() { if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } } }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 64 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "function foo() { if (1) { class C { static { if (1) { if (2) {} } } } if (2) { if (3) {} } } }", options: [2], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, line: 1, column: 80 - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/max-len.js b/tests/lib/rules/max-len.js index 091461d9d10..20d160c87b8 100644 --- a/tests/lib/rules/max-len.js +++ b/tests/lib/rules/max-len.js @@ -770,6 +770,7 @@ ruleTester.run("max-len", rule, { { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string`;", options: [29, { ignoreStrings: false, ignoreTemplateLiterals: false }], + languageOptions, errors: [ { messageId: "max", @@ -780,12 +781,12 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 40 } - ], - languageOptions + ] }, { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string\nand this is another line that is very long`;", options: [29, { ignoreStrings: false, ignoreTemplateLiterals: false }], + languageOptions, errors: [ { messageId: "max", @@ -805,12 +806,12 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 45 } - ], - languageOptions + ] }, { code: "var foo =

this is a very very very long string
;", options: [29, 4, { ignoreStrings: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -821,8 +822,7 @@ ruleTester.run("max-len", rule, { endLine: 1, endColumn: 59 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, // Multi-code-point unicode glyphs @@ -864,6 +864,7 @@ ruleTester.run("max-len", rule, { " { /* this line has 38 characters */}\n" + ")", options: [15, { comments: 37 }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "maxComment", @@ -874,14 +875,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + "\t\t{ /* this line has 40 characters */}\n" + ")", options: [15, 4, { comments: 40 }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "maxComment", @@ -892,14 +893,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + "{ 38/* this line has 38 characters */}\n" + ")", options: [15, { comments: 38 }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -910,14 +911,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + "{ 38/* this line has 38 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -928,14 +929,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + "{ 38/* this line has 38 characters */}\n" + ")", options: [37, { ignoreComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -946,14 +947,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 39 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + " <> 50 { 50/* this line has 50 characters */}\n" + ")", options: [49, { comments: 100 }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -964,8 +965,7 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 51 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -973,6 +973,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line has 44 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -983,14 +984,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 45 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = ;", options: [56], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1001,14 +1002,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 58 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = ;", options: [56], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1019,14 +1020,14 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 58 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = ;", options: [55, { ignoreTrailingComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1037,8 +1038,7 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 57 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = ;", options: [30, { comments: 44 }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1056,8 +1057,7 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 52 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -1065,6 +1065,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 80 characters */}\n" + ")", options: [79], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1075,14 +1076,14 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 81 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + " <> {/* this line with two separate comments */} {/* have 87 characters */} <> \n" + ")", options: [85, { ignoreTrailingComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1093,8 +1094,7 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 88 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -1102,6 +1102,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 87 characters */} <> \n" + ")", options: [37, { ignoreComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1112,8 +1113,7 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 88 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -1121,6 +1121,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have > 80 characters */ /* another comment in same braces */}\n" + ")", options: [37], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1131,8 +1132,7 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 120 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -1140,6 +1140,7 @@ ruleTester.run("max-len", rule, { " <> {/* this is not treated as a comment */ a & b} {/* trailing */ /* comments */}\n" + ")", options: [37, { ignoreTrailingComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1150,8 +1151,7 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 56 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -1159,6 +1159,7 @@ ruleTester.run("max-len", rule, { " <> {/* this is not treated as a comment */ a & b} {/* trailing */ /* comments */}\n" + ")", options: [37, { ignoreComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1169,8 +1170,7 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 56 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -1178,6 +1178,7 @@ ruleTester.run("max-len", rule, { "*/}\n" + ")", options: [14, { ignoreTrailingComments: true }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1188,8 +1189,7 @@ ruleTester.run("max-len", rule, { endLine: 2, endColumn: 16 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "var jsx = (<>\n" + @@ -1197,6 +1197,7 @@ ruleTester.run("max-len", rule, { "this line has 31 characters */}\n" + ")", options: [30, { comments: 100 }], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1207,8 +1208,7 @@ ruleTester.run("max-len", rule, { endLine: 3, endColumn: 32 } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] } ] }); diff --git a/tests/lib/rules/max-nested-callbacks.js b/tests/lib/rules/max-nested-callbacks.js index 9b5efd67d0d..e5cda7b1c89 100644 --- a/tests/lib/rules/max-nested-callbacks.js +++ b/tests/lib/rules/max-nested-callbacks.js @@ -61,14 +61,14 @@ ruleTester.run("max-nested-callbacks", rule, { { code: "foo(function() { bar(thing, (data) => { baz(function() {}); }); });", options: [2], - errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }] }, { code: "foo(() => { bar(thing, (data) => { baz( () => {}); }); });", options: [2], - errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "ArrowFunctionExpression" }] }, { code: "foo(function() { if (isTrue) { bar(function(data) { baz(function() {}); }); } });", diff --git a/tests/lib/rules/max-params.js b/tests/lib/rules/max-params.js index 6b6c0a52329..1743cb52fb3 100644 --- a/tests/lib/rules/max-params.js +++ b/tests/lib/rules/max-params.js @@ -58,12 +58,12 @@ ruleTester.run("max-params", rule, { { code: "var test = (a, b, c, d) => {};", options: [3], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { name: "Arrow function", count: 4, max: 3.0 }, type: "ArrowFunctionExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function(a, b, c, d) {});", diff --git a/tests/lib/rules/max-statements-per-line.js b/tests/lib/rules/max-statements-per-line.js index 51ae79ef8c1..18682e2d91d 100644 --- a/tests/lib/rules/max-statements-per-line.js +++ b/tests/lib/rules/max-statements-per-line.js @@ -131,7 +131,7 @@ ruleTester.run("max-statements-per-line", rule, { { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] }, { code: "(function() { var bar = 1; })();", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] }, { code: "var foo = function foo() { var bar = 1; };", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] }, - { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 1 }], errors: [{ messageId: "exceed" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 1 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed" }] }, { code: "var bar = 1; var baz = 2; var qux = 3;", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "if (condition) { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, @@ -142,19 +142,19 @@ ruleTester.run("max-statements-per-line", rule, { { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "(function() { var bar = 1; var baz = 2; })();", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "var foo = function foo() { var bar = 1; var baz = 2; };", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, - { code: "var foo = { prop: () => { var bar = 1; var baz = 2; } };", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = { prop: () => { var bar = 1; var baz = 2; } };", options: [{ max: 2 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] }, { code: "var bar = 1; var baz = 2; var qux = 3; var waldo = 4;", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, { code: "if (condition) { var bar = 1; var baz = 2; var qux = 3; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, { code: "if (condition) { var bar = 1; var baz = 2; } else { var bar = 1; var baz = 2; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 3.0 } }] }, { code: "switch (discriminant) { case 'test': var bar = 1; break; default: var bar = 1; break; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 3.0 } }] }, - { code: "let bar = bar => { a; }, baz = baz => { b; }, qux = qux => { c; };", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }], languageOptions: { ecmaVersion: 6 } }, - { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }], languageOptions: { ecmaVersion: 6 } }, - { code: "bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; };", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, - { code: "[bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; }];", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, - { code: "foo(bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; });", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({ bar: bar => { a; }, baz: baz => { b; }, qux: qux => { c; }, quux: quux => { d; }});", options: [{ max: 4 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }], languageOptions: { ecmaVersion: 6 } }, + { code: "let bar = bar => { a; }, baz = baz => { b; }, qux = qux => { c; };", options: [{ max: 3 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, + { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 3 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] }, + { code: "bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; };", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, + { code: "[bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; }];", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, + { code: "foo(bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; });", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, + { code: "({ bar: bar => { a; }, baz: baz => { b; }, qux: qux => { c; }, quux: quux => { d; }});", options: [{ max: 4 }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] }, { code: "a; if (b) { c; d; }\nz;", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 2.0 } }] }, - { code: "export default function foo() { console.log('test') }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function foo() { console.log('test') }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } } + { code: "export default function foo() { console.log('test') }", options: [{ max: 1 }], languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "exceed" }] }, + { code: "export function foo() { console.log('test') }", options: [{ max: 1 }], languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "exceed" }] } ] }); diff --git a/tests/lib/rules/max-statements.js b/tests/lib/rules/max-statements.js index 9edbbe7fa04..649726d6af9 100644 --- a/tests/lib/rules/max-statements.js +++ b/tests/lib/rules/max-statements.js @@ -70,8 +70,8 @@ ruleTester.run("max-statements", rule, { { code: "var foo = () => { var bar = 1; var baz = 2; var qux = 3; };", options: [2], - errors: [{ messageId: "exceed", data: { name: "Arrow function", count: "3", max: 2 } }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "exceed", data: { name: "Arrow function", count: "3", max: 2 } }] }, { code: "var foo = function() { var bar = 1; var baz = 2; var qux = 3; };", @@ -135,8 +135,8 @@ ruleTester.run("max-statements", rule, { { code: "var foo = { thing() { var bar = 1; var baz = 2; var baz2; } }", options: [2], - errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }] }, /* @@ -152,8 +152,8 @@ ruleTester.run("max-statements", rule, { { code: "var foo = { thing: () => { var bar = 1; var baz = 2; var baz2; } }", options: [2], - errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }] }, { code: "var foo = { thing: function() { var bar = 1; var baz = 2; var baz2; } }", @@ -173,26 +173,26 @@ ruleTester.run("max-statements", rule, { { code: "function foo() { foo_1; /* foo_ 2 */ class C { static { one; two; three; four; { five; six; seven; eight; } } } foo_3 }", options: [2], - errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: 3, max: 2 } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: 3, max: 2 } }] }, { code: "class C { static { one; two; three; four; function not_top_level() { 1; 2; 3; } five; six; seven; eight; } }", options: [2, { ignoreTopLevelFunctions: true }], - errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }] }, { code: "class C { static { { one; two; three; four; function not_top_level() { 1; 2; 3; } five; six; seven; eight; } } }", options: [2, { ignoreTopLevelFunctions: true }], - errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }] }, { code: "class C { static { { one; two; three; four; } function not_top_level() { 1; 2; 3; } { five; six; seven; eight; } } }", options: [2, { ignoreTopLevelFunctions: true }], - errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }] } ] }); diff --git a/tests/lib/rules/new-cap.js b/tests/lib/rules/new-cap.js index bef4e0350c1..35ee12c6bcb 100644 --- a/tests/lib/rules/new-cap.js +++ b/tests/lib/rules/new-cap.js @@ -272,6 +272,7 @@ ruleTester.run("new-cap", rule, { }, { code: "var a = new b[ ( 'foo' ) ]();", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "lower", @@ -281,11 +282,11 @@ ruleTester.run("new-cap", rule, { endLine: 1, endColumn: 23 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var a = new b[`foo`];", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "lower", @@ -295,11 +296,11 @@ ruleTester.run("new-cap", rule, { endLine: 1, endColumn: 20 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var a = b[`\\\nFoo`]();", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "upper", @@ -309,8 +310,7 @@ ruleTester.run("new-cap", rule, { endLine: 2, endColumn: 5 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { @@ -339,18 +339,18 @@ ruleTester.run("new-cap", rule, { // Optional chaining { code: "new (foo?.bar)();", - errors: [{ messageId: "lower", column: 11, endColumn: 14 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "lower", column: 11, endColumn: 14 }] }, { code: "foo?.Bar();", - errors: [{ messageId: "upper", column: 6, endColumn: 9 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "upper", column: 6, endColumn: 9 }] }, { code: "(foo?.Bar)();", - errors: [{ messageId: "upper", column: 7, endColumn: 10 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "upper", column: 7, endColumn: 10 }] } ] }); diff --git a/tests/lib/rules/newline-after-var.js b/tests/lib/rules/newline-after-var.js index a93ef59c059..7f638619376 100644 --- a/tests/lib/rules/newline-after-var.js +++ b/tests/lib/rules/newline-after-var.js @@ -274,11 +274,11 @@ ruleTester.run("newline-after-var", rule, { { code: MULTI_VAR_NO_BLANK, output: MULTI_VAR_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, { code: MULTI_DEC_NO_BLANK, output: MULTI_DEC_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, { code: MULTI_LINE_NO_BLANK, output: MULTI_LINE_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, - { code: LET_NO_BLANK, output: LET_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR], languageOptions: { ecmaVersion: 6 } }, - { code: CONST_NO_BLANK, output: CONST_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR], languageOptions: { ecmaVersion: 6 } }, + { code: LET_NO_BLANK, output: LET_ONE_BLANK, options: ["always"], languageOptions: { ecmaVersion: 6 }, errors: [ALWAYS_ERROR] }, + { code: CONST_NO_BLANK, output: CONST_ONE_BLANK, options: ["always"], languageOptions: { ecmaVersion: 6 }, errors: [ALWAYS_ERROR] }, { code: NOT_END_OF_FUNCTION, output: NOT_END_OF_FUNCTION_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, { code: NOT_END_OF_FUNCTION_EXPRESSION, output: NOT_END_OF_FUNCTION_EXPRESSION_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR] }, - { code: NOT_END_OF_ARROW_FUNCTION, output: NOT_END_OF_ARROW_FUNCTION_ONE_BLANK, options: ["always"], errors: [ALWAYS_ERROR], languageOptions: { ecmaVersion: 6 } }, + { code: NOT_END_OF_ARROW_FUNCTION, output: NOT_END_OF_ARROW_FUNCTION_ONE_BLANK, options: ["always"], languageOptions: { ecmaVersion: 6 }, errors: [ALWAYS_ERROR] }, { code: NO_BLANK_BEFORE_CASE, output: ONE_BLANK_BEFORE_CASE, options: ["always"], errors: [ALWAYS_ERROR] }, // should disallow blank lines in "never" mode @@ -291,8 +291,8 @@ ruleTester.run("newline-after-var", rule, { { code: MULTI_DEC_ONE_BLANK, output: MULTI_DEC_NO_BLANK, options: ["never"], errors: [NEVER_ERROR] }, { code: MULTI_LINE_ONE_BLANK, output: MULTI_LINE_NO_BLANK, options: ["never"], errors: [NEVER_ERROR] }, { code: MULTI_LINE_ONE_BLANK_WITH_COMMENTS, output: MULTI_LINE_NO_BLANK_WITH_COMMENTS, options: ["never"], errors: [NEVER_ERROR] }, - { code: LET_ONE_BLANK, output: LET_NO_BLANK, options: ["never"], errors: [NEVER_ERROR], languageOptions: { ecmaVersion: 6 } }, - { code: CONST_ONE_BLANK, output: CONST_NO_BLANK, options: ["never"], errors: [NEVER_ERROR], languageOptions: { ecmaVersion: 6 } }, + { code: LET_ONE_BLANK, output: LET_NO_BLANK, options: ["never"], languageOptions: { ecmaVersion: 6 }, errors: [NEVER_ERROR] }, + { code: CONST_ONE_BLANK, output: CONST_NO_BLANK, options: ["never"], languageOptions: { ecmaVersion: 6 }, errors: [NEVER_ERROR] }, { code: ONE_BLANK_BEFORE_CASE, output: NO_BLANK_BEFORE_CASE, options: ["never"], errors: [NEVER_ERROR] }, // should disallow a comment on the next line that's not in turn followed by a blank in "always" mode diff --git a/tests/lib/rules/newline-before-return.js b/tests/lib/rules/newline-before-return.js index ae3525fc642..d0c9769abfb 100644 --- a/tests/lib/rules/newline-before-return.js +++ b/tests/lib/rules/newline-before-return.js @@ -160,8 +160,8 @@ ruleTester.run("newline-before-return", rule, { { code: "function a() {\nfor (b of c) {\nd();\nreturn;\n}\n}", output: "function a() {\nfor (b of c) {\nd();\n\nreturn;\n}\n}", - errors: [error], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [error] }, { code: "function a() {\nif (b) {\nc();\n}\n//comment\nreturn b;\n}", @@ -196,14 +196,14 @@ ruleTester.run("newline-before-return", rule, { { code: "var a;\nreturn;", output: "var a;\n\nreturn;", - errors: [error], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: [error] }, { code: "var a; return;", output: "var a; \n\nreturn;", - errors: [error], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: [error] }, { code: "function a() {\n{\n//comment\n}\nreturn\n}", diff --git a/tests/lib/rules/newline-per-chained-call.js b/tests/lib/rules/newline-per-chained-call.js index 0d13fb4e551..b57c27843d8 100644 --- a/tests/lib/rules/newline-per-chained-call.js +++ b/tests/lib/rules/newline-per-chained-call.js @@ -351,61 +351,61 @@ ruleTester.run("newline-per-chained-call", rule, { code: "obj?.foo1()?.foo2()?.foo3()", output: "obj?.foo1()\n?.foo2()\n?.foo3()", options: [{ ignoreChainWithDepth: 1 }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(obj?.foo1()?.foo2)()?.foo3()", output: "(obj?.foo1()\n?.foo2)()\n?.foo3()", options: [{ ignoreChainWithDepth: 1 }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(obj?.foo1())?.foo2()?.foo3()", output: "(obj?.foo1())\n?.foo2()\n?.foo3()", options: [{ ignoreChainWithDepth: 1 }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "obj?.[foo1]()?.[foo2]()?.[foo3]()", output: "obj?.[foo1]()\n?.[foo2]()\n?.[foo3]()", options: [{ ignoreChainWithDepth: 1 }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(obj?.[foo1]()?.[foo2])()?.[foo3]()", output: "(obj?.[foo1]()\n?.[foo2])()\n?.[foo3]()", options: [{ ignoreChainWithDepth: 1 }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(obj?.[foo1]())?.[foo2]()?.[foo3]()", output: "(obj?.[foo1]())\n?.[foo2]()\n?.[foo3]()", options: [{ ignoreChainWithDepth: 1 }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] } ] diff --git a/tests/lib/rules/no-alert.js b/tests/lib/rules/no-alert.js index 6f85bc39e5f..3b4aeed42c0 100644 --- a/tests/lib/rules/no-alert.js +++ b/tests/lib/rules/no-alert.js @@ -117,30 +117,30 @@ ruleTester.run("no-alert", rule, { }, { code: "globalThis['alert'](foo)", - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "globalThis.alert();", - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "function foo() { var globalThis = bar; globalThis.alert(); }\nglobalThis.alert();", - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] }, // Optional chaining { code: "window?.alert(foo)", - errors: [{ messageId: "unexpected", data: { name: "alert" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { name: "alert" } }] }, { code: "(window?.alert)(foo)", - errors: [{ messageId: "unexpected", data: { name: "alert" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { name: "alert" } }] } ] }); diff --git a/tests/lib/rules/no-case-declarations.js b/tests/lib/rules/no-case-declarations.js index 815b48e191c..ad2c945d0e7 100644 --- a/tests/lib/rules/no-case-declarations.js +++ b/tests/lib/rules/no-case-declarations.js @@ -68,48 +68,48 @@ ruleTester.run("no-case-declarations", rule, { let x; } `, - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { case 1: let x = 1; break; }", - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { default: let x = 2; break; }", - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { case 1: const x = 1; break; }", - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { default: const x = 2; break; }", - errors: [{ messageId: "unexpected", type: "VariableDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { case 1: function f() {} break; }", - errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }] }, { code: "switch (a) { default: function f() {} break; }", - errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }] }, { code: "switch (a) { case 1: class C {} break; }", - errors: [{ messageId: "unexpected", type: "ClassDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "ClassDeclaration" }] }, { code: "switch (a) { default: class C {} break; }", - errors: [{ messageId: "unexpected", type: "ClassDeclaration" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "ClassDeclaration" }] } ] }); diff --git a/tests/lib/rules/no-console.js b/tests/lib/rules/no-console.js index 12d769023d8..81cc452c8dc 100644 --- a/tests/lib/rules/no-console.js +++ b/tests/lib/rules/no-console.js @@ -142,6 +142,7 @@ ruleTester.run("no-console", rule, { }, { code: "class A { static { console.info(foo) } }", + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -150,29 +151,29 @@ ruleTester.run("no-console", rule, { data: { propertyName: "info" }, output: "class A { static { } }" }] - }], - languageOptions: { ecmaVersion: "latest" } + }] }, { code: "a()\nconsole.log(foo);\n[1, 2, 3].forEach(a => doSomething(a))", + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", suggestions: null - }], - languageOptions: { ecmaVersion: "latest" } + }] }, { code: "a++\nconsole.log();\n/b/", + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", suggestions: null - }], - languageOptions: { ecmaVersion: "latest" } + }] }, { code: "a();\nconsole.log(foo);\n[1, 2, 3].forEach(a => doSomething(a));", + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -181,8 +182,7 @@ ruleTester.run("no-console", rule, { data: { propertyName: "log" }, output: "a();\n\n[1, 2, 3].forEach(a => doSomething(a));" }] - }], - languageOptions: { ecmaVersion: "latest" } + }] }, // one option @@ -285,6 +285,7 @@ ruleTester.run("no-console", rule, { { code: "class A { static { console.error(foo) } }", options: [{ allow: ["log"] }], + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -293,8 +294,7 @@ ruleTester.run("no-console", rule, { data: { propertyName: "error" }, output: "class A { static { } }" }] - }], - languageOptions: { ecmaVersion: "latest" } + }] }, // multiple options @@ -397,6 +397,7 @@ ruleTester.run("no-console", rule, { { code: "class A { static { console.info(foo) } }", options: [{ allow: ["log", "error", "warn"] }], + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -405,13 +406,17 @@ ruleTester.run("no-console", rule, { data: { propertyName: "info" }, output: "class A { static { } }" }] - }], - languageOptions: { ecmaVersion: "latest" } + }] }, // In case that implicit global variable of 'console' exists { code: "console.log(foo)", + languageOptions: { + globals: { + console: "readonly" + } + }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -420,12 +425,7 @@ ruleTester.run("no-console", rule, { data: { propertyName: "log" }, output: "" }] - }], - languageOptions: { - globals: { - console: "readonly" - } - } + }] } ] }); diff --git a/tests/lib/rules/no-constant-binary-expression.js b/tests/lib/rules/no-constant-binary-expression.js index a2af011b115..cbf93c77ab3 100644 --- a/tests/lib/rules/no-constant-binary-expression.js +++ b/tests/lib/rules/no-constant-binary-expression.js @@ -312,8 +312,8 @@ ruleTester.run("no-constant-binary-expression", rule, { { code: "x === (function() {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === (class {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === new Boolean()", errors: [{ messageId: "alwaysNew" }] }, - { code: "x === new Promise()", errors: [{ messageId: "alwaysNew" }], languageOptions: { ecmaVersion: 6 } }, - { code: "x === new WeakSet()", errors: [{ messageId: "alwaysNew" }], languageOptions: { ecmaVersion: 6 } }, + { code: "x === new Promise()", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "alwaysNew" }] }, + { code: "x === new WeakSet()", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "alwaysNew" }] }, { code: "x === (foo, {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === (y = {})", errors: [{ messageId: "alwaysNew" }] }, { code: "x === (y ? {} : [])", errors: [{ messageId: "alwaysNew" }] }, diff --git a/tests/lib/rules/no-constant-condition.js b/tests/lib/rules/no-constant-condition.js index b74deec078d..96579ab9e91 100644 --- a/tests/lib/rules/no-constant-condition.js +++ b/tests/lib/rules/no-constant-condition.js @@ -386,15 +386,15 @@ ruleTester.run("no-constant-condition", rule, { }, // #13238 - { code: "if(/foo/ui);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0b0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0o0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0x0n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0b1n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0o1n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0x1n);", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 11 } }, - { code: "if(0x1n || foo);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }], languageOptions: { ecmaVersion: 11 } }, + { code: "if(/foo/ui);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0n);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0b0n);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0o0n);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0x0n);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0b1n);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0o1n);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0x1n);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if(0x1n || foo);", languageOptions: { ecmaVersion: 11 }, errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, // Classes and instances are always truthy { code: "if(class {}) {}", errors: [{ messageId: "unexpected" }] }, diff --git a/tests/lib/rules/no-control-regex.js b/tests/lib/rules/no-control-regex.js index 4904685960d..7db45944c93 100644 --- a/tests/lib/rules/no-control-regex.js +++ b/tests/lib/rules/no-control-regex.js @@ -49,13 +49,13 @@ ruleTester.run("no-control-regex", rule, { { code: "var regex = RegExp('\\x1f')", errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: "var regex = /(?\\x1f)/", - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`var regex = /(?<\u{1d49c}>.)\x1f/`, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`new RegExp("\\u001F", flags)`, @@ -63,23 +63,23 @@ ruleTester.run("no-control-regex", rule, { }, { code: String.raw`/\u{1111}*\x1F/u`, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`new RegExp("\\u{1111}*\\x1F", "u")`, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`/\u{1F}/u`, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`/\u{1F}/gui`, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`new RegExp("\\u{1F}", "u")`, @@ -95,13 +95,13 @@ ruleTester.run("no-control-regex", rule, { }, { code: String.raw`/[\u{1F}--B]/v`, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }], - languageOptions: { ecmaVersion: 2024 } + languageOptions: { ecmaVersion: 2024 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`/\x11/; RegExp("foo", "uv");`, - errors: [{ messageId: "unexpected", data: { controlChars: "\\x11" }, type: "Literal", column: 1 }], - languageOptions: { ecmaVersion: 2024 } + languageOptions: { ecmaVersion: 2024 }, + errors: [{ messageId: "unexpected", data: { controlChars: "\\x11" }, type: "Literal", column: 1 }] } ] }); diff --git a/tests/lib/rules/no-dupe-class-members.js b/tests/lib/rules/no-dupe-class-members.js index 7484261d9b3..73310d8880c 100644 --- a/tests/lib/rules/no-dupe-class-members.js +++ b/tests/lib/rules/no-dupe-class-members.js @@ -187,10 +187,10 @@ ruleTester.run("no-dupe-class-members", rule, { }, { code: "class A { [123n]() {} 123() {} }", + languageOptions: { ecmaVersion: 2020 }, errors: [ { type: "MethodDefinition", line: 1, column: 23, messageId: "unexpected", data: { name: "123" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "class A { [null]() {} 'null'() {} }", diff --git a/tests/lib/rules/no-dupe-keys.js b/tests/lib/rules/no-dupe-keys.js index a00bad3dc90..20aa29c3454 100644 --- a/tests/lib/rules/no-dupe-keys.js +++ b/tests/lib/rules/no-dupe-keys.js @@ -43,21 +43,21 @@ ruleTester.run("no-dupe-keys", rule, { { code: "var x = { 1_0: 1, 1: 2 };", languageOptions: { ecmaVersion: 2021 } } ], invalid: [ - { code: "var x = { a: b, ['a']: b };", errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { a: b, ['a']: b };", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, { code: "var x = { y: 1, y: 2 };", errors: [{ messageId: "unexpected", data: { name: "y" }, type: "ObjectExpression" }] }, { code: "var x = { '': 1, '': 2 };", errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] }, - { code: "var x = { '': 1, [``]: 2 };", errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var x = { '': 1, [``]: 2 };", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] }, { code: "var foo = { 0x1: 1, 1: 2};", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, { code: "var x = { 012: 1, 10: 2 };", errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }] }, - { code: "var x = { 0b1: 1, 1: 2 };", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "var x = { 0o1: 1, 1: 2 };", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "var x = { 1n: 1, 1: 2 };", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 2020 } }, - { code: "var x = { 1_0: 1, 10: 2 };", errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 2021 } }, + { code: "var x = { 0b1: 1, 1: 2 };", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, + { code: "var x = { 0o1: 1, 1: 2 };", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, + { code: "var x = { 1n: 1, 1: 2 };", languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, + { code: "var x = { 1_0: 1, 10: 2 };", languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { name: "10" }, type: "ObjectExpression" }] }, { code: "var x = { \"z\": 1, z: 2 };", errors: [{ messageId: "unexpected", data: { name: "z" }, type: "ObjectExpression" }] }, { code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ messageId: "unexpected", data: { name: "bar" }, line: 3, column: 3 }] }, - { code: "var x = { a: 1, get a() {} };", errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "var x = { a: 1, set a(value) {} };", errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "var x = { a: 1, b: { a: 2 }, get b() {} };", errors: [{ messageId: "unexpected", data: { name: "b" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "var x = ({ '/(?0)/': 1, [/(?0)/]: 2 })", errors: [{ messageId: "unexpected", data: { name: "/(?0)/" }, type: "ObjectExpression" }], languageOptions: { ecmaVersion: 2018 } } + { code: "var x = { a: 1, get a() {} };", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, + { code: "var x = { a: 1, set a(value) {} };", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, + { code: "var x = { a: 1, b: { a: 2 }, get b() {} };", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "b" }, type: "ObjectExpression" }] }, + { code: "var x = ({ '/(?0)/': 1, [/(?0)/]: 2 })", languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "unexpected", data: { name: "/(?0)/" }, type: "ObjectExpression" }] } ] }); diff --git a/tests/lib/rules/no-else-return.js b/tests/lib/rules/no-else-return.js index 21963809f4c..470e38262a0 100644 --- a/tests/lib/rules/no-else-return.js +++ b/tests/lib/rules/no-else-return.js @@ -203,307 +203,307 @@ ruleTester.run("no-else-return", rule, { { code: "function foo() { var a; if (bar) { return true; } else { var a; } }", output: "function foo() { var a; if (bar) { return true; } var a; }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", output: "function foo() { if (bar) { var a; if (baz) { return true; } var a; } }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { let a; if (bar) { return true; } else { let a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "class foo { bar() { let a; if (baz) { return true; } else { let a; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { let a; if (baz) { return true; } else { let a; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() {let a; if (bar) { if (baz) { return true; } else { let a; } } }", output: "function foo() {let a; if (bar) { if (baz) { return true; } let a; } }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { const a = 1; if (bar) { return true; } else { let a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { const a = 1; if (baz) { return true; } else { let a; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { let a; if (bar) { return true; } else { const a = 1 } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { let a; if (baz) { return true; } else { const a = 1; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { class a {}; if (bar) { return true; } else { const a = 1; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { class a {}; if (baz) { return true; } else { const a = 1; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { const a = 1; if (bar) { return true; } else { class a {} } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { const a = 1; if (baz) { return true; } else { class a {} } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { var a; if (bar) { return true; } else { let a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { var a; return true; } else { let a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } while (baz) { var a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo(a) { if (bar) { return true; } else { let a; } }", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "BlockStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(a = 1) { if (bar) { return true; } else { let a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo(a, b = a) { if (bar) { return true; } else { let a; } if (bar) { return true; } else { let b; }}", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "BlockStatement" }, { messageId: "unexpected", type: "BlockStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo(...args) { if (bar) { return true; } else { let args; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { try {} catch (a) { if (bar) { return true; } else { let a; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } else { let a; } } } }", output: "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } let a; } } }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { try {} catch ({bar, a = 1}) { if (baz) { return true; } else { let a; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let arguments; } }", output: "function foo() { if (bar) { return true; } let arguments; }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let arguments; } return arguments[0]; }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let arguments; } if (baz) { return arguments[0]; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let arguments; } } }", output: "function foo() { if (bar) { if (baz) { return true; } let arguments; } }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } a; }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } if (baz) { a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } a; }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } a; }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { a; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function a() { if (foo) { return true; } else { let a; } a(); }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function a() { if (a) { return true; } else { let a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function a() { if (foo) { return a; } else { let a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } function baz() { a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } (() => a) } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } var a; }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } var a; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } var { a } = {}; } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { var a; } } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { var a; } }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { var a; } }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } else { let a; } } }", output: "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } let a; } }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } function a(){} }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (baz) { if (bar) { return true; } else { let a; } function a(){} } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { function a(){} } }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { function a(){} } }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { if (baz) { return true; } else { let a; } } function a(){} }", output: "function foo() { if (bar) { if (baz) { return true; } let a; } function a(){} }", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { let a; if (bar) { return true; } else { function a(){} } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { var a; if (bar) { return true; } else { function a(){} } }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else function baz() {} };", @@ -513,14 +513,14 @@ ruleTester.run("no-else-return", rule, { { code: "if (foo) { return true; } else { let a; }", output: "if (foo) { return true; } let a; ", - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } + languageOptions: { ecmaVersion: 6, sourceType: "commonjs" }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "let a; if (foo) { return true; } else { let a; }", output: null, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } + languageOptions: { ecmaVersion: 6, sourceType: "commonjs" }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] } ] }); diff --git a/tests/lib/rules/no-empty-character-class.js b/tests/lib/rules/no-empty-character-class.js index 2b07a50d294..4aeab04d1f5 100644 --- a/tests/lib/rules/no-empty-character-class.js +++ b/tests/lib/rules/no-empty-character-class.js @@ -54,15 +54,15 @@ ruleTester.run("no-empty-character-class", rule, { { code: "var foo = /[]]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "var foo = /\\[[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "var foo = /\\[\\[\\]a-z[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, - { code: "var foo = /[]]/d;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2022 } }, - { code: "var foo = /[(]\\u{0}*[]/u;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2015 } }, - { code: "var foo = /[]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[a][]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[a[[b[]c]]d]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[a--[]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[]--b]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[a&&[]]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } }, - { code: "var foo = /[[]&&b]/v;", errors: [{ messageId: "unexpected", type: "Literal" }], languageOptions: { ecmaVersion: 2024 } } + { code: "var foo = /[]]/d;", languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[(]\\u{0}*[]/u;", languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[[]]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[[a][]]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[a[[b[]c]]d]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[a--[]]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[[]--b]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[a&&[]]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[[]&&b]/v;", languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", type: "Literal" }] } ] }); diff --git a/tests/lib/rules/no-empty-pattern.js b/tests/lib/rules/no-empty-pattern.js index 47ec0f86cd4..ea5086e33d7 100644 --- a/tests/lib/rules/no-empty-pattern.js +++ b/tests/lib/rules/no-empty-pattern.js @@ -39,184 +39,184 @@ ruleTester.run("no-empty-pattern", rule, { invalid: [ { code: "var {} = foo", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [] = foo", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {a: {}} = foo", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {a, b: {}} = foo", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {a: []} = foo", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo({}) {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo([]) {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo({a: {}}) {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo({a: []}) {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo({}) {}", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function({}) {}", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = ({}) => {}", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo({} = {}) {}", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function({} = {}) {}", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = ({} = {}) => {}", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = ({a: {}}) => {}", options: [{ allowObjectPatternsAsParameters: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = ({} = bar) => {}", options: [{ allowObjectPatternsAsParameters: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = ({} = { bar: 1 }) => {}", options: [{ allowObjectPatternsAsParameters: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = ([]) => {}", options: [{ allowObjectPatternsAsParameters: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, type: "ArrayPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/no-eval.js b/tests/lib/rules/no-eval.js index 7b057cb728a..64c63731c71 100644 --- a/tests/lib/rules/no-eval.js +++ b/tests/lib/rules/no-eval.js @@ -101,79 +101,79 @@ ruleTester.run("no-eval", rule, { // Indirect eval { code: "(0, eval)('foo')", errors: [{ messageId: "unexpected", type: "Identifier", column: 5, endColumn: 9 }] }, - { code: "(0, window.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 16 }], languageOptions: { globals: { window: "readonly" } } }, - { code: "(0, window['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 18 }], languageOptions: { globals: { window: "readonly" } } }, + { code: "(0, window.eval)('foo')", languageOptions: { globals: { window: "readonly" } }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 16 }] }, + { code: "(0, window['eval'])('foo')", languageOptions: { globals: { window: "readonly" } }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 18 }] }, { code: "var EVAL = eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "Identifier", column: 12, endColumn: 16 }] }, { code: "var EVAL = this.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 17, endColumn: 21 }] }, { code: "'use strict'; var EVAL = this.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 31, endColumn: 35 }] }, - { code: "() => { this.eval('foo'); }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 14, endColumn: 18 }], languageOptions: { ecmaVersion: 6 } }, - { code: "() => { 'use strict'; this.eval('foo'); }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }], languageOptions: { ecmaVersion: 6 } }, - { code: "'use strict'; () => { this.eval('foo'); }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }], languageOptions: { ecmaVersion: 6 } }, - { code: "() => { 'use strict'; () => { this.eval('foo'); } }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 36, endColumn: 40 }], languageOptions: { ecmaVersion: 6 } }, + { code: "() => { this.eval('foo'); }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 14, endColumn: 18 }] }, + { code: "() => { 'use strict'; this.eval('foo'); }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }] }, + { code: "'use strict'; () => { this.eval('foo'); }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 28, endColumn: 32 }] }, + { code: "() => { 'use strict'; () => { this.eval('foo'); } }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 36, endColumn: 40 }] }, { code: "(function(exe){ exe('foo') })(eval);", errors: [{ messageId: "unexpected", type: "Identifier", column: 31, endColumn: 35 }] }, - { code: "window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], languageOptions: { globals: { window: "readonly" } } }, - { code: "window.window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], languageOptions: { globals: { window: "readonly" } } }, - { code: "window.window['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], languageOptions: { globals: { window: "readonly" } } }, - { code: "global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], languageOptions: { sourceType: "commonjs" } }, - { code: "global.global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], languageOptions: { sourceType: "commonjs" } }, - { code: "global.global[`eval`]('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, + { code: "window.eval('foo')", languageOptions: { globals: { window: "readonly" } }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }] }, + { code: "window.window.eval('foo')", languageOptions: { globals: { window: "readonly" } }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }] }, + { code: "window.window['eval']('foo')", languageOptions: { globals: { window: "readonly" } }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }] }, + { code: "global.eval('foo')", languageOptions: { sourceType: "commonjs" }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }] }, + { code: "global.global.eval('foo')", languageOptions: { sourceType: "commonjs" }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }] }, + { code: "global.global[`eval`]('foo')", languageOptions: { ecmaVersion: 6, sourceType: "commonjs" }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }] }, { code: "this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 6, endColumn: 10 }] }, { code: "'use strict'; this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 20, endColumn: 24 }] }, { code: "function foo() { this.eval('foo') }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }] }, - { code: "var EVAL = globalThis.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 23, endColumn: 27 }], languageOptions: { ecmaVersion: 2020 } }, - { code: "globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 12, endColumn: 16 }], languageOptions: { ecmaVersion: 2020 } }, - { code: "globalThis.globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }], languageOptions: { ecmaVersion: 2020 } }, - { code: "globalThis.globalThis['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 29 }], languageOptions: { ecmaVersion: 2020 } }, - { code: "(0, globalThis.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 20 }], languageOptions: { ecmaVersion: 2020 } }, - { code: "(0, globalThis['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 22 }], languageOptions: { ecmaVersion: 2020 } }, + { code: "var EVAL = globalThis.eval; EVAL('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 23, endColumn: 27 }] }, + { code: "globalThis.eval('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 12, endColumn: 16 }] }, + { code: "globalThis.globalThis.eval('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }] }, + { code: "globalThis.globalThis['eval']('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 29 }] }, + { code: "(0, globalThis.eval)('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 20 }] }, + { code: "(0, globalThis['eval'])('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 22 }] }, // Optional chaining { code: "window?.eval('foo')", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } }, + errors: [{ messageId: "unexpected" }] }, { code: "(window?.eval)('foo')", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } }, + errors: [{ messageId: "unexpected" }] }, { code: "(window?.window).eval('foo')", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } } + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } }, + errors: [{ messageId: "unexpected" }] }, // Class fields { code: "class C { [this.eval('foo')] }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected" }] }, { code: "'use strict'; class C { [this.eval('foo')] }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected" }] }, { code: "class A { static {} [this.eval()]; }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected" }] }, // in es3, "use strict" directives do not apply { code: "function foo() { 'use strict'; this.eval(); }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 3 } + languageOptions: { ecmaVersion: 3 }, + errors: [{ messageId: "unexpected" }] }, // this.eval in callbacks (not user-defined) { code: "array.findLast(x => this.eval.includes(x), { eval: 'abc' });", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2023 } + languageOptions: { ecmaVersion: 2023 }, + errors: [{ messageId: "unexpected" }] }, { code: "callbacks.findLastIndex(function (cb) { return cb(eval); }, this);", diff --git a/tests/lib/rules/no-ex-assign.js b/tests/lib/rules/no-ex-assign.js index ec7d0268c33..f4d91808478 100644 --- a/tests/lib/rules/no-ex-assign.js +++ b/tests/lib/rules/no-ex-assign.js @@ -27,8 +27,8 @@ ruleTester.run("no-ex-assign", rule, { invalid: [ { code: "try { } catch (e) { e = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "try { } catch (ex) { ex = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }] }, - { code: "try { } catch (ex) { [ex] = []; }", errors: [{ messageId: "unexpected", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, - { code: "try { } catch (ex) { ({x: ex = 0} = {}); }", errors: [{ messageId: "unexpected", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, - { code: "try { } catch ({message}) { message = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } } + { code: "try { } catch (ex) { [ex] = []; }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "try { } catch (ex) { ({x: ex = 0} = {}); }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "try { } catch ({message}) { message = 10; }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] } ] }); diff --git a/tests/lib/rules/no-extend-native.js b/tests/lib/rules/no-extend-native.js index 2d36848d2b5..32fcf96a018 100644 --- a/tests/lib/rules/no-extend-native.js +++ b/tests/lib/rules/no-extend-native.js @@ -64,36 +64,36 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "BigInt.prototype.p = 0", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { builtin: "BigInt" }, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "WeakRef.prototype.p = 0", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "WeakRef" }, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "FinalizationRegistry.prototype.p = 0", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "FinalizationRegistry" }, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "AggregateError.prototype.p = 0", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "AggregateError" }, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "Function.prototype['p'] = 0", errors: [{ @@ -172,40 +172,40 @@ ruleTester.run("no-extend-native", rule, { // Optional chaining { code: "(Object?.prototype).p = 0", - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, { code: "Object.defineProperty(Object?.prototype, 'p', { value: 0 })", - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, { code: "Object?.defineProperty(Object.prototype, 'p', { value: 0 })", - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, { code: "(Object?.defineProperty)(Object.prototype, 'p', { value: 0 })", - errors: [{ messageId: "unexpected", data: { builtin: "Object" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, // Logical assignments { code: "Array.prototype.p &&= 0", - errors: [{ messageId: "unexpected", data: { builtin: "Array" } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] }, { code: "Array.prototype.p ||= 0", - errors: [{ messageId: "unexpected", data: { builtin: "Array" } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] }, { code: "Array.prototype.p ??= 0", - errors: [{ messageId: "unexpected", data: { builtin: "Array" } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] } ] diff --git a/tests/lib/rules/no-extra-bind.js b/tests/lib/rules/no-extra-bind.js index f6ab33f737e..d43810e2ab5 100644 --- a/tests/lib/rules/no-extra-bind.js +++ b/tests/lib/rules/no-extra-bind.js @@ -60,6 +60,7 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { return 1; }[`bind`](b)", output: "var a = function() { return 1; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", @@ -67,20 +68,19 @@ ruleTester.run("no-extra-bind", rule, { column: 34, endLine: 1, endColumn: 40 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = (() => { return 1; }).bind(b)", output: "var a = (() => { return 1; })", - errors, - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors }, { code: "var a = (() => { return this; }).bind(b)", output: "var a = (() => { return this; })", - errors, - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors }, { code: "var a = function() { (function(){ this.c }) }.bind(b)", @@ -196,38 +196,38 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { return 1; }.bind?.(b)", output: "var a = function() { return 1; }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var a = function() { return 1; }?.bind(b)", output: "var a = function() { return 1; }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var a = (function() { return 1; }?.bind)(b)", output: "var a = (function() { return 1; })", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var a = function() { return 1; }['bind']?.(b)", output: "var a = function() { return 1; }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var a = function() { return 1; }?.['bind'](b)", output: "var a = function() { return 1; }", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var a = (function() { return 1; }?.['bind'])(b)", output: "var a = (function() { return 1; })", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] } ] }); diff --git a/tests/lib/rules/no-extra-boolean-cast.js b/tests/lib/rules/no-extra-boolean-cast.js index 97dde6504b8..21a68cd8c27 100644 --- a/tests/lib/rules/no-extra-boolean-cast.js +++ b/tests/lib/rules/no-extra-boolean-cast.js @@ -279,11 +279,11 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "!Boolean(...foo);", output: null, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "!Boolean(foo, bar());", @@ -379,56 +379,56 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield!!a ? b : c }", output: "function *foo() { yield a ? b : c }", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield!! a ? b : c }", output: "function *foo() { yield a ? b : c }", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield! !a ? b : c }", output: "function *foo() { yield a ? b : c }", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield !!a ? b : c }", output: "function *foo() { yield a ? b : c }", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield(!!a) ? b : c }", output: "function *foo() { yield(a) ? b : c }", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield/**/!!a ? b : c }", output: "function *foo() { yield/**/a ? b : c }", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "x=!!a ? b : c ", @@ -934,11 +934,11 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(...foo) || bar;", output: null, options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "!Boolean(foo, bar()) || bar;", @@ -1028,51 +1028,51 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "function *foo() { yield(!!a || d) ? b : c }", output: "function *foo() { yield(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield(!! a || d) ? b : c }", output: "function *foo() { yield(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield(! !a || d) ? b : c }", output: "function *foo() { yield(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield (!!a || d) ? b : c }", output: "function *foo() { yield (a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function *foo() { yield/**/(!!a || d) ? b : c }", output: "function *foo() { yield/**/(a || d) ? b : c }", options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "x=!!a || d ? b : c ", @@ -1371,13 +1371,13 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "function *foo() { yield!!a || d ? b : c }", output: "function *foo() { yield a || d ? b : c }", options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression", column: 24, endColumn: 27 - }], - languageOptions: { ecmaVersion: 6 } + }] }, // test parentheses in autofix @@ -2005,26 +2005,26 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "!!!(a ** b)", output: "!(a ** b)", - errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }], - languageOptions: { ecmaVersion: 2016 } + languageOptions: { ecmaVersion: 2016 }, + errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }] }, { code: "!Boolean(a ** b)", output: "!(a ** b)", - errors: [{ messageId: "unexpectedCall", type: "CallExpression" }], - languageOptions: { ecmaVersion: 2016 } + languageOptions: { ecmaVersion: 2016 }, + errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] }, { code: "async function f() { !!!(await a) }", output: "async function f() { !await a }", - errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }] }, { code: "async function f() { !Boolean(await a) }", output: "async function f() { !await a }", - errors: [{ messageId: "unexpectedCall", type: "CallExpression" }], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] }, { code: "!!!!a", @@ -2207,11 +2207,11 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "if (Boolean(a **= b) && Boolean(c **= d)) {}", output: "if ((a **= b) && (c **= d)) {}", options: [{ enforceForLogicalOperands: true }], + languageOptions: { ecmaVersion: 2016 }, errors: [ { messageId: "unexpectedCall", type: "CallExpression" }, { messageId: "unexpectedCall", type: "CallExpression" } - ], - languageOptions: { ecmaVersion: 2016 } + ] }, { code: "if (!!(a ? b : c) || !!(d ? e : f)) {}", @@ -2407,34 +2407,34 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "if (Boolean(a ?? b) || c) {}", output: "if ((a ?? b) || c) {}", options: [{ enforceForLogicalOperands: true }], - errors: [{ messageId: "unexpectedCall", type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] }, // Optional chaining { code: "if (Boolean?.(foo)) ;", output: "if (foo) ;", - errors: [{ messageId: "unexpectedCall" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall" }] }, { code: "if (Boolean?.(a ?? b) || c) {}", output: "if ((a ?? b) || c) {}", options: [{ enforceForLogicalOperands: true }], - errors: [{ messageId: "unexpectedCall" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall" }] }, // https://github.com/eslint/eslint/issues/17173 { code: "if (!Boolean(a as any)) { }", output: "if (!(a as any)) { }", - errors: [{ messageId: "unexpectedCall" }], languageOptions: { parser: require(parser("typescript-parsers/boolean-cast-with-assertion")), ecmaVersion: 2020 - } + }, + errors: [{ messageId: "unexpectedCall" }] } ] }); diff --git a/tests/lib/rules/no-extra-label.js b/tests/lib/rules/no-extra-label.js index 0437bad774d..8d4cc01c02b 100644 --- a/tests/lib/rules/no-extra-label.js +++ b/tests/lib/rules/no-extra-label.js @@ -70,8 +70,8 @@ ruleTester.run("no-extra-label", rule, { { code: "A: for (a of ary) { break A; }", output: "A: for (a of ary) { break; }", - errors: [{ messageId: "unexpected", data: { name: "A" } }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "A: switch (a) { case 0: break A; }", diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index dbedafa254d..553a2c69433 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -3194,68 +3194,68 @@ ruleTester.run("no-extra-parens", rule, { { code: "var v = ((a ?? b)) || c", output: "var v = (a ?? b) || c", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = a ?? ((b || c))", output: "var v = a ?? (b || c)", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = ((a ?? b)) && c", output: "var v = (a ?? b) && c", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = a ?? ((b && c))", output: "var v = a ?? (b && c)", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = ((a || b)) ?? c", output: "var v = (a || b) ?? c", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = a || ((b ?? c))", output: "var v = a || (b ?? c)", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = ((a && b)) ?? c", output: "var v = (a && b) ?? c", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = a && ((b ?? c))", output: "var v = a && (b ?? c)", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = (a ?? b) ? b : c", output: "var v = a ?? b ? b : c", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = (a | b) ?? c | d", output: "var v = a | b ?? c | d", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = a | b ?? (c | d)", output: "var v = a | b ?? c | d", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, // "allowParensAfterCommentPattern" option (off by default) @@ -3416,35 +3416,35 @@ ruleTester.run("no-extra-parens", rule, { { code: "var v = (obj?.aaa)?.aaa", output: "var v = obj?.aaa?.aaa", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var v = (obj.aaa)?.aaa", output: "var v = obj.aaa?.aaa", - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var foo = (function(){})?.call()", output: "var foo = function(){}?.call()", options: ["all", { enforceForFunctionPrototypeMethods: true }], - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "var foo = (function(){}?.call())", output: "var foo = function(){}?.call()", options: ["all", { enforceForFunctionPrototypeMethods: true }], - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, { code: "(Object.prototype.toString.call())", output: "Object.prototype.toString.call()", options: ["all"], - errors: [{ messageId: "unexpected" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpected" }] }, // https://github.com/eslint/eslint/issues/16850 diff --git a/tests/lib/rules/no-extra-semi.js b/tests/lib/rules/no-extra-semi.js index 560d2f6bcde..a69d3412380 100644 --- a/tests/lib/rules/no-extra-semi.js +++ b/tests/lib/rules/no-extra-semi.js @@ -85,8 +85,8 @@ ruleTester.run("no-extra-semi", rule, { { code: "for(a of b);;", output: "for(a of b);", - errors: [{ messageId: "unexpected", type: "EmptyStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "EmptyStatement" }] }, { code: "if(true);;", @@ -121,80 +121,80 @@ ruleTester.run("no-extra-semi", rule, { { code: "class A { static { ; } }", output: "class A { static { } }", - errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 20 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 20 }] }, { code: "class A { static { a;; } }", output: "class A { static { a; } }", - errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 22 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 22 }] }, // Class body. { code: "class A { ; }", output: "class A { }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }] }, { code: "class A { /*a*/; }", output: "class A { /*a*/ }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 16 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 16 }] }, { code: "class A { ; a() {} }", output: "class A { a() {} }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }] }, { code: "class A { a() {}; }", output: "class A { a() {} }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A { a() {}; b() {} }", output: "class A { a() {} b() {} }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A {; a() {}; b() {}; }", output: "class A { a() {} b() {} }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "Punctuator", column: 10 }, { messageId: "unexpected", type: "Punctuator", column: 18 }, { messageId: "unexpected", type: "Punctuator", column: 26 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A { a() {}; get b() {} }", output: "class A { a() {} get b() {} }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A { field;; }", output: "class A { field; }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A { static {}; }", output: "class A { static {} }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 20 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 20 }] }, { code: "class A { static { a; }; foo(){} }", output: "class A { static { a; } foo(){} }", - errors: [{ messageId: "unexpected", type: "Punctuator", column: 24 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpected", type: "Punctuator", column: 24 }] }, // https://github.com/eslint/eslint/issues/16988 diff --git a/tests/lib/rules/no-floating-decimal.js b/tests/lib/rules/no-floating-decimal.js index 10a4d2ce1aa..8ad6bb36083 100644 --- a/tests/lib/rules/no-floating-decimal.js +++ b/tests/lib/rules/no-floating-decimal.js @@ -54,8 +54,8 @@ ruleTester.run("no-floating-decimal", rule, { { code: "for(foo of.2);", output: "for(foo of 0.2);", - errors: [leadingError], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [leadingError] } ] }); diff --git a/tests/lib/rules/no-func-assign.js b/tests/lib/rules/no-func-assign.js index dbcbef1f7c0..877cefe01ab 100644 --- a/tests/lib/rules/no-func-assign.js +++ b/tests/lib/rules/no-func-assign.js @@ -55,39 +55,39 @@ ruleTester.run("no-func-assign", rule, { }, { code: "[foo] = bar; function foo() { };", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "({x: foo = 0} = bar); function foo() { };", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { [foo] = bar; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function() { ({x: foo = 0} = bar); function foo() { }; })();", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = function foo() { foo = 123; };", diff --git a/tests/lib/rules/no-global-assign.js b/tests/lib/rules/no-global-assign.js index 48d04920dde..ec68a78bfe9 100644 --- a/tests/lib/rules/no-global-assign.js +++ b/tests/lib/rules/no-global-assign.js @@ -54,6 +54,7 @@ ruleTester.run("no-global-assign", rule, { }, { code: "({Object = 0, String = 0} = {});", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "globalShouldNotBeModified", @@ -65,26 +66,25 @@ ruleTester.run("no-global-assign", rule, { data: { name: "String" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "top = 0;", + languageOptions: { globals: globals.browser }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "top" }, type: "Identifier" - }], - languageOptions: { globals: globals.browser } + }] }, { code: "require = 0;", + languageOptions: { sourceType: "commonjs" }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "require" }, type: "Identifier" - }], - languageOptions: { sourceType: "commonjs" } + }] }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 @@ -98,12 +98,12 @@ ruleTester.run("no-global-assign", rule, { }, { code: "function f() { b = 1; }", + languageOptions: { globals: { b: false } }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "b" }, type: "Identifier" - }], - languageOptions: { globals: { b: false } } + }] }, { code: "/*global b:false*/ function f() { b++; }", diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index beec5c9b851..f0fa8b728d4 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -205,12 +205,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "``+foo", output: "String(foo)", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "BinaryExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo+\"\"", @@ -224,12 +224,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo+``", output: "String(foo)", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "BinaryExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "\"\"+foo.bar", @@ -243,12 +243,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "``+foo.bar", output: "String(foo.bar)", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo.bar)" }, type: "BinaryExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo.bar+\"\"", @@ -262,45 +262,45 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo.bar+``", output: "String(foo.bar)", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo.bar)" }, type: "BinaryExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`${foo}`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`\\\n${foo}`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`${foo}\\\n`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo += \"\"", @@ -314,12 +314,12 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo += ``", output: "foo = String(foo)", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "foo = String(foo)" }, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = !!foo", @@ -375,12 +375,12 @@ ruleTester.run("no-implicit-coercion", rule, { code: "var a = `` + foo", output: "var a = String(foo)", options: [{ boolean: true, allow: ["*"] }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, type: "BinaryExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "typeof+foo", @@ -403,34 +403,34 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "let x ='' + 1n;", output: "let x =String(1n);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(1n)" }, type: "BinaryExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, // Optional chaining { code: "~foo?.indexOf(1)", output: null, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "foo?.indexOf(1) >= 0" }, type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "~(foo?.indexOf)(1)", output: null, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "(foo?.indexOf)(1) !== -1" }, type: "UnaryExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, // https://github.com/eslint/eslint/issues/16373 regression tests diff --git a/tests/lib/rules/no-implicit-globals.js b/tests/lib/rules/no-implicit-globals.js index 56921d208d2..b0c39c3616c 100644 --- a/tests/lib/rules/no-implicit-globals.js +++ b/tests/lib/rules/no-implicit-globals.js @@ -552,33 +552,33 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "function *foo() {}", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "async function foo() {}", + languageOptions: { ecmaVersion: 2017 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ], - languageOptions: { ecmaVersion: 2017 } + ] }, { code: "async function *foo() {}", + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var foo = function() {};", @@ -600,23 +600,23 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "var foo = function*() {};", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "var foo = function *foo() {};", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "var foo = 1, bar = 2;", @@ -641,93 +641,93 @@ ruleTester.run("no-implicit-globals", rule, { { code: "const a = 1;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: constMessage - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "let a;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: letMessage - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "let a = 1;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: letMessage - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "class A {}", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: classMessage - }], - languageOptions: { ecmaVersion: 2015 } + }] }, // Multiple and mixed tests { code: "const a = 1; const b = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "const a = 1, b = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "let a, b = 1;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage }, { message: letMessage } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "const a = 1; let b; class C {}", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: letMessage }, { message: classMessage } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "const [a, b, ...c] = [];", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage }, { message: constMessage } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "let { a, foo: b, bar: { c } } = {};", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage }, { message: letMessage }, { message: letMessage } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, //------------------------------------------------------------------------------ @@ -755,13 +755,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = function*() {};", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "window.foo = function() { bar = 1; }", @@ -792,45 +792,45 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "for (foo of []);", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "ForOfStatement" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, // Not implicit strict { code: "window.foo = { bar() { foo = 1 } }", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "foo = 1", + languageOptions: { sourceType: "commonjs" }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { sourceType: "commonjs" } + ] }, { code: "foo = 1;", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, // Multiple and mixed @@ -924,6 +924,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "[foo, bar] = [];", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -933,28 +934,27 @@ ruleTester.run("no-implicit-globals", rule, { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:writable*/ [foo, bar] = [];", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global bar:writable*/ [foo, bar] = [];", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, //------------------------------------------------------------------------------ @@ -973,13 +973,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "window = 1;", + languageOptions: { globals: globals.browser }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ], - languageOptions: { globals: globals.browser } + ] }, { code: "/*global foo:readonly*/ foo = 1", @@ -992,13 +992,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1;", + languageOptions: { globals: { foo: "readonly" } }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ], - languageOptions: { globals: { foo: "readonly" } } + ] }, { code: "/*global foo:readonly*/ for (foo in {});", @@ -1011,13 +1011,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/*global foo:readonly*/ for (foo of []);", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyAssignmentMessage, type: "ForOfStatement" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, // Basic redeclaration tests @@ -1060,46 +1060,46 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly*/ const foo = 1", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:readonly*/ let foo", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:readonly*/ let foo = 1", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global Foo:readonly*/ class Foo {}", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "ClassDeclaration" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, // Multiple and mixed assignments @@ -1222,6 +1222,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly, bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1231,34 +1232,34 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:writable, bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:readonly, bar: writable*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1268,12 +1269,12 @@ ruleTester.run("no-implicit-globals", rule, { message: constMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1283,12 +1284,12 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:readonly, bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1298,34 +1299,34 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:writable, bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:readonly, bar: writable*/ let foo, bar;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global foo:readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1335,12 +1336,12 @@ ruleTester.run("no-implicit-globals", rule, { message: letMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/*global bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1350,8 +1351,7 @@ ruleTester.run("no-implicit-globals", rule, { message: readonlyRedeclarationMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, //------------------------------------------------------------------------------ @@ -1379,33 +1379,33 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ function *foo() {}", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported bar */ async function foo() {}", + languageOptions: { ecmaVersion: 2017 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ], - languageOptions: { ecmaVersion: 2017 } + ] }, { code: "/* exported bar */ async function *foo() {}", + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: functionMessage, type: "FunctionDeclaration" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "/* exported bar */ var foo = function() {};", @@ -1427,23 +1427,23 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ var foo = function*() {};", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported bar */ var foo = function *foo() {};", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported bar */ var foo = 1, bar = 2;", @@ -1459,83 +1459,84 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported b */ const a = 1;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported b */ let a;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported b */ let a = 1;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported B */ class A {}", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: classMessage, type: "ClassDeclaration" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported a */ const a = 1; const b = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported a */ const a = 1, b = 2;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported a */ let a, b = 1;", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported a */ const a = 1; let b; class C {}", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1545,12 +1546,12 @@ ruleTester.run("no-implicit-globals", rule, { message: classMessage, type: "ClassDeclaration" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported a */ const [a, b, ...c] = [];", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1560,12 +1561,12 @@ ruleTester.run("no-implicit-globals", rule, { message: constMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported a */ let { a, foo: b, bar: { c } } = {};", options: [{ lexicalBindings: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1575,8 +1576,7 @@ ruleTester.run("no-implicit-globals", rule, { message: letMessage, type: "VariableDeclarator" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, // Global variable leaks @@ -1600,13 +1600,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported foo */ foo = function*() {};", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "/* exported foo */ window.foo = function() { bar = 1; }", @@ -1637,13 +1637,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported foo */ for (foo of []);", + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, type: "ForOfStatement" } - ], - languageOptions: { ecmaVersion: 2015 } + ] } ] }); diff --git a/tests/lib/rules/no-implied-eval.js b/tests/lib/rules/no-implied-eval.js index 952c3c24986..b57aff9df8d 100644 --- a/tests/lib/rules/no-implied-eval.js +++ b/tests/lib/rules/no-implied-eval.js @@ -131,47 +131,47 @@ ruleTester.run("no-implied-eval", rule, { { code: "setInterval(\"x = 1;\");", errors: [expectedError] }, { code: "execScript(\"x = 1;\");", errors: [expectedError] }, - { code: "const s = 'x=1'; setTimeout(s, 100);", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, - { code: "setTimeout(String('x=1'), 100);", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, + { code: "const s = 'x=1'; setTimeout(s, 100);", languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, + { code: "setTimeout(String('x=1'), 100);", languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, // member expressions - { code: "window.setTimeout('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "window.setInterval('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "window['setTimeout']('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "window['setInterval']('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "window[`setInterval`]('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, - { code: "window.window['setInterval']('foo')", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "global.setTimeout('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "global.setInterval('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "global['setTimeout']('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "global['setInterval']('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "global[`setInterval`]('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, - { code: "global.global['setInterval']('foo')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "globalThis.setTimeout('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 2020 } }, - { code: "globalThis.setInterval('foo')", errors: [expectedError], languageOptions: { ecmaVersion: 2020 } }, + { code: "window.setTimeout('foo')", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "window.setInterval('foo')", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "window['setTimeout']('foo')", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "window['setInterval']('foo')", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "window[`setInterval`]('foo')", languageOptions: { ecmaVersion: 6, globals: globals.browser }, errors: [expectedError] }, + { code: "window.window['setInterval']('foo')", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "global.setTimeout('foo')", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global.setInterval('foo')", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global['setTimeout']('foo')", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global['setInterval']('foo')", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global[`setInterval`]('foo')", languageOptions: { ecmaVersion: 6, sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global.global['setInterval']('foo')", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "globalThis.setTimeout('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [expectedError] }, + { code: "globalThis.setInterval('foo')", languageOptions: { ecmaVersion: 2020 }, errors: [expectedError] }, // template literals - { code: "setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, - { code: "window.setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, - { code: "window.window.setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, - { code: "global.global.setTimeout(`foo${bar}`)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.node } }, + { code: "setTimeout(`foo${bar}`)", languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, + { code: "window.setTimeout(`foo${bar}`)", languageOptions: { ecmaVersion: 6, globals: globals.browser }, errors: [expectedError] }, + { code: "window.window.setTimeout(`foo${bar}`)", languageOptions: { ecmaVersion: 6, globals: globals.browser }, errors: [expectedError] }, + { code: "global.global.setTimeout(`foo${bar}`)", languageOptions: { ecmaVersion: 6, globals: globals.node }, errors: [expectedError] }, // string concatenation { code: "setTimeout('foo' + bar)", errors: [expectedError] }, { code: "setTimeout(foo + 'bar')", errors: [expectedError] }, - { code: "setTimeout(`foo` + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 6 } }, + { code: "setTimeout(`foo` + bar)", languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, { code: "setTimeout(1 + ';' + 1)", errors: [expectedError] }, - { code: "window.setTimeout('foo' + bar)", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "window.setTimeout(foo + 'bar')", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "window.setTimeout(`foo` + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 6, globals: globals.browser } }, - { code: "window.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "window.window.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { globals: globals.browser } }, - { code: "global.setTimeout('foo' + bar)", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "global.setTimeout(foo + 'bar')", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "global.setTimeout(`foo` + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 6, sourceType: "commonjs" } }, - { code: "global.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "global.global.setTimeout(1 + ';' + 1)", errors: [expectedError], languageOptions: { sourceType: "commonjs" } }, - { code: "globalThis.setTimeout('foo' + bar)", errors: [expectedError], languageOptions: { ecmaVersion: 2020 } }, + { code: "window.setTimeout('foo' + bar)", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "window.setTimeout(foo + 'bar')", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "window.setTimeout(`foo` + bar)", languageOptions: { ecmaVersion: 6, globals: globals.browser }, errors: [expectedError] }, + { code: "window.setTimeout(1 + ';' + 1)", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "window.window.setTimeout(1 + ';' + 1)", languageOptions: { globals: globals.browser }, errors: [expectedError] }, + { code: "global.setTimeout('foo' + bar)", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global.setTimeout(foo + 'bar')", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global.setTimeout(`foo` + bar)", languageOptions: { ecmaVersion: 6, sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global.setTimeout(1 + ';' + 1)", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "global.global.setTimeout(1 + ';' + 1)", languageOptions: { sourceType: "commonjs" }, errors: [expectedError] }, + { code: "globalThis.setTimeout('foo' + bar)", languageOptions: { ecmaVersion: 2020 }, errors: [expectedError] }, // gives the correct node when dealing with nesting { @@ -203,6 +203,7 @@ ruleTester.run("no-implied-eval", rule, { " window.execScript('str');\n" + " return 'bar';\n" + "})())", + languageOptions: { globals: globals.browser }, errors: [ { messageId: "impliedEval", @@ -216,8 +217,7 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ], - languageOptions: { globals: globals.browser } + ] }, { code: @@ -226,6 +226,7 @@ ruleTester.run("no-implied-eval", rule, { " global.execScript('str');\n" + " return 'bar';\n" + "})())", + languageOptions: { sourceType: "commonjs" }, errors: [ { messageId: "impliedEval", @@ -239,26 +240,25 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ], - languageOptions: { sourceType: "commonjs" } + ] }, // Optional chaining { code: "window?.setTimeout('code', 0)", - errors: [{ messageId: "impliedEval" }], languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } - } + }, + errors: [{ messageId: "impliedEval" }] }, { code: "(window?.setTimeout)('code', 0)", - errors: [{ messageId: "impliedEval" }], languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } - } + }, + errors: [{ messageId: "impliedEval" }] } ] }); diff --git a/tests/lib/rules/no-import-assign.js b/tests/lib/rules/no-import-assign.js index b410b515537..8d3d68378fc 100644 --- a/tests/lib/rules/no-import-assign.js +++ b/tests/lib/rules/no-import-assign.js @@ -315,18 +315,18 @@ ruleTester.run("no-import-assign", rule, { // Optional chaining { code: "import * as mod from 'mod'; Object?.defineProperty(mod, key, d)", - errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] }, { code: "import * as mod from 'mod'; (Object?.defineProperty)(mod, key, d)", - errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] }, { code: "import * as mod from 'mod'; delete mod?.prop", - errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] } ] }); diff --git a/tests/lib/rules/no-inner-declarations.js b/tests/lib/rules/no-inner-declarations.js index 9dcc5274fc5..3d42e398001 100644 --- a/tests/lib/rules/no-inner-declarations.js +++ b/tests/lib/rules/no-inner-declarations.js @@ -286,6 +286,7 @@ ruleTester.run("no-inner-declarations", rule, { }, { code: "const doSomething = () => { if (test) { var foo = 42; } }", options: ["both"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -293,11 +294,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "function body" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C { method() { if(test) { var foo; } } }", options: ["both"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -305,11 +306,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "function body" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C { static { if (test) { function foo() {} } } }", options: ["both"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -317,11 +318,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "class static block body" }, type: "FunctionDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { if (test) { var foo; } } }", options: ["both"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -329,11 +330,11 @@ ruleTester.run("no-inner-declarations", rule, { body: "class static block body" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { if (test) { if (anotherTest) { var foo; } } } }", options: ["both"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -341,8 +342,7 @@ ruleTester.run("no-inner-declarations", rule, { body: "class static block body" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/no-irregular-whitespace.js b/tests/lib/rules/no-irregular-whitespace.js index 48fc2f0d1af..85d176fc060 100644 --- a/tests/lib/rules/no-irregular-whitespace.js +++ b/tests/lib/rules/no-irregular-whitespace.js @@ -541,6 +541,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "var any = `\u3000`, other = `\u000B`;", options: [{ skipTemplates: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -554,12 +555,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 25 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`something ${\u3000 10} another thing`", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -567,12 +568,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`something ${10\u3000} another thing`", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -580,12 +581,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "\u3000\n`\u3000template`", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -593,12 +594,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "\u3000\n`\u3000multiline\ntemplate`", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -606,12 +607,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "\u3000`\u3000template`", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -619,12 +620,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "\u3000`\u3000multiline\ntemplate`", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -632,12 +633,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`\u3000template`\u3000", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -645,12 +646,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`\u3000multiline\ntemplate`\u3000", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -658,12 +659,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 2, column: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`\u3000template`\n\u3000", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -671,12 +672,12 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 2, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`\u3000multiline\ntemplate`\n\u3000", options: [{ skipTemplates: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -684,8 +685,7 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 3, column: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // full location tests @@ -1018,6 +1018,13 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u000B
;", + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } + } + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1025,17 +1032,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u000C
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u000C
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1043,17 +1050,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u0085
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u0085
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1061,17 +1068,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u00A0
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u00A0
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1079,17 +1086,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u180E
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u180E
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1097,17 +1104,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\ufeff
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\ufeff
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1115,17 +1122,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2000
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2000
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1133,17 +1140,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2001
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2001
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1151,17 +1158,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2002
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2002
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1169,17 +1176,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2003
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2003
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1187,17 +1194,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2004
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2004
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1205,17 +1212,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2005
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2005
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1223,17 +1230,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2006
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2006
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1241,17 +1248,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2007
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2007
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1259,17 +1266,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2008
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2008
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1277,17 +1284,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u2009
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u2009
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1295,17 +1302,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u200A
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u200A
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1313,17 +1320,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u200B
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u200B
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1331,17 +1338,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u202F
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u202F
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1349,17 +1356,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u205f
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u205f
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1367,17 +1374,17 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], + ] + }, + { + code: "
\u3000
;", languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } - }, - { - code: "
\u3000
;", + }, errors: [ { messageId: "noIrregularWhitespace", @@ -1385,14 +1392,7 @@ ruleTester.run("no-irregular-whitespace", rule, { line: 1, column: 6 } - ], - languageOptions: { - parserOptions: { - ecmaFeatures: { - jsx: true - } - } - } + ] } ] }); diff --git a/tests/lib/rules/no-iterator.js b/tests/lib/rules/no-iterator.js index 10160b109d8..a3a71841f3b 100644 --- a/tests/lib/rules/no-iterator.js +++ b/tests/lib/rules/no-iterator.js @@ -49,19 +49,19 @@ ruleTester.run("no-iterator", rule, { }, { code: "var a = test[`__iterator__`];", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noIterator", type: "MemberExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "test[`__iterator__`] = function () {};", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noIterator", type: "MemberExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/no-lone-blocks.js b/tests/lib/rules/no-lone-blocks.js index ec7a4f56d7f..8b013756ea9 100644 --- a/tests/lib/rules/no-lone-blocks.js +++ b/tests/lib/rules/no-lone-blocks.js @@ -135,41 +135,42 @@ ruleTester.run("no-lone-blocks", rule, { // Non-block-level bindings, even in ES6 { code: "{ function bar() {} }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{var x = 1;}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ \n{var x = 1;}\n let y = 2; } {let z = 1;}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 2 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ \n{let x = 1;}\n var y = 2; } {let z = 1;}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement", line: 1 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ \n{var x = 1;}\n var y = 2; }\n {var z = 1;}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "redundantBlock", @@ -186,8 +187,7 @@ ruleTester.run("no-lone-blocks", rule, { type: "BlockStatement", line: 4 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -229,12 +229,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 3 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: ` @@ -262,12 +262,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -282,12 +282,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -299,12 +299,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -316,12 +316,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -333,12 +333,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -350,12 +350,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -367,12 +367,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -385,12 +385,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -403,12 +403,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -421,12 +421,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 4 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: ` @@ -439,12 +439,12 @@ ruleTester.run("no-lone-blocks", rule, { } } `, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", line: 5 - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/no-lonely-if.js b/tests/lib/rules/no-lonely-if.js index e04a302f0fa..ba8731e173b 100644 --- a/tests/lib/rules/no-lonely-if.js +++ b/tests/lib/rules/no-lonely-if.js @@ -177,8 +177,8 @@ ruleTester.run("no-lonely-if", rule, { "}\n" + "`template literal`;", output: null, - errors, - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors }, { code: diff --git a/tests/lib/rules/no-loop-func.js b/tests/lib/rules/no-loop-func.js index 4586703c142..3a3efce5636 100644 --- a/tests/lib/rules/no-loop-func.js +++ b/tests/lib/rules/no-loop-func.js @@ -174,13 +174,13 @@ ruleTester.run("no-loop-func", rule, { }, { code: "for (var i of {}) { (function() { i; }) }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }] }, { code: "for (var i=0; i < l; i++) { (() => { i; }) }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }] }, { code: "for (var i=0; i < l; i++) { var a = function() { i; } }", @@ -202,73 +202,73 @@ ruleTester.run("no-loop-func", rule, { // Warns functions which are using modified variables. { code: "let a; for (let i=0; i { (function() { a; }); }); } a = 1;", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "ArrowFunctionExpression" }] }, { code: "for (var i = 0; i < 10; ++i) { for (let x in xs.filter(x => x != i)) { } }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }] }, { code: "for (let x of xs) { let a; for (let y of ys) { a = 1; (function() { a; }); } }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] }, { code: "for (var x of xs) { for (let y of ys) { (function() { x; }); } }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }] }, { code: "for (var x of xs) { (function() { x; }); }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }] }, { code: "var a; for (let x of xs) { a = 1; (function() { a; }); }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] }, { code: "var a; for (let x of xs) { (function() { a; }); a = 1; }", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] }, { code: "let a; function foo() { a = 10; } for (let x of xs) { (function() { a; }); } foo();", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] }, { code: "let a; function foo() { a = 10; for (let x of xs) { (function() { a; }); } } foo();", - errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unsafeRefs", data: { varNames: "'a'" }, type: "FunctionExpression" }] } ] }); diff --git a/tests/lib/rules/no-loss-of-precision.js b/tests/lib/rules/no-loss-of-precision.js index 9d51eb6d694..cbefdf6ca95 100644 --- a/tests/lib/rules/no-loss-of-precision.js +++ b/tests/lib/rules/no-loss-of-precision.js @@ -121,33 +121,33 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 900719925474099_3", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 90_0719925_4740.9_93e3", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 9.0_0719925_474099_3e15", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = -9_00719_9254_740993", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 900_719.92_54740_994", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = -900_719.92_5474_0994", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 5123000000000000000000000000001", @@ -179,23 +179,23 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 0b100000000000000000000000000000000000000000000000000001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0B100000000000000000000000000000000000000000000000000001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0o400000000000000001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0O400000000000000001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0400000000000000001", @@ -211,68 +211,68 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 5123_00000000000000000000000000_1", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = -5_12300000000000000000000_0000001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 123_00000000000000000000_00.0_0", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 1.0_00000000000000000_0000123", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 174_980057982_640953949800178169_409709228253554471456994_914061648512796239935950073857881054_1618443059_2", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 2e9_99", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = .1_23000000000000_00000_0000_0", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0b1_0000000000000000000000000000000000000000000000000000_1", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0B10000000000_0000000000000000000000000000_000000000000001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0o4_00000000000000_001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0O4_0000000000000000_1", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0x2_0000000000001", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0X200000_0000000_1", - errors: [{ messageId: "noLossOfPrecision" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noLossOfPrecision" }] } ] }); diff --git a/tests/lib/rules/no-magic-numbers.js b/tests/lib/rules/no-magic-numbers.js index 18c2b82949b..7f6ea455c7e 100644 --- a/tests/lib/rules/no-magic-numbers.js +++ b/tests/lib/rules/no-magic-numbers.js @@ -299,8 +299,8 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - errors: [{ messageId: "useConst" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "useConst" }] }, { code: "var foo = 0 + 1;", @@ -314,20 +314,20 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - errors: [{ messageId: "useConst" }], languageOptions: { ecmaVersion: 2020 - } + }, + errors: [{ messageId: "useConst" }] }, { code: "var foo = 0n + 1n;", + languageOptions: { + ecmaVersion: 2020 + }, errors: [ { messageId: "noMagic", data: { raw: "0n" } }, { messageId: "noMagic", data: { raw: "1n" } } - ], - languageOptions: { - ecmaVersion: 2020 - } + ] }, { code: "a = a + 5;", @@ -369,14 +369,14 @@ ruleTester.run("no-magic-numbers", rule, { ] }, { code: "console.log(0x1A + 0x02); console.log(071);", + languageOptions: { + sourceType: "script" + }, errors: [ { messageId: "noMagic", data: { raw: "0x1A" } }, { messageId: "noMagic", data: { raw: "0x02" } }, { messageId: "noMagic", data: { raw: "071" } } - ], - languageOptions: { - sourceType: "script" - } + ] }, { code: "var stats = {avg: 42};", options: [{ @@ -428,6 +428,7 @@ ruleTester.run("no-magic-numbers", rule, { "function invokeInTen(func) {\n" + "setTimeout(func, 10);\n" + "}\n", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "10" }, line: 7 }, { messageId: "noMagic", data: { raw: "10" }, line: 7 }, @@ -435,8 +436,7 @@ ruleTester.run("no-magic-numbers", rule, { { messageId: "noMagic", data: { raw: "1000" }, line: 15 }, { messageId: "noMagic", data: { raw: "0" }, line: 19 }, { messageId: "noMagic", data: { raw: "10" }, line: 22 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var data = ['foo', 'bar', 'baz']; var third = data[3];", @@ -501,20 +501,20 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "noMagic", data: { raw: "-0b110" }, line: 1 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "foo[-0o71]", options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "noMagic", data: { raw: "-0o71" }, line: 1 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "foo[-0x12]", @@ -530,10 +530,10 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], + languageOptions: { sourceType: "script" }, errors: [{ messageId: "noMagic", data: { raw: "-012" }, line: 1 - }], - languageOptions: { sourceType: "script" } + }] }, { code: "foo[0.1]", @@ -639,40 +639,40 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-1n" }, line: 1 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "foo[-100n]", options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-100n" }, line: 1 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "foo[-0x12n]", options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-0x12n" }, line: 1 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "foo[4294967295n]", // first above the max index options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "4294967295n" }, line: 1 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "foo[+0]", // Consistent with the default behavior, which doesn't allow: var foo = +0 @@ -706,30 +706,30 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "0n" }, line: 1 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "foo[+1n]", // Consistent with the default behavior, which doesn't allow: var foo = +1n options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "1n" }, line: 1 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "foo[- -1n]", // Consistent with the default behavior, which doesn't allow: var foo = - -1n options: [{ ignoreArrayIndexes: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-1n" }, line: 1 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "100 .toString()", @@ -751,18 +751,18 @@ ruleTester.run("no-magic-numbers", rule, { }, { code: "var a =
;", - errors: [ - { messageId: "noMagic", data: { raw: "1" }, line: 1 }, - { messageId: "noMagic", data: { raw: "2" }, line: 1 }, - { messageId: "noMagic", data: { raw: "3" }, line: 1 } - ], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } - } + }, + errors: [ + { messageId: "noMagic", data: { raw: "1" }, line: 1 }, + { messageId: "noMagic", data: { raw: "2" }, line: 1 }, + { messageId: "noMagic", data: { raw: "3" }, line: 1 } + ] }, { code: "var min, max, mean; min = 1; max = 10; mean = 4;", @@ -776,26 +776,26 @@ ruleTester.run("no-magic-numbers", rule, { { code: "f(100n)", options: [{ ignore: [100] }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "100n" }, line: 1 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "f(-100n)", options: [{ ignore: ["100n"] }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "-100n" }, line: 1 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "f(100n)", options: [{ ignore: ["-100n"] }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "100n" }, line: 1 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "f(100)", @@ -807,133 +807,133 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const func = (param = 123) => {}", options: [{ ignoreDefaultValues: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { param = 123 } = sourceObject;", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { param = 123 } = sourceObject;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const { param = 123 } = sourceObject;", options: [{ ignoreDefaultValues: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var one, two; [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // ignoreClassFieldInitialValues { code: "class C { foo = 2; }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { foo = 2; }", options: [{}], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { foo = -2; }", options: [{ ignoreClassFieldInitialValues: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "-2" }, line: 1, column: 17 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 24 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { #foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 18 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static #foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 25 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { foo = 2 + 3; }", options: [{ ignoreClassFieldInitialValues: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 }, { messageId: "noMagic", data: { raw: "3" }, line: 1, column: 21 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { 2; }", options: [{ ignoreClassFieldInitialValues: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 11 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { [2]; }", options: [{ ignoreClassFieldInitialValues: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 12 } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/no-misleading-character-class.js b/tests/lib/rules/no-misleading-character-class.js index 3bb2a33accb..41945f73aee 100644 --- a/tests/lib/rules/no-misleading-character-class.js +++ b/tests/lib/rules/no-misleading-character-class.js @@ -97,19 +97,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /[👍]/", + languageOptions: { ecmaVersion: 3, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }], - languageOptions: { ecmaVersion: 3, sourceType: "script" } + }] }, { code: "var r = /[👍]/", + languageOptions: { ecmaVersion: 5, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }], - languageOptions: { ecmaVersion: 5, sourceType: "script" } + }] }, { code: "var r = /[👍]\\a/", @@ -120,19 +120,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /(?<=[👍])/", + languageOptions: { ecmaVersion: 9 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /(?<=[👍])/u" }] - }], - languageOptions: { ecmaVersion: 9 } + }] }, { code: "var r = /(?<=[👍])/", + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /(?<=[👍])/u" }] - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "var r = /[Á]/", @@ -340,19 +340,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("[👍]", "")`, + languageOptions: { ecmaVersion: 3, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }], - languageOptions: { ecmaVersion: 3, sourceType: "script" } + }] }, { code: String.raw`var r = new RegExp("[👍]", "")`, + languageOptions: { ecmaVersion: 5, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag - }], - languageOptions: { ecmaVersion: 5, sourceType: "script" } + }] }, { code: String.raw`var r = new RegExp("[👍]\\a", "")`, @@ -363,19 +363,19 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("/(?<=[👍])", "")`, + languageOptions: { ecmaVersion: 9 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("/(?<=[👍])", "u")` }] - }], - languageOptions: { ecmaVersion: 9 } + }] }, { code: String.raw`var r = new RegExp("/(?<=[👍])", "")`, + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("/(?<=[👍])", "u")` }] - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: String.raw`var r = new RegExp("[Á]", "")`, @@ -512,11 +512,11 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("[🇯🇵]",)`, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("[🇯🇵]", "u",)` }] - }], - languageOptions: { ecmaVersion: 2017 } + }] }, { code: String.raw`var r = new RegExp(("[🇯🇵]"))`, @@ -534,11 +534,11 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp(("[🇯🇵]"),)`, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp(("[🇯🇵]"), "u",)` }] - }], - languageOptions: { ecmaVersion: 2017 } + }] }, { code: String.raw`var r = new RegExp("[🇯🇵]", "u")`, @@ -597,35 +597,35 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[❇️]", "")`, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "combiningClass", suggestions: null - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: String.raw`var r = new globalThis.RegExp("[👶🏻]", "u")`, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "emojiModifier", suggestions: null - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "")`, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "u")` }] - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: String.raw`var r = new globalThis.RegExp("[\\u{1F468}\\u{200D}\\u{1F469}\\u{200D}\\u{1F466}]", "u")`, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "zwj", suggestions: null - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: String.raw`/[\ud83d\u{dc4d}]/u`, @@ -660,32 +660,32 @@ ruleTester.run("no-misleading-character-class", rule, { // ES2024 { code: "var r = /[[👶🏻]]/v", + languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "emojiModifier", suggestions: null - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: "var r = /[👍]/", - errors: [{ - messageId: "surrogatePairWithoutUFlag", - suggestions: null // ecmaVersion doesn't support the 'u' flag - }], languageOptions: { ecmaVersion: 5, sourceType: "script" - } + }, + errors: [{ + messageId: "surrogatePairWithoutUFlag", + suggestions: null // ecmaVersion doesn't support the 'u' flag + }] }, { code: "var r = /[👍]/", + languageOptions: { + ecmaVersion: 2015 + }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /[👍]/u" }] - }], - languageOptions: { - ecmaVersion: 2015 - } + }] } ] diff --git a/tests/lib/rules/no-mixed-operators.js b/tests/lib/rules/no-mixed-operators.js index 144770a70d7..c43044d9650 100644 --- a/tests/lib/rules/no-mixed-operators.js +++ b/tests/lib/rules/no-mixed-operators.js @@ -383,6 +383,7 @@ ruleTester.run("no-mixed-operators", rule, { { code: "a + b ?? c", options: [{ groups: [["+", "??"]] }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { column: 3, @@ -402,8 +403,7 @@ ruleTester.run("no-mixed-operators", rule, { rightOperator: "??" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] } ] }); diff --git a/tests/lib/rules/no-mixed-spaces-and-tabs.js b/tests/lib/rules/no-mixed-spaces-and-tabs.js index e60e4f08e79..aa3a399e2ab 100644 --- a/tests/lib/rules/no-mixed-spaces-and-tabs.js +++ b/tests/lib/rules/no-mixed-spaces-and-tabs.js @@ -278,6 +278,7 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { { code: "`foo${\n \t 5 }bar`;", options: ["smart-tabs"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -287,11 +288,11 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`foo${\n\t 5 }bar`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -301,8 +302,7 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: " \t'';", diff --git a/tests/lib/rules/no-multi-assign.js b/tests/lib/rules/no-multi-assign.js index 38daffc10e9..4c4a9088693 100644 --- a/tests/lib/rules/no-multi-assign.js +++ b/tests/lib/rules/no-multi-assign.js @@ -75,11 +75,11 @@ ruleTester.run("no-multi-assign", rule, { }, { code: "let foo = bar = cee = 100;", + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 11, "AssignmentExpression"), errorAt(1, 17, "AssignmentExpression") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "a=b=c=d=e", @@ -146,50 +146,50 @@ ruleTester.run("no-multi-assign", rule, { { code: "const x = {};\nconst y = x.one = 1;", options: [{ ignoreNonDeclaration: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(2, 11, "AssignmentExpression") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let a, b;a = b = 1", options: [{}], + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 14, "AssignmentExpression") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let x, y;x = y = 'baz'", options: [{ ignoreNonDeclaration: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 14, "AssignmentExpression") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const a = b = 1", options: [{ ignoreNonDeclaration: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 11, "AssignmentExpression") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class C { field = foo = 0 }", + languageOptions: { ecmaVersion: 2022 }, errors: [ errorAt(1, 19, "AssignmentExpression") - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { field = foo = 0 }", options: [{ ignoreNonDeclaration: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ errorAt(1, 19, "AssignmentExpression") - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/no-multi-spaces.js b/tests/lib/rules/no-multi-spaces.js index 19643842c00..9d0f588494c 100644 --- a/tests/lib/rules/no-multi-spaces.js +++ b/tests/lib/rules/no-multi-spaces.js @@ -121,14 +121,14 @@ ruleTester.run("no-multi-spaces", rule, { { code: "var foo = (a, b) => {}", output: "var foo = (a, b) => {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "multipleSpaces", data: { displayValue: "b" }, type: "Identifier", column: 14, endColumn: 16 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = 1", diff --git a/tests/lib/rules/no-multiple-empty-lines.js b/tests/lib/rules/no-multiple-empty-lines.js index 2c9f33d6448..eb0f8a2e2e5 100644 --- a/tests/lib/rules/no-multiple-empty-lines.js +++ b/tests/lib/rules/no-multiple-empty-lines.js @@ -301,15 +301,15 @@ ruleTester.run("no-multiple-empty-lines", rule, { "`bar`;\n" + "`baz`;", options: [{ max: 1 }], - errors: [getExpectedError(1)], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [getExpectedError(1)] }, { code: "`template ${foo\n\n\n} literal`;", output: "`template ${foo\n\n} literal`;", options: [{ max: 1 }], - errors: [getExpectedError(1)], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [getExpectedError(1)] }, { diff --git a/tests/lib/rules/no-native-reassign.js b/tests/lib/rules/no-native-reassign.js index df17114295d..a85c85d56de 100644 --- a/tests/lib/rules/no-native-reassign.js +++ b/tests/lib/rules/no-native-reassign.js @@ -36,26 +36,26 @@ ruleTester.run("no-native-reassign", rule, { { code: "String++;", errors: [{ messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" }] }, { code: "({Object = 0, String = 0} = {});", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "nativeReassign", data: { name: "Object" }, type: "Identifier" }, { messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "top = 0;", - errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }], - languageOptions: { globals: globals.browser } + languageOptions: { globals: globals.browser }, + errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }] }, { code: "require = 0;", - errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }], - languageOptions: { sourceType: "commonjs" } + languageOptions: { sourceType: "commonjs" }, + errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }] }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 { code: "/*global b:false*/ function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, - { code: "function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }], languageOptions: { globals: { b: false } } }, + { code: "function f() { b = 1; }", languageOptions: { globals: { b: false } }, errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, { code: "/*global b:false*/ function f() { b++; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, { code: "/*global b*/ b = 1;", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, { code: "Array = 1;", errors: [{ messageId: "nativeReassign", data: { name: "Array" }, type: "Identifier" }] } diff --git a/tests/lib/rules/no-new-func.js b/tests/lib/rules/no-new-func.js index 426a74694ac..a92814a0c02 100644 --- a/tests/lib/rules/no-new-func.js +++ b/tests/lib/rules/no-new-func.js @@ -96,21 +96,21 @@ ruleTester.run("no-new-func", rule, { }, { code: "var a = (Function?.call)(null, \"b\", \"c\", \"return b+c\");", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noFunctionConstructor", type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "const fn = () => { class Function {} }; new Function('', '')", + languageOptions: { + ecmaVersion: 2015 + }, errors: [{ messageId: "noFunctionConstructor", type: "NewExpression" - }], - languageOptions: { - ecmaVersion: 2015 - } + }] }, { code: "var fn = function () { function Function() {} }; Function('', '')", diff --git a/tests/lib/rules/no-new-object.js b/tests/lib/rules/no-new-object.js index acef865ad46..e38156e7a3b 100644 --- a/tests/lib/rules/no-new-object.js +++ b/tests/lib/rules/no-new-object.js @@ -62,8 +62,8 @@ ruleTester.run("no-new-object", rule, { }, { code: "const a = new Object()", - errors: [{ messageId: "preferLiteral", type: "NewExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "preferLiteral", type: "NewExpression" }] } ] }); diff --git a/tests/lib/rules/no-new-wrappers.js b/tests/lib/rules/no-new-wrappers.js index 62181bc99fd..972e10bbc66 100644 --- a/tests/lib/rules/no-new-wrappers.js +++ b/tests/lib/rules/no-new-wrappers.js @@ -93,6 +93,7 @@ ruleTester.run("no-new-wrappers", rule, { const b = new String('foo'); } `, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noConstructor", data: { @@ -100,8 +101,7 @@ ruleTester.run("no-new-wrappers", rule, { }, type: "NewExpression", line: 2 - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/no-obj-calls.js b/tests/lib/rules/no-obj-calls.js index 3595ae0149c..1a786e88751 100644 --- a/tests/lib/rules/no-obj-calls.js +++ b/tests/lib/rules/no-obj-calls.js @@ -212,18 +212,18 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = new Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] }, { code: "var x = Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "/*globals Reflect: true*/ Reflect();", @@ -235,38 +235,38 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = new Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], - languageOptions: { ecmaVersion: 2017 } + languageOptions: { ecmaVersion: 2017 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] }, { code: "var x = Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - languageOptions: { globals: { Atomics: false } } + languageOptions: { globals: { Atomics: false } }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = new Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], - languageOptions: { globals: { Atomics: "writable" } } + languageOptions: { globals: { Atomics: "writable" } }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] }, { code: "var x = Intl();", - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }], - languageOptions: { globals: globals.browser } + languageOptions: { globals: globals.browser }, + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] }, { code: "var x = new Intl();", - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }], - languageOptions: { globals: globals.browser } + languageOptions: { globals: globals.browser }, + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }] }, { code: "/*globals Intl: true*/ Intl();", @@ -278,81 +278,81 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = globalThis.Math();", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Math();", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }] }, { code: "f(globalThis.Math());", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }] }, { code: "globalThis.Math().foo;", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }] }, { code: "new globalThis.Math().foo;", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }] }, { code: "var x = globalThis.JSON();", - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] }, { code: "x = globalThis.JSON(str);", - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] }, { code: "globalThis.Math( globalThis.JSON() );", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 37 }, { messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression", column: 18, endColumn: 35 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "var x = globalThis.Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Reflect;", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] }, { code: "/*globals Reflect: true*/ Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = globalThis.Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = globalThis.Intl();", - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }], - languageOptions: { globals: globals.browser, ecmaVersion: 2020 } + languageOptions: { globals: globals.browser, ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Intl;", - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }], - languageOptions: { globals: globals.browser, ecmaVersion: 2020 } + languageOptions: { globals: globals.browser, ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }] }, { code: "/*globals Intl: true*/ Intl();", - errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }], - languageOptions: { globals: globals.browser, ecmaVersion: 2020 } + languageOptions: { globals: globals.browser, ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] }, { code: "var foo = bar ? baz: JSON; foo();", @@ -364,45 +364,45 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var foo = bar ? baz: globalThis.JSON; foo();", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }] }, { code: "var foo = bar ? baz: globalThis.JSON; new foo();", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }] }, { code: "var foo = window.Atomics; foo();", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020, globals: globals.browser } + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }] }, { code: "var foo = window.Atomics; new foo;", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }], - languageOptions: { ecmaVersion: 2020, globals: globals.browser } + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }] }, { code: "var foo = window.Intl; foo();", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020, globals: globals.browser } + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "CallExpression" }] }, { code: "var foo = window.Intl; new foo;", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "NewExpression" }], - languageOptions: { ecmaVersion: 2020, globals: globals.browser } + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "NewExpression" }] }, // Optional chaining { code: "var x = globalThis?.Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = (globalThis?.Reflect)();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] } ] }); diff --git a/tests/lib/rules/no-param-reassign.js b/tests/lib/rules/no-param-reassign.js index 43c78dfd7bd..90101b6d66b 100644 --- a/tests/lib/rules/no-param-reassign.js +++ b/tests/lib/rules/no-param-reassign.js @@ -154,35 +154,35 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo({bar}) { bar = 13; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo([, {bar}]) { bar = 13; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { ({bar} = {}); }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { ({x: [, bar = 0]} = {}); }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { for (bar in baz); }", @@ -193,11 +193,11 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(bar) { for (bar of baz); }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { @@ -243,11 +243,11 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { for (bar.a of []); }", options: [{ props: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { (bar ? bar : [])[0] = 1; }", @@ -260,165 +260,165 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsForRegex: ["^a.*$"] }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsForRegex: ["^B.*$"] }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(bar) { ({foo: bar.a} = {}); }", options: [{ props: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { ({a} = obj); }", options: [{ props: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { ([...a] = obj); }", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function foo(a) { ({...a} = obj); }", + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "function foo(a) { ([...a.b] = obj); }", options: [{ props: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "function foo(a) { ({...a.b} = obj); }", options: [{ props: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "function foo(a) { for ({bar: a.b} in {}); }", options: [{ props: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { for ([a.b] of []); }", options: [{ props: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { a &&= b; }", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "function foo(a) { a ||= b; }", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "function foo(a) { a ??= b; }", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "function foo(a) { a.b &&= c; }", options: [{ props: true }], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "function foo(a) { a.b.c ||= d; }", options: [{ props: true }], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "function foo(a) { a[b] ??= c; }", options: [{ props: true }], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2021 } + }] } ] }); diff --git a/tests/lib/rules/no-promise-executor-return.js b/tests/lib/rules/no-promise-executor-return.js index 7d75595efe8..b7413da60f9 100644 --- a/tests/lib/rules/no-promise-executor-return.js +++ b/tests/lib/rules/no-promise-executor-return.js @@ -873,6 +873,9 @@ ruleTester.run("no-promise-executor-return", rule, { }, { code: "() => new Promise(() => async () => 1);", + languageOptions: { ecmaVersion: 2017 }, + + // for async errors: [{ messageId: "returnsValue", type: "ArrowFunctionExpression", @@ -883,10 +886,7 @@ ruleTester.run("no-promise-executor-return", rule, { output: "() => new Promise(() => {async () => 1});" } ] - }], - - // for async - languageOptions: { ecmaVersion: 2017 } + }] }, { code: "() => new Promise(() => function () {});", diff --git a/tests/lib/rules/no-proto.js b/tests/lib/rules/no-proto.js index 9c28b67fc4d..78698612dfa 100644 --- a/tests/lib/rules/no-proto.js +++ b/tests/lib/rules/no-proto.js @@ -29,7 +29,7 @@ ruleTester.run("no-proto", rule, { invalid: [ { code: "var a = test.__proto__;", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, { code: "var a = test['__proto__'];", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, - { code: "var a = test[`__proto__`];", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "test[`__proto__`] = function () {};", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } } + { code: "var a = test[`__proto__`];", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, + { code: "test[`__proto__`] = function () {};", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] } ] }); diff --git a/tests/lib/rules/no-prototype-builtins.js b/tests/lib/rules/no-prototype-builtins.js index 0be0755280b..27e1f54b0cd 100644 --- a/tests/lib/rules/no-prototype-builtins.js +++ b/tests/lib/rules/no-prototype-builtins.js @@ -161,6 +161,7 @@ ruleTester.run("no-prototype-builtins", rule, { }, { code: "foo[`isPrototypeOf`]('bar').baz", + languageOptions: { ecmaVersion: 2015 }, errors: [{ line: 1, column: 5, @@ -175,8 +176,7 @@ ruleTester.run("no-prototype-builtins", rule, { } ], type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: String.raw`foo.bar["propertyIsEnumerable"]('baz')`, @@ -203,31 +203,31 @@ ruleTester.run("no-prototype-builtins", rule, { errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { + name: "Can't suggest Object.prototype when there is no Object global variable", code: "foo.hasOwnProperty('bar')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], languageOptions: { globals: { Object: "off" } }, - name: "Can't suggest Object.prototype when there is no Object global variable" + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, // Optional chaining { code: "foo?.hasOwnProperty('bar')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "foo?.bar.hasOwnProperty('baz')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "foo.hasOwnProperty?.('bar')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { @@ -236,8 +236,8 @@ ruleTester.run("no-prototype-builtins", rule, { * and the optional part is before it, then don't suggest the fix */ code: "foo?.hasOwnProperty('bar').baz", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { @@ -246,6 +246,7 @@ ruleTester.run("no-prototype-builtins", rule, { * but the optional part is after it, then the fix is safe */ code: "foo.hasOwnProperty('bar')?.baz", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, @@ -255,12 +256,12 @@ ruleTester.run("no-prototype-builtins", rule, { output: "Object.prototype.hasOwnProperty.call(foo, 'bar')?.baz" } ] - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "(a,b).hasOwnProperty('bar')", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, @@ -272,33 +273,32 @@ ruleTester.run("no-prototype-builtins", rule, { output: "Object.prototype.hasOwnProperty.call((a,b), 'bar')" } ] - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { // No suggestion where no-unsafe-optional-chaining is reported on the call code: "(foo?.hasOwnProperty)('bar')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "(foo?.hasOwnProperty)?.('bar')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "foo?.['hasOwnProperty']('bar')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { // No suggestion where no-unsafe-optional-chaining is reported on the call code: "(foo?.[`hasOwnProperty`])('bar')", - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] } ] }); diff --git a/tests/lib/rules/no-redeclare.js b/tests/lib/rules/no-redeclare.js index 672f121beb7..6bfd974229a 100644 --- a/tests/lib/rules/no-redeclare.js +++ b/tests/lib/rules/no-redeclare.js @@ -147,7 +147,7 @@ ruleTester.run("no-redeclare", rule, { } ], invalid: [ - { code: "var a = 3; var a = 10;", errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var a = 3; var a = 10;", languageOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "switch(foo) { case a: var b = 3;\ncase b: var b = 4}", errors: [{ message: "'b' is already defined.", type: "Identifier" }] }, { code: "var a = 3; var a = 10;", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "var a = {}; var a = [];", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, @@ -156,37 +156,37 @@ ruleTester.run("no-redeclare", rule, { { code: "var a = function() { }; var a = function() { }", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "var a = function() { }; var a = new Date();", errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "var a = 3; var a = 10; var a = 15;", errors: [{ message: "'a' is already defined.", type: "Identifier" }, { message: "'a' is already defined.", type: "Identifier" }] }, - { code: "var a; var a;", errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export var a; var a;", errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "var a; var a;", languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, + { code: "export var a; var a;", languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, // `var` redeclaration in class static blocks. Redeclaration of functions is not allowed in class static blocks. { code: "class C { static { var a; var a; } }", - errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "class C { static { var a; { var a; } } }", - errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "class C { static { { var a; } var a; } }", - errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "class C { static { { var a; } { var a; } } }", - errors: [{ message: "'a' is already defined.", type: "Identifier" }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { @@ -197,56 +197,56 @@ ruleTester.run("no-redeclare", rule, { { code: "var top = 0;", options: [{ builtinGlobals: true }], - errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }], - languageOptions: { globals: globals.browser } + languageOptions: { globals: globals.browser }, + errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }] }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "'a' is already defined.", type: "Identifier" }, { message: "'Object' is already defined as a built-in global variable.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "'a' is already defined.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { message: "'a' is already defined.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "'a' is already defined.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var globalThis = 0;", options: [{ builtinGlobals: true }], - errors: [{ message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" }] }, { code: "var a; var {a = 0, b: globalThis = 0} = {};", options: [{ builtinGlobals: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { message: "'a' is already defined.", type: "Identifier" }, { message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "/*global b:false*/ var b = 1;", @@ -305,10 +305,10 @@ ruleTester.run("no-redeclare", rule, { }, { code: "var top = 0;", + languageOptions: { globals: globals.browser }, errors: [ { message: "'top' is already defined as a built-in global variable.", type: "Identifier" } - ], - languageOptions: { globals: globals.browser } + ] }, // Comments and built-ins. @@ -459,6 +459,7 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */", options: [{ builtinGlobals: true }], + languageOptions: { globals: { a: "readonly" } }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -466,12 +467,12 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }], - languageOptions: { globals: { a: "readonly" } } + }] }, { code: "/*globals a */", options: [{ builtinGlobals: true }], + languageOptions: { globals: { a: "writable" } }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -479,8 +480,7 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }], - languageOptions: { globals: { a: "writable" } } + }] }, { code: "/*globals a */ /*globals a */", @@ -496,6 +496,7 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */ /*globals a */ var a = 0", options: [{ builtinGlobals: true }], + languageOptions: { globals: { a: "writable" } }, errors: [ { message: "'a' is already defined as a built-in global variable.", @@ -521,8 +522,7 @@ ruleTester.run("no-redeclare", rule, { endLine: 1, endColumn: 36 } - ], - languageOptions: { globals: { a: "writable" } } + ] } ] }); diff --git a/tests/lib/rules/no-regex-spaces.js b/tests/lib/rules/no-regex-spaces.js index f47661d31b9..c809aec888b 100644 --- a/tests/lib/rules/no-regex-spaces.js +++ b/tests/lib/rules/no-regex-spaces.js @@ -148,14 +148,14 @@ ruleTester.run("no-regex-spaces", rule, { // `RegExp` is not shadowed in the scope where it's called code: "{ let RegExp = function() {}; } var foo = RegExp('bar baz');", output: "{ let RegExp = function() {}; } var foo = RegExp('bar {4}baz');", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "multipleSpaces", data: { length: "4" }, type: "CallExpression" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = /bar {3}baz/;", @@ -386,16 +386,16 @@ ruleTester.run("no-regex-spaces", rule, { { code: "var foo = /[[ ] ] /v;", output: "var foo = /[[ ] ] {4}/v;", + languageOptions: { + ecmaVersion: 2024 + }, errors: [ { messageId: "multipleSpaces", data: { length: "4" }, type: "Literal" } - ], - languageOptions: { - ecmaVersion: 2024 - } + ] }, { code: "var foo = new RegExp('[[ ] ] ', 'v');", diff --git a/tests/lib/rules/no-restricted-globals.js b/tests/lib/rules/no-restricted-globals.js index 38f37a5e12a..79abe9e0b68 100644 --- a/tests/lib/rules/no-restricted-globals.js +++ b/tests/lib/rules/no-restricted-globals.js @@ -80,36 +80,36 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: ["foo"], + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { - globals: { foo: false } - } + }] }, { code: "event", options: ["foo", "event"], + languageOptions: { globals: globals.browser }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }], - languageOptions: { globals: globals.browser } + }] }, { code: "foo", options: ["foo"], + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { - globals: { foo: false } - } + }] }, { code: "foo()", @@ -150,36 +150,36 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo" }], + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { - globals: { foo: false } - } + }] }, { code: "event", options: ["foo", { name: "event" }], + languageOptions: { globals: globals.browser }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }], - languageOptions: { globals: globals.browser } + }] }, { code: "foo", options: [{ name: "foo" }], + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - languageOptions: { - globals: { foo: false } - } + }] }, { code: "foo()", @@ -220,36 +220,36 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo", message: customMessage }], + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }], - languageOptions: { - globals: { foo: false } - } + }] }, { code: "event", options: ["foo", { name: "event", message: "Use local event parameter." }], + languageOptions: { globals: globals.browser }, errors: [{ messageId: "customMessage", data: { name: "event", customMessage: "Use local event parameter." }, type: "Identifier" - }], - languageOptions: { globals: globals.browser } + }] }, { code: "foo", options: [{ name: "foo", message: customMessage }], + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }], - languageOptions: { - globals: { foo: false } - } + }] }, { code: "foo()", @@ -272,12 +272,12 @@ ruleTester.run("no-restricted-globals", rule, { { code: "var foo = obj => hasOwnProperty(obj, 'name');", options: ["hasOwnProperty"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "defaultMessage", data: { name: "hasOwnProperty" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/no-restricted-modules.js b/tests/lib/rules/no-restricted-modules.js index 735e49f9e68..488849adb8a 100644 --- a/tests/lib/rules/no-restricted-modules.js +++ b/tests/lib/rules/no-restricted-modules.js @@ -117,13 +117,13 @@ ruleTester.run("no-restricted-modules", rule, { }, { code: "require(`fs`)", options: ["fs"], - errors: [{ messageId: "defaultMessage", data: { name: "fs" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "defaultMessage", data: { name: "fs" }, type: "CallExpression" }] }, { code: "require(`crypt\\o`);", options: ["crypto"], - errors: [{ messageId: "defaultMessage", data: { name: "crypto" }, type: "CallExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "defaultMessage", data: { name: "crypto" }, type: "CallExpression" }] }, { code: "var relative = require('../foo');", diff --git a/tests/lib/rules/no-restricted-properties.js b/tests/lib/rules/no-restricted-properties.js index 2cca4fbcc27..d470a18da97 100644 --- a/tests/lib/rules/no-restricted-properties.js +++ b/tests/lib/rules/no-restricted-properties.js @@ -339,6 +339,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "foo[/(?0)/]", options: [{ property: "/(?0)/" }], + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "restrictedProperty", data: { @@ -347,8 +348,7 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "MemberExpression" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "require.call({}, 'foo')", options: [{ @@ -381,6 +381,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar} = foo;", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -389,11 +390,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let {bar: baz} = foo;", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -402,11 +403,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let {'bar': baz} = foo;", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -415,11 +416,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let {bar: {baz: qux}} = foo;", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -428,11 +429,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let {bar} = foo;", options: [{ object: "foo" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -441,11 +442,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let {bar: baz} = foo;", options: [{ object: "foo" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -454,11 +455,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let {bar} = foo;", options: [{ property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedProperty", data: { @@ -467,11 +468,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let bar; ({bar} = foo);", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -480,11 +481,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let bar; ({bar: baz = 1} = foo);", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -493,11 +494,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function qux({bar} = foo) {}", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -506,11 +507,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function qux({bar: baz} = foo) {}", options: [{ object: "foo", property: "bar" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -519,11 +520,11 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {['foo']: qux, bar} = baz", options: [{ object: "baz", property: "foo" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -532,8 +533,7 @@ ruleTester.run("no-restricted-properties", rule, { message: "" }, type: "ObjectPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "obj['#foo']", options: [{ property: "#foo" }], diff --git a/tests/lib/rules/no-restricted-syntax.js b/tests/lib/rules/no-restricted-syntax.js index fd17c72df5a..7fb4c414664 100644 --- a/tests/lib/rules/no-restricted-syntax.js +++ b/tests/lib/rules/no-restricted-syntax.js @@ -80,8 +80,8 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "() => {}", options: ["ArrowFunctionExpression > BlockStatement"], - errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ArrowFunctionExpression > BlockStatement' is not allowed." }, type: "BlockStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ArrowFunctionExpression > BlockStatement' is not allowed." }, type: "BlockStatement" }] }, { code: "({ foo: 1, 'bar': 2 })", @@ -134,37 +134,37 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "var foo = foo?.bar?.();", options: ["ChainExpression"], - errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ChainExpression' is not allowed." }, type: "ChainExpression" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ChainExpression' is not allowed." }, type: "ChainExpression" }] }, { code: "var foo = foo?.bar?.();", options: ["[optional=true]"], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using '[optional=true]' is not allowed." }, type: "CallExpression" }, { messageId: "restrictedSyntax", data: { message: "Using '[optional=true]' is not allowed." }, type: "MemberExpression" } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, // fix https://github.com/estools/esquery/issues/110 { code: "a?.b", options: [":nth-child(1)"], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using ':nth-child(1)' is not allowed." }, type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, // https://github.com/eslint/eslint/issues/13639#issuecomment-683976062 { code: "const foo = [
,
]", options: ["* ~ *"], + languageOptions: { ecmaVersion: 2020, parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using '* ~ *' is not allowed." }, type: "JSXElement" } - ], - languageOptions: { ecmaVersion: 2020, parserOptions: { ecmaFeatures: { jsx: true } } } + ] } ] }); diff --git a/tests/lib/rules/no-return-assign.js b/tests/lib/rules/no-return-assign.js index f93fb39723a..c7d8d6ae9ce 100644 --- a/tests/lib/rules/no-return-assign.js +++ b/tests/lib/rules/no-return-assign.js @@ -138,25 +138,25 @@ ruleTester.run("no-return-assign", rule, { code: `function doSomething() { return foo = () => a }`, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "returnAssignment", type: "ReturnStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: `function doSomething() { return () => a = () => b }`, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "arrowAssignment", type: "ArrowFunctionExpression" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: `function foo(a){ @@ -168,13 +168,13 @@ ruleTester.run("no-return-assign", rule, { }, { code: "const foo = (a) => (b) => a = b", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "arrowAssignment", type: "ArrowFunctionExpression" } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/no-script-url.js b/tests/lib/rules/no-script-url.js index af7472aa26b..cb234cf1a2d 100644 --- a/tests/lib/rules/no-script-url.js +++ b/tests/lib/rules/no-script-url.js @@ -51,17 +51,17 @@ ruleTester.run("no-script-url", rule, { }, { code: "var a = `javascript:`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedScriptURL", type: "TemplateLiteral" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var a = `JavaScript:`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedScriptURL", type: "TemplateLiteral" } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/no-self-assign.js b/tests/lib/rules/no-self-assign.js index f67dbb7e473..84864e82628 100644 --- a/tests/lib/rules/no-self-assign.js +++ b/tests/lib/rules/no-self-assign.js @@ -93,28 +93,28 @@ ruleTester.run("no-self-assign", rule, { ], invalid: [ { code: "a = a", errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, - { code: "[a] = [a]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "[a, b] = [a, b]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "[a, b] = [a, c]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "[a, b] = [, b]", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "[a, ...b] = [a, ...b]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "[[a], {b}] = [[a], {b}]", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a} = {a})", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a: b} = {a: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({'a': b} = {'a': b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a: b} = {'a': b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({'a': b} = {a: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({1: b} = {1: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({1: b} = {'1': b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({'1': b} = {1: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({['a']: b} = {a: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({'a': b} = {[`a`]: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({1: b} = {[1]: b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a, b} = {a, b})", errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a, b} = {b, a})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a, b} = {c, a})", errors: [{ messageId: "selfAssignment", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a: {b}, c: [d]} = {a: {b}, c: [d]})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "d" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a, b} = {a, ...x, b})", errors: [{ messageId: "selfAssignment", data: { name: "b" } }], languageOptions: { ecmaVersion: 2018 } }, + { code: "[a] = [a]", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "[a, b] = [a, b]", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "[a, b] = [a, c]", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "[a, b] = [, b]", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "[a, ...b] = [a, ...b]", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "[[a], {b}] = [[a], {b}]", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a} = {a})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "({a: b} = {a: b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'a': b} = {'a': b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a: b} = {'a': b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'a': b} = {a: b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({1: b} = {1: b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({1: b} = {'1': b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'1': b} = {1: b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({['a']: b} = {a: b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'a': b} = {[`a`]: b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({1: b} = {[1]: b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a, b} = {a, b})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a, b} = {b, a})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "({a, b} = {c, a})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "({a: {b}, c: [d]} = {a: {b}, c: [d]})", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "d" } }] }, + { code: "({a, b} = {a, ...x, b})", languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, { code: "a.b = a.b", errors: [{ messageId: "selfAssignment", data: { name: "a.b" } }] @@ -145,47 +145,47 @@ ruleTester.run("no-self-assign", rule, { options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "this.x" } }] }, - { code: "a['/(?0)/'] = a[/(?0)/]", options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "a[/(?0)/]" } }], languageOptions: { ecmaVersion: 2018 } }, + { code: "a['/(?0)/'] = a[/(?0)/]", options: [{ props: true }], languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "selfAssignment", data: { name: "a[/(?0)/]" } }] }, // Optional chaining { code: "(a?.b).c = (a?.b).c", - errors: [{ messageId: "selfAssignment", data: { name: "(a?.b).c" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "selfAssignment", data: { name: "(a?.b).c" } }] }, { code: "a.b = a?.b", - errors: [{ messageId: "selfAssignment", data: { name: "a?.b" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "selfAssignment", data: { name: "a?.b" } }] }, // Private members { code: "class C { #field; foo() { this.#field = this.#field; } }", - errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }] }, { code: "class C { #field; foo() { [this.#field] = [this.#field]; } }", - errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }] }, // logical assignment { code: "a &&= a", - errors: [{ messageId: "selfAssignment", data: { name: "a" } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, { code: "a ||= a", - errors: [{ messageId: "selfAssignment", data: { name: "a" } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, { code: "a ??= a", - errors: [{ messageId: "selfAssignment", data: { name: "a" } }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "selfAssignment", data: { name: "a" } }] } ] }); diff --git a/tests/lib/rules/no-self-compare.js b/tests/lib/rules/no-self-compare.js index ee927174ddb..c078ad8896f 100644 --- a/tests/lib/rules/no-self-compare.js +++ b/tests/lib/rules/no-self-compare.js @@ -50,8 +50,8 @@ ruleTester.run("no-self-compare", rule, { { code: "foo.bar().baz.qux >= foo.bar ().baz .qux", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, { code: "class C { #field; foo() { this.#field === this.#field; } }", - errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] } ] }); diff --git a/tests/lib/rules/no-sequences.js b/tests/lib/rules/no-sequences.js index 5b8a664fb8f..717bf7034f4 100644 --- a/tests/lib/rules/no-sequences.js +++ b/tests/lib/rules/no-sequences.js @@ -91,7 +91,7 @@ ruleTester.run("no-sequences", rule, { { code: "switch (doSomething(), val) {}", errors: errors(22) }, { code: "while (doSomething(), !!test);", errors: errors(21) }, { code: "with (doSomething(), val) {}", errors: errors(20) }, - { code: "a => (doSomething(), a)", errors: errors(20), languageOptions: { ecmaVersion: 6 } }, + { code: "a => (doSomething(), a)", languageOptions: { ecmaVersion: 6 }, errors: errors(20) }, { code: "(1), 2", errors: errors(4) }, { code: "((1)) , (2)", errors: errors(7) }, { code: "while((1) , 2);", errors: errors(11) }, @@ -106,6 +106,6 @@ ruleTester.run("no-sequences", rule, { { code: "switch ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(23) }, { code: "while ((doSomething(), !!test));", options: [{ allowInParentheses: false }], errors: errors(22) }, { code: "with ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(21) }, - { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], errors: errors(21), languageOptions: { ecmaVersion: 6 } } + { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], languageOptions: { ecmaVersion: 6 }, errors: errors(21) } ] }); diff --git a/tests/lib/rules/no-setter-return.js b/tests/lib/rules/no-setter-return.js index 6c481516add..0cd634df733 100644 --- a/tests/lib/rules/no-setter-return.js +++ b/tests/lib/rules/no-setter-return.js @@ -404,8 +404,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "return; ({ set a(val) { return 1; } }); return 2;", - errors: [error(25)], - languageOptions: { sourceType: "commonjs" } + languageOptions: { sourceType: "commonjs" }, + errors: [error(25)] }, //------------------------------------------------------------------------------ @@ -419,8 +419,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { return 1; } })", - errors: [error()], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [error()] }, { code: "Object.defineProperties(foo, { baz: { set(val) { return 1; } } })", @@ -438,8 +438,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set: val => f(val) })", - errors: [error(50, "CallExpression")], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [error(50, "CallExpression")] }, { code: "Object.defineProperties(foo, { baz: { set: val => a + b } })", @@ -457,8 +457,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { try { return f(val) } catch (e) { return e }; } })", - errors: [error(55), error(83)], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [error(55), error(83)] }, { code: "Object.defineProperties(foo, { bar: { get(){ return null; }, set(val) { return null; } } })", @@ -489,8 +489,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { 'set'(val) { return 1; } })", - errors: [error()], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [error()] }, { code: "Object[`defineProperties`](foo, { baz: { ['set'](val) { return 1; } } })", @@ -514,13 +514,13 @@ ruleTester.run("no-setter-return", rule, { // Optional chaining { code: "Object?.defineProperty(foo, 'bar', { set(val) { return 1; } })", - errors: [error()], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [error()] }, { code: "(Object?.defineProperty)(foo, 'bar', { set(val) { return 1; } })", - errors: [error()], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [error()] } ] }); diff --git a/tests/lib/rules/no-shadow-restricted-names.js b/tests/lib/rules/no-shadow-restricted-names.js index 209f2a01663..abb3a35c965 100644 --- a/tests/lib/rules/no-shadow-restricted-names.js +++ b/tests/lib/rules/no-shadow-restricted-names.js @@ -99,6 +99,7 @@ ruleTester.run("no-shadow-restricted-names", rule, { }, { code: "var eval = (eval) => { var eval; !function eval(eval) { try {} catch(eval) {} }; }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, @@ -106,25 +107,24 @@ ruleTester.run("no-shadow-restricted-names", rule, { { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var [undefined] = [1]", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {undefined} = obj; var {a: undefined} = obj; var {a: {b: {undefined}}} = obj; var {a, ...undefined} = obj;", + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 9 } + ] }, { code: "var undefined; undefined = 5;", diff --git a/tests/lib/rules/no-shadow.js b/tests/lib/rules/no-shadow.js index 09fa52324ae..c95da147132 100644 --- a/tests/lib/rules/no-shadow.js +++ b/tests/lib/rules/no-shadow.js @@ -116,6 +116,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "var a = (x) => { var b = () => { var x = 'foo'; }; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -126,8 +127,7 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 38 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function a(x) { var b = function () { var x = 'foo'; }; }", @@ -205,6 +205,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "var x = 1; { let x = 2; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -213,11 +214,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 5 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let x = 1; { const x = 2; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -226,11 +227,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 5 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ let a; } function a() {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -239,11 +240,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 21 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ const a = 0; } function a() {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -252,11 +253,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 27 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { let a; } function a() {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -265,11 +266,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { var a; } function a() {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -278,11 +279,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { } function a() {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -291,12 +292,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 30 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ let a; } let a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -305,12 +306,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 16 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ let a; } var a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -319,12 +320,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 16 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ let a; } function a() {}", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -333,12 +334,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 21 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ const a = 0; } const a = 1;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -347,12 +348,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 24 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ const a = 0; } var a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -361,12 +362,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 22 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ const a = 0; } function a() {}", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -375,12 +376,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 27 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { let a; } let a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -389,12 +390,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { let a; } var a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -403,12 +404,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { let a; } function a() {}", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -417,12 +418,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { var a; } let a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -431,12 +432,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { var a; } var a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -445,12 +446,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 31 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { var a; } function a() {}", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -459,12 +460,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 36 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { } let a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -473,12 +474,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 25 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { } var a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -487,12 +488,12 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 25 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a) { } function a() {}", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -501,8 +502,7 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 30 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function a() { function a(){} })()", @@ -518,6 +518,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function a() { class a{} })()", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -526,8 +527,7 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 11 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function a() { (function a(){}); })()", @@ -543,6 +543,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function a() { (class a{}); })()", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -551,8 +552,7 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 11 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function() { var a = function(a) {}; })()", @@ -580,6 +580,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function() { var a = function() { class a{} }; })()", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -588,8 +589,7 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 19 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function() { var a = function() { (function a() {}); }; })()", @@ -605,6 +605,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function() { var a = function() { (class a{}); }; })()", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -613,11 +614,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 19 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function() { var a = class { constructor() { class a {} } }; })()", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -626,11 +627,11 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 19 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class A { constructor() { var A; } }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -639,8 +640,7 @@ ruleTester.run("no-shadow", rule, { shadowedColumn: 7 }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function a() { function a(){ function a(){} } })()", @@ -683,69 +683,69 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var top = 0; }", options: [{ builtinGlobals: true }], + languageOptions: { globals: globals.browser }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }], - languageOptions: { globals: globals.browser } + }] }, { code: "var Object = 0;", options: [{ builtinGlobals: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "noShadowGlobal", data: { name: "Object" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var top = 0;", options: [{ builtinGlobals: true }], + languageOptions: { + ecmaVersion: 6, + sourceType: "module", + globals: globals.browser + }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }], - languageOptions: { - ecmaVersion: 6, - sourceType: "module", - globals: globals.browser - } + }] }, { code: "var Object = 0;", options: [{ builtinGlobals: true }], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [{ messageId: "noShadowGlobal", data: { name: "Object" }, type: "Identifier" - }], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + }] }, { code: "var top = 0;", options: [{ builtinGlobals: true }], + languageOptions: { + parserOptions: { ecmaFeatures: { globalReturn: true } }, + globals: globals.browser + }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }], - languageOptions: { - parserOptions: { ecmaFeatures: { globalReturn: true } }, - globals: globals.browser - } + }] }, { code: "function foo(cb) { (function (cb) { cb(42); })(cb); }", @@ -763,6 +763,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "class C { static { let a; { let a; } } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -773,11 +774,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 33 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var C; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -788,11 +789,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { let C; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -803,11 +804,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "var a; class C { static { var a; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -818,12 +819,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 31 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var a; } } var a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -834,12 +835,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { let a; } } let a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -850,12 +851,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var a; } } let a;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -866,11 +867,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var a; class D { static { var a; } } } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -881,11 +882,11 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 50 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { let a; class D { static { let a; } } } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -896,12 +897,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 50 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "let x = foo((x,y) => {});\nlet y;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noShadow", @@ -921,12 +922,12 @@ ruleTester.run("no-shadow", rule, { }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const a = fn(()=>{ class C { fn () { const a = 42; return a } } return new C() })", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -937,12 +938,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 44 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function a() {}\nfoo(a => {});", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -953,12 +954,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 2, column: 5 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = fn(()=>{ function C() { this.fn=function() { const a = 42; return a } } return new C() });", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -969,12 +970,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 62 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const x = foo(() => { const bar = () => { return x => {}; }; return bar; });", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -985,12 +986,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 50 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const x = foo(() => { return { bar(x) {} }; });", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1001,12 +1002,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 36 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const x = () => { foo(x => x); }", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1017,12 +1018,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 23 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const foo = () => { let x; bar(x => x); }", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1033,12 +1034,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 32 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo(() => { const x = x => x; });", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1049,12 +1050,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 23 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const foo = (x) => { bar(x => {}) }", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1065,12 +1066,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 26 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let x = ((x,y) => {})();\nlet y;", options: [{ hoist: "all" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noShadow", @@ -1090,12 +1091,12 @@ ruleTester.run("no-shadow", rule, { }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "const a = (()=>{ class C { fn () { const a = 42; return a } } return new C() })()", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1106,12 +1107,12 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 42 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const x = () => { (x => x)(); }", options: [{ ignoreOnInitialization: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1122,8 +1123,7 @@ ruleTester.run("no-shadow", rule, { type: "Identifier", line: 1, column: 20 - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/no-this-before-super.js b/tests/lib/rules/no-this-before-super.js index 021f84b8c02..8712d122a7a 100644 --- a/tests/lib/rules/no-this-before-super.js +++ b/tests/lib/rules/no-this-before-super.js @@ -174,18 +174,18 @@ ruleTester.run("no-this-before-super", rule, { }, { code: "class A extends B { constructor() { foo &&= super().a; this.c(); } }", - errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { foo ||= super().a; this.c(); } }", - errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { foo ??= super().a; this.c(); } }", - errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }], - languageOptions: { ecmaVersion: 2021 } + languageOptions: { ecmaVersion: 2021 }, + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] } ] }); diff --git a/tests/lib/rules/no-throw-literal.js b/tests/lib/rules/no-throw-literal.js index 4d4d80b531e..5ff6b9bda8f 100644 --- a/tests/lib/rules/no-throw-literal.js +++ b/tests/lib/rules/no-throw-literal.js @@ -129,11 +129,11 @@ ruleTester.run("no-throw-literal", rule, { }, { code: "throw foo &&= 'literal'", // evaluates either to a falsy value of `foo` (which, then, cannot be an Error object), or to 'literal' + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "object", type: "ThrowStatement" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, // SequenceExpression @@ -173,12 +173,12 @@ ruleTester.run("no-throw-literal", rule, { // TemplateLiteral { code: "throw `${err}`;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "object", type: "ThrowStatement" - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/no-trailing-spaces.js b/tests/lib/rules/no-trailing-spaces.js index 7c36e56a608..b614fd94009 100644 --- a/tests/lib/rules/no-trailing-spaces.js +++ b/tests/lib/rules/no-trailing-spaces.js @@ -173,11 +173,11 @@ ruleTester.run("no-trailing-spaces", rule, { " short,\n" + " short2\n" + "}\n", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "trailingSpace", type: "Program" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: @@ -366,6 +366,7 @@ ruleTester.run("no-trailing-spaces", rule, { { code: "let str = `${a}\n \n${b}`; \n", output: "let str = `${a}\n \n${b}`;\n", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "trailingSpace", type: "Program", @@ -373,12 +374,12 @@ ruleTester.run("no-trailing-spaces", rule, { column: 7, endLine: 3, endColumn: 9 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let str = `\n${a}\n \n${b}`; \n\t", output: "let str = `\n${a}\n \n${b}`;\n", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -396,12 +397,12 @@ ruleTester.run("no-trailing-spaces", rule, { endLine: 5, endColumn: 2 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let str = ` \n ${a}\n \n${b}`; \n", output: "let str = ` \n ${a}\n \n${b}`;\n", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -411,8 +412,7 @@ ruleTester.run("no-trailing-spaces", rule, { endLine: 4, endColumn: 9 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "let str = `${a}\n \n${b}`; \n \n", @@ -420,6 +420,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ skipBlankLines: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -429,8 +430,7 @@ ruleTester.run("no-trailing-spaces", rule, { endLine: 3, endColumn: 9 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // https://github.com/eslint/eslint/issues/6933 diff --git a/tests/lib/rules/no-undef-init.js b/tests/lib/rules/no-undef-init.js index 38ef2ca8255..6cd38116b6f 100644 --- a/tests/lib/rules/no-undef-init.js +++ b/tests/lib/rules/no-undef-init.js @@ -47,14 +47,14 @@ ruleTester.run("no-undef-init", rule, { { code: "var [a] = undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] }, { code: "var {a} = undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }] }, { code: "for(var i in [1,2,3]){var a = undefined; for(var j in [1,2,3]){}}", @@ -64,94 +64,94 @@ ruleTester.run("no-undef-init", rule, { { code: "let a = undefined;", output: "let a;", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined, b = 1;", output: "let a, b = 1;", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = 1, b = undefined, c = 5;", output: "let a = 1, b, c = 5;", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "b" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "b" }, type: "VariableDeclarator" }] }, { code: "let [a] = undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] }, { code: "let {a} = undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }] }, { code: "for(var i in [1,2,3]){let a = undefined; for(var j in [1,2,3]){}}", output: "for(var i in [1,2,3]){let a; for(var j in [1,2,3]){}}", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, // Should not autofix if it would remove comments { code: "let /* comment */a = undefined;", output: "let /* comment */a;", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a/**/ = undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a /**/ = undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a//\n= undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = /**/undefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = //\nundefined;", output: null, - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined/* comment */;", output: "let a/* comment */;", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined/* comment */, b;", output: "let a/* comment */, b;", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined//comment\n, b;", output: "let a//comment\n, b;", - errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] } ] }); diff --git a/tests/lib/rules/no-undef.js b/tests/lib/rules/no-undef.js index 9574e05ed9c..5a599658b9d 100644 --- a/tests/lib/rules/no-undef.js +++ b/tests/lib/rules/no-undef.js @@ -108,18 +108,18 @@ ruleTester.run("no-undef", rule, { // class static blocks { code: "let a; class C { static {} } a;", - errors: [{ messageId: "undef", data: { name: "a" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "undef", data: { name: "a" } }] }, { code: "var a; class C { static {} } a;", - errors: [{ messageId: "undef", data: { name: "a" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "undef", data: { name: "a" } }] }, { code: "a; class C { static {} } var a;", - errors: [{ messageId: "undef", data: { name: "a" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "undef", data: { name: "a" } }] }, { code: "class C { static { C; } }", @@ -173,113 +173,113 @@ ruleTester.run("no-undef", rule, { { code: "function f() { b; }", errors: [{ messageId: "undef", data: { name: "b" }, type: "Identifier" }] }, { code: "window;", errors: [{ messageId: "undef", data: { name: "window" }, type: "Identifier" }] }, { code: "require(\"a\");", errors: [{ messageId: "undef", data: { name: "require" }, type: "Identifier" }] }, - { code: "var React; React.render();", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, - { code: "var React, App; React.render();", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } } }, - { code: "[a] = [0];", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({a} = {});", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "({b: a} = {});", errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 6 } }, - { code: "[obj.a, obj.b] = [0, 1];", errors: [{ messageId: "undef", data: { name: "obj" } }, { messageId: "undef", data: { name: "obj" } }], languageOptions: { ecmaVersion: 6 } }, + { code: "var React; React.render();", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [{ messageId: "undef", data: { name: "a" } }] }, + { code: "var React, App; React.render();", languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [{ messageId: "undef", data: { name: "a" } }] }, + { code: "[a] = [0];", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, + { code: "({a} = {});", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, + { code: "({b: a} = {});", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, + { code: "[obj.a, obj.b] = [0, 1];", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "obj" } }, { messageId: "undef", data: { name: "obj" } }] }, // Experimental { code: "const c = 0; const a = {...b, c};", - errors: [{ messageId: "undef", data: { name: "b" } }], languageOptions: { ecmaVersion: 2018 - } + }, + errors: [{ messageId: "undef", data: { name: "b" } }] }, // class static blocks { code: "class C { static { a; } }", - errors: [{ messageId: "undef", data: { name: "a" } }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" } }] }, { code: "class C { static { { let a; } a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }] }, { code: "class C { static { { function a() {} } a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 40 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 40 }] }, { code: "class C { static { function foo() { var a; } a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 47 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 47 }] }, { code: "class C { static { var a; } static { a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }] }, { code: "class C { static { let a; } static { a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }] }, { code: "class C { static { function a(){} } static { a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 46 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 46 }] }, { code: "class C { static { var a; } foo() { a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }] }, { code: "class C { static { let a; } foo() { a; } }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }] }, { code: "class C { static { var a; } [a]; }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }] }, { code: "class C { static { let a; } [a]; }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }] }, { code: "class C { static { function a() {} } [a]; }", - errors: [{ messageId: "undef", data: { name: "a" }, column: 39 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 39 }] }, { code: "class C { static { var a; } } a;", - errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }] } ] }); diff --git a/tests/lib/rules/no-undefined.js b/tests/lib/rules/no-undefined.js index a6801b29b4c..be9cc771a5f 100644 --- a/tests/lib/rules/no-undefined.js +++ b/tests/lib/rules/no-undefined.js @@ -93,23 +93,23 @@ ruleTester.run("no-undefined", rule, { }, { code: "import undefined from 'foo'", - errors, - languageOptions: ES6_MODULE + languageOptions: ES6_MODULE, + errors }, { code: "import * as undefined from 'foo'", - errors, - languageOptions: ES6_MODULE + languageOptions: ES6_MODULE, + errors }, { code: "import { undefined } from 'foo'", - errors, - languageOptions: ES6_MODULE + languageOptions: ES6_MODULE, + errors }, { code: "import { a as undefined } from 'foo'", - errors, - languageOptions: ES6_MODULE + languageOptions: ES6_MODULE, + errors }, /* diff --git a/tests/lib/rules/no-underscore-dangle.js b/tests/lib/rules/no-underscore-dangle.js index 37dd3f2b8f0..e4c845edc1c 100644 --- a/tests/lib/rules/no-underscore-dangle.js +++ b/tests/lib/rules/no-underscore-dangle.js @@ -95,129 +95,129 @@ ruleTester.run("no-underscore-dangle", rule, { { code: "var __proto__ = 1;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "__proto__" }, type: "VariableDeclarator" }] }, { code: "foo._bar;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "MemberExpression" }] }, { code: "this._prop;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, - { code: "class foo { constructor() { super._prop; } }", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "class foo { constructor() { this._prop; } }", options: [{ allowAfterSuper: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }], languageOptions: { ecmaVersion: 6 } }, - { code: "class foo { _onClick() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "MethodDefinition" }], languageOptions: { ecmaVersion: 6 } }, - { code: "class foo { onClick_() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "MethodDefinition" }], languageOptions: { ecmaVersion: 6 } }, - { code: "const o = { _onClick() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "Property" }], languageOptions: { ecmaVersion: 6 } }, - { code: "const o = { onClick_() { } }", options: [{ enforceInMethodNames: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "Property" }], languageOptions: { ecmaVersion: 6 } }, + { code: "class foo { constructor() { super._prop; } }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, + { code: "class foo { constructor() { this._prop; } }", options: [{ allowAfterSuper: true }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, + { code: "class foo { _onClick() { } }", options: [{ enforceInMethodNames: true }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "MethodDefinition" }] }, + { code: "class foo { onClick_() { } }", options: [{ enforceInMethodNames: true }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "MethodDefinition" }] }, + { code: "const o = { _onClick() { } }", options: [{ enforceInMethodNames: true }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "Property" }] }, + { code: "const o = { onClick_() { } }", options: [{ enforceInMethodNames: true }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "Property" }] }, { code: "this.constructor._bar", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "MemberExpression" }] }, { code: "function foo(_bar) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, { code: "(function foo(_bar) {})", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, { code: "function foo(bar, _foo) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" }, type: "Identifier" }] }, - { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, - { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }], languageOptions: { ecmaVersion: 6 } }, - { code: "function foo(_bar = 0) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }], languageOptions: { ecmaVersion: 6 } }, - { code: "const foo = { onClick(_bar = 0) { } }", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }], languageOptions: { ecmaVersion: 6 } }, - { code: "const foo = (_bar = 0) => {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }], languageOptions: { ecmaVersion: 6 } }, - { code: "function foo(..._bar) {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }], languageOptions: { ecmaVersion: 6 } }, - { code: "const foo = { onClick(..._bar) { } }", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }], languageOptions: { ecmaVersion: 6 } }, - { code: "const foo = (..._bar) => {}", options: [{ allowFunctionParams: false }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }], languageOptions: { ecmaVersion: 6 } }, + { code: "const foo = { onClick(_bar) { } }", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, + { code: "const foo = (_bar) => {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "Identifier" }] }, + { code: "function foo(_bar = 0) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }] }, + { code: "const foo = { onClick(_bar = 0) { } }", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }] }, + { code: "const foo = (_bar = 0) => {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "AssignmentPattern" }] }, + { code: "function foo(..._bar) {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] }, + { code: "const foo = { onClick(..._bar) { } }", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] }, + { code: "const foo = (..._bar) => {}", options: [{ allowFunctionParams: false }], languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "RestElement" }] }, { code: "const [foo, _bar] = [1, 2]", options: [{ allowInArrayDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }] }, { code: "const [_foo = 1] = arr", options: [{ allowInArrayDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const [foo, ..._rest] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }] }, { code: "const [foo, [bar_, baz]] = [1, [2, 3]]", options: [{ allowInArrayDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "bar_" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "bar_" } }] }, { code: "const { _foo, bar } = { _foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { _foo = 1 } = obj", options: [{ allowInObjectDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { bar: _foo = 1 } = obj", options: [{ allowInObjectDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { foo: _foo, bar } = { foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { foo, ..._rest} = { foo: 1, bar: 2, baz: 3 }", options: [{ allowInObjectDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }] }, { code: "const { foo: [_bar, { a: _a, b } ] } = { foo: [1, { a: 'a', b: 'b' }] }", options: [{ allowInArrayDestructuring: false, allowInObjectDestructuring: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }, { messageId: "unexpectedUnderscore", data: { identifier: "_a" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "const { foo: [_bar, { a: _a, b } ] } = { foo: [1, { a: 'a', b: 'b' }] }", options: [{ allowInArrayDestructuring: true, allowInObjectDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_a" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_a" } }] }, { code: "const [{ foo: [_bar, _, { bar: _baz }] }] = [{ foo: [1, 2, { bar: 'a' }] }]", options: [{ allowInArrayDestructuring: false, allowInObjectDestructuring: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }, { messageId: "unexpectedUnderscore", data: { identifier: "_baz" } } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "const { foo, bar: { baz, _qux } } = { foo: 1, bar: { baz: 3, _qux: 4 } }", options: [{ allowInObjectDestructuring: false }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_qux" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_qux" } }] }, { code: "class foo { #_bar() {} }", options: [{ enforceInMethodNames: true }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_bar" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_bar" } }] }, { code: "class foo { #bar_() {} }", options: [{ enforceInMethodNames: true }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }] }, { code: "class foo { _field; }", options: [{ enforceInClassFields: true }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }] }, { code: "class foo { #_field; }", options: [{ enforceInClassFields: true }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }] }, { code: "class foo { field_; }", options: [{ enforceInClassFields: true }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "field_" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "field_" } }] }, { code: "class foo { #field_; }", options: [{ enforceInClassFields: true }], - errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#field_" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#field_" } }] } ] }); diff --git a/tests/lib/rules/no-unexpected-multiline.js b/tests/lib/rules/no-unexpected-multiline.js index 11e08b446d9..2857572eb7d 100644 --- a/tests/lib/rules/no-unexpected-multiline.js +++ b/tests/lib/rules/no-unexpected-multiline.js @@ -237,36 +237,36 @@ ruleTester.run("no-unexpected-multiline", rule, { }, { code: "let x = function() {}\n `hello`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 2, endLine: 2, endColumn: 3, messageId: "taggedTemplate" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let x = function() {}\nx\n`hello`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 3, column: 1, endLine: 3, endColumn: 2, messageId: "taggedTemplate" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "x\n.y\nz\n`Invalid Test Case`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, endLine: 4, endColumn: 2, messageId: "taggedTemplate" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: ` @@ -343,6 +343,9 @@ ruleTester.run("no-unexpected-multiline", rule, { "test", "*/`foo`" ].join("\n"), + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment") + }, errors: [ { line: 5, @@ -351,15 +354,13 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 4, messageId: "taggedTemplate" } - ], - languageOptions: { - parser: require("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment") - } + ] }, // Class fields { code: "class C { field1 = obj\n[field2]; }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { line: 2, @@ -368,11 +369,11 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 2, messageId: "property" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { field1 = function() {}\n[field2]; }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { line: 2, @@ -381,8 +382,7 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 2, messageId: "property" } - ], - languageOptions: { ecmaVersion: 2022 } + ] } // "class C { field1 = obj\n*gen() {} }" is syntax error: Unexpected token '{' diff --git a/tests/lib/rules/no-unneeded-ternary.js b/tests/lib/rules/no-unneeded-ternary.js index 334198e5f7a..f1bdcf7738f 100644 --- a/tests/lib/rules/no-unneeded-ternary.js +++ b/tests/lib/rules/no-unneeded-ternary.js @@ -242,6 +242,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "function* fn() { foo ? foo : yield bar }", output: "function* fn() { foo || (yield bar) }", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -249,8 +250,7 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 18, endLine: 1, endColumn: 39 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = foo ? foo : 'No';", @@ -282,6 +282,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = b ? b : c => c;", output: "var a = b || (c => c);", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -289,13 +290,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 23 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var a = b ? b : c = 0;", output: "var a = b || (c = 0);", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -303,13 +304,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 22 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var a = b ? b : (c => c);", output: "var a = b || (c => c);", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -317,13 +318,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 25 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var a = b ? b : (c = 0);", output: "var a = b || (c = 0);", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -331,13 +332,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 24 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var a = b ? b : (c) => (c);", output: "var a = b || ((c) => (c));", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -345,13 +346,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 27 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var a = b ? b : c, d; // this is ((b ? b : c), (d))", output: "var a = b || c, d; // this is ((b ? b : c), (d))", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -359,13 +360,13 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 18 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var a = b ? b : (c, d);", output: "var a = b || (c, d);", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -373,8 +374,7 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 23 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "f(x ? x : 1);", @@ -419,6 +419,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = foo ? foo : a ?? b;", output: "var a = foo || (a ?? b);", options: [{ defaultAssignment: false }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -426,35 +427,34 @@ ruleTester.run("no-unneeded-ternary", rule, { column: 9, endLine: 1, endColumn: 27 - }], - languageOptions: { ecmaVersion: 2020 } + }] }, // https://github.com/eslint/eslint/issues/17173 { code: "foo as any ? false : true", output: "!(foo as any)", - errors: [{ - messageId: "unnecessaryConditionalExpression", - type: "ConditionalExpression" - }], languageOptions: { parser: require(parser("typescript-parsers/unneeded-ternary-1")), ecmaVersion: 6 - } + }, + errors: [{ + messageId: "unnecessaryConditionalExpression", + type: "ConditionalExpression" + }] }, { code: "foo ? foo : bar as any", output: "foo || (bar as any)", options: [{ defaultAssignment: false }], - errors: [{ - messageId: "unnecessaryConditionalAssignment", - type: "ConditionalExpression" - }], languageOptions: { parser: require(parser("typescript-parsers/unneeded-ternary-2")), ecmaVersion: 6 - } + }, + errors: [{ + messageId: "unnecessaryConditionalAssignment", + type: "ConditionalExpression" + }] } ] }); diff --git a/tests/lib/rules/no-unreachable.js b/tests/lib/rules/no-unreachable.js index f6e4be5e4d7..0cf0cfa4045 100644 --- a/tests/lib/rules/no-unreachable.js +++ b/tests/lib/rules/no-unreachable.js @@ -115,6 +115,7 @@ ruleTester.run("no-unreachable", rule, { { code: "function foo() { var x = 1; while (true) { } x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, { code: "const arrow_direction = arrow => { switch (arrow) { default: throw new Error(); }; g() }", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unreachableCode", @@ -124,8 +125,7 @@ ruleTester.run("no-unreachable", rule, { endLine: 1, endColumn: 89 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // Merge the warnings of continuous unreachable nodes. @@ -259,6 +259,9 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "unreachableCode", @@ -268,10 +271,7 @@ ruleTester.run("no-unreachable", rule, { endLine: 7, endColumn: 22 } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, { code: ` @@ -282,6 +282,9 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "unreachableCode", @@ -291,10 +294,7 @@ ruleTester.run("no-unreachable", rule, { endLine: 7, endColumn: 22 } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, { code: ` @@ -306,6 +306,9 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "unreachableCode", @@ -323,10 +326,7 @@ ruleTester.run("no-unreachable", rule, { endLine: 8, endColumn: 22 } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, /* @@ -338,56 +338,56 @@ ruleTester.run("no-unreachable", rule, { */ { code: "class C extends B { foo; constructor() {} }", - errors: [{ messageId: "unreachableCode", column: 21, endColumn: 25 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unreachableCode", column: 21, endColumn: 25 }] }, { code: "class C extends B { foo = unreachable + code; constructor() {} }", - errors: [{ messageId: "unreachableCode", column: 21, endColumn: 46 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unreachableCode", column: 21, endColumn: 46 }] }, { code: "class C extends B { foo; bar; constructor() {} }", - errors: [{ messageId: "unreachableCode", column: 21, endColumn: 30 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unreachableCode", column: 21, endColumn: 30 }] }, { code: "class C extends B { foo; constructor() {} bar; }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 21, endColumn: 25 }, { messageId: "unreachableCode", column: 43, endColumn: 47 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "(class extends B { foo; constructor() {} bar; })", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 20, endColumn: 24 }, { messageId: "unreachableCode", column: 42, endColumn: 46 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class B extends A { x; constructor() { class C extends D { [super().x]; constructor() {} } } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 60, endColumn: 72 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class B extends A { x; constructor() { class C extends super().x { y; constructor() {} } } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 68, endColumn: 70 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class B extends A { x; static y; z; static q; constructor() {} }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 21, endColumn: 23 }, { messageId: "unreachableCode", column: 34, endColumn: 36 } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/no-unsafe-optional-chaining.js b/tests/lib/rules/no-unsafe-optional-chaining.js index 3ce551ab89a..ca91156cc19 100644 --- a/tests/lib/rules/no-unsafe-optional-chaining.js +++ b/tests/lib/rules/no-unsafe-optional-chaining.js @@ -296,6 +296,9 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { }, { code: "with (obj?.foo) {};", + languageOptions: { + sourceType: "script" + }, errors: [ { messageId: "unsafeOptionalChain", @@ -303,13 +306,13 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { line: 1, column: 7 } - ], - languageOptions: { - sourceType: "script" - } + ] }, { code: "async function foo() { with ( await obj?.foo) {}; }", + languageOptions: { + sourceType: "script" + }, errors: [ { messageId: "unsafeOptionalChain", @@ -317,10 +320,7 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { line: 1, column: 37 } - ], - languageOptions: { - sourceType: "script" - } + ] }, { code: "(foo ? obj?.foo : obj?.bar).bar", diff --git a/tests/lib/rules/no-unused-expressions.js b/tests/lib/rules/no-unused-expressions.js index f51447a04f0..b86213e544d 100644 --- a/tests/lib/rules/no-unused-expressions.js +++ b/tests/lib/rules/no-unused-expressions.js @@ -120,13 +120,13 @@ ruleTester.run("no-unused-expressions", rule, { { code: "a ? b() || (c = d) : e", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "`untagged template literal`", - errors: [{ messageId: "unusedExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unusedExpression" }] }, { code: "tag`tagged template literal`", - errors: [{ messageId: "unusedExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unusedExpression" }] }, { code: "a && b()", options: [{ allowTernary: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "a ? b() : c()", options: [{ allowShortCircuit: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, @@ -141,65 +141,66 @@ ruleTester.run("no-unused-expressions", rule, { { code: "function foo() {\"directive one\"; f(); \"directive two\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "if (0) { \"not a directive\"; f(); }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "function foo() { var foo = true; \"use strict\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, - { code: "var foo = () => { var foo = true; \"use strict\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], languageOptions: { ecmaVersion: 6 } }, + { code: "var foo = () => { var foo = true; \"use strict\"; }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: true }], - errors: [{ messageId: "unusedExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unusedExpression" }] }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: false }], - errors: [{ messageId: "unusedExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unusedExpression" }] }, { code: "tag`tagged template literal`", options: [{ allowTaggedTemplates: false }], - errors: [{ messageId: "unusedExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unusedExpression" }] }, // Optional chaining { code: "obj?.foo", - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "obj?.foo.bar", - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "obj?.foo().bar", - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, // JSX { code: "
", options: [{ enforceForJSX: true }], - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "<>", options: [{ enforceForJSX: true }], - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, // class static blocks do not have directive prologues { code: "class C { static { 'use strict'; } }", - errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "class C { static { \n'foo'\n'bar'\n } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unusedExpression", @@ -211,8 +212,7 @@ ruleTester.run("no-unused-expressions", rule, { type: "ExpressionStatement", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/no-unused-labels.js b/tests/lib/rules/no-unused-labels.js index af8ed6db606..42fd69dedd5 100644 --- a/tests/lib/rules/no-unused-labels.js +++ b/tests/lib/rules/no-unused-labels.js @@ -94,8 +94,8 @@ ruleTester.run("no-unused-labels", rule, { { code: "A: `use strict`", // `use strict` may be changed to "use strict" by another rule. output: null, - errors: [{ messageId: "unused" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unused" }] }, { code: "if (foo) { bar: 'baz' }", diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js index 64fb566865c..6d98d258d7e 100644 --- a/tests/lib/rules/no-unused-vars.js +++ b/tests/lib/rules/no-unused-vars.js @@ -482,13 +482,13 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function z(foo) { var bar = 33; })();", options: [{ vars: "all", args: "all" }], errors: [definedError("foo"), assignedError("bar")] }, { code: "(function z(foo) { z(); })();", options: [{}], errors: [definedError("foo")] }, { code: "function f() { var a = 1; return function(){ f(a = 2); }; }", options: [{}], errors: [definedError("f"), assignedError("a")] }, - { code: "import x from \"y\";", errors: [definedError("x")], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function fn2({ x, y }) {\n console.log(x); \n};", errors: [definedError("y")], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export function fn2( x, y ) {\n console.log(x); \n};", errors: [definedError("y")], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, + { code: "import x from \"y\";", languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("x")] }, + { code: "export function fn2({ x, y }) {\n console.log(x); \n};", languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("y")] }, + { code: "export function fn2( x, y ) {\n console.log(x); \n};", languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("y")] }, // exported { code: "/*exported max*/ var max = 1, min = {min: 1}", errors: [assignedError("min")] }, - { code: "/*exported x*/ var { x, y } = z", errors: [assignedError("y")], languageOptions: { ecmaVersion: 6 } }, + { code: "/*exported x*/ var { x, y } = z", languageOptions: { ecmaVersion: 6 }, errors: [assignedError("y")] }, // ignore pattern { @@ -564,6 +564,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "var [ firstItemIgnored, secondItem ] = items;", options: [{ vars: "all", varsIgnorePattern: "[iI]gnored" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 25, @@ -573,8 +574,7 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: ". Allowed unused vars must match /[iI]gnored/u" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, // https://github.com/eslint/eslint/issues/15611 @@ -585,12 +585,12 @@ ruleTester.run("no-unused-vars", rule, { const newArray = [a, c]; `, options: [{ destructuredArrayIgnorePattern: "^_" }], + languageOptions: { ecmaVersion: 2020 }, errors: [ // should report only `newArray` { ...assignedError("newArray"), line: 4, column: 19 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: ` @@ -598,6 +598,7 @@ ruleTester.run("no-unused-vars", rule, { const [a, _b, c] = array; `, options: [{ destructuredArrayIgnorePattern: "^_" }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("a", ". Allowed unused elements of array destructuring patterns must match /^_/u"), @@ -609,8 +610,7 @@ ruleTester.run("no-unused-vars", rule, { line: 3, column: 27 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: ` @@ -621,6 +621,7 @@ ruleTester.run("no-unused-vars", rule, { const ignoreArray = ['ignore']; `, options: [{ destructuredArrayIgnorePattern: "^_", varsIgnorePattern: "ignore" }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("a", ". Allowed unused elements of array destructuring patterns must match /^_/u"), @@ -642,8 +643,7 @@ ruleTester.run("no-unused-vars", rule, { line: 5, column: 19 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: ` @@ -652,14 +652,14 @@ ruleTester.run("no-unused-vars", rule, { console.log(foo); `, options: [{ destructuredArrayIgnorePattern: "^_" }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("_a"), line: 3, column: 21 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: ` @@ -669,14 +669,14 @@ ruleTester.run("no-unused-vars", rule, { foo(); `, options: [{ destructuredArrayIgnorePattern: "^_" }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...definedError("_a"), line: 2, column: 28 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: ` @@ -687,6 +687,7 @@ ruleTester.run("no-unused-vars", rule, { }); `, options: [{ destructuredArrayIgnorePattern: "^_" }], + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...definedError("_a"), @@ -698,8 +699,7 @@ ruleTester.run("no-unused-vars", rule, { line: 2, column: 21 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, // for-in loops (see #2342) @@ -746,6 +746,7 @@ ruleTester.run("no-unused-vars", rule, { // For-of loops { code: "(function(iter) { var name; for ( name of iter ) { i(); return; } })({});", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 35, @@ -755,11 +756,11 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: "" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function(iter) { var name; for ( name of iter ) { } })({});", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 35, @@ -769,11 +770,11 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: "" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(function(iter) { for ( var name of iter ) { } })({});", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 29, @@ -783,8 +784,7 @@ ruleTester.run("no-unused-vars", rule, { action: "assigned a value", additional: "" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, // https://github.com/eslint/eslint/issues/3617 @@ -850,6 +850,7 @@ ruleTester.run("no-unused-vars", rule, { // Rest property sibling without ignoreRestSiblings { code: "const data = { type: 'coords', x: 1, y: 2 };\nconst { type, ...coords } = data;\n console.log(coords);", + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -861,14 +862,14 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // Unused rest property with ignoreRestSiblings { code: "const data = { type: 'coords', x: 2, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", options: [{ ignoreRestSiblings: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -880,12 +881,12 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "let type, coords;\n({ type, ...coords } = data);\n console.log(type)", options: [{ ignoreRestSiblings: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -897,13 +898,13 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // Unused rest property without ignoreRestSiblings { code: "const data = { type: 'coords', x: 3, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -915,13 +916,13 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // Nested array destructuring with rest property { code: "const data = { vars: ['x','y'], x: 1, y: 2 };\nconst { vars: [x], ...coords } = data;\n console.log(coords)", + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -933,13 +934,13 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // Nested object destructuring with rest property { code: "const data = { defaults: { x: 0 }, x: 1, y: 2 };\nconst { defaults: { x }, ...coords } = data;\n console.log(coords)", + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -951,16 +952,15 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // https://github.com/eslint/eslint/issues/8119 { code: "(({a, ...rest}) => {})", options: [{ args: "all", ignoreRestSiblings: true }], - errors: [definedError("rest")], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [definedError("rest")] }, // https://github.com/eslint/eslint/issues/3714 @@ -1072,6 +1072,7 @@ ruleTester.run("no-unused-vars", rule, { // surrogate pair. { code: "/*global 𠮷𩸽, 𠮷*/\n\\u{20BB7}\\u{29E3D};", + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -1085,40 +1086,39 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // https://github.com/eslint/eslint/issues/4047 { code: "export default function(a) {}", - errors: [definedError("a")], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [definedError("a")] }, { code: "export default function(a, b) { console.log(a); }", - errors: [definedError("b")], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [definedError("b")] }, { code: "export default (function(a) {});", - errors: [definedError("a")], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [definedError("a")] }, { code: "export default (function(a, b) { console.log(a); });", - errors: [definedError("b")], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [definedError("b")] }, { code: "export default (a) => {};", - errors: [definedError("a")], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [definedError("a")] }, { code: "export default (a, b) => { console.log(a); };", - errors: [definedError("b")], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [definedError("b")] }, // caughtErrors @@ -1225,31 +1225,31 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "[cd]" }], + languageOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /[cd]/u"), definedError("b", ". Allowed unused args must match /[cd]/u") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "c" }], + languageOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /c/u"), definedError("b", ". Allowed unused args must match /c/u"), definedError("d", ". Allowed unused args must match /c/u") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "d" }], + languageOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /d/u"), definedError("b", ". Allowed unused args must match /d/u"), definedError("c", ". Allowed unused args must match /d/u") - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "/*global\rfoo*/", @@ -1270,83 +1270,83 @@ ruleTester.run("no-unused-vars", rule, { // https://github.com/eslint/eslint/issues/8442 { code: "(function ({ a }, b ) { return b; })();", + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a") - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "(function ({ a }, { b, c } ) { return b; })();", + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ], - languageOptions: { ecmaVersion: 2015 } + ] }, // https://github.com/eslint/eslint/issues/14325 { code: `let x = 0; x++, x = 0;`, - errors: [{ ...assignedError("x"), line: 2, column: 18 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 2, column: 18 }] }, { code: `let x = 0; x++, x = 0; x=3;`, - errors: [{ ...assignedError("x"), line: 3, column: 13 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 3, column: 13 }] }, { code: "let x = 0; x++, 0;", - errors: [{ ...assignedError("x"), line: 1, column: 12 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 12 }] }, { code: "let x = 0; 0, x++;", - errors: [{ ...assignedError("x"), line: 1, column: 15 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 15 }] }, { code: "let x = 0; 0, (1, x++);", - errors: [{ ...assignedError("x"), line: 1, column: 19 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = (x++, 0);", - errors: [{ ...assignedError("x"), line: 1, column: 19 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = ((0, x++), 0);", - errors: [{ ...assignedError("x"), line: 1, column: 23 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 23 }] }, { code: "let x = 0; x += 1, 0;", - errors: [{ ...assignedError("x"), line: 1, column: 12 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 12 }] }, { code: "let x = 0; 0, x += 1;", - errors: [{ ...assignedError("x"), line: 1, column: 15 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 15 }] }, { code: "let x = 0; 0, (1, x += 1);", - errors: [{ ...assignedError("x"), line: 1, column: 19 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = (x += 1, 0);", - errors: [{ ...assignedError("x"), line: 1, column: 19 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = ((0, x += 1), 0);", - errors: [{ ...assignedError("x"), line: 1, column: 23 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 1, column: 23 }] }, // https://github.com/eslint/eslint/issues/14866 @@ -1354,79 +1354,79 @@ ruleTester.run("no-unused-vars", rule, { code: `let z = 0; z = z + 1, z = 2; `, - errors: [{ ...assignedError("z"), line: 2, column: 24 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("z"), line: 2, column: 24 }] }, { code: `let z = 0; z = z+1, z = 2; z = 3;`, - errors: [{ ...assignedError("z"), line: 3, column: 13 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("z"), line: 3, column: 13 }] }, { code: `let z = 0; z = z+1, z = 2; z = z+3; `, - errors: [{ ...assignedError("z"), line: 3, column: 13 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("z"), line: 3, column: 13 }] }, { code: "let x = 0; 0, x = x+1;", - errors: [{ ...assignedError("x"), line: 1, column: 15 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("x"), line: 1, column: 15 }] }, { code: "let x = 0; x = x+1, 0;", - errors: [{ ...assignedError("x"), line: 1, column: 12 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("x"), line: 1, column: 12 }] }, { code: "let x = 0; foo = ((0, x = x + 1), 0);", - errors: [{ ...assignedError("x"), line: 1, column: 23 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("x"), line: 1, column: 23 }] }, { code: "let x = 0; foo = (x = x+1, 0);", - errors: [{ ...assignedError("x"), line: 1, column: 19 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; 0, (1, x=x+1);", - errors: [{ ...assignedError("x"), line: 1, column: 19 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "(function ({ a, b }, { c } ) { return b; })();", + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "(function ([ a ], b ) { return b; })();", + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a") - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "(function ([ a ], [ b, c ] ) { return b; })();", + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "(function ([ a, b ], [ c ] ) { return b; })();", + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") - ], - languageOptions: { ecmaVersion: 2015 } + ] }, // https://github.com/eslint/eslint/issues/9774 @@ -1452,24 +1452,24 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "const a = () => { a(); };", - errors: [assignedError("a")], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [assignedError("a")] }, { code: "const a = () => () => { a(); };", - errors: [assignedError("a")], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [assignedError("a")] }, { code: `let myArray = [1,2,3,4].filter((x) => x == 0); myArray = myArray.filter((x) => x == 1);`, - errors: [{ ...assignedError("myArray"), line: 2, column: 5 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("myArray"), line: 2, column: 5 }] }, { code: "const a = 1; a += 1;", - errors: [{ ...assignedError("a"), line: 1, column: 14 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("a"), line: 1, column: 14 }] }, { code: "var a = function() { a(); };", @@ -1481,20 +1481,20 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "const a = () => { a(); };", - errors: [{ ...assignedError("a"), line: 1, column: 7 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("a"), line: 1, column: 7 }] }, { code: "const a = () => () => { a(); };", - errors: [{ ...assignedError("a"), line: 1, column: 7 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("a"), line: 1, column: 7 }] }, // https://github.com/eslint/eslint/issues/14324 { code: "let x = [];\nx = x.concat(x);", - errors: [{ ...assignedError("x"), line: 2, column: 1 }], - languageOptions: { ecmaVersion: 2015 } + languageOptions: { ecmaVersion: 2015 }, + errors: [{ ...assignedError("x"), line: 2, column: 1 }] }, { @@ -1506,8 +1506,8 @@ ruleTester.run("no-unused-vars", rule, { a = 13 } }`, - errors: [{ ...assignedError("a"), line: 2, column: 13 }, { ...definedError("foo"), line: 3, column: 22 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("a"), line: 2, column: 13 }, { ...definedError("foo"), line: 3, column: 22 }] }, { code: `let foo; @@ -1516,16 +1516,16 @@ ruleTester.run("no-unused-vars", rule, { function init() { foo = 1; }`, - errors: [{ ...assignedError("foo"), line: 3, column: 13 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("foo"), line: 3, column: 13 }] }, { code: `function foo(n) { if (n < 2) return 1; return n * foo(n - 1); }`, - errors: [{ ...definedError("foo"), line: 1, column: 10 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...definedError("foo"), line: 1, column: 10 }] }, { code: `let c = 'c' @@ -1538,8 +1538,8 @@ function foo1() { } c = foo1`, - errors: [{ ...assignedError("c"), line: 10, column: 1 }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ ...assignedError("c"), line: 10, column: 1 }] } ] }); diff --git a/tests/lib/rules/no-use-before-define.js b/tests/lib/rules/no-use-before-define.js index c1707bff484..18ba7c3edf2 100644 --- a/tests/lib/rules/no-use-before-define.js +++ b/tests/lib/rules/no-use-before-define.js @@ -251,21 +251,21 @@ ruleTester.run("no-use-before-define", rule, { invalid: [ { code: "a++; var a=19;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "a++; var a=19;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "a++; var a=19;", @@ -317,21 +317,21 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "(() => { alert(a); var a = 42; })();", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(() => a())(); function a() { }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "\"use strict\"; a(); { function a() {} }", @@ -351,95 +351,95 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var f = () => a; var a;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "new A(); class A {};", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { new A(); } class A {};", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "new A(); var A = class {};", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { new A(); } var A = class {};", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, // Block-level bindings { code: "a++; { var a; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "\"use strict\"; { a(); function a() {} }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{a; let a = 1}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "switch (foo) { case 1: a();\n default: \n let a;}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "if (true) { function foo() { a; } let a;}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, // object style options @@ -455,32 +455,32 @@ ruleTester.run("no-use-before-define", rule, { { code: "new A(); class A {};", options: [{ functions: false, classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "new A(); var A = class {};", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { new A(); } var A = class {};", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, // invalid initializers @@ -494,84 +494,84 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "let a = a + b;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = foo(a);", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a = a) {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {a = a} = [];", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [a = a] = [];", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {b = a, a} = {};", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [b = a, a] = {};", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {a = 0} = a;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var [a = 0] = a;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "for (var a in a) {}", @@ -583,12 +583,12 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "for (var a of a) {}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, type: "Identifier" - }], - languageOptions: { ecmaVersion: 6 } + }] }, // "variables" option @@ -614,520 +614,520 @@ ruleTester.run("no-use-before-define", rule, { // https://github.com/eslint/eslint/issues/10227 { code: "for (let x = x;;); let x = 0", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "for (let x in xs); let xs = []", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "xs" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "for (let x of xs); let xs = []", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "xs" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "try {} catch ({message = x}) {} let x = ''", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "with (obj) x; let x = {}", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, // WithStatements. { code: "with (x); let x = {}", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "with (obj) { x } let x = {}", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "with (obj) { if (a) { x } } let x = {}", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "with (obj) { (() => { if (a) { x } })() } let x = {}", + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } - }], - languageOptions: { ecmaVersion: 2015 } + }] }, // Tests related to class definition evaluation. These are TDZ errors. { code: "class C extends C {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const C = class extends C {};", options: [{ variables: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C extends (class { [C](){} }) {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const C = class extends (class { [C](){} }) {};", options: [{ variables: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C extends (class { static field = C; }) {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class extends (class { static field = C; }) {};", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [C](){} }", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(class C { [C](){} });", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const C = class { [C](){} };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C { static [C](){} }", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "(class C { static [C](){} });", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const C = class { static [C](){} };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C { [C]; }", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "(class C { [C]; });", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { [C]; };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [C] = foo; }", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "(class C { [C] = foo; });", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { [C] = foo; };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static [C]; }", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "(class C { static [C]; });", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static [C]; };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static [C] = foo; }", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "(class C { static [C] = foo; });", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static [C] = foo; };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static field = C; };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static field = class extends C {}; };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static field = class { [C]; } };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static field = class { static field = C; }; };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C extends D {} class D {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C extends (class { [a](){} }) {} let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C extends (class { static field = a; }) {} let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [a]() {} } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C { static [a]() {} } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C { [a]; } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static [a]; } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [a] = foo; } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static [a] = foo; } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static field = a; } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static field = D; } class D {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static field = class extends D {}; } class D {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static field = class { [a](){} } } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static field = class { static field = a; }; } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static { C; } };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "const C = class { static { (class extends C {}); } };", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { a; } } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { D; } } class D {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { (class extends D {}); } } class D {}", options: [{ classes: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { (class { [a](){} }); } } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { (class { static field = a; }); } } let a;", options: [{ variables: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, /* @@ -1164,49 +1164,50 @@ ruleTester.run("no-use-before-define", rule, { // "allowNamedExports" option { code: "export { a }; const a = 1;", + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export { a }; const a = 1;", options: [{}], + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export { a }; const a = 1;", options: [{ allowNamedExports: false }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export { a }; const a = 1;", options: ["nofunc"], + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export { a as b }; const a = 1;", + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export { a, b }; let a, b;", + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [ { messageId: "usedBeforeDefined", @@ -1216,68 +1217,67 @@ ruleTester.run("no-use-before-define", rule, { messageId: "usedBeforeDefined", data: { name: "b" } } - ], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + ] }, { code: "export { a }; var a;", + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export { f }; function f() {}", + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "f" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export { C }; class C {}", + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export const foo = a; const a = 1;", options: [{ allowNamedExports: true }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export default a; const a = 1;", options: [{ allowNamedExports: true }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export function foo() { return a; }; const a = 1;", options: [{ allowNamedExports: true }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] }, { code: "export class C { foo() { return a; } }; const a = 1;", options: [{ allowNamedExports: true }], + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } - }], - languageOptions: { ecmaVersion: 2015, sourceType: "module" } + }] } ] }); diff --git a/tests/lib/rules/no-useless-call.js b/tests/lib/rules/no-useless-call.js index 2366c921d30..2956adc40a6 100644 --- a/tests/lib/rules/no-useless-call.js +++ b/tests/lib/rules/no-useless-call.js @@ -187,81 +187,81 @@ ruleTester.run("no-useless-call", rule, { // Optional chaining { code: "foo.call?.(undefined, 1, 2);", - errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] }, { code: "foo?.call(undefined, 1, 2);", - errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] }, { code: "(foo?.call)(undefined, 1, 2);", - errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] }, { code: "obj.foo.call?.(obj, 1, 2);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "obj?.foo.call(obj, 1, 2);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "(obj?.foo).call(obj, 1, 2);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "(obj?.foo.call)(obj, 1, 2);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "obj?.foo.bar.call(obj?.foo, 1, 2);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "(obj?.foo).bar.call(obj?.foo, 1, 2);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "obj.foo?.bar.call(obj.foo, 1, 2);", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, type: "CallExpression" - }], - languageOptions: { ecmaVersion: 2020 } + }] } ] }); diff --git a/tests/lib/rules/no-useless-catch.js b/tests/lib/rules/no-useless-catch.js index dff492c72ba..99745fbe8c7 100644 --- a/tests/lib/rules/no-useless-catch.js +++ b/tests/lib/rules/no-useless-catch.js @@ -185,11 +185,11 @@ ruleTester.run("no-useless-catch", rule, { } } `, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessaryCatch", type: "TryStatement" - }], - languageOptions: { ecmaVersion: 8 } + }] } ] }); diff --git a/tests/lib/rules/no-useless-computed-key.js b/tests/lib/rules/no-useless-computed-key.js index 3a112d0de82..d97d6fe71ea 100644 --- a/tests/lib/rules/no-useless-computed-key.js +++ b/tests/lib/rules/no-useless-computed-key.js @@ -131,12 +131,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async ['x']() {} })", output: "({ async 'x'() {} })", + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "'x'" }, type: "Property" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "({ get[.2]() {} })", output: "({ get.2() {} })", @@ -156,12 +156,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async[.2]() {} })", output: "({ async.2() {} })", + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: ".2" }, type: "Property" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "({ [2]() {} })", output: "({ 2() {} })", @@ -189,12 +189,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async [2]() {} })", output: "({ async 2() {} })", + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "Property" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "({ get[2]() {} })", output: "({ get 2() {} })", @@ -214,12 +214,12 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async[2]() {} })", output: "({ async 2() {} })", + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "Property" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "({ get['foo']() {} })", output: "({ get'foo'() {} })", @@ -327,12 +327,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async ['x']() {} }", output: "class Foo { async 'x'() {} }", options: [{ enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "'x'" }, type: "MethodDefinition" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "class Foo { get[.2]() {} }", output: "class Foo { get.2() {} }", @@ -355,12 +355,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async[.2]() {} }", output: "class Foo { async.2() {} }", options: [{ enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: ".2" }, type: "MethodDefinition" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "class Foo { [2]() {} }", output: "class Foo { 2() {} }", @@ -392,12 +392,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async [2]() {} }", output: "class Foo { async 2() {} }", options: [{ enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "MethodDefinition" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "class Foo { get[2]() {} }", output: "class Foo { get 2() {} }", @@ -420,12 +420,12 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async[2]() {} }", output: "class Foo { async 2() {} }", options: [{ enforceForClassMembers: true }], + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, type: "MethodDefinition" - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "class Foo { get['foo']() {} }", output: "class Foo { get'foo'() {} }", diff --git a/tests/lib/rules/no-useless-concat.js b/tests/lib/rules/no-useless-concat.js index 6b917dd7e1e..807b5092dc7 100644 --- a/tests/lib/rules/no-useless-concat.js +++ b/tests/lib/rules/no-useless-concat.js @@ -96,24 +96,24 @@ ruleTester.run("no-useless-concat", rule, { }, { code: "`a` + 'b'", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "`a` + `b`", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo + `a` + `b`", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } - ], - languageOptions: { ecmaVersion: 6 } + ] } ] }); diff --git a/tests/lib/rules/no-useless-escape.js b/tests/lib/rules/no-useless-escape.js index c6d50a2a157..3fdcfa7b703 100644 --- a/tests/lib/rules/no-useless-escape.js +++ b/tests/lib/rules/no-useless-escape.js @@ -447,6 +447,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "", + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [{ line: 1, column: 13, @@ -460,8 +461,7 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "" }] - }], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + }] }, { code: "var foo = '\\`';", @@ -482,6 +482,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\\"`;", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -495,11 +496,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\\"`;" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = `\\'`;", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -513,11 +514,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\'`;" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = `\\#`;", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -531,8 +532,7 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\#`;" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = '\\`foo\\`';", @@ -569,6 +569,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\\"${foo}\\\"`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -598,11 +599,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\\"${foo}\\\\\"`;" }] } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = `\\'${foo}\\'`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -632,11 +633,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\'${foo}\\\\'`;" }] } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = `\\#${foo}`;", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -650,11 +651,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "var foo = `\\\\#${foo}`;" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let foo = '\\ ';", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -668,11 +669,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "let foo = '\\\\ ';" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let foo = /\\ /;", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -686,11 +687,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "let foo = /\\\\ /;" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = `\\$\\{{${foo}`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -706,11 +707,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\\\$\\{{${foo}`;" }] } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = `\\$a${foo}`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -726,11 +727,11 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `\\\\$a${foo}`;" }] } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = `a\\{{${foo}`;", + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -746,8 +747,7 @@ ruleTester.run("no-useless-escape", rule, { output: "var foo = `a\\\\{{${foo}`;" }] } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: String.raw`var foo = /[ab\-]/`, @@ -1006,6 +1006,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`multiline template\nliteral with useless \\escape`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 22, @@ -1019,11 +1020,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`multiline template\nliteral with useless \\\\escape`" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`multiline template\r\nliteral with useless \\escape`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 22, @@ -1037,11 +1038,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`multiline template\r\nliteral with useless \\\\escape`" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`template literal with line continuation \\\nand useless \\escape`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 13, @@ -1055,11 +1056,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with line continuation \\\nand useless \\\\escape`" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`template literal with line continuation \\\r\nand useless \\escape`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 13, @@ -1073,11 +1074,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with line continuation \\\r\nand useless \\\\escape`" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`template literal with mixed linebreaks \r\r\n\n\\and useless escape`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, @@ -1091,11 +1092,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with mixed linebreaks \r\r\n\n\\\\and useless escape`" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`template literal with mixed linebreaks in line continuations \\\n\\\r\\\r\n\\and useless escape`", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, @@ -1109,11 +1110,11 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`template literal with mixed linebreaks in line continuations \\\n\\\r\\\r\n\\\\and useless escape`" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "`\\a```", + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 2, @@ -1127,8 +1128,7 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: "`\\\\a```" }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, // https://github.com/eslint/eslint/issues/16988 @@ -1151,6 +1151,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`({ foo() { "foo"; "bar"; "ba\z" } })`, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 29, @@ -1164,8 +1165,7 @@ ruleTester.run("no-useless-escape", rule, { messageId: "escapeBackslash", output: String.raw`({ foo() { "foo"; "bar"; "ba\\z" } })` }] - }], - languageOptions: { ecmaVersion: 6 } + }] }, // Carets @@ -1190,6 +1190,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[^\^]/u`, + languageOptions: { ecmaVersion: 2015 }, errors: [{ line: 1, column: 4, @@ -1205,13 +1206,13 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[^\\^]/u` } ] - }], - languageOptions: { ecmaVersion: 2015 } + }] }, // ES2024 { code: String.raw`/[\$]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1228,11 +1229,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\$]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\&\&]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1248,11 +1249,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\&\&]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\!\!]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1268,11 +1269,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\!\!]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\#\#]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1288,11 +1289,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\#\#]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\%\%]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1308,11 +1309,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\%\%]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\*\*]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1328,11 +1329,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\*\*]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\+\+]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1348,11 +1349,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\+\+]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\,\,]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1368,11 +1369,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\,\,]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\.\.]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1388,11 +1389,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\.\.]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\:\:]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1408,11 +1409,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\:\:]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\;\;]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1428,11 +1429,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\;\;]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\<\<]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1448,11 +1449,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\<\<]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\=\=]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1468,11 +1469,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\=\=]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\>\>]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1488,11 +1489,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\>\>]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\?\?]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1508,11 +1509,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\?\?]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\@\@]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1528,11 +1529,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\@\@]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: "/[\\`\\`]/v", + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1548,11 +1549,11 @@ ruleTester.run("no-useless-escape", rule, { output: "/[\\\\`\\`]/v" } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\~\~]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1568,11 +1569,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\~\~]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[^\^\^]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1588,11 +1589,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[^\\^\^]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[_\^\^]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1608,11 +1609,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[_\\^\^]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\&\&&\&]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1628,11 +1629,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\\&\&&\&]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\p{ASCII}--\.]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 14, @@ -1644,11 +1645,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\p{ASCII}--.]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\p{ASCII}&&\.]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 14, @@ -1660,11 +1661,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\p{ASCII}&&.]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\.--[.&]]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1676,11 +1677,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[.--[.&]]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\.&&[.&]]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1692,11 +1693,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[.&&[.&]]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\.--\.--\.]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1730,11 +1731,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\.--\.--.]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[\.&&\.&&\.]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1768,11 +1769,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[\.&&\.&&.]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[[\.&]--[\.&]]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1803,11 +1804,11 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[[\.&]--[\\.&]]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] }, { code: String.raw`/[[\.&]&&[\.&]]/v`, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1838,8 +1839,7 @@ ruleTester.run("no-useless-escape", rule, { output: String.raw`/[[\.&]&&[\\.&]]/v` } ] - }], - languageOptions: { ecmaVersion: 2024 } + }] } ] }); diff --git a/tests/lib/rules/no-useless-rename.js b/tests/lib/rules/no-useless-rename.js index de9608b3163..d60ad921b11 100644 --- a/tests/lib/rules/no-useless-rename.js +++ b/tests/lib/rules/no-useless-rename.js @@ -391,23 +391,23 @@ ruleTester.run("no-useless-rename", rule, { { code: "const {foo: foo, ...stuff} = myObject;", output: "const {foo, ...stuff} = myObject;", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "const {foo: foo, bar: baz, ...stuff} = myObject;", output: "const {foo, bar: baz, ...stuff} = myObject;", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "const {foo: foo, bar: bar, ...stuff} = myObject;", output: "const {foo, bar, ...stuff} = myObject;", + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "import {foo as foo} from 'foo';", @@ -417,8 +417,8 @@ ruleTester.run("no-useless-rename", rule, { { code: "import {'foo' as foo} from 'foo';", output: "import {foo} from 'foo';", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {\\u0061 as a} from 'foo';", @@ -461,38 +461,38 @@ ruleTester.run("no-useless-rename", rule, { { code: "var foo = 0; export {foo as 'foo'};", output: "var foo = 0; export {foo};", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "export {foo as 'foo'} from 'bar';", output: "export {foo} from 'bar';", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "export {'foo' as foo} from 'bar';", output: "export {'foo'} from 'bar';", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "export {'foo' as 'foo'} from 'bar';", output: "export {'foo'} from 'bar';", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "export {' 👍 ' as ' 👍 '} from 'bar';", output: "export {' 👍 '} from 'bar';", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: " 👍 " } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: " 👍 " } }] }, { code: "export {'' as ''} from 'bar';", output: "export {''} from 'bar';", - errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "" } }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "" } }] }, { code: "var a = 0; export {a as \\u0061};", diff --git a/tests/lib/rules/no-var.js b/tests/lib/rules/no-var.js index cabb2343050..d035ff097d8 100644 --- a/tests/lib/rules/no-var.js +++ b/tests/lib/rules/no-var.js @@ -36,222 +36,222 @@ ruleTester.run("no-var", rule, { { code: "var foo = bar;", output: "let foo = bar;", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var foo = bar, toast = most;", output: "let foo = bar, toast = most;", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var foo = bar; let toast = most;", output: "let foo = bar; let toast = most;", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (var a of b) { console.log(a); }", output: "for (let a of b) { console.log(a); }", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (var a in b) { console.log(a); }", output: "for (let a in b) { console.log(a); }", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (let a of b) { var c = 1; console.log(c); }", output: "for (let a of b) { let c = 1; console.log(c); }", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (var i = 0; i < list.length; ++i) { foo(i) }", output: "for (let i = 0; i < list.length; ++i) { foo(i) }", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (var i = 0, i = 0; false;);", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var i = 0; for (var i = 1; false;); console.log(i);", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" }, { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, // Not fix if it's redeclared or it's used from outside of the scope or it's declared on a case chunk. { code: "var a, b, c; var a;", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var a; if (b) { var a; }", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "if (foo) { var a, b, c; } a;", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (var i = 0; i < 10; ++i) {} i;", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (var a in obj) {} a;", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (var a of list) {} a;", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "switch (a) { case 0: var b = 1 }", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, // Don't fix if the variable is in a loop and the behavior might change. { code: "for (var a of b) { arr.push(() => a); }", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "for (let a of b) { var c; console.log(c); c = 'hello'; }", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, // https://github.com/eslint/eslint/issues/7950 { code: "var a = a", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var {a = a} = {}", output: null, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var {a = b, b} = {}", output: null, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var {a, b = a} = {}", output: "let {a, b = a} = {}", + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var a = b, b = 1", output: null, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "var a = b; var b = 1", output: "let a = b; var b = 1", + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, /* @@ -261,20 +261,20 @@ ruleTester.run("no-var", rule, { { code: "function foo() { a } var a = 1; foo()", output: null, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, // https://github.com/eslint/eslint/issues/7961 { code: "if (foo) var bar = 1;", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, // https://github.com/eslint/eslint/issues/9520 @@ -296,20 +296,20 @@ ruleTester.run("no-var", rule, { { code: "var foo = 1", output: "let foo = 1", - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, // https://github.com/eslint/eslint/issues/11594 { code: "declare var foo = 2;", output: "declare let foo = 2;", - errors: [{ messageId: "unexpectedVar" }], languageOptions: { ecmaVersion: 6, sourceType: "module", parser: require("../../fixtures/parsers/typescript-parsers/declare-var") - } + }, + errors: [{ messageId: "unexpectedVar" }] }, // https://github.com/eslint/eslint/issues/11830 @@ -328,68 +328,68 @@ ruleTester.run("no-var", rule, { { code: "var fx = function (i = 0) { if (i < 5) { return fx(i + 1); } console.log(i); }; fx();", output: "let fx = function (i = 0) { if (i < 5) { return fx(i + 1); } console.log(i); }; fx();", - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = function () { foo() };", output: "let foo = function () { foo() };", - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = () => foo();", output: "let foo = () => foo();", - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = (function () { foo(); })();", output: null, - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = bar(function () { foo(); });", output: null, - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var bar = foo, foo = function () { foo(); };", output: null, - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var bar = foo; var foo = function () { foo(); };", output: "let bar = foo; var foo = function () { foo(); };", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var { foo = foo } = function () { foo(); };", output: null, - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var { bar = foo, foo } = function () { foo(); };", output: null, - errors: [{ messageId: "unexpectedVar" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedVar" }] }, { code: "var bar = function () { foo(); }; var foo = function() {};", output: "let bar = function () { foo(); }; var foo = function() {};", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] } ] }); diff --git a/tests/lib/rules/no-whitespace-before-property.js b/tests/lib/rules/no-whitespace-before-property.js index 7b2feecfc49..c3b5aa697ee 100644 --- a/tests/lib/rules/no-whitespace-before-property.js +++ b/tests/lib/rules/no-whitespace-before-property.js @@ -845,38 +845,38 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "08 .toExponential()", output: null, // Not fixed + languageOptions: { sourceType: "script" }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }], - languageOptions: { sourceType: "script" } + }] }, { code: "0192 .toExponential()", output: null, // Not fixed + languageOptions: { sourceType: "script" }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }], - languageOptions: { sourceType: "script" } + }] }, { code: "5_000 .toExponential()", output: null, // Not fixed, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "5_000_00 .toExponential()", output: null, // Not fixed, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "5. .toExponential()", @@ -897,11 +897,11 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "5.0_0 .toExponential()", output: "5.0_0.toExponential()", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "0x5 .toExponential()", @@ -914,11 +914,11 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "0x56_78 .toExponential()", output: "0x56_78.toExponential()", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "5e0 .toExponential()", @@ -947,61 +947,61 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "05 .toExponential()", output: "05.toExponential()", + languageOptions: { sourceType: "script" }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } - }], - languageOptions: { sourceType: "script" } + }] }, // Optional chaining { code: "obj?. prop", output: "obj?.prop", - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "obj ?.prop", output: "obj?.prop", - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "obj?. [key]", output: "obj?.[key]", - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] }, { code: "obj ?.[key]", output: "obj?.[key]", - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] }, { code: "5 ?. prop", output: "5?.prop", - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "5 ?. [key]", output: "5?.[key]", - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] }, { code: "obj/* comment */?. prop", output: null, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "obj ?./* comment */prop", output: null, - errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] } ] }); diff --git a/tests/lib/rules/object-curly-newline.js b/tests/lib/rules/object-curly-newline.js index bc29cba3b2b..e6c772e5eda 100644 --- a/tests/lib/rules/object-curly-newline.js +++ b/tests/lib/rules/object-curly-newline.js @@ -690,13 +690,13 @@ ruleTester.run("object-curly-newline", rule, { "} : MyType) {}" ].join("\n"), options: ["always"], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline")) + }, errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { - parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline")) - } + ] }, { code: "function foo({ a, b } : { a : string, b : string }) {}", @@ -706,13 +706,13 @@ ruleTester.run("object-curly-newline", rule, { "} : { a : string, b : string }) {}" ].join("\n"), options: ["always"], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal")) + }, errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { - parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal")) - } + ] }, // "never" ------------------------------------------------------------ @@ -820,13 +820,13 @@ ruleTester.run("object-curly-newline", rule, { " b} : MyType) {}" ].join("\n"), options: ["never"], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline")) + }, errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { - parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline")) - } + ] }, { code: [ @@ -840,13 +840,13 @@ ruleTester.run("object-curly-newline", rule, { " b} : { a : string, b : string }) {}" ].join("\n"), options: ["never"], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal")) + }, errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { - parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal")) - } + ] }, // "multiline" --------------------------------------------------------- @@ -1332,10 +1332,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a} = {a: 1}" ].join("\n"), options: [{ multiline: true, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1346,10 +1346,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a} = {a: 1}" ].join("\n"), options: [{ multiline: true, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1360,10 +1360,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a, b} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1374,10 +1374,10 @@ ruleTester.run("object-curly-newline", rule, { "let {a, b} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1391,11 +1391,11 @@ ruleTester.run("object-curly-newline", rule, { "} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 2, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1411,11 +1411,11 @@ ruleTester.run("object-curly-newline", rule, { "} = a;" ].join("\n"), options: [{ multiline: true, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1458,10 +1458,10 @@ ruleTester.run("object-curly-newline", rule, { "b} = {a: 1, b: 2};" ].join("\n"), options: [{ multiline: false, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -1474,10 +1474,10 @@ ruleTester.run("object-curly-newline", rule, { "b} = {a: 1, b: 2};" ].join("\n"), options: [{ multiline: false, consistent: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // "consistent" and "minProperties" ------------------------------------------ @@ -1510,11 +1510,11 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ multiline: true, consistent: true, minProperties: 2 }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 10, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // "ObjectExpression" and "ObjectPattern" --------------------------------------------- @@ -1530,13 +1530,13 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ ObjectExpression: "always", ObjectPattern: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" }, { line: 3, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 3, column: 16, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // "ImportDeclaration" --------------------------------------------- diff --git a/tests/lib/rules/object-curly-spacing.js b/tests/lib/rules/object-curly-spacing.js index 2e7a126f4ce..520d11f6915 100644 --- a/tests/lib/rules/object-curly-spacing.js +++ b/tests/lib/rules/object-curly-spacing.js @@ -186,6 +186,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import {bar} from 'foo.js';", output: "import { bar } from 'foo.js';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -205,13 +206,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 13 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { bar as y} from 'foo.js';", output: "import { bar as y } from 'foo.js';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -222,13 +223,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 19 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import {bar as y} from 'foo.js';", output: "import { bar as y } from 'foo.js';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -248,13 +249,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 18 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { bar} from 'foo.js';", output: "import { bar } from 'foo.js';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -265,13 +266,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 14 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import x, { bar} from 'foo';", output: "import x, { bar } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -283,13 +284,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 17 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import x, { bar/* */} from 'foo';", output: "import x, { bar/* */ } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -300,13 +301,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 22 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import x, {/* */bar } from 'foo';", output: "import x, { /* */bar } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -317,13 +318,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import x, {//\n bar } from 'foo';", output: "import x, { //\n bar } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -334,13 +335,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import x, { bar, baz} from 'foo';", output: "import x, { bar, baz } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -352,13 +353,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 22 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import x, {bar} from 'foo';", output: "import x, { bar } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -379,13 +380,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 16 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import x, {bar, baz} from 'foo';", output: "import x, { bar, baz } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -405,13 +406,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 21 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import {bar,} from 'foo';", output: "import { bar, } from 'foo';", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -432,13 +433,13 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 14 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { bar, } from 'foo';", output: "import {bar,} from 'foo';", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -458,13 +459,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import { /* */ bar, /* */ } from 'foo';", output: "import {/* */ bar, /* */} from 'foo';", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -484,13 +485,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 27 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var bar = 0;\nexport {bar};", output: "var bar = 0;\nexport { bar };", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -508,13 +509,13 @@ ruleTester.run("object-curly-spacing", rule, { line: 2, column: 12 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var bar = 0;\nexport {/* */ bar /* */};", output: "var bar = 0;\nexport { /* */ bar /* */ };", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -534,13 +535,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 2, endColumn: 25 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var bar = 0;\nexport {//\n bar };", output: "var bar = 0;\nexport { //\n bar };", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -551,13 +552,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 2, endColumn: 9 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var bar = 0;\nexport { /* */ bar /* */ };", output: "var bar = 0;\nexport {/* */ bar /* */};", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -577,8 +578,7 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 2, endColumn: 26 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, // always - arraysInObjects @@ -654,6 +654,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { a,} = x;", output: "var { a, } = x;", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -664,13 +665,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {a, } = x;", output: "var {a,} = x;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -681,13 +682,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 9 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {a:b } = x;", output: "var {a:b} = x;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -698,13 +699,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 10 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -724,13 +725,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -750,13 +751,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 13 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -776,8 +777,7 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // never-objectsInObjects @@ -1136,6 +1136,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "export const thing = {value: 1 };", output: "export const thing = { value: 1 };", options: ["always"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -1146,8 +1147,7 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 23 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, // destructuring @@ -1155,6 +1155,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {x, y} = y", output: "var { x, y } = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1174,13 +1175,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { x, y} = y", output: "var { x, y } = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1191,13 +1192,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { x, y/* */} = y", output: "var { x, y/* */ } = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1208,13 +1209,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 17 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {/* */x, y } = y", output: "var { /* */x, y } = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1225,13 +1226,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 6 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {//\n x } = y", output: "var { //\n x } = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1242,13 +1243,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 6 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { x, y } = y", output: "var {x, y} = y", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1268,13 +1269,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {x, y } = y", output: "var {x, y} = y", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1285,13 +1286,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {x, y/* */ } = y", output: "var {x, y/* */} = y", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1302,13 +1303,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { /* */x, y} = y", output: "var {/* */x, y} = y", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1319,13 +1320,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 7 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var { x=10} = y", output: "var { x=10 } = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1336,13 +1337,13 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 12 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var {x=10 } = y", output: "var { x=10 } = y", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1353,8 +1354,7 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 6 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // never - arraysInObjects @@ -1396,6 +1396,9 @@ ruleTester.run("object-curly-spacing", rule, { code: "function foo ({a, b }: Props) {\n}", output: "function foo ({a, b}: Props) {\n}", options: ["never"], + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid")) + }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1406,10 +1409,7 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 21 } - ], - languageOptions: { - parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid")) - } + ] } ] }); diff --git a/tests/lib/rules/object-property-newline.js b/tests/lib/rules/object-property-newline.js index 0802956c984..16d60c4d03e 100644 --- a/tests/lib/rules/object-property-newline.js +++ b/tests/lib/rules/object-property-newline.js @@ -231,6 +231,7 @@ ruleTester.run("object-property-newline", rule, { { code: "var obj = { k1: 'val1', [\nk2]: 'val2' };", output: "var obj = { k1: 'val1',\n[\nk2]: 'val2' };", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -240,12 +241,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 26 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var obj = { k1: 'val1', ...{} };", output: "var obj = { k1: 'val1',\n...{} };", + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -255,12 +256,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 28 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {\nk1: 'val1', ...{}\n};", output: "var obj = {\nk1: 'val1',\n...{}\n};", + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -270,8 +271,7 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "foo({ k1: 'val1', k2: 'val2' });", @@ -304,6 +304,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({ a, b });", output: "foo({ a,\nb });", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -313,12 +314,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 11 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo({\na, b\n});", output: "foo({\na,\nb\n});", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -328,12 +329,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 5 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo({\nbar() {}, baz\n});", output: "foo({\nbar() {},\nbaz\n});", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -343,12 +344,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo({\n[bar]: 'baz', baz\n})", output: "foo({\n[bar]: 'baz',\nbaz\n})", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -358,12 +359,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 18 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo({ k1: 'val1', [\nk2]: 'val2' })", output: "foo({ k1: 'val1',\n[\nk2]: 'val2' })", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -373,12 +374,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 20 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo({ k1: 'val1', ...{} })", output: "foo({ k1: 'val1',\n...{} })", + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -388,12 +389,12 @@ ruleTester.run("object-property-newline", rule, { endLine: 1, endColumn: 22 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "foo({\nk1: 'val1', ...{}\n})", output: "foo({\nk1: 'val1',\n...{}\n})", + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -403,8 +404,7 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {\na: {\nb: 1,\nc: 2\n}, d: 2\n};", @@ -560,6 +560,7 @@ ruleTester.run("object-property-newline", rule, { code: "var obj = { [\nk1]: 'val1', k2: 'val2' };", output: "var obj = { [\nk1]: 'val1',\nk2: 'val2' };", options: [{ allowAllPropertiesOnSameLine: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -569,13 +570,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var obj = {\nk1: 'val1',\nk2: 'val2', ...{}\n};", output: "var obj = {\nk1: 'val1',\nk2: 'val2',\n...{}\n};", options: [{ allowAllPropertiesOnSameLine: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -585,13 +586,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {\n...{},\nk1: 'val1', k2: 'val2'\n};", output: "var obj = {\n...{},\nk1: 'val1',\nk2: 'val2'\n};", options: [{ allowAllPropertiesOnSameLine: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -601,13 +602,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "foo({ [\nk1]: 'val1', k2: 'val2' })", output: "foo({ [\nk1]: 'val1',\nk2: 'val2' })", options: [{ allowAllPropertiesOnSameLine: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -617,13 +618,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 2, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "foo({\nk1: 'val1',\nk2: 'val2', ...{}\n})", output: "foo({\nk1: 'val1',\nk2: 'val2',\n...{}\n})", options: [{ allowAllPropertiesOnSameLine: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -633,13 +634,13 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "foo({\n...{},\nk1: 'val1', k2: 'val2'\n})", output: "foo({\n...{},\nk1: 'val1',\nk2: 'val2'\n})", options: [{ allowAllPropertiesOnSameLine: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -649,8 +650,7 @@ ruleTester.run("object-property-newline", rule, { endLine: 3, endColumn: 15 } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // allowMultiplePropertiesPerLine: true (deprecated) diff --git a/tests/lib/rules/object-shorthand.js b/tests/lib/rules/object-shorthand.js index 32cac815b7f..1864dc9351d 100644 --- a/tests/lib/rules/object-shorthand.js +++ b/tests/lib/rules/object-shorthand.js @@ -579,20 +579,20 @@ ruleTester.run("object-shorthand", rule, { { code: "({ foo: async function () {} })", output: "({ async foo () {} })", - errors: [METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [METHOD_ERROR] }, { code: "({ 'foo': async function() {} })", output: "({ async 'foo'() {} })", - errors: [METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [METHOD_ERROR] }, { code: "({ [foo]: async function() {} })", output: "({ async [foo]() {} })", - errors: [METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [METHOD_ERROR] }, { code: "({ [foo.bar]: function*() {} })", @@ -607,8 +607,8 @@ ruleTester.run("object-shorthand", rule, { { code: "({ [ foo ]: async function() {} })", output: "({ async [ foo ]() {} })", - errors: [METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [METHOD_ERROR] }, { code: "({ foo: function *() {} })", @@ -659,8 +659,8 @@ ruleTester.run("object-shorthand", rule, { { code: "({ [(foo)]: async function() { return; } })", output: "({ async [(foo)]() { return; } })", - errors: [METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [METHOD_ERROR] }, { code: "({ [(((((((foo)))))))]: function() { return; } })", @@ -677,8 +677,8 @@ ruleTester.run("object-shorthand", rule, { code: "({ async [(foo)]() { return; } })", output: "({ [(foo)]: async function() { return; } })", options: ["never"], - errors: [LONGFORM_METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [LONGFORM_METHOD_ERROR] }, { code: "({ *[((foo))]() { return; } })", @@ -708,15 +708,15 @@ ruleTester.run("object-shorthand", rule, { code: "({ async foo() { return; } })", output: "({ foo: async function() { return; } })", options: ["never"], - errors: [LONGFORM_METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [LONGFORM_METHOD_ERROR] }, { code: "({ *['foo bar']() { return; } })", output: "({ ['foo bar']: function*() { return; } })", options: ["never"], - errors: [LONGFORM_METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [LONGFORM_METHOD_ERROR] }, { code: "var x = {x: x}", @@ -776,15 +776,15 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {foo: foo, bar: baz, ...qux}", output: "var x = {foo, bar: baz, ...qux}", options: ["always"], - errors: [PROPERTY_ERROR], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [PROPERTY_ERROR] }, { code: "var x = {foo, bar: baz, ...qux}", output: "var x = {foo: foo, bar: baz, ...qux}", options: ["never"], - errors: [LONGFORM_PROPERTY_ERROR], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [LONGFORM_PROPERTY_ERROR] }, // ignoreConstructors @@ -920,8 +920,8 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {foo, bar: baz, ...qux}", output: null, options: ["consistent"], - errors: [MIXED_SHORTHAND_ERROR], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [MIXED_SHORTHAND_ERROR] }, // consistent-as-needed @@ -948,15 +948,15 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {a: a, b: b, ...baz}", output: null, options: ["consistent-as-needed"], - errors: [ALL_SHORTHAND_ERROR], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [ALL_SHORTHAND_ERROR] }, { code: "var x = {foo, bar: bar, ...qux}", output: null, options: ["consistent-as-needed"], - errors: [MIXED_SHORTHAND_ERROR], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [MIXED_SHORTHAND_ERROR] }, // avoidExplicitReturnArrows @@ -1084,15 +1084,15 @@ ruleTester.run("object-shorthand", rule, { code: "({ a: 1, foo: async (bar = 1) => { return; } })", output: "({ a: 1, async foo(bar = 1) { return; } })", options: ["always", { avoidExplicitReturnArrows: true }], - errors: [METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [METHOD_ERROR] }, { code: "({ [ foo ]: async bar => { return; } })", output: "({ async [ foo ](bar) { return; } })", options: ["always", { avoidExplicitReturnArrows: true }], - errors: [METHOD_ERROR], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [METHOD_ERROR] }, { @@ -1263,10 +1263,10 @@ ruleTester.run("object-shorthand", rule, { } `, options: ["always", { avoidExplicitReturnArrows: true }], - errors: Array(18).fill(METHOD_ERROR), languageOptions: { parser: require("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props") - } + }, + errors: Array(18).fill(METHOD_ERROR) } ] }); diff --git a/tests/lib/rules/one-var-declaration-per-line.js b/tests/lib/rules/one-var-declaration-per-line.js index 99c21642a68..b611212673d 100644 --- a/tests/lib/rules/one-var-declaration-per-line.js +++ b/tests/lib/rules/one-var-declaration-per-line.js @@ -70,12 +70,12 @@ ruleTester.run("one-var-declaration-per-line", rule, { invalid: [ { code: "var foo, bar;", output: "var foo, \nbar;", options: ["always"], errors: [{ line: 1, column: 10, endLine: 1, endColumn: 13 }] }, { code: "var a, b;", output: "var a, \nb;", options: ["always"], errors: [errorAt(1, 8)] }, - { code: "let a, b;", output: "let a, \nb;", options: ["always"], errors: [errorAt(1, 8)], languageOptions: { ecmaVersion: 6 } }, + { code: "let a, b;", output: "let a, \nb;", options: ["always"], languageOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] }, { code: "var a, b = 0;", output: "var a, \nb = 0;", options: ["always"], errors: [errorAt(1, 8)] }, { code: "var a = {\n foo: bar\n}, b;", output: "var a = {\n foo: bar\n}, \nb;", options: ["always"], errors: [errorAt(3, 4)] }, { code: "var a\n=0, b;", output: "var a\n=0, \nb;", options: ["always"], errors: [errorAt(2, 5)] }, - { code: "let a, b = 0;", output: "let a, \nb = 0;", options: ["always"], errors: [errorAt(1, 8)], languageOptions: { ecmaVersion: 6 } }, - { code: "const a = 0, b = 0;", output: "const a = 0, \nb = 0;", options: ["always"], errors: [errorAt(1, 14)], languageOptions: { ecmaVersion: 6 } }, + { code: "let a, b = 0;", output: "let a, \nb = 0;", options: ["always"], languageOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] }, + { code: "const a = 0, b = 0;", output: "const a = 0, \nb = 0;", options: ["always"], languageOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 14)] }, { code: "var foo, bar, baz = 0;", output: "var foo, bar, \nbaz = 0;", options: ["initializations"], errors: [{ line: 1, column: 15, endLine: 1, endColumn: 22 }] }, { code: "var a, b, c = 0;", output: "var a, b, \nc = 0;", options: ["initializations"], errors: [errorAt(1, 11)] }, @@ -85,7 +85,7 @@ ruleTester.run("one-var-declaration-per-line", rule, { { code: "var a = {\n foo: bar\n}, b;", output: "var a = {\n foo: bar\n}, \nb;", options: ["initializations"], errors: [errorAt(3, 4)] }, { code: "for(var a = 0, b = 0;;){\nvar c,d;}", output: "for(var a = 0, b = 0;;){\nvar c,\nd;}", options: ["always"], errors: [errorAt(2, 7)] }, - { code: "export let a, b;", output: "export let a, \nb;", options: ["always"], errors: [errorAt(1, 15)], languageOptions: { ecmaVersion: 6, sourceType: "module" } }, - { code: "export let a, b = 0;", output: "export let a, \nb = 0;", options: ["initializations"], errors: [errorAt(1, 15)], languageOptions: { ecmaVersion: 6, sourceType: "module" } } + { code: "export let a, b;", output: "export let a, \nb;", options: ["always"], languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [errorAt(1, 15)] }, + { code: "export let a, b = 0;", output: "export let a, \nb = 0;", options: ["initializations"], languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [errorAt(1, 15)] } ] }); diff --git a/tests/lib/rules/one-var.js b/tests/lib/rules/one-var.js index da76d3dbfd8..37739da1899 100644 --- a/tests/lib/rules/one-var.js +++ b/tests/lib/rules/one-var.js @@ -986,14 +986,14 @@ ruleTester.run("one-var", rule, { { code: "var foo = () => { var bar = true; var baz = false; }", output: "var foo = () => { var bar = true, baz = false; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 35 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function() { var bar = true; if (qux) { var baz = false; } }", @@ -1093,27 +1093,27 @@ ruleTester.run("one-var", rule, { code: "var {foo} = 1, [bar] = 2;", output: "var {foo} = 1; var [bar] = 2;", options: [{ initialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const foo = 1,\n bar = 2;", output: "const foo = 1;\n const bar = 2;", options: [{ initialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 1 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = 1,\n bar = 2;", @@ -1273,53 +1273,53 @@ ruleTester.run("one-var", rule, { code: "let a = 1, b; let c;", output: "let a = 1, b, c;", options: ["consecutive"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a = 0, b = 1; let c = 2;", output: "let a = 0, b = 1, c = 2;", options: ["consecutive"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0, b = 1; const c = 2;", output: "const a = 0, b = 1, c = 2;", options: ["consecutive"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; var b = 1; var c = 2; const d = 3;", output: "const a = 0; var b = 1, c = 2; const d = 3;", options: ["consecutive"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = true; var b = false;", @@ -1337,27 +1337,27 @@ ruleTester.run("one-var", rule, { code: "const a = 0; let b = 1; let c = 2; const d = 3;", output: "const a = 0; let b = 1, c = 2; const d = 3;", options: ["consecutive"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a = 0; const b = 1; const c = 1; var d = 2;", output: "let a = 0; const b = 1, c = 1; var d = 2;", options: ["consecutive"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 25 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = 0; var b; var c; var d = 1", @@ -1394,19 +1394,20 @@ ruleTester.run("one-var", rule, { code: "let a = 0; let b; let c; let d = 1;", output: "let a = 0; let b, c; let d = 1;", options: [{ initialized: "consecutive", uninitialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a = 0; let b = 1; let c; let d;", output: "let a = 0, b = 1; let c, d;", options: [{ initialized: "consecutive", uninitialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -1420,26 +1421,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 30 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; let b; let c; const d = 1;", output: "const a = 0; let b, c; const d = 1;", options: [{ initialized: "consecutive", uninitialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 21 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; const b = 1; let c; let d;", output: "const a = 0, b = 1; let c, d;", options: [{ initialized: "consecutive", uninitialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", type: "VariableDeclaration", @@ -1452,8 +1453,7 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 34 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = 0; var b = 1; var c, d;", @@ -1490,6 +1490,7 @@ ruleTester.run("one-var", rule, { code: "let a = 0; let b = 1; let c, d;", output: "let a = 0, b = 1; let c; let d;", options: [{ initialized: "consecutive", uninitialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -1503,26 +1504,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 23 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a = 0; let b, c; let d = 1;", output: "let a = 0; let b; let c; let d = 1;", options: [{ initialized: "consecutive", uninitialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; const b = 1; let c, d;", output: "const a = 0, b = 1; let c; let d;", options: [{ initialized: "consecutive", uninitialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "const" }, @@ -1536,21 +1537,20 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 27 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; let b, c; const d = 1;", output: "const a = 0; let b; let c; const d = 1;", options: [{ initialized: "consecutive", uninitialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitUninitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 14 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a; var b; var c = 0; var d = 1;", @@ -1587,6 +1587,7 @@ ruleTester.run("one-var", rule, { code: "let a; let b; let c = 0; let d = 1;", output: "let a, b; let c = 0, d = 1;", options: [{ uninitialized: "consecutive", initialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1600,26 +1601,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 26 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; let b = 0; let c = 1; let d;", output: "let a; let b = 0, c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; let b; const c = 0; const d = 1;", output: "let a, b; const c = 0, d = 1;", options: [{ uninitialized: "consecutive", initialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1633,21 +1634,20 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; const b = 0; const c = 1; let d;", output: "let a; const b = 0, c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a; var b; var c = 0, d = 1;", @@ -1684,6 +1684,7 @@ ruleTester.run("one-var", rule, { code: "let a; let b; let c = 0, d = 1;", output: "let a, b; let c = 0; let d = 1;", options: [{ uninitialized: "consecutive", initialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1697,26 +1698,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; let b = 0, c = 1; let d;", output: "let a; let b = 0; let c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; let b; const c = 0, d = 1;", output: "let a, b; const c = 0; const d = 1;", options: [{ uninitialized: "consecutive", initialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1730,21 +1731,20 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; const b = 0, c = 1; let d;", output: "let a; const b = 0; const c = 1; let d;", options: [{ uninitialized: "consecutive", initialized: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 8 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a = 0; var b = 1;", @@ -1762,32 +1762,33 @@ ruleTester.run("one-var", rule, { code: "let a = 0; let b = 1;", output: "let a = 0, b = 1;", options: [{ let: "consecutive" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; const b = 1;", output: "const a = 0, b = 1;", options: [{ const: "consecutive" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 14 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; let b; const c = 0; const d = 1;", output: "let a, b; const c = 0, d = 1;", options: [{ let: "consecutive", const: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1801,26 +1802,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 28 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; const b = 0; const c = 1; let d;", output: "let a; const b = 0, c = 1; let d;", options: [{ let: "consecutive", const: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; let b; const c = 0, d = 1;", output: "let a, b; const c = 0; const d = 1;", options: [{ let: "consecutive", const: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1834,26 +1835,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "let a; const b = 0, c = 1; let d;", output: "let a; const b = 0; const c = 1; let d;", options: [{ let: "consecutive", const: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 8 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; const b = 1; let c; let d;", output: "const a = 0, b = 1; let c, d;", options: [{ const: "consecutive", let: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1867,26 +1868,26 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 34 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; let b; let c; const d = 1;", output: "const a = 0; let b, c; const d = 1;", options: [{ const: "consecutive", let: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 21 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; const b = 1; let c, d;", output: "const a = 0, b = 1; let c; let d;", options: [{ const: "consecutive", let: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1900,21 +1901,20 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 27 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "const a = 0; let b, c; const d = 1;", output: "const a = 0; let b; let c; const d = 1;", options: [{ const: "consecutive", let: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "split", data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 14 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var bar; var baz;", @@ -1951,6 +1951,7 @@ ruleTester.run("one-var", rule, { code: "let a, b; let c; var d, e;", output: "let a, b, c; var d; var e;", options: [{ var: "never", let: "consecutive", const: "consecutive" }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1964,8 +1965,7 @@ ruleTester.run("one-var", rule, { type: "VariableDeclaration", line: 1, column: 18 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var a; var b;", @@ -2040,89 +2040,89 @@ ruleTester.run("one-var", rule, { code: "export const foo=1, bar=2;", output: "export const foo=1; export const bar=2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, { code: "const foo=1,\n bar=2;", output: "const foo=1;\n const bar=2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, { code: "export const foo=1,\n bar=2;", output: "export const foo=1;\n export const bar=2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, { code: "export const foo=1\n, bar=2;", output: "export const foo=1\n; export const bar=2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, { code: "export const foo= a, bar=2;", output: "export const foo= a; export const bar=2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, { code: "export const foo=() => a, bar=2;", output: "export const foo=() => a; export const bar=2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, { code: "export const foo= a, bar=2, bar2=2;", output: "export const foo= a; export const bar=2; export const bar2=2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, { code: "export const foo = 1,bar = 2;", output: "export const foo = 1; export const bar = 2;", options: ["never"], + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2021, sourceType: "module" } + }] }, // "never" should not autofix declarations in a block position @@ -2262,122 +2262,122 @@ ruleTester.run("one-var", rule, { code: "class C { static { let x, y; } }", output: "class C { static { let x; let y; } }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "split", data: { type: "let" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var x, y; } }", output: "class C { static { var x; var y; } }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "split", data: { type: "var" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { let x; let y; } }", output: "class C { static { let x, y; } }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var x; var y; } }", output: "class C { static { var x, y; } }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { let x; foo; let y; } }", output: null, options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var x; foo; var y; } }", output: null, options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var x; if (foo) { var y; } } }", output: null, options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { let x; let y; } }", output: "class C { static { let x, y; } }", options: ["consecutive"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var x; var y; } }", output: "class C { static { var x, y; } }", options: ["consecutive"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { let a = 0; let b = 1; } }", output: "class C { static { let a = 0, b = 1; } }", options: [{ initialized: "consecutive" }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { var a = 0; var b = 1; } }", output: "class C { static { var a = 0, b = 1; } }", options: [{ initialized: "consecutive" }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combineInitialized", data: { type: "var" }, type: "VariableDeclaration" - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/operator-linebreak.js b/tests/lib/rules/operator-linebreak.js index 39a0b6ba355..0a1a162208d 100644 --- a/tests/lib/rules/operator-linebreak.js +++ b/tests/lib/rules/operator-linebreak.js @@ -721,17 +721,18 @@ ruleTester.run("operator-linebreak", rule, { code: "foo ??\n bar", output: "foo\n ?? bar", options: ["after", { overrides: { "??": "before" } }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "??" } - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "a \n &&= b", output: "a &&= \n b", options: ["after"], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "&&=" }, @@ -740,13 +741,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 2, endColumn: 6 - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "a ||=\n b", output: "a\n ||= b", options: ["before"], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "||=" }, @@ -755,13 +756,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 1, endColumn: 6 - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "a ??=\n b", output: "a ??= b", options: ["none"], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLinebreak", data: { operator: "??=" }, @@ -770,13 +771,13 @@ ruleTester.run("operator-linebreak", rule, { column: 4, endLine: 1, endColumn: 7 - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "a \n &&= b", output: "a &&= b", options: ["before", { overrides: { "&&=": "none" } }], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLinebreak", data: { operator: "&&=" }, @@ -785,13 +786,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 2, endColumn: 6 - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "a ||=\nb", output: "a\n||= b", options: ["after", { overrides: { "||=": "before" } }], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "||=" }, @@ -800,13 +801,13 @@ ruleTester.run("operator-linebreak", rule, { column: 3, endLine: 1, endColumn: 6 - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "a\n??=b", output: "a??=\nb", options: ["none", { overrides: { "??=": "after" } }], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "??=" }, @@ -815,8 +816,7 @@ ruleTester.run("operator-linebreak", rule, { column: 1, endLine: 2, endColumn: 4 - }], - languageOptions: { ecmaVersion: 2021 } + }] }, // class fields @@ -824,6 +824,7 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { a\n= 0; }", output: "class C { a =\n0; }", options: ["after"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "=" }, @@ -832,13 +833,13 @@ ruleTester.run("operator-linebreak", rule, { column: 1, endLine: 2, endColumn: 2 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { a =\n0; }", output: "class C { a\n= 0; }", options: ["before"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "=" }, @@ -847,13 +848,13 @@ ruleTester.run("operator-linebreak", rule, { column: 13, endLine: 1, endColumn: 14 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { a =\n0; }", output: "class C { a =0; }", options: ["none"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noLinebreak", data: { operator: "=" }, @@ -862,13 +863,13 @@ ruleTester.run("operator-linebreak", rule, { column: 13, endLine: 1, endColumn: 14 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [a]\n= 0; }", output: "class C { [a] =\n0; }", options: ["after"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "=" }, @@ -877,13 +878,13 @@ ruleTester.run("operator-linebreak", rule, { column: 1, endLine: 2, endColumn: 2 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [a] =\n0; }", output: "class C { [a]\n= 0; }", options: ["before"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "=" }, @@ -892,13 +893,13 @@ ruleTester.run("operator-linebreak", rule, { column: 15, endLine: 1, endColumn: 16 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [a]\n =0; }", output: "class C { [a] =0; }", options: ["none"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noLinebreak", data: { operator: "=" }, @@ -907,8 +908,7 @@ ruleTester.run("operator-linebreak", rule, { column: 2, endLine: 2, endColumn: 3 - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/padded-blocks.js b/tests/lib/rules/padded-blocks.js index 1eeee4aa408..8621a65b12e 100644 --- a/tests/lib/rules/padded-blocks.js +++ b/tests/lib/rules/padded-blocks.js @@ -440,6 +440,7 @@ ruleTester.run("padded-blocks", rule, { code: "class A {\nconstructor(){}\n}", output: "class A {\n\nconstructor(){}\n\n}", options: ["always"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "alwaysPadBlock", @@ -455,13 +456,13 @@ ruleTester.run("padded-blocks", rule, { endLine: 3, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A {\nconstructor(){}\n}", output: "class A {\n\nconstructor(){}\n\n}", options: [{ classes: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "alwaysPadBlock", @@ -477,8 +478,7 @@ ruleTester.run("padded-blocks", rule, { endLine: 3, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "{a();}", @@ -728,6 +728,7 @@ ruleTester.run("padded-blocks", rule, { code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", output: "class A {\nconstructor(){\nfoo();\n}\n}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -757,13 +758,13 @@ ruleTester.run("padded-blocks", rule, { endLine: 9, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", output: "class A {\nconstructor(){\n\nfoo();\n\n}\n}", options: [{ classes: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -779,13 +780,13 @@ ruleTester.run("padded-blocks", rule, { endLine: 9, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", output: "class A {\nconstructor(){\nfoo();\n}\n}", options: [{ blocks: "never", classes: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -815,8 +816,7 @@ ruleTester.run("padded-blocks", rule, { endLine: 9, endColumn: 1 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function foo() { // a\n\n b;\n}", @@ -857,15 +857,15 @@ ruleTester.run("padded-blocks", rule, { { code: "class A{\nfoo;\n}", output: "class A{\n\nfoo;\n\n}", - errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] }, { code: "class A{\n\nfoo;\n\n}", output: "class A{\nfoo;\n}", options: ["never"], - errors: [{ messageId: "neverPadBlock" }, { messageId: "neverPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "neverPadBlock" }, { messageId: "neverPadBlock" }] }, // class static blocks @@ -873,157 +873,157 @@ ruleTester.run("padded-blocks", rule, { code: "class C {\n\n static {\nfoo;\n\n} \n\n}", output: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", options: ["always"], - errors: [{ messageId: "alwaysPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "alwaysPadBlock" }] }, { code: "class C {\n\n static\n {\nfoo;\n\n} \n\n}", output: "class C {\n\n static\n {\n\nfoo;\n\n} \n\n}", options: ["always"], - errors: [{ messageId: "alwaysPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "alwaysPadBlock" }] }, { code: "class C {\n\n static\n\n {\nfoo;\n\n} \n\n}", output: "class C {\n\n static\n\n {\n\nfoo;\n\n} \n\n}", options: ["always"], - errors: [{ messageId: "alwaysPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "alwaysPadBlock" }] }, { code: "class C {\n\n static {\n\nfoo;\n} \n\n}", output: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", options: ["always"], - errors: [{ messageId: "alwaysPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "alwaysPadBlock" }] }, { code: "class C {\n\n static {foo;} \n\n}", output: "class C {\n\n static {\nfoo;\n} \n\n}", // this is still not padded, the subsequent fix below will add another pair of `\n`. options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n\n static {\nfoo;\n} \n\n}", output: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n\n static {// comment\nfoo;\n/* comment */} \n\n}", output: "class C {\n\n static {// comment\n\nfoo;\n\n/* comment */} \n\n}", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n\n static {\n// comment\nfoo;\n// comment\n} \n\n}", output: "class C {\n\n static {\n\n// comment\nfoo;\n// comment\n\n} \n\n}", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n\n static {\n// comment\n\nfoo;\n\n// comment\n} \n\n}", output: "class C {\n\n static {\n\n// comment\n\nfoo;\n\n// comment\n\n} \n\n}", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n static {\nfoo;\n} \n}", output: "class C {\n static {\n\nfoo;\n\n} \n}", options: [{ blocks: "always", classes: "never" }], // "blocks" applies to static blocks + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n static {\n\nfoo;\n} \n}", output: "class C {\n static {\nfoo;\n} \n}", options: ["never"], - errors: [{ messageId: "neverPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "neverPadBlock" }] }, { code: "class C {\n static\n {\n\nfoo;\n} \n}", output: "class C {\n static\n {\nfoo;\n} \n}", options: ["never"], - errors: [{ messageId: "neverPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "neverPadBlock" }] }, { code: "class C {\n static\n\n {\n\nfoo;\n} \n}", output: "class C {\n static\n\n {\nfoo;\n} \n}", options: ["never"], - errors: [{ messageId: "neverPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "neverPadBlock" }] }, { code: "class C {\n static {\nfoo;\n\n} \n}", output: "class C {\n static {\nfoo;\n} \n}", options: ["never"], - errors: [{ messageId: "neverPadBlock" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "neverPadBlock" }] }, { code: "class C {\n static {\n\nfoo;\n\n} \n}", output: "class C {\n static {\nfoo;\n} \n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n static {// comment\n\nfoo;\n\n/* comment */} \n}", output: "class C {\n static {// comment\nfoo;\n/* comment */} \n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n static {\n\n// comment\nfoo;\n// comment\n\n} \n}", output: "class C {\n static {\n// comment\nfoo;\n// comment\n} \n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C {\n\n static {\n\nfoo;\n\n} \n\n}", output: "class C {\n\n static {\nfoo;\n} \n\n}", options: [{ blocks: "never", classes: "always" }], // "blocks" applies to static blocks + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/padding-line-between-statements.js b/tests/lib/rules/padding-line-between-statements.js index d4e83ea7e38..f52c4a19d63 100644 --- a/tests/lib/rules/padding-line-between-statements.js +++ b/tests/lib/rules/padding-line-between-statements.js @@ -3534,8 +3534,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "export let a=1\n\nfoo()", @@ -3543,8 +3543,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a = 0;export {a}\n\nfoo()", @@ -3552,8 +3552,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "export default 1\nfoo()", @@ -3561,8 +3561,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "export let a=1\nfoo()", @@ -3570,8 +3570,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a = 0;export {a}\nfoo()", @@ -3579,8 +3579,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3745,15 +3745,15 @@ ruleTester.run("padding-line-between-statements", rule, { code: "(function(){\n})?.()\nvar a = 2;", output: "(function(){\n})?.()\n\nvar a = 2;", options: [{ blankLine: "always", prev: "iife", next: "*" }], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "void (function(){\n})?.()\nvar a = 2;", output: "void (function(){\n})?.()\n\nvar a = 2;", options: [{ blankLine: "always", prev: "iife", next: "*" }], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3766,8 +3766,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "import * as a from 'a'\n\nfoo()", @@ -3775,8 +3775,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "import {a} from 'a'\n\nfoo()", @@ -3784,8 +3784,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "import a from 'a'\nfoo()", @@ -3793,8 +3793,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "import * as a from 'a'\nfoo()", @@ -3802,8 +3802,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "import {a} from 'a'\nfoo()", @@ -3811,8 +3811,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4692,8 +4692,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a; return;", @@ -4701,8 +4701,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\n{\n//comment\n}\nreturn\n}", @@ -5093,8 +5093,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "expression" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C {\n static {\n let x;\n\n foo();\n }\n }", @@ -5102,8 +5102,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "let", next: "expression" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n }\n }", @@ -5111,8 +5111,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "const" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n }\n }", @@ -5120,8 +5120,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "expression", next: "const" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "class C {\n static {\n let x;\n foo();\n const y = 1;\n const z = 1;\n }\n }", @@ -5129,8 +5129,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "const" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C {\n static {\n let x;\n foo();\n\n const y = 1;\n const z = 1;\n }\n }", @@ -5138,8 +5138,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "expression", next: "const" } ], - errors: [{ messageId: "unexpectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "class C {\n static {\n let a = 0;\n bar();\n }\n }", @@ -5148,8 +5148,8 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C { static { let x; { let y; let z; } let q; } }", @@ -5157,8 +5157,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "let" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C { static { { let x; } let y; let z; } }", @@ -5166,8 +5166,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "let" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C { static { foo(); if (bar) {} } }", @@ -5175,8 +5175,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "block-like" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C { static { let x; } } let y;", @@ -5184,8 +5184,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "class", next: "let" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] }, { code: "class C { static { 'use strict'; let x; } }", // 'use strict'; is "expression", because class static blocks don't have directives @@ -5193,8 +5193,8 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "let" } ], - errors: [{ messageId: "expectedBlankLine" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "expectedBlankLine" }] } ] }); diff --git a/tests/lib/rules/prefer-const.js b/tests/lib/rules/prefer-const.js index 341b78ca01c..675b6d22ef9 100644 --- a/tests/lib/rules/prefer-const.js +++ b/tests/lib/rules/prefer-const.js @@ -213,20 +213,20 @@ ruleTester.run("prefer-const", rule, { { code: "class C { static { let a, b; if (foo) { ({ a, b } = foo); } } }", output: null, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { let a, b; if (foo) ({ a, b } = foo); } }", output: null, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { a; } } let a = 1; ", @@ -440,17 +440,17 @@ ruleTester.run("prefer-const", rule, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", output: null, options: [{ destructuring: "any" }], - errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }], - languageOptions: { ecmaVersion: 2018 } + languageOptions: { ecmaVersion: 2018 }, + errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }] }, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", output: null, options: [{ destructuring: "any" }], - errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }], languageOptions: { parser: require(fixtureParser("babel-eslint5/destructuring-object-spread")) - } + }, + errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }] }, // Warnings are located at declaration if there are reading references before assignments. @@ -464,8 +464,8 @@ ruleTester.run("prefer-const", rule, { { code: "/*eslint custom/use-x:error*/ let x = 1", output: "/*eslint custom/use-x:error*/ const x = 1", - errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }] }, { code: "/*eslint custom/use-x:error*/ { let x = 1 }", @@ -500,26 +500,26 @@ ruleTester.run("prefer-const", rule, { { code: "let predicate; [, {foo:returnType, predicate}] = foo();", output: null, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "let predicate; [, {foo:returnType, predicate}, ...bar ] = foo();", output: null, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "let predicate; [, {foo:returnType, ...predicate} ] = foo();", output: null, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "let x = 'x', y = 'y';", @@ -626,81 +626,81 @@ ruleTester.run("prefer-const", rule, { { code: "let a = 1; class C { static { a; } }", output: "const a = 1; class C { static { a; } }", - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { // this is a TDZ error with either `let` or `const`, but that isn't a concern of this rule code: "class C { static { a; } } let a = 1;", output: "class C { static { a; } } const a = 1;", - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { code: "class C { static { let a = 1; } }", output: "class C { static { const a = 1; } }", - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { code: "class C { static { if (foo) { let a = 1; } } }", output: "class C { static { if (foo) { const a = 1; } } }", - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { code: "class C { static { let a = 1; if (foo) { a; } } }", output: "class C { static { const a = 1; if (foo) { a; } } }", - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { code: "class C { static { if (foo) { let a; a = 1; } } }", output: null, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { code: "class C { static { let a; a = 1; } }", output: null, - errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier", column: 27 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier", column: 27 }] }, { code: "class C { static { let { a, b } = foo; } }", output: "class C { static { const { a, b } = foo; } }", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { let a, b; ({ a, b } = foo); } }", output: null, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { let a; let b; ({ a, b } = foo); } }", output: null, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { static { let a; a = 0; console.log(a); } }", output: null, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // https://github.com/eslint/eslint/issues/16266 @@ -714,12 +714,12 @@ ruleTester.run("prefer-const", rule, { `, output: null, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, { messageId: "useConst", data: { name: "obj" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: ` @@ -733,12 +733,12 @@ ruleTester.run("prefer-const", rule, { console.log(itemId, list, obj); `, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, { messageId: "useConst", data: { name: "obj" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: ` @@ -749,11 +749,11 @@ ruleTester.run("prefer-const", rule, { `, output: null, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: ` @@ -767,12 +767,12 @@ ruleTester.run("prefer-const", rule, { console.log(itemId, list, obj); `, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, { messageId: "useConst", data: { name: "obj" }, type: "Identifier" } - ], - languageOptions: { ecmaVersion: 2022 } + ] } ] }); diff --git a/tests/lib/rules/prefer-exponentiation-operator.js b/tests/lib/rules/prefer-exponentiation-operator.js index 8b6b9adc3b4..7f1f4b1adfe 100644 --- a/tests/lib/rules/prefer-exponentiation-operator.js +++ b/tests/lib/rules/prefer-exponentiation-operator.js @@ -94,6 +94,7 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "globalThis.Math.pow(a, b)", output: "a**b", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useExponentiation", @@ -103,12 +104,12 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 26 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "globalThis.Math['pow'](a, b)", output: "a**b", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useExponentiation", @@ -118,8 +119,7 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 29 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, // able to catch some workarounds @@ -364,41 +364,41 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "Math.pow(a, b as any)", output: "a**(b as any)", + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-1")) + }, errors: [ { messageId: "useExponentiation", type: "CallExpression" } - ], - languageOptions: { - parser: require(parser("typescript-parsers/exponentiation-with-assertion-1")) - } + ] }, { code: "Math.pow(a as any, b)", output: "(a as any)**b", + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-2")) + }, errors: [ { messageId: "useExponentiation", type: "CallExpression" } - ], - languageOptions: { - parser: require(parser("typescript-parsers/exponentiation-with-assertion-2")) - } + ] }, { code: "Math.pow(a, b) as any", output: "(a**b) as any", + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-3")) + }, errors: [ { messageId: "useExponentiation", type: "CallExpression" } - ], - languageOptions: { - parser: require(parser("typescript-parsers/exponentiation-with-assertion-3")) - } + ] } ] }); diff --git a/tests/lib/rules/prefer-named-capture-group.js b/tests/lib/rules/prefer-named-capture-group.js index b1dc9042087..f4477c28387 100644 --- a/tests/lib/rules/prefer-named-capture-group.js +++ b/tests/lib/rules/prefer-named-capture-group.js @@ -529,6 +529,7 @@ ruleTester.run("prefer-named-capture-group", rule, { }, { code: "new globalThis.RegExp('([0-9]{4})')", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "required", type: "NewExpression", @@ -546,11 +547,11 @@ ruleTester.run("prefer-named-capture-group", rule, { output: "new globalThis.RegExp('(?:[0-9]{4})')" } ] - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "globalThis.RegExp('([0-9]{4})')", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "required", type: "CallExpression", @@ -568,14 +569,14 @@ ruleTester.run("prefer-named-capture-group", rule, { output: "globalThis.RegExp('(?:[0-9]{4})')" } ] - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: ` function foo() { var globalThis = bar; } new globalThis.RegExp('([0-9]{4})'); `, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "required", type: "NewExpression", @@ -599,8 +600,7 @@ ruleTester.run("prefer-named-capture-group", rule, { ` } ] - }], - languageOptions: { ecmaVersion: 2020 } + }] }, // ES2024 diff --git a/tests/lib/rules/prefer-numeric-literals.js b/tests/lib/rules/prefer-numeric-literals.js index dbbb42ac8f0..e5e69e96060 100644 --- a/tests/lib/rules/prefer-numeric-literals.js +++ b/tests/lib/rules/prefer-numeric-literals.js @@ -178,38 +178,38 @@ ruleTester.run("prefer-numeric-literals", rule, { { code: "function *f(){ yield(Number).parseInt('11', 2) }", output: "function *f(){ yield 0b11 }", - errors: [{ message: "Use binary literals instead of (Number).parseInt()." }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Use binary literals instead of (Number).parseInt()." }] }, { code: "function *f(){ yield(Number.parseInt)('67', 8) }", output: "function *f(){ yield 0o67 }", - errors: [{ message: "Use octal literals instead of Number.parseInt()." }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Use octal literals instead of Number.parseInt()." }] }, { code: "function *f(){ yield(parseInt)('A', 16) }", output: "function *f(){ yield 0xA }", - errors: [{ message: "Use hexadecimal literals instead of parseInt()." }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Use hexadecimal literals instead of parseInt()." }] }, { code: "function *f(){ yield Number.parseInt('11', 2) }", output: "function *f(){ yield 0b11 }", - errors: [{ message: "Use binary literals instead of Number.parseInt()." }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Use binary literals instead of Number.parseInt()." }] }, { code: "function *f(){ yield/**/Number.parseInt('67', 8) }", output: "function *f(){ yield/**/0o67 }", - errors: [{ message: "Use octal literals instead of Number.parseInt()." }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Use octal literals instead of Number.parseInt()." }] }, { code: "function *f(){ yield(parseInt('A', 16)) }", output: "function *f(){ yield(0xA) }", - errors: [{ message: "Use hexadecimal literals instead of parseInt()." }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ message: "Use hexadecimal literals instead of parseInt()." }] }, { code: "parseInt('11', 2)+5", diff --git a/tests/lib/rules/prefer-object-spread.js b/tests/lib/rules/prefer-object-spread.js index 3ea4ed01275..4c6da365436 100644 --- a/tests/lib/rules/prefer-object-spread.js +++ b/tests/lib/rules/prefer-object-spread.js @@ -347,6 +347,9 @@ ruleTester.run("prefer-object-spread", rule, { baz: "cats" --> weird }`, + languageOptions: { + sourceType: "script" + }, errors: [ { messageId: "useSpreadMessage", @@ -354,10 +357,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 14 } - ], - languageOptions: { - sourceType: "script" - } + ] }, { @@ -899,6 +899,7 @@ ruleTester.run("prefer-object-spread", rule, { { code: "globalThis.Object.assign({ });", output: "({});", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -906,12 +907,12 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "globalThis.Object.assign({\n});", output: "({});", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -919,8 +920,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: ` @@ -931,6 +931,7 @@ ruleTester.run("prefer-object-spread", rule, { function foo () { var globalThis = bar; } ({}); `, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -938,8 +939,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: ` @@ -950,6 +950,7 @@ ruleTester.run("prefer-object-spread", rule, { const Foo = require('foo'); ({foo: Foo}); `, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -957,8 +958,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, // report Object.assign() with getters/setters if the function call has only 1 argument @@ -979,6 +979,9 @@ ruleTester.run("prefer-object-spread", rule, { { code: "const obj = Object.assign<{}, Record>({}, getObject());", output: "const obj = { ...getObject()};", + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1") + }, errors: [ { messageId: "useSpreadMessage", @@ -986,14 +989,14 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 13 } - ], - languageOptions: { - parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1") - } + ] }, { code: "Object.assign<{}, A>({}, foo);", output: "({ ...foo});", + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2") + }, errors: [ { messageId: "useSpreadMessage", @@ -1001,10 +1004,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ], - languageOptions: { - parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2") - } + ] } ] }); diff --git a/tests/lib/rules/prefer-regex-literals.js b/tests/lib/rules/prefer-regex-literals.js index 231483b6dc4..bc15b9a7d89 100644 --- a/tests/lib/rules/prefer-regex-literals.js +++ b/tests/lib/rules/prefer-regex-literals.js @@ -541,6 +541,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('a');", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedRegExp", @@ -552,11 +553,11 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "globalThis.RegExp('a');", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedRegExp", @@ -568,8 +569,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "new RegExp(/a/);", @@ -910,6 +910,9 @@ ruleTester.run("prefer-regex-literals", rule, { disallowRedundantWrapping: true } ], + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -918,10 +921,7 @@ ruleTester.run("prefer-regex-literals", rule, { column: 1, suggestions: null } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "(a)\nnew RegExp(/b/);", @@ -1081,31 +1081,34 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('abc', 'u');", + languageOptions: { + ecmaVersion: 3, + sourceType: "script" + }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ], - languageOptions: { - ecmaVersion: 3, - sourceType: "script" - } + ] }, { code: "new RegExp('abc', 'd');", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "RegExp('abc', 'd');", + languageOptions: { + ecmaVersion: 2022 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1116,10 +1119,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2022 - } + ] }, { code: "RegExp('\\\\\\\\', '');", @@ -1137,6 +1137,9 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('\\n', '');", + languageOptions: { + ecmaVersion: 2022 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1147,10 +1150,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2022 - } + ] }, { code: "RegExp('\\n\\n', '');", @@ -1349,6 +1349,11 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('\\\\W', '');", + languageOptions: { + globals: { + globalThis: "readonly" + } + }, errors: [ { messageId: "unexpectedRegExp", @@ -1359,12 +1364,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - globals: { - globalThis: "readonly" - } - } + ] }, { code: "RegExp('\\\\s', '');", @@ -1396,6 +1396,11 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "globalThis.RegExp('\\\\d', '');", + languageOptions: { + globals: { + globalThis: "readonly" + } + }, errors: [ { messageId: "unexpectedRegExp", @@ -1406,15 +1411,15 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], + ] + }, + { + code: "globalThis.RegExp('\\\\D', '')", languageOptions: { globals: { globalThis: "readonly" } - } - }, - { - code: "globalThis.RegExp('\\\\D', '')", + }, errors: [ { messageId: "unexpectedRegExp", @@ -1425,15 +1430,15 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], + ] + }, + { + code: "globalThis.RegExp('\\\\\\\\\\\\D', '')", languageOptions: { globals: { globalThis: "readonly" } - } - }, - { - code: "globalThis.RegExp('\\\\\\\\\\\\D', '')", + }, errors: [ { messageId: "unexpectedRegExp", @@ -1444,12 +1449,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - globals: { - globalThis: "readonly" - } - } + ] }, { code: "new RegExp('\\\\D\\\\D', '')", @@ -1467,6 +1467,11 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('\\\\0\\\\0', '');", + languageOptions: { + globals: { + globalThis: "writable" + } + }, errors: [ { messageId: "unexpectedRegExp", @@ -1477,12 +1482,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - globals: { - globalThis: "writable" - } - } + ] }, { code: "new RegExp('\\\\0\\\\0', '');", @@ -1523,6 +1523,9 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('\\\\78\\\\126\\\\5934', '')", + languageOptions: { + ecmaVersion: 2022 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1533,13 +1536,15 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2022 - } + ] }, { code: "new window['RegExp']('\\\\x56\\\\x78\\\\x45', '');", + languageOptions: { + globals: { + window: "readonly" + } + }, errors: [ { messageId: "unexpectedRegExp", @@ -1550,12 +1555,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - globals: { - window: "readonly" - } - } + ] }, { code: "a in(RegExp('abc'))", @@ -1765,16 +1765,16 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "async function abc(){await new RegExp(\"foo\")}", + languageOptions: { + ecmaVersion: 8, + sourceType: "module" + }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ], - languageOptions: { - ecmaVersion: 8, - sourceType: "module" - } + ] }, { code: "function* abc(){yield new RegExp(\"foo\")}", @@ -1903,6 +1903,9 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ == new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1913,13 +1916,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ === new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1930,13 +1933,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ != new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1947,13 +1950,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ !== new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1964,13 +1967,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ > new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1981,13 +1984,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ < new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -1998,13 +2001,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ >= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2015,13 +2018,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ <= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2032,13 +2035,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ << new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2049,13 +2052,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ >> new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2066,13 +2069,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ >>> new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2083,13 +2086,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ ^ new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2100,13 +2103,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ & new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2117,13 +2120,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n /abc/ | new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2134,13 +2137,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n null ?? new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2151,13 +2154,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc *= new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2168,13 +2171,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n console.log({a: new RegExp('sup')})\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2185,13 +2188,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n console.log(() => {new RegExp('sup')})\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2202,13 +2205,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n function abc() {new RegExp('sup')}\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2219,13 +2222,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n function abc() {return new RegExp('sup')}\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2236,13 +2239,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc <<= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2253,13 +2256,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc >>= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2270,13 +2273,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc >>>= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2287,13 +2290,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc ^= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2304,13 +2307,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc &= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2321,13 +2324,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc |= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2338,13 +2341,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc ??= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2355,13 +2358,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc &&= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2372,13 +2375,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc ||= new RegExp('cba');\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2389,13 +2392,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc **= new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2406,13 +2409,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc /= new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2423,13 +2426,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc += new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2440,13 +2443,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc -= new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2457,13 +2460,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n abc %= new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2474,13 +2477,13 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "\n () => new RegExp('blah')\n ", + languageOptions: { + ecmaVersion: 2021 + }, errors: [ { messageId: "unexpectedRegExp", @@ -2491,10 +2494,7 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { - ecmaVersion: 2021 - } + ] }, { code: "a/RegExp(\"foo\")in b", @@ -2605,15 +2605,15 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "(async function(){for await (value of new RegExp('something being searched')) { console.log(value) }})()", + languageOptions: { + ecmaVersion: 2018 + }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ], - languageOptions: { - ecmaVersion: 2018 - } + ] }, { code: "for (value in new RegExp('something being searched')) { console.log(value) }", @@ -2833,6 +2833,7 @@ ruleTester.run("prefer-regex-literals", rule, { // ES2024 { code: "new RegExp('[[A--B]]', 'v')", + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", @@ -2843,42 +2844,42 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp('[[A--B]]', 'v')", + languageOptions: { ecmaVersion: 2023 }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ], - languageOptions: { ecmaVersion: 2023 } + ] }, { code: "new RegExp('[[A&&&]]', 'v')", + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp('a', 'uv')", + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", suggestions: null } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp(/a/, 'v')", options: [{ disallowRedundantWrapping: true }], + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2892,23 +2893,23 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp(/a/, 'v')", options: [{ disallowRedundantWrapping: true }], + languageOptions: { ecmaVersion: 2023 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", suggestions: null } - ], - languageOptions: { ecmaVersion: 2023 } + ] }, { code: "new RegExp(/a/g, 'v')", options: [{ disallowRedundantWrapping: true }], + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2929,12 +2930,12 @@ ruleTester.run("prefer-regex-literals", rule, { } ] } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp(/[[A--B]]/v, 'g')", options: [{ disallowRedundantWrapping: true }], + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2950,12 +2951,12 @@ ruleTester.run("prefer-regex-literals", rule, { // suggestion with flags `g` would be invalid ] } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp(/a/u, 'v')", options: [{ disallowRedundantWrapping: true }], + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2971,12 +2972,12 @@ ruleTester.run("prefer-regex-literals", rule, { // suggestion with merged flags `uv` would be invalid ] } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp(/a/v, 'u')", options: [{ disallowRedundantWrapping: true }], + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2992,22 +2993,24 @@ ruleTester.run("prefer-regex-literals", rule, { // suggestion with merged flags `vu` would be invalid ] } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "new RegExp(/[[A--B]]/v, 'u')", options: [{ disallowRedundantWrapping: true }], + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", suggestions: null } - ], - languageOptions: { ecmaVersion: 2024 } + ] }, { code: "var regex = new RegExp('foo', 'u');", + languageOptions: { + ecmaVersion: 2015 + }, errors: [{ messageId: "unexpectedRegExp", suggestions: [ @@ -3016,10 +3019,7 @@ ruleTester.run("prefer-regex-literals", rule, { output: "var regex = /foo/u;" } ] - }], - languageOptions: { - ecmaVersion: 2015 - } + }] } ] diff --git a/tests/lib/rules/quote-props.js b/tests/lib/rules/quote-props.js index 2aa08eb4361..3b3ea58ac68 100644 --- a/tests/lib/rules/quote-props.js +++ b/tests/lib/rules/quote-props.js @@ -182,18 +182,18 @@ ruleTester.run("quote-props", rule, { code: "({ 'a': 0, [x]: 0 })", output: "({ a: 0, [x]: 0 })", options: ["consistent-as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "redundantQuoting", type: "Property" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "({ 'a': 0, x })", output: "({ a: 0, x })", options: ["consistent-as-needed"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantQuoting", type: "Property" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "({ 'true': 0, 'null': 0 })", output: "({ true: 0, null: 0 })", @@ -375,56 +375,56 @@ ruleTester.run("quote-props", rule, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["always"], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "1" } } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["as-needed", { numbers: true }], + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unquotedNumericProperty", data: { property: "1" } - }], - languageOptions: { ecmaVersion: 2020 } + }] }, { code: "({ 1_0: 1 })", output: "({ \"10\": 1 })", options: ["as-needed", { numbers: true }], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedNumericProperty", data: { property: "10" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "({ 1_2.3_4e0_2: 1 })", output: "({ \"1234\": 1 })", options: ["always"], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "1234" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "({ 0b1_000: 1 })", output: "({ \"8\": 1 })", options: ["always"], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "8" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "({ 1_000: a, '1_000': b })", output: "({ \"1000\": a, '1_000': b })", options: ["consistent-as-needed"], + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "inconsistentlyQuotedProperty", data: { key: "1000" } - }], - languageOptions: { ecmaVersion: 2021 } + }] }] }); diff --git a/tests/lib/rules/quotes.js b/tests/lib/rules/quotes.js index f3195e6aa94..549275e1d2a 100644 --- a/tests/lib/rules/quotes.js +++ b/tests/lib/rules/quotes.js @@ -122,14 +122,14 @@ ruleTester.run("quotes", rule, { code: "var foo = `bar`;", output: "var foo = 'bar';", options: ["single"], + languageOptions: { + ecmaVersion: 6 + }, errors: [{ messageId: "wrongQuotes", data: { description: "singlequote" }, type: "TemplateLiteral" - }], - languageOptions: { - ecmaVersion: 6 - } + }] }, { code: "var foo = 'don\\'t';", @@ -173,14 +173,14 @@ ruleTester.run("quotes", rule, { code: "var foo = `bar`;", output: "var foo = \"bar\";", options: ["double"], + languageOptions: { + ecmaVersion: 6 + }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { - ecmaVersion: 6 - } + }] }, { code: "var foo = \"bar\";", @@ -236,56 +236,56 @@ ruleTester.run("quotes", rule, { code: "var foo = 'bar';", output: "var foo = `bar`;", options: ["backtick"], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var foo = 'b${x}a$r';", output: "var foo = `b\\${x}a$r`;", options: ["backtick"], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var foo = \"bar\";", output: "var foo = `bar`;", options: ["backtick"], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var foo = \"bar\";", output: "var foo = `bar`;", options: ["backtick", { avoidEscape: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: "var foo = 'bar';", output: "var foo = `bar`;", options: ["backtick", { avoidEscape: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 2015 } + }] }, // "use strict" is *not* a directive prologue in these statements so is subject to the rule @@ -293,34 +293,34 @@ ruleTester.run("quotes", rule, { code: "var foo = `backtick`; \"use strict\";", output: "var foo = `backtick`; `use strict`;", options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "{ \"use strict\"; var foo = `backtick`; }", output: "{ `use strict`; var foo = `backtick`; }", options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "if (1) { \"use strict\"; var foo = `backtick`; }", output: "if (1) { `use strict`; var foo = `backtick`; }", options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 6 } + }] }, // `backtick` should warn computed property names. @@ -328,6 +328,7 @@ ruleTester.run("quotes", rule, { code: "var obj = {[\"key0\"]: 0, ['key1']: 1};", output: "var obj = {[`key0`]: 0, [`key1`]: 1};", options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -339,13 +340,13 @@ ruleTester.run("quotes", rule, { data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class Foo { ['a'](){} static ['b'](){} }", output: "class Foo { [`a`](){} static [`b`](){} }", options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -357,8 +358,7 @@ ruleTester.run("quotes", rule, { data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // https://github.com/eslint/eslint/issues/7084 @@ -366,146 +366,146 @@ ruleTester.run("quotes", rule, { code: "
", output: "
", options: ["single"], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "wrongQuotes", data: { description: "singlequote" }, type: "Literal" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "
", output: "
", options: ["double"], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "wrongQuotes", data: { description: "doublequote" }, type: "Literal" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } + ] }, { code: "
", output: "
", options: ["backtick"], + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } }, ecmaVersion: 2015 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } }, ecmaVersion: 2015 } + ] }, // https://github.com/eslint/eslint/issues/7610 { code: "`use strict`;", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo() { `use strict`; foo(); }", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo = function() { `use strict`; foo(); }", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "() => { `use strict`; foo(); }", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "() => { foo(); `use strict`; }", output: null, // no autofix + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo(); `use strict`;", output: null, // no autofix + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, // https://github.com/eslint/eslint/issues/7646 { code: "var foo = `foo\\nbar`;", output: "var foo = \"foo\\nbar\";", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = `foo\\\nbar`;", // 1 backslash followed by a newline output: "var foo = \"foo\\\nbar\";", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = `foo\\\\\\\nbar`;", // 3 backslashes followed by a newline output: "var foo = \"foo\\\\\\\nbar\";", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "````", output: "\"\"``", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral", line: 1, column: 1 - }], - languageOptions: { ecmaVersion: 6 } + }] }, // Strings containing octal escape sequences. Don't autofix to backticks. @@ -537,118 +537,118 @@ ruleTester.run("quotes", rule, { code: "var notoctal = '\\0'", output: "var notoctal = `\\0`", options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = '\\1'", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = \"\\1\"", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = '\\01'", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = '\\0\\1'", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = '\\08'", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = 'prefix \\33'", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = 'prefix \\75 suffix'", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var nonOctalDecimalEscape = '\\8'", output: null, options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, @@ -657,96 +657,97 @@ ruleTester.run("quotes", rule, { code: "class C { 'foo'; }", output: "class C { \"foo\"; }", options: ["double"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "doublequote" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { 'foo'() {} }", output: "class C { \"foo\"() {} }", options: ["double"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "doublequote" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { \"foo\"; }", output: "class C { 'foo'; }", options: ["single"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "singlequote" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { \"foo\"() {} }", output: "class C { 'foo'() {} }", options: ["single"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "singlequote" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { [\"foo\"]; }", output: "class C { [`foo`]; }", options: ["backtick"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { foo = \"foo\"; }", output: "class C { foo = `foo`; }", options: ["backtick"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, // https://github.com/eslint/eslint/pull/17022 { code: "() => { foo(); (`use strict`); }", output: "() => { foo(); (\"use strict\"); }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "('foo'); \"bar\";", output: "(`foo`); `bar`;", options: ["backtick"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -755,8 +756,7 @@ ruleTester.run("quotes", rule, { messageId: "wrongQuotes", data: { description: "backtick" }, type: "Literal" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "; 'use asm';", @@ -770,22 +770,22 @@ ruleTester.run("quotes", rule, { { code: "{ `foobar`; }", output: "{ \"foobar\"; }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo(() => `bar`);", output: "foo(() => \"bar\");", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, type: "TemplateLiteral" - }], - languageOptions: { ecmaVersion: 6 } + }] } ] }); diff --git a/tests/lib/rules/radix.js b/tests/lib/rules/radix.js index da90c460975..c5acd6f254b 100644 --- a/tests/lib/rules/radix.js +++ b/tests/lib/rules/radix.js @@ -90,12 +90,12 @@ ruleTester.run("radix", rule, { }, { code: "parseInt(\"10\",);", // Function parameter with trailing comma + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "parseInt(\"10\", 10,);" }] - }], - languageOptions: { ecmaVersion: 2017 } + }] }, { code: "parseInt((0, \"10\"));", // Sequence expression (no trailing comma). @@ -107,12 +107,12 @@ ruleTester.run("radix", rule, { }, { code: "parseInt((0, \"10\"),);", // Sequence expression (with trailing comma). + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "parseInt((0, \"10\"), 10,);" }] - }], - languageOptions: { ecmaVersion: 2017 } + }] }, { code: "parseInt(\"10\", null);", @@ -226,47 +226,47 @@ ruleTester.run("radix", rule, { // Optional chaining { code: "parseInt?.(\"10\");", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "parseInt?.(\"10\", 10);" }] } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "Number.parseInt?.(\"10\");", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "Number.parseInt?.(\"10\", 10);" }] } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "Number?.parseInt(\"10\");", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "Number?.parseInt(\"10\", 10);" }] } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "(Number?.parseInt)(\"10\");", + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", type: "CallExpression", suggestions: [{ messageId: "addRadixParameter10", output: "(Number?.parseInt)(\"10\", 10);" }] } - ], - languageOptions: { ecmaVersion: 2020 } + ] } ] }); diff --git a/tests/lib/rules/require-atomic-updates.js b/tests/lib/rules/require-atomic-updates.js index 37bd1dd1da0..25dfb277279 100644 --- a/tests/lib/rules/require-atomic-updates.js +++ b/tests/lib/rules/require-atomic-updates.js @@ -365,6 +365,7 @@ ruleTester.run("require-atomic-updates", rule, { } }; `, + languageOptions: { sourceType: "commonjs", globals: { process: "readonly" } }, errors: [ { messageId: "nonAtomicObjectUpdate", @@ -378,8 +379,7 @@ ruleTester.run("require-atomic-updates", rule, { type: "AssignmentExpression", line: 8 } - ], - languageOptions: { sourceType: "commonjs", globals: { process: "readonly" } } + ] }, // allowProperties diff --git a/tests/lib/rules/require-jsdoc.js b/tests/lib/rules/require-jsdoc.js index 67414f84db4..0ad2fb15f41 100644 --- a/tests/lib/rules/require-jsdoc.js +++ b/tests/lib/rules/require-jsdoc.js @@ -256,11 +256,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "FunctionExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: @@ -279,11 +279,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: @@ -302,11 +302,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: @@ -325,11 +325,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: @@ -348,11 +348,11 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var myFunction = () => {}", @@ -361,11 +361,11 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ArrowFunctionExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var myFunction = () => () => {}", @@ -374,11 +374,11 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ArrowFunctionExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = function() {}", @@ -399,11 +399,11 @@ ruleTester.run("require-jsdoc", rule, { FunctionExpression: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "FunctionExpression" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var foo = {bar: function() {}}", diff --git a/tests/lib/rules/require-unicode-regexp.js b/tests/lib/rules/require-unicode-regexp.js index b53426b335d..ff9bfb41ce5 100644 --- a/tests/lib/rules/require-unicode-regexp.js +++ b/tests/lib/rules/require-unicode-regexp.js @@ -266,6 +266,7 @@ ruleTester.run("require-unicode-regexp", rule, { }, { code: "new window.RegExp('foo')", + languageOptions: { globals: globals.browser }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -274,11 +275,11 @@ ruleTester.run("require-unicode-regexp", rule, { output: "new window.RegExp('foo', \"u\")" } ] - }], - languageOptions: { globals: globals.browser } + }] }, { code: "new global.RegExp('foo')", + languageOptions: { sourceType: "commonjs" }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -287,11 +288,11 @@ ruleTester.run("require-unicode-regexp", rule, { output: "new global.RegExp('foo', \"u\")" } ] - }], - languageOptions: { sourceType: "commonjs" } + }] }, { code: "new globalThis.RegExp('foo')", + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -300,8 +301,7 @@ ruleTester.run("require-unicode-regexp", rule, { output: "new globalThis.RegExp('foo', \"u\")" } ] - }], - languageOptions: { ecmaVersion: 2020 } + }] } ] }); diff --git a/tests/lib/rules/rest-spread-spacing.js b/tests/lib/rules/rest-spread-spacing.js index e36256c5483..6962813dcf8 100644 --- a/tests/lib/rules/rest-spread-spacing.js +++ b/tests/lib/rules/rest-spread-spacing.js @@ -503,6 +503,7 @@ ruleTester.run("rest-spread-spacing", rule, { { code: "let n = { x, y, ... z };", output: "let n = { x, y, ...z };", + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -511,12 +512,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ...\tz };", output: "let n = { x, y, ...z };", + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -525,12 +526,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ...\nz };", output: "let n = { x, y, ...z };", + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -539,13 +540,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ... z };", output: "let n = { x, y, ...z };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -554,13 +555,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ...\tz };", output: "let n = { x, y, ...z };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -569,13 +570,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ...\nz };", output: "let n = { x, y, ...z };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -584,13 +585,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ...z };", output: "let n = { x, y, ... z };", options: ["always"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -599,13 +600,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ... (z) };", output: "let n = { x, y, ...(z) };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -614,13 +615,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ... ( z ) };", output: "let n = { x, y, ...( z ) };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -629,13 +630,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ...(z) };", output: "let n = { x, y, ... (z) };", options: ["always"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -644,13 +645,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let n = { x, y, ...( z ) };", output: "let n = { x, y, ... ( z ) };", options: ["always"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -659,12 +660,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "spread property" }, type: "SpreadElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -673,12 +674,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -687,12 +688,12 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -701,13 +702,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -716,13 +717,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -731,13 +732,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -746,13 +747,13 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "unexpectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] }, { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", output: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 13, @@ -761,8 +762,7 @@ ruleTester.run("rest-spread-spacing", rule, { messageId: "expectedWhitespace", data: { type: "rest property" }, type: "RestElement" - }], - languageOptions: { ecmaVersion: 2018 } + }] } ] }); diff --git a/tests/lib/rules/semi-spacing.js b/tests/lib/rules/semi-spacing.js index f3377073511..972bc78e928 100644 --- a/tests/lib/rules/semi-spacing.js +++ b/tests/lib/rules/semi-spacing.js @@ -280,51 +280,52 @@ ruleTester.run("semi-spacing", rule, { code: "import Foo from 'bar' ;", output: "import Foo from 'bar';", options: [{ before: false, after: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 22 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "import * as foo from 'bar' ;", output: "import * as foo from 'bar';", options: [{ before: false, after: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 27 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "var foo = 0; export {foo} ;", output: "var foo = 0; export {foo};", options: [{ before: false, after: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportNamedDeclaration", line: 1, column: 26 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export * from 'foo' ;", output: "export * from 'foo';", options: [{ before: false, after: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportAllDeclaration", line: 1, column: 20 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "export default foo ;", output: "export default foo;", options: [{ before: false, after: true }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportDefaultDeclaration", line: 1, column: 19 } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "while(foo) {continue ;}", output: "while(foo) {continue;}", options: [{ before: false, after: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -334,13 +335,13 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 24 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "if(foo) {throw new Error() ; }", output: "if(foo) {throw new Error(); }", options: [{ before: false, after: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -350,13 +351,13 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 30 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "for(a ; ; );", output: "for(a;; );", options: [{ before: false, after: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ type: "ForStatement", messageId: "unexpectedWhitespaceBefore", @@ -372,13 +373,13 @@ ruleTester.run("semi-spacing", rule, { column: 8, endLine: 1, endColumn: 9 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "for(a ; \n ; );", output: "for(a; \n ; );", options: [{ before: false, after: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ type: "ForStatement", messageId: "unexpectedWhitespaceBefore", @@ -387,8 +388,7 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 7 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "do {} while (true) ;", @@ -440,6 +440,7 @@ ruleTester.run("semi-spacing", rule, { { code: "class C { foo ;bar;}", output: "class C { foo; bar;}", + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -457,13 +458,13 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { foo; bar ; }", output: "class C { foo ;bar ; }", options: [{ before: true, after: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingWhitespaceBefore", @@ -481,12 +482,12 @@ ruleTester.run("semi-spacing", rule, { endLine: 1, endColumn: 16 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "class C { foo;static {}}", output: "class C { foo; static {}}", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingWhitespaceAfter", type: "PropertyDefinition", @@ -494,8 +495,7 @@ ruleTester.run("semi-spacing", rule, { column: 14, endLine: 1, endColumn: 15 - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/semi-style.js b/tests/lib/rules/semi-style.js index a035d2ec550..428487c88e9 100644 --- a/tests/lib/rules/semi-style.js +++ b/tests/lib/rules/semi-style.js @@ -591,25 +591,25 @@ ruleTester.run("semi-style", rule, { code: "class C { foo\n;bar }", output: "class C { foo;\nbar }", options: ["last"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { foo;\nbar }", output: "class C { foo\n;bar }", options: ["first"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the beginning of the next line" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, // Class static blocks @@ -617,49 +617,49 @@ ruleTester.run("semi-style", rule, { code: "class C { static { foo\n; } }", output: "class C { static { foo;\n} }", options: ["last"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo\n ;bar } }", output: "class C { static { foo;\nbar } }", options: ["last"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo;\nbar\n ; } }", output: "class C { static { foo;\nbar;\n} }", options: ["last"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the end of the previous line" } - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo;\nbar } }", output: "class C { static { foo\n;bar } }", options: ["first"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { pos: "the beginning of the next line" } - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/semi.js b/tests/lib/rules/semi.js index 73527812621..3d8e88371a4 100644 --- a/tests/lib/rules/semi.js +++ b/tests/lib/rules/semi.js @@ -582,6 +582,7 @@ ruleTester.run("semi", rule, { { code: "import * as utils from './utils'", output: "import * as utils from './utils';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -589,12 +590,12 @@ ruleTester.run("semi", rule, { column: 33, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { square, diag } from 'lib'", output: "import { square, diag } from 'lib';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -602,12 +603,12 @@ ruleTester.run("semi", rule, { column: 35, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import { default as foo } from 'lib'", output: "import { default as foo } from 'lib';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -615,12 +616,12 @@ ruleTester.run("semi", rule, { column: 37, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import 'src/mylib'", output: "import 'src/mylib';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -628,12 +629,12 @@ ruleTester.run("semi", rule, { column: 19, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "import theDefault, { named1, named2 } from 'src/mylib'", output: "import theDefault, { named1, named2 } from 'src/mylib';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -641,8 +642,7 @@ ruleTester.run("semi", rule, { column: 55, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "function foo() { return [] }", @@ -683,6 +683,7 @@ ruleTester.run("semi", rule, { { code: "let x = 5", output: "let x = 5;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -690,8 +691,7 @@ ruleTester.run("semi", rule, { column: 10, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var x = 5", @@ -975,6 +975,7 @@ ruleTester.run("semi", rule, { code: "let x = 5;", output: "let x = 5", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -982,8 +983,7 @@ ruleTester.run("semi", rule, { column: 10, endLine: 1, endColumn: 11 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var x = 5;", @@ -1106,6 +1106,7 @@ ruleTester.run("semi", rule, { code: "import theDefault, { named1, named2 } from 'src/mylib';", output: "import theDefault, { named1, named2 } from 'src/mylib'", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ImportDeclaration", @@ -1113,8 +1114,7 @@ ruleTester.run("semi", rule, { column: 55, endLine: 1, endColumn: 56 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "do{}while(true);", @@ -1132,6 +1132,7 @@ ruleTester.run("semi", rule, { { code: "class C { static { foo() } }", output: "class C { static { foo(); } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1139,13 +1140,13 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo() } }", output: "class C { static { foo(); } }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1153,12 +1154,12 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo(); bar() } }", output: "class C { static { foo(); bar(); } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1166,12 +1167,12 @@ ruleTester.run("semi", rule, { column: 32, endLine: 1, endColumn: 33 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo()\nbar(); } }", output: "class C { static { foo();\nbar(); } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1179,12 +1180,12 @@ ruleTester.run("semi", rule, { column: 25, endLine: 2, endColumn: 1 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo(); bar()\nbaz(); } }", output: "class C { static { foo(); bar();\nbaz(); } }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1192,13 +1193,13 @@ ruleTester.run("semi", rule, { column: 32, endLine: 2, endColumn: 1 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo(); } }", output: "class C { static { foo() } }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1206,13 +1207,13 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo();\nbar() } }", output: "class C { static { foo()\nbar() } }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1220,13 +1221,13 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo()\nbar(); } }", output: "class C { static { foo()\nbar() } }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1234,13 +1235,13 @@ ruleTester.run("semi", rule, { column: 6, endLine: 2, endColumn: 7 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { foo()\nbar();\nbaz() } }", output: "class C { static { foo()\nbar()\nbaz() } }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1248,13 +1249,13 @@ ruleTester.run("semi", rule, { column: 6, endLine: 2, endColumn: 7 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { do ; while (foo)\n (a)} }", output: "class C { static { do ; while (foo);\n (a)} }", options: ["never", { beforeStatementContinuationChars: "always" }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "DoWhileStatement", @@ -1262,13 +1263,13 @@ ruleTester.run("semi", rule, { column: 36, endLine: 2, endColumn: 1 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static { do ; while (foo)\n ;(a)} }", output: "class C { static { do ; while (foo)\n (a)} }", options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "DoWhileStatement", @@ -1276,8 +1277,7 @@ ruleTester.run("semi", rule, { column: 2, endLine: 2, endColumn: 3 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, // omitLastInOneLineBlock: true @@ -1381,105 +1381,105 @@ ruleTester.run("semi", rule, { code: "class C {\nfoo() { bar(); baz(); }\n}", output: "class C {\nfoo() { bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", line: 2, column: 21, endLine: 2, endColumn: 22 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C {\nfoo() \n{ bar(); baz(); }\n}", output: "class C {\nfoo() \n{ bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", line: 3, column: 15, endLine: 3, endColumn: 16 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C {\nfoo() {\n bar(); baz() }\n}", output: "class C {\nfoo() {\n bar(); baz(); }\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", line: 3, column: 14, endLine: 3, endColumn: 15 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C {\nfoo() { bar(); baz() \n}\n}", output: "class C {\nfoo() { bar(); baz(); \n}\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", line: 2, column: 21, endLine: 2, endColumn: 22 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "class C {\nstatic { bar(); baz(); }\n}", output: "class C {\nstatic { bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 2, column: 22, endLine: 2, endColumn: 23 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C {\nstatic \n{ bar(); baz(); }\n}", output: "class C {\nstatic \n{ bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 3, column: 15, endLine: 3, endColumn: 16 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C {\nstatic {\n bar(); baz() }\n}", output: "class C {\nstatic {\n bar(); baz(); }\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 3, column: 14, endLine: 3, endColumn: 15 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C {\nfoo() { bar(); baz() \n}\n}", output: "class C {\nfoo() { bar(); baz(); \n}\n}", options: ["always", { omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 2, column: 21, endLine: 2, endColumn: 22 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, @@ -1487,6 +1487,7 @@ ruleTester.run("semi", rule, { { code: "export * from 'foo'", output: "export * from 'foo';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportAllDeclaration", @@ -1494,12 +1495,12 @@ ruleTester.run("semi", rule, { column: 20, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo } from 'foo'", output: "export { foo } from 'foo';", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportNamedDeclaration", @@ -1507,12 +1508,12 @@ ruleTester.run("semi", rule, { column: 26, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var foo = 0;export { foo }", output: "var foo = 0;export { foo };", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportNamedDeclaration", @@ -1520,12 +1521,12 @@ ruleTester.run("semi", rule, { column: 27, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export var foo", output: "export var foo;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1533,12 +1534,12 @@ ruleTester.run("semi", rule, { column: 15, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export let foo", output: "export let foo;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1546,12 +1547,12 @@ ruleTester.run("semi", rule, { column: 15, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export const FOO = 42", output: "export const FOO = 42;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1559,12 +1560,12 @@ ruleTester.run("semi", rule, { column: 22, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default foo || bar", output: "export default foo || bar;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1572,12 +1573,12 @@ ruleTester.run("semi", rule, { column: 26, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default (foo) => foo.bar()", output: "export default (foo) => foo.bar();", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1585,12 +1586,12 @@ ruleTester.run("semi", rule, { column: 34, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default foo = 42", output: "export default foo = 42;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1598,12 +1599,12 @@ ruleTester.run("semi", rule, { column: 24, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default foo += 42", output: "export default foo += 42;", + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1611,8 +1612,7 @@ ruleTester.run("semi", rule, { column: 25, endLine: void 0, endColumn: void 0 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, // exports, "never" @@ -1620,6 +1620,7 @@ ruleTester.run("semi", rule, { code: "export * from 'foo';", output: "export * from 'foo'", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportAllDeclaration", @@ -1627,13 +1628,13 @@ ruleTester.run("semi", rule, { column: 20, endLine: 1, endColumn: 21 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export { foo } from 'foo';", output: "export { foo } from 'foo'", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportNamedDeclaration", @@ -1641,13 +1642,13 @@ ruleTester.run("semi", rule, { column: 26, endLine: 1, endColumn: 27 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "var foo = 0;export { foo };", output: "var foo = 0;export { foo }", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportNamedDeclaration", @@ -1655,13 +1656,13 @@ ruleTester.run("semi", rule, { column: 27, endLine: 1, endColumn: 28 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export var foo;", output: "export var foo", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1669,13 +1670,13 @@ ruleTester.run("semi", rule, { column: 15, endLine: 1, endColumn: 16 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export let foo;", output: "export let foo", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1683,13 +1684,13 @@ ruleTester.run("semi", rule, { column: 15, endLine: 1, endColumn: 16 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export const FOO = 42;", output: "export const FOO = 42", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1697,13 +1698,13 @@ ruleTester.run("semi", rule, { column: 22, endLine: 1, endColumn: 23 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default foo || bar;", output: "export default foo || bar", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1711,13 +1712,13 @@ ruleTester.run("semi", rule, { column: 26, endLine: 1, endColumn: 27 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default (foo) => foo.bar();", output: "export default (foo) => foo.bar()", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1725,13 +1726,13 @@ ruleTester.run("semi", rule, { column: 34, endLine: 1, endColumn: 35 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default foo = 42;", output: "export default foo = 42", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1739,13 +1740,13 @@ ruleTester.run("semi", rule, { column: 24, endLine: 1, endColumn: 25 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "export default foo += 42;", output: "export default foo += 42", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1753,8 +1754,7 @@ ruleTester.run("semi", rule, { column: 25, endLine: 1, endColumn: 26 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "a;\n++b", @@ -1811,14 +1811,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", line: 2, column: 34, endLine: 3, endColumn: 1 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: ` @@ -1830,14 +1830,14 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "always" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", line: 2, column: 38, endLine: 3, endColumn: 1 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: ` @@ -1853,14 +1853,14 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "always" }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "missingSemi", line: 3, column: 27, endLine: 4, endColumn: 1 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: ` @@ -1934,14 +1934,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "missingSemi", line: 2, column: 35, endLine: 3, endColumn: 1 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: ` @@ -1953,14 +1953,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 2, column: 34, endLine: 2, endColumn: 35 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: ` @@ -1972,14 +1972,14 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 2, column: 38, endLine: 2, endColumn: 39 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: ` @@ -1995,14 +1995,14 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 3, column: 27, endLine: 3, endColumn: 28 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: ` @@ -2076,14 +2076,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 2, column: 35, endLine: 2, endColumn: 36 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, { code: ` @@ -2095,14 +2095,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 3, column: 17, endLine: 3, endColumn: 18 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: ` @@ -2114,14 +2114,14 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 3, column: 17, endLine: 3, endColumn: 18 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: ` @@ -2217,67 +2217,67 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 3, column: 17, endLine: 3, endColumn: 18 - }], - languageOptions: { ecmaVersion: 2015 } + }] }, // Class fields { code: "class C { foo }", output: "class C { foo; }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, column: 14, endLine: 1, endColumn: 15 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { foo }", output: "class C { foo; }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, column: 14, endLine: 1, endColumn: 15 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { foo; }", output: "class C { foo }", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 14, endLine: 1, endColumn: 15 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { foo\n[bar]; }", output: "class C { foo;\n[bar]; }", options: ["always"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, column: 14, endLine: 2, endColumn: 1 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, // class fields @@ -2285,105 +2285,105 @@ ruleTester.run("semi", rule, { code: "class C { [get];\nfoo\n}", output: "class C { [get]\nfoo\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 16, endLine: 1, endColumn: 17 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [set];\nfoo\n}", output: "class C { [set]\nfoo\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 16, endLine: 1, endColumn: 17 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { #get;\nfoo\n}", output: "class C { #get\nfoo\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 15, endLine: 1, endColumn: 16 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { #set;\nfoo\n}", output: "class C { #set\nfoo\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 15, endLine: 1, endColumn: 16 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { #static;\nfoo\n}", output: "class C { #static\nfoo\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 18, endLine: 1, endColumn: 19 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { get=1;\nfoo\n}", output: "class C { get=1\nfoo\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 16, endLine: 1, endColumn: 17 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static static;\nfoo\n}", output: "class C { static static\nfoo\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 24, endLine: 1, endColumn: 25 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { static;\n}", output: "class C { static\n}", options: ["never"], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, column: 17, endLine: 1, endColumn: 18 - }], - languageOptions: { ecmaVersion: 2022 } + }] }, // omitLastInOneLineClassBody @@ -2407,6 +2407,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1;} `, options: ["always", { omitLastInOneLineClassBody: false }], + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2415,8 +2416,7 @@ ruleTester.run("semi", rule, { endLine: 8, endColumn: 64 } - ], - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + ] }, { code: ` @@ -2438,6 +2438,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1;} `, options: ["always", { omitLastInOneLineClassBody: false, omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2446,8 +2447,7 @@ ruleTester.run("semi", rule, { endLine: 8, endColumn: 64 } - ], - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + ] }, { code: ` @@ -2469,6 +2469,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1} `, options: ["always", { omitLastInOneLineClassBody: true, omitLastInOneLineBlock: false }], + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "extraSemi", @@ -2477,8 +2478,7 @@ ruleTester.run("semi", rule, { endLine: 8, endColumn: 64 } - ], - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + ] }, { code: ` @@ -2502,6 +2502,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1; anotherType=2;} `, options: ["always", { omitLastInOneLineClassBody: false, omitLastInOneLineBlock: true }], + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2510,8 +2511,7 @@ ruleTester.run("semi", rule, { endLine: 9, endColumn: 79 } - ], - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + ] } ] }); diff --git a/tests/lib/rules/sort-keys.js b/tests/lib/rules/sort-keys.js index a8eda97ec04..4577ac9840f 100644 --- a/tests/lib/rules/sort-keys.js +++ b/tests/lib/rules/sort-keys.js @@ -380,6 +380,7 @@ ruleTester.run("sort-keys", rule, { }, { code: "var obj = {a:1, [``]:2} // default", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -391,8 +392,7 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var obj = {a:1, _:2, b:3} // default", @@ -501,6 +501,7 @@ ruleTester.run("sort-keys", rule, { }, { code: "var obj = { null: 1, [/(?0)/]: 2 }", + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -512,14 +513,14 @@ ruleTester.run("sort-keys", rule, { prevName: "null" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // not ignore properties not separated by spread properties { code: "var obj = {...z, c:1, b:1}", options: [], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -531,12 +532,12 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {...z, ...c, d:4, b:1, ...y, ...f, e:2, a:1}", options: [], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -558,12 +559,12 @@ ruleTester.run("sort-keys", rule, { prevName: "e" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {c:1, b:1, ...a}", options: [], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -575,12 +576,12 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {...z, ...a, c:1, b:1}", options: [], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -592,12 +593,12 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {...z, b:1, a:1, ...d, ...c}", options: [], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -609,12 +610,12 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {...z, a:2, b:0, ...x, ...c}", options: ["desc"], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -626,12 +627,12 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {...z, a:2, b:0, ...x}", options: ["desc"], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -643,12 +644,12 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "var obj = {...z, '':1, a:2}", options: ["desc"], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -660,13 +661,13 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, // ignore non-simple computed properties, but their position shouldn't affect other comparisons. { code: "var obj = {a:1, [b+c]:2, '':3}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -678,12 +679,12 @@ ruleTester.run("sort-keys", rule, { prevName: "a" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var obj = {'':1, [b+c]:2, a:3}", options: ["desc"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -695,12 +696,12 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var obj = {b:1, [f()]:2, '':3, a:4}", options: ["desc"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -712,13 +713,13 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // not ignore simple computed properties. { code: "var obj = {a:1, b:3, [a]: -1, c:2}", + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -730,8 +731,7 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // nested @@ -1277,6 +1277,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {[``]:1, a:'2'} // desc", options: ["desc"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -1288,8 +1289,7 @@ ruleTester.run("sort-keys", rule, { prevName: "" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var obj = {a:1, _:2, b:3} // desc", @@ -1990,6 +1990,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: false }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2001,8 +2002,7 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, // When allowLineSeparatedGroups option is true @@ -2017,6 +2017,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2028,8 +2029,7 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2044,6 +2044,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2055,8 +2056,7 @@ ruleTester.run("sort-keys", rule, { prevName: "z" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2069,6 +2069,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2080,8 +2081,7 @@ ruleTester.run("sort-keys", rule, { prevName: "c" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2092,6 +2092,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2103,8 +2104,7 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2119,6 +2119,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2130,8 +2131,7 @@ ruleTester.run("sort-keys", rule, { prevName: "d" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2153,6 +2153,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2174,8 +2175,7 @@ ruleTester.run("sort-keys", rule, { prevName: "f" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2207,6 +2207,7 @@ ruleTester.run("sort-keys", rule, { }; `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2218,8 +2219,7 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: ` @@ -2233,6 +2233,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -2244,8 +2245,7 @@ ruleTester.run("sort-keys", rule, { prevName: "b" } } - ], - languageOptions: { ecmaVersion: 2018 } + ] } ] }); diff --git a/tests/lib/rules/sort-vars.js b/tests/lib/rules/sort-vars.js index 19c9315e3de..782ef1c40a5 100644 --- a/tests/lib/rules/sort-vars.js +++ b/tests/lib/rules/sort-vars.js @@ -189,22 +189,22 @@ ruleTester.run("sort-vars", rule, { code: "var d, a, [b, c] = {};", output: "var a, d, [b, c] = {};", options: ignoreCaseArgs, - errors: [expectedError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedError] }, { code: "var d, a, [b, {x: {c, e}}] = {};", output: "var a, d, [b, {x: {c, e}}] = {};", options: ignoreCaseArgs, - errors: [expectedError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedError] }, { code: "var {} = 1, b, a", output: "var {} = 1, a, b", options: ignoreCaseArgs, - errors: [expectedError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedError] }, { code: "var b=10, a=f();", @@ -219,14 +219,14 @@ ruleTester.run("sort-vars", rule, { { code: "var b = 0, a = `${b}`;", output: null, - errors: [expectedError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedError] }, { code: "var b = 0, a = `${f()}`", output: null, - errors: [expectedError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedError] }, { code: "var b = 0, c = b, a;", @@ -246,8 +246,8 @@ ruleTester.run("sort-vars", rule, { { code: "var b = `${f()}`, c, d, a;", output: null, - errors: [expectedError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedError] }, { code: "var c, a = b = 0", diff --git a/tests/lib/rules/space-before-blocks.js b/tests/lib/rules/space-before-blocks.js index 952068e797a..4dd25219303 100644 --- a/tests/lib/rules/space-before-blocks.js +++ b/tests/lib/rules/space-before-blocks.js @@ -430,77 +430,77 @@ ruleTester.run("space-before-blocks", rule, { code: "export function a() { if(b) {} }", output: "export function a() { if(b){} }", options: functionsOnlyArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [expectedNoSpacingError] }, { code: "export function a(){ if(b){} }", output: "export function a(){ if(b) {} }", options: keywordOnlyArgs, - errors: [expectedSpacingError], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [expectedSpacingError] }, { code: "export function a(){}", output: "export function a() {}", options: functionsOnlyArgs, - errors: [expectedSpacingError], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [expectedSpacingError] }, { code: "export default function (a) {}", output: "export default function (a){}", options: keywordOnlyArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [expectedNoSpacingError] }, { code: "export function a() {}", output: "export function a(){}", options: keywordOnlyArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + languageOptions: { ecmaVersion: 6, sourceType: "module" }, + errors: [expectedNoSpacingError] }, { code: "class test{}", output: "class test {}", - errors: [expectedSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedSpacingError] }, { code: "class test{}", output: "class test {}", options: classesOnlyArgs, - errors: [expectedSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedSpacingError] }, { code: "class test{ constructor(){} }", output: "class test{ constructor() {} }", options: functionsOnlyArgs, - errors: [expectedSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedSpacingError] }, { code: "class test { constructor() {} }", output: "class test { constructor(){} }", options: classesOnlyArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedNoSpacingError] }, { code: "class test {}", output: "class test{}", options: functionsOnlyArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedNoSpacingError] }, { code: "class test {}", output: "class test{}", options: neverArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedNoSpacingError] }, { code: "if(a){ function a(){} }", @@ -530,15 +530,15 @@ ruleTester.run("space-before-blocks", rule, { code: "class test{ constructor(){} }", output: "class test { constructor(){} }", options: classesAlwaysOthersOffArgs, - errors: [expectedSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedSpacingError] }, { code: "class test{ constructor() {} }", output: "class test { constructor() {} }", options: classesAlwaysOthersOffArgs, - errors: [expectedSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedSpacingError] }, { code: "if(a){ function a() {} }", @@ -568,34 +568,34 @@ ruleTester.run("space-before-blocks", rule, { code: "class test { constructor(){} }", output: "class test{ constructor(){} }", options: classesNeverOthersOffArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedNoSpacingError] }, { code: "class test { constructor() {} }", output: "class test{ constructor() {} }", options: classesNeverOthersOffArgs, - errors: [expectedNoSpacingError], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [expectedNoSpacingError] }, // https://github.com/eslint/eslint/issues/13553 { code: "class A { foo(bar: string): void{} }", output: "class A { foo(bar: string): void {} }", - errors: [expectedSpacingError], languageOptions: { parser: require(fixtureParser("space-before-blocks", "return-type-keyword-1")) - } + }, + errors: [expectedSpacingError] }, { code: "function foo(): null {}", output: "function foo(): null{}", options: neverArgs, - errors: [expectedNoSpacingError], languageOptions: { parser: require(fixtureParser("space-before-blocks", "return-type-keyword-2")) - } + }, + errors: [expectedNoSpacingError] }, // https://github.com/eslint/eslint/issues/15082 regression tests (only blocks after switch case colons should be excluded) diff --git a/tests/lib/rules/space-before-function-paren.js b/tests/lib/rules/space-before-function-paren.js index 928450dbd51..6eec7d8d2d2 100644 --- a/tests/lib/rules/space-before-function-paren.js +++ b/tests/lib/rules/space-before-function-paren.js @@ -201,6 +201,7 @@ ruleTester.run("space-before-function-paren", rule, { { code: "var obj = { foo() {} };", output: "var obj = { foo () {} };", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -208,12 +209,12 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function* foo() {}", output: "function* foo () {}", + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -221,8 +222,7 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { @@ -383,6 +383,7 @@ ruleTester.run("space-before-function-paren", rule, { code: "var obj = { foo () {} };", output: "var obj = { foo() {} };", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -390,13 +391,13 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "function* foo () {}", output: "function* foo() {}", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -404,8 +405,7 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 14 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { @@ -420,6 +420,7 @@ ruleTester.run("space-before-function-paren", rule, { "var obj = { get foo() {}, set foo(val) {}, bar() {} };" ].join("\n"), options: [{ named: "never", anonymous: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -451,13 +452,13 @@ ruleTester.run("space-before-function-paren", rule, { line: 3, column: 49 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "class Foo { constructor () {} *method () {} }", output: "class Foo { constructor() {} *method() {} }", options: [{ named: "never", anonymous: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -471,13 +472,13 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 38 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = { bar () {} }", output: "var foo = { bar() {} }", options: [{ named: "never", anonymous: "always" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -485,8 +486,7 @@ ruleTester.run("space-before-function-paren", rule, { line: 1, column: 16 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: [ @@ -500,6 +500,7 @@ ruleTester.run("space-before-function-paren", rule, { "var obj = { get foo () {}, set foo (val) {}, bar () {} };" ].join("\n"), options: [{ named: "always", anonymous: "never" }], + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -531,8 +532,7 @@ ruleTester.run("space-before-function-paren", rule, { line: 3, column: 47 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = function() {}", @@ -592,35 +592,35 @@ ruleTester.run("space-before-function-paren", rule, { code: "async() => 1", output: "async () => 1", options: [{ asyncArrow: "always" }], - errors: ["Missing space before function parentheses."], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: ["Missing space before function parentheses."] }, { code: "async () => 1", output: "async() => 1", options: [{ asyncArrow: "never" }], - errors: ["Unexpected space before function parentheses."], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: ["Unexpected space before function parentheses."] }, { code: "async() => 1", output: "async () => 1", - errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] }, { code: "async() => 1", output: "async () => 1", options: ["always"], - errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] }, { code: "async () => 1", output: "async() => 1", options: ["never"], - errors: [{ messageId: "unexpectedSpace", type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 8 } + languageOptions: { ecmaVersion: 8 }, + errors: [{ messageId: "unexpectedSpace", type: "ArrowFunctionExpression" }] } ] }); diff --git a/tests/lib/rules/space-in-parens.js b/tests/lib/rules/space-in-parens.js index 5a65e77dc69..6e0e2041c46 100644 --- a/tests/lib/rules/space-in-parens.js +++ b/tests/lib/rules/space-in-parens.js @@ -552,18 +552,18 @@ ruleTester.run("space-in-parens", rule, { code: "var foo = `(bar ${( 1 + 2 )})`;", output: "var foo = `(bar ${(1 + 2)})`;", options: ["never"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "rejectedOpeningSpace", line: 1, column: 20 }, { messageId: "rejectedClosingSpace", line: 1, column: 26 } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = `(bar ${(1 + 2 )})`;", output: "var foo = `(bar ${( 1 + 2 )})`;", options: ["always"], - errors: [{ messageId: "missingOpeningSpace", line: 1, column: 19 }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "missingOpeningSpace", line: 1, column: 19 }] } ] }); diff --git a/tests/lib/rules/space-infix-ops.js b/tests/lib/rules/space-infix-ops.js index da84199b12d..8212c7c6352 100644 --- a/tests/lib/rules/space-infix-ops.js +++ b/tests/lib/rules/space-infix-ops.js @@ -403,18 +403,19 @@ ruleTester.run("space-infix-ops", rule, { { code: "const my_object={key: 'value'}", output: "const my_object = {key: 'value'}", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 16 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "var {a=0}=bar;", output: "var {a = 0} = bar;", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -427,32 +428,31 @@ ruleTester.run("space-infix-ops", rule, { line: 1, column: 10, type: "VariableDeclarator" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function foo(a=0) { }", output: "function foo(a = 0) { }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, line: 1, column: 15, type: "AssignmentPattern" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "a**b", output: "a ** b", + languageOptions: { ecmaVersion: 7 }, errors: [{ messageId: "missingSpace", data: { operator: "**" }, line: 1, column: 2, type: "BinaryExpression" - }], - languageOptions: { ecmaVersion: 7 } + }] }, { code: "'foo'in{}", @@ -481,37 +481,38 @@ ruleTester.run("space-infix-ops", rule, { { code: "var a: Foo= b;", output: "var a: Foo = b;", + languageOptions: { + parser: require(parser("type-annotations/variable-declaration-init-type-annotation-no-space")) + }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 11 - }], - languageOptions: { - parser: require(parser("type-annotations/variable-declaration-init-type-annotation-no-space")) - } + }] }, { code: "function foo(a: number=0): Foo { }", output: "function foo(a: number = 0): Foo { }", + languageOptions: { + ecmaVersion: 6, + parser: require(parser("type-annotations/function-declaration-type-annotation-no-space")) + }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, line: 1, column: 23, type: "AssignmentPattern" - }], - languageOptions: { - ecmaVersion: 6, - parser: require(parser("type-annotations/function-declaration-type-annotation-no-space")) - } + }] }, // Logical Assignments { code: "a&&=b", output: "a &&= b", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "&&=" }, @@ -520,12 +521,12 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 5, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "a ||=b", output: "a ||= b", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "||=" }, @@ -534,12 +535,12 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 6, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, { code: "a??= b", output: "a ??= b", + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "??=" }, @@ -548,14 +549,14 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 5, type: "AssignmentExpression" - }], - languageOptions: { ecmaVersion: 2021 } + }] }, // Class Fields { code: "class C { a=b; }", output: "class C { a = b; }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -564,12 +565,12 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 13, type: "PropertyDefinition" - }], - languageOptions: { ecmaVersion: 2022 } + }] }, { code: "class C { [a ]= b; }", output: "class C { [a ] = b; }", + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -578,8 +579,7 @@ ruleTester.run("space-infix-ops", rule, { endLine: 1, endColumn: 16, type: "PropertyDefinition" - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/space-unary-ops.js b/tests/lib/rules/space-unary-ops.js index 5b256bb05ad..76c851059f1 100644 --- a/tests/lib/rules/space-unary-ops.js +++ b/tests/lib/rules/space-unary-ops.js @@ -628,39 +628,39 @@ ruleTester.run("space-unary-ops", rule, { { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function *foo() { yield (0) }", output: "function *foo() { yield(0) }", options: [{ words: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function *foo() { yield+0 }", output: "function *foo() { yield +0 }", + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "foo++", @@ -738,91 +738,91 @@ ruleTester.run("space-unary-ops", rule, { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", options: [{ words: true, overrides: { yield: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", options: [{ words: false, overrides: { yield: true } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 19 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "async function foo() { await{foo: 'bar'} }", output: "async function foo() { await {foo: 'bar'} }", + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "wordOperator", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "async function foo() { await{baz: 'qux'} }", output: "async function foo() { await {baz: 'qux'} }", options: [{ words: false, overrides: { await: true } }], + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "wordOperator", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "async function foo() { await {foo: 1} }", output: "async function foo() { await{foo: 1} }", options: [{ words: false }], + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "async function foo() { await {bar: 2} }", output: "async function foo() { await{bar: 2} }", options: [{ words: true, overrides: { await: false } }], + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "await" }, type: "AwaitExpression", line: 1, column: 24 - }], - languageOptions: { ecmaVersion: 8 } + }] }, { code: "class C { #x; *foo(bar) { yield #x in bar; } }", output: "class C { #x; *foo(bar) { yield#x in bar; } }", options: [{ words: false }], + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "yield" }, type: "YieldExpression", line: 1, column: 27 - }], - languageOptions: { ecmaVersion: 2022 } + }] } ] }); diff --git a/tests/lib/rules/strict.js b/tests/lib/rules/strict.js index 469e7931a99..5fa646c6413 100644 --- a/tests/lib/rules/strict.js +++ b/tests/lib/rules/strict.js @@ -165,28 +165,28 @@ ruleTester.run("strict", rule, { code: "\"use strict\"; foo();", output: " foo();", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["never"], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["never"], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, // "global" mode @@ -217,11 +217,11 @@ ruleTester.run("strict", rule, { code: "var foo = () => { 'use strict'; return () => 1; }", output: null, options: ["global"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: null, @@ -247,28 +247,28 @@ ruleTester.run("strict", rule, { code: "'use strict'; foo();", output: " foo();", options: ["global"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["global"], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["global"], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, // "function" mode @@ -304,18 +304,18 @@ ruleTester.run("strict", rule, { code: "(() => { return true; })();", output: null, options: ["function"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "function", type: "ArrowFunctionExpression" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "(() => true)();", output: null, options: ["function"], + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "function", type: "ArrowFunctionExpression" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "var foo = function() { foo(); 'use strict'; return; }; function bar() { foo(); 'use strict'; }", output: null, @@ -342,28 +342,28 @@ ruleTester.run("strict", rule, { code: "var foo = function() { 'use strict'; return; }", output: "var foo = function() { return; }", options: ["function"], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["function"], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["function"], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, { code: "function foo() { return function() { 'use strict'; return; }; }", output: null, @@ -413,8 +413,8 @@ ruleTester.run("strict", rule, { code: "var foo = () => { return; };", output: null, options: ["function"], - errors: [{ messageId: "function", type: "ArrowFunctionExpression" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "function", type: "ArrowFunctionExpression" }] }, // Classes @@ -422,36 +422,36 @@ ruleTester.run("strict", rule, { code: "class A { constructor() { \"use strict\"; } }", output: "class A { constructor() { } }", options: ["function"], - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, { code: "class A { foo() { \"use strict\"; } }", output: "class A { foo() { } }", options: ["function"], - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, { code: "class A { foo() { function bar() { \"use strict\"; } } }", output: "class A { foo() { function bar() { } } }", options: ["function"], - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, { code: "class A { field = () => { \"use strict\"; } }", output: "class A { field = () => { } }", options: ["function"], - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, { code: "class A { field = function() { \"use strict\"; } }", output: "class A { field = function() { } }", options: ["function"], - errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, // "safe" mode corresponds to "global" if ecmaFeatures.globalReturn is true, otherwise "function" @@ -468,31 +468,31 @@ ruleTester.run("strict", rule, { code: "function foo() { 'use strict'; return; }", output: null, options: ["safe"], + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["safe"], + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["safe"], + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, // Default to "safe" mode @@ -512,29 +512,29 @@ ruleTester.run("strict", rule, { { code: "function foo() { 'use strict'; return; }", output: null, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } - ], - languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } - ], - languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } } + ] }, // Reports deprecated syntax: https://github.com/eslint/eslint/issues/6405 @@ -542,84 +542,84 @@ ruleTester.run("strict", rule, { code: "function foo(a = 0) { 'use strict' }", output: null, options: [], - errors: [{ messageId: "nonSimpleParameterList" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())", output: null, options: [], - errors: [{ messageId: "nonSimpleParameterList" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: [], + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ "Use the global form of 'use strict'.", { messageId: "nonSimpleParameterList" } - ], - languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } } + ] }, { code: "'use strict'; function foo(a = 0) { 'use strict' }", output: null, options: [], - errors: [{ messageId: "nonSimpleParameterList" }], - languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } } + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } }, + errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["never"], - errors: [{ messageId: "nonSimpleParameterList" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["global"], + languageOptions: { ecmaVersion: 6 }, errors: [ "Use the global form of 'use strict'.", { messageId: "nonSimpleParameterList" } - ], - languageOptions: { ecmaVersion: 6 } + ] }, { code: "'use strict'; function foo(a = 0) { 'use strict' }", output: null, options: ["global"], - errors: [{ messageId: "nonSimpleParameterList" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["function"], - errors: [{ messageId: "nonSimpleParameterList" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())", output: null, options: ["function"], - errors: [{ messageId: "nonSimpleParameterList" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { }", output: null, options: ["function"], - errors: [{ messageId: "wrap", data: { name: "function 'foo'" } }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "wrap", data: { name: "function 'foo'" } }] }, { code: "(function() { function foo(a = 0) { } }())", output: null, options: ["function"], - errors: ["Use the function form of 'use strict'."], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: ["Use the function form of 'use strict'."] }, // functions inside class static blocks should be checked @@ -627,74 +627,74 @@ ruleTester.run("strict", rule, { code: "'use strict'; class C { static { function foo() { \n'use strict'; } } }", output: null, options: ["global"], - errors: [{ messageId: "global", line: 2 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "global", line: 2 }] }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: null, options: ["never"], - errors: [{ messageId: "never", line: 2 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "never", line: 2 }] }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: "class C { static { function foo() { \n } } }", options: ["safe"], - errors: [{ messageId: "module", line: 2 }], - languageOptions: { ecmaVersion: 2022, sourceType: "module" } + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, + errors: [{ messageId: "module", line: 2 }] }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: "class C { static { function foo() { \n } } }", options: ["safe"], - errors: [{ messageId: "implied", line: 2 }], - languageOptions: { ecmaVersion: 2022, parserOptions: { ecmaFeatures: { impliedStrict: true } } } + languageOptions: { ecmaVersion: 2022, parserOptions: { ecmaFeatures: { impliedStrict: true } } }, + errors: [{ messageId: "implied", line: 2 }] }, { code: "function foo() {'use strict'; class C { static { function foo() { \n'use strict'; } } } }", output: "function foo() {'use strict'; class C { static { function foo() { \n } } } }", options: ["function"], - errors: [{ messageId: "unnecessary", line: 2 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessary", line: 2 }] }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: "class C { static { function foo() { \n } } }", options: ["function"], - errors: [{ messageId: "unnecessaryInClasses", line: 2 }], - languageOptions: { ecmaVersion: 2022 } + languageOptions: { ecmaVersion: 2022 }, + errors: [{ messageId: "unnecessaryInClasses", line: 2 }] }, { code: "class C { static { function foo() { \n'use strict';\n'use strict'; } } }", output: "class C { static { function foo() { \n\n } } }", options: ["function"], + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unnecessaryInClasses", line: 2 }, { messageId: "multiple", line: 3 } - ], - languageOptions: { ecmaVersion: 2022 } + ] }, { code: "module.exports = function identity (value) { return value; }", output: null, options: ["safe"], - errors: [ - { messageId: "global", line: 1 } - ], languageOptions: { sourceType: "commonjs" - } + }, + errors: [ + { messageId: "global", line: 1 } + ] }, { code: "module.exports = function identity (value) { return value; }", output: null, - errors: [ - { messageId: "global", line: 1 } - ], languageOptions: { sourceType: "commonjs" - } + }, + errors: [ + { messageId: "global", line: 1 } + ] } ] }); diff --git a/tests/lib/rules/use-isnan.js b/tests/lib/rules/use-isnan.js index 5307b34ab07..a23e9e202ec 100644 --- a/tests/lib/rules/use-isnan.js +++ b/tests/lib/rules/use-isnan.js @@ -477,8 +477,8 @@ ruleTester.run("use-isnan", rule, { }, { code: "x === Number?.NaN;", - errors: [comparisonError], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [comparisonError] }, { code: "x === Number['NaN'];", @@ -685,20 +685,20 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf?.(NaN)", options: [{ enforceForIndexOf: true }], - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "foo?.indexOf(NaN)", options: [{ enforceForIndexOf: true }], - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "(foo?.indexOf)(NaN)", options: [{ enforceForIndexOf: true }], - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "foo.indexOf(Number.NaN)", @@ -733,20 +733,20 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf?.(Number.NaN)", options: [{ enforceForIndexOf: true }], - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "foo?.indexOf(Number.NaN)", options: [{ enforceForIndexOf: true }], - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "(foo?.indexOf)(Number.NaN)", options: [{ enforceForIndexOf: true }], - errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] } ] }); diff --git a/tests/lib/rules/valid-jsdoc.js b/tests/lib/rules/valid-jsdoc.js index 324efcd1036..1f2cd367336 100644 --- a/tests/lib/rules/valid-jsdoc.js +++ b/tests/lib/rules/valid-jsdoc.js @@ -1188,6 +1188,7 @@ ruleTester.run("valid-jsdoc", rule, { code: "/** Foo \n@return {void} Foo\n */\nfoo.bar = () => {}", output: "/** Foo \n@returns {void} Foo\n */\nfoo.bar = () => {}", options: [{ prefer: { return: "returns" } }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1196,8 +1197,7 @@ ruleTester.run("valid-jsdoc", rule, { column: 1, endLine: 2, endColumn: 8 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "/** Foo \n@param {void Foo\n */\nfunction foo(){}", @@ -1311,6 +1311,9 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: true, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "unsatisfiedDesc", @@ -1321,10 +1324,7 @@ ruleTester.run("valid-jsdoc", rule, { data: { returns: "returns" }, type: "Block" } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, { code: "/**\n* Foo\n* @returns {string} \n*/\nfunction foo(){}", @@ -1346,16 +1346,17 @@ ruleTester.run("valid-jsdoc", rule, { { code: "/**\n* Foo\n* @returns {string} something \n*/\nvar foo = \nfunction foo(a = 1){}", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingParam", data: { name: "a" }, type: "Block" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "/**\n* Foo\n* @param {string} a Description \n* @param {string} b Description \n* @returns {string} something \n*/\nvar foo = \nfunction foo(b, a = 1){}", output: null, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expected", data: { name: "b", jsdocName: "a" }, @@ -1373,8 +1374,7 @@ ruleTester.run("valid-jsdoc", rule, { column: 3, endLine: 4, endColumn: 32 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "/**\n* Foo\n* @param {string} p desc\n* @param {string} p desc \n*/\nfunction foo(){}", @@ -1470,6 +1470,7 @@ ruleTester.run("valid-jsdoc", rule, { code: "/**\n * Does something. \n* @param {string} a - this is a \n* @return {Array} The result of doing it \n*/\n export function doSomething(a) { }", output: "/**\n * Does something. \n* @param {string} a - this is a \n* @returns {Array} The result of doing it \n*/\n export function doSomething(a) { }", options: [{ prefer: { return: "returns" } }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1478,13 +1479,13 @@ ruleTester.run("valid-jsdoc", rule, { column: 3, endLine: 4, endColumn: 10 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "/**\n * Does something. \n* @param {string} a - this is a \n* @return {Array} The result of doing it \n*/\n export default function doSomething(a) { }", output: "/**\n * Does something. \n* @param {string} a - this is a \n* @returns {Array} The result of doing it \n*/\n export default function doSomething(a) { }", options: [{ prefer: { return: "returns" } }], + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1493,35 +1494,35 @@ ruleTester.run("valid-jsdoc", rule, { column: 3, endLine: 4, endColumn: 10 - }], - languageOptions: { ecmaVersion: 6, sourceType: "module" } + }] }, { code: "/** foo */ var foo = () => bar();", output: null, options: [{ requireReturn: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, type: "Block" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "/** foo */ var foo = () => { return bar(); };", output: null, options: [{ requireReturn: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, type: "Block" - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "/** @returns {object} foo */ var foo = () => { bar(); };", output: null, options: [{ requireReturn: false }], + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedTag", data: { title: "returns" }, @@ -1530,8 +1531,7 @@ ruleTester.run("valid-jsdoc", rule, { column: 5, endLine: 1, endColumn: 26 - }], - languageOptions: { ecmaVersion: 6 } + }] }, { code: "/**\n* @param fields [Array]\n */\n function foo(){}", @@ -1611,6 +1611,9 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: false, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "unsatisfiedDesc", @@ -1620,10 +1623,7 @@ ruleTester.run("valid-jsdoc", rule, { messageId: "unsatisfiedDesc", type: "Block" } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, { code: @@ -1644,6 +1644,9 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: true, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "unsatisfiedDesc", @@ -1654,10 +1657,7 @@ ruleTester.run("valid-jsdoc", rule, { data: { returns: "returns" }, type: "Block" } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, { code: @@ -1682,6 +1682,9 @@ ruleTester.run("valid-jsdoc", rule, { "}", output: null, options: [], + languageOptions: { + ecmaVersion: 6 + }, errors: [ { messageId: "missingReturn", @@ -1693,10 +1696,7 @@ ruleTester.run("valid-jsdoc", rule, { data: { name: "xs" }, type: "Block" } - ], - languageOptions: { - ecmaVersion: 6 - } + ] }, { code: @@ -1736,14 +1736,14 @@ ruleTester.run("valid-jsdoc", rule, { "async function a() {}", output: null, options: [{ requireReturn: true }], + languageOptions: { + ecmaVersion: 2017 + }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, type: "Block" - }], - languageOptions: { - ecmaVersion: 2017 - } + }] }, // type validations diff --git a/tests/lib/rules/valid-typeof.js b/tests/lib/rules/valid-typeof.js index 7298d3a6262..608ea04bc2e 100644 --- a/tests/lib/rules/valid-typeof.js +++ b/tests/lib/rules/valid-typeof.js @@ -129,8 +129,8 @@ ruleTester.run("valid-typeof", rule, { }, { code: "if (typeof bar === `umdefined`) {}", - errors: [{ messageId: "invalidValue", type: "TemplateLiteral" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "invalidValue", type: "TemplateLiteral" }] }, { code: "typeof foo == 'invalid string'", @@ -208,14 +208,14 @@ ruleTester.run("valid-typeof", rule, { { code: "typeof foo === `undefined${foo}`", options: [{ requireStringLiterals: true }], - errors: [{ messageId: "notString", type: "TemplateLiteral" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "notString", type: "TemplateLiteral" }] }, { code: "typeof foo === `${string}`", options: [{ requireStringLiterals: true }], - errors: [{ messageId: "notString", type: "TemplateLiteral" }], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [{ messageId: "notString", type: "TemplateLiteral" }] } ] }); diff --git a/tests/lib/rules/vars-on-top.js b/tests/lib/rules/vars-on-top.js index 28892c7b0d7..c793b334db8 100644 --- a/tests/lib/rules/vars-on-top.js +++ b/tests/lib/rules/vars-on-top.js @@ -430,8 +430,8 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - errors: [error], - languageOptions: { ecmaVersion: 6 } + languageOptions: { ecmaVersion: 6 }, + errors: [error] }, { code: "'use strict'; 0; var x; f();", @@ -454,11 +454,11 @@ ruleTester.run("vars-on-top", rule, { "export function f() {}", "var x;" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 6, sourceType: "module" - } + }, + errors: [error] }, { code: [ @@ -466,11 +466,11 @@ ruleTester.run("vars-on-top", rule, { "export function f() {}", "var y;" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 6, sourceType: "module" - } + }, + errors: [error] }, { code: [ @@ -478,33 +478,33 @@ ruleTester.run("vars-on-top", rule, { "export {foo};", "var test = 1;" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 6, sourceType: "module" - } + }, + errors: [error] }, { code: [ "export {foo} from 'foo';", "var test = 1;" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 6, sourceType: "module" - } + }, + errors: [error] }, { code: [ "export * from 'foo';", "var test = 1;" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 6, sourceType: "module" - } + }, + errors: [error] }, { code: [ @@ -515,10 +515,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [error] }, { code: [ @@ -529,10 +529,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [error] }, { code: [ @@ -544,10 +544,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - errors: [{ ...error, line: 5 }], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [{ ...error, line: 5 }] }, { code: [ @@ -559,10 +559,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [error] }, { code: [ @@ -573,10 +573,10 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - errors: [error], languageOptions: { ecmaVersion: 2022 - } + }, + errors: [error] } ] }); diff --git a/tests/lib/rules/wrap-iife.js b/tests/lib/rules/wrap-iife.js index 7087ff3403a..18a22762caf 100644 --- a/tests/lib/rules/wrap-iife.js +++ b/tests/lib/rules/wrap-iife.js @@ -483,8 +483,8 @@ ruleTester.run("wrap-iife", rule, { code: "import(function (){}())", output: "import((function (){})())", // wrap function expression, but don't remove mandatory parens options: ["inside"], - errors: [wrapExpressionError], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [wrapExpressionError] }, { @@ -606,8 +606,8 @@ ruleTester.run("wrap-iife", rule, { code: "import(function (){}.call())", output: "import((function (){}).call())", // wrap function expression, but don't remove mandatory parens options: ["inside", { functionPrototypeMethods: true }], - errors: [wrapExpressionError], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [wrapExpressionError] }, // Optional chaining @@ -615,29 +615,29 @@ ruleTester.run("wrap-iife", rule, { code: "window.bar = function() { return 3; }.call?.(this, arg1);", output: "window.bar = (function() { return 3; }).call?.(this, arg1);", options: ["inside", { functionPrototypeMethods: true }], - errors: [wrapInvocationError], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [wrapInvocationError] }, { code: "window.bar = function() { return 3; }?.call(this, arg1);", output: "window.bar = (function() { return 3; })?.call(this, arg1);", options: ["inside", { functionPrototypeMethods: true }], - errors: [wrapInvocationError], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [wrapInvocationError] }, { code: "window.bar = (function() { return 3; }?.call)(this, arg1);", output: "window.bar = ((function() { return 3; })?.call)(this, arg1);", options: ["inside", { functionPrototypeMethods: true }], - errors: [wrapInvocationError], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [wrapInvocationError] }, { code: "new (function () {} ?.());", output: "new ((function () {}) ?.());", options: ["inside"], - errors: [wrapExpressionError], - languageOptions: { ecmaVersion: 2020 } + languageOptions: { ecmaVersion: 2020 }, + errors: [wrapExpressionError] } ] }); diff --git a/tests/lib/rules/yoda.js b/tests/lib/rules/yoda.js index c7be95e9ec7..e7e938e99a1 100644 --- a/tests/lib/rules/yoda.js +++ b/tests/lib/rules/yoda.js @@ -371,14 +371,14 @@ ruleTester.run("yoda", rule, { code: "if (5n != value) {}", output: "if (value != 5n) {}", options: ["never"], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "!=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: "if (null !== value) {}", @@ -408,40 +408,40 @@ ruleTester.run("yoda", rule, { code: "if (`red` <= value) {}", output: "if (value >= `red`) {}", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (`red` <= `${foo}`) {}", output: "if (`${foo}` >= `red`) {}", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: 'if (`red` <= `${"red"}`) {}', output: 'if (`${"red"}` >= `red`) {}', options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (true >= value) {}", @@ -507,14 +507,14 @@ ruleTester.run("yoda", rule, { code: "if (value == `red`) {}", output: "if (`red` == value) {}", options: ["always"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "==" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (value === true) {}", @@ -532,27 +532,27 @@ ruleTester.run("yoda", rule, { code: "if (value === 5n) {}", output: "if (5n === value) {}", options: ["always"], + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "===" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2020 } + ] }, { code: 'if (`${"red"}` <= `red`) {}', output: 'if (`red` >= `${"red"}`) {}', options: ["always"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (a < 0 && 0 <= b && b < 1) {}", @@ -642,27 +642,27 @@ ruleTester.run("yoda", rule, { code: "var a = (b < `0` && `0` <= b);", output: "var a = (`0` > b && `0` <= b);", options: ["always", { exceptRange: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (`green` < x.y && x.y < `blue`) {}", output: "if (x.y > `green` && x.y < `blue`) {}", options: ["never", { exceptRange: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (0 <= a[b] && a['b'] < 1) {}", @@ -680,27 +680,27 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a[b] && a[`b`] < 1) {}", output: "if (a[b] >= 0 && a[`b`] < 1) {}", options: ["never", { exceptRange: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (`0` <= a[b] && a[`b`] < `1`) {}", output: "if (a[b] >= `0` && a[`b`] < `1`) {}", options: ["never", { exceptRange: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (0 <= a[b] && a.b < 1) {}", @@ -754,14 +754,14 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a[``] && a[null] < 1) {}", output: "if (a[``] >= 0 && a[null] < 1) {}", options: ["never", { exceptRange: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (0 <= a[''] && a[b] < 1) {}", @@ -791,14 +791,14 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a[``] && a[b()] < 1) {}", output: "if (a[``] >= 0 && a[b()] < 1) {}", options: ["never", { exceptRange: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (0 <= a[b()] && a[b()] < 1) {}", @@ -816,14 +816,14 @@ ruleTester.run("yoda", rule, { code: "if (0 <= a.null && a[/(?0)/] <= 1) {}", output: "if (a.null >= 0 && a[/(?0)/] <= 1) {}", options: ["never", { exceptRange: true }], + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<=" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2018 } + ] }, { code: "if (3 == a) {}", @@ -865,14 +865,14 @@ ruleTester.run("yoda", rule, { code: "foo(a === `3`);", output: "foo(`3` === a);", options: ["always", { onlyEquality: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "===" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if (0 <= x && x < 1) {}", @@ -1001,79 +1001,79 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield(1) < a }", output: "function *foo() { yield a > (1) }", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield((1)) < a }", output: "function *foo() { yield a > ((1)) }", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield 1 < a }", output: "function *foo() { yield a > 1 }", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield/**/1 < a }", output: "function *foo() { yield/**/a > 1 }", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield(1) < ++a }", output: "function *foo() { yield++a > (1) }", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield(1) < (a) }", output: "function *foo() { yield(a) > (1) }", options: ["never"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "right", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "x=1 < a", @@ -1091,66 +1091,66 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield++a < 1 }", output: "function *foo() { yield 1 > ++a }", options: ["always"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield(a) < 1 }", output: "function *foo() { yield 1 > (a) }", options: ["always"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield a < 1 }", output: "function *foo() { yield 1 > a }", options: ["always"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield/**/a < 1 }", output: "function *foo() { yield/**/1 > a }", options: ["always"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "function *foo() { yield++a < (1) }", output: "function *foo() { yield(1) > ++a }", options: ["always"], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "x=a < 1", @@ -1312,14 +1312,14 @@ ruleTester.run("yoda", rule, { code: "if (`green` < x.y && x.y < `blue`) {}", output: "if (`green` < x.y && `blue` > x.y) {}", options: ["always", { exceptRange: true }], + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", data: { expectedSide: "left", operator: "<" }, type: "BinaryExpression" } - ], - languageOptions: { ecmaVersion: 2015 } + ] }, { code: "if('a' <= x && x < 'b') {}",