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/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..f9154fd1b63 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,37 +668,37 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get ['abc']() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for getter.", type: "Property" }] }, @@ -726,37 +726,37 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { set ['abc'](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Getter is not present for setter.", type: "Property" }] }, @@ -828,7 +828,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get [`a`]() {}, set b(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -837,7 +837,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get [a]() {}, set [b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -846,7 +846,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get [a]() {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -855,7 +855,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get a() {}, set [a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -864,7 +864,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get [a + b]() {}, set [a - b](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -873,7 +873,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get [`${0} `]() {}, set [`${0}`](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -970,7 +970,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get a() {}, get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -979,7 +979,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { set a(foo) {}, set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -990,13 +990,13 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { a, get b() {}, c };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1005,43 +1005,43 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = { get a() {}, a:1 };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ message: "Getter is not present for setter 'a'.", type: "Property", column: 11 }] }, @@ -1061,7 +1061,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "var o = {\n set [\n a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: "Getter is not present for setter.", type: "Property", @@ -1094,42 +1094,42 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "Reflect?.defineProperty(obj, 'foo', {set: function(value) {}});", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "Object?.defineProperties(obj, {foo: {set: function(value) {}}});", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "Object?.create(null, {foo: {set: function(value) {}}});", - parserOptions: { 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});", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "(Reflect?.defineProperty)(obj, 'foo', {set: function(value) {}});", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "(Object?.defineProperties)(obj, {foo: {set: function(value) {}}});", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, { code: "(Object?.create)(null, {foo: {set: function(value) {}}});", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ message: "Getter is not present in property descriptor.", type: "ObjectExpression" }] }, @@ -1140,49 +1140,49 @@ ruleTester.run("accessor-pairs", rule, { // Test default settings { code: "class A { set a(foo) {} }", - parserOptions: { 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: [{}], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 6 }, + 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" } @@ -1191,45 +1191,45 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { set a(value) {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition" }] }, { code: "class A { set '#a'(foo) {} }", - parserOptions: { ecmaVersion: 13 }, + languageOptions: { ecmaVersion: 13 }, errors: [{ message: "Getter is not present for class setter '#a'.", type: "MethodDefinition" }] }, { code: "class A { set #a(foo) {} }", - parserOptions: { 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) {} }", - parserOptions: { 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) {} }", - parserOptions: { ecmaVersion: 13 }, + languageOptions: { ecmaVersion: 13 }, errors: [{ message: "Getter is not present for class static private setter #a.", type: "MethodDefinition" }] }, @@ -1237,55 +1237,55 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { set a(value) {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 13 }, + languageOptions: { ecmaVersion: 13 }, errors: [{ message: "Setter is not present for class static private getter #a.", type: "MethodDefinition" }] }, @@ -1293,67 +1293,67 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get abc() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for class getter 'constructor'.", type: "MethodDefinition" }] }, @@ -1361,7 +1361,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1370,7 +1370,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { set a(foo) {} get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1379,7 +1379,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { static get a() {} static set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1388,7 +1388,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: false, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 11 } ] @@ -1396,7 +1396,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: false, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'b'.", type: "MethodDefinition", column: 22 } ] @@ -1404,7 +1404,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get 'a '() {} set 'a'(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1413,7 +1413,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get 'a'() {} set 1(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1422,7 +1422,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get 1() {} set 2(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1431,7 +1431,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get ''() {} set null(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1440,7 +1440,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} set [a](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1449,7 +1449,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get [a]() {} set [b](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1458,7 +1458,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get [a]() {} set [a++](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1467,7 +1467,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get [a + b]() {} set [a - b](foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1476,7 +1476,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get #a() {} set '#a'(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, + 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 } @@ -1485,7 +1485,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get '#a'() {} set #a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 13 }, + 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 } @@ -1496,7 +1496,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} static set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1505,7 +1505,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { static get a() {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1514,7 +1514,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { set [a](foo) {} static get [a]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1523,7 +1523,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { static set [a](foo) {} get [a]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1534,7 +1534,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1543,7 +1543,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { get a() {} get [b]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1552,7 +1552,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get [a]() {} get [b]() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1561,7 +1561,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { set a(foo) {} set b(bar) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1570,7 +1570,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { static get a() {} static get b() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1579,7 +1579,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { static set a(foo) {} static set b(bar) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1588,7 +1588,7 @@ ruleTester.run("accessor-pairs", rule, { { 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 }, + 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 }, @@ -1601,7 +1601,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} } class B { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1610,7 +1610,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { set a(foo) {} }, class { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1619,7 +1619,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { get a() {} }, { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1628,7 +1628,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = { get a() {} }, class { set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1639,49 +1639,49 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} get b() {} set b(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 6 }, + 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 }, @@ -1694,7 +1694,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1703,7 +1703,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { set a(foo) {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1712,7 +1712,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { static get a() {} static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1721,7 +1721,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { set a(foo) {} set a(foo) {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1732,7 +1732,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { a() {} get b() {} c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 18 } ] @@ -1740,7 +1740,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { a() {} get b() {} c() {} set d(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + 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 } @@ -1749,7 +1749,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { static a() {} get b() {} static c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'b'.", type: "MethodDefinition", column: 25 } ] @@ -1757,7 +1757,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { a() {} get a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", column: 18 } ] @@ -1765,7 +1765,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { static a() {} set a(foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class setter 'a'.", type: "MethodDefinition", column: 27 } ] @@ -1773,7 +1773,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { a() {} static get b() {} c() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'b'.", type: "MethodDefinition", column: 18 } ] @@ -1781,7 +1781,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class { static a() {} static set b(foo) {} static c() {} d() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'b'.", type: "MethodDefinition", column: 27 } ] @@ -1789,7 +1789,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { a() {} static get a() {} a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", column: 18 } ] @@ -1797,7 +1797,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { static set a(foo) {} static a() {} }", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Getter is not present for class static setter 'a'.", type: "MethodDefinition", column: 11 } ] @@ -1807,7 +1807,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for class getter 'a'.", type: "MethodDefinition", @@ -1820,7 +1820,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "A = class {\n set [\n a](foo) {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Getter is not present for class setter.", type: "MethodDefinition", @@ -1833,7 +1833,7 @@ ruleTester.run("accessor-pairs", rule, { { code: "class A { static get a() {} };", options: [{ setWithoutGet: true, getWithoutSet: true, enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Setter is not present for class static getter 'a'.", type: "MethodDefinition", diff --git a/tests/lib/rules/array-bracket-newline.js b/tests/lib/rules/array-bracket-newline.js index 3f2b66f549f..74f1ac3076c 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,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [] = foo;", output: "var [\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1756,7 +1756,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a] = foo;", output: "var [\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1776,7 +1776,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [ // any comment\na] = foo;", output: "var [ // any comment\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1790,7 +1790,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [ /* any comment */\na] = foo;", output: "var [ /* any comment */\na\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1804,7 +1804,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a, b] = foo;", output: "var [\na, b\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1824,7 +1824,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a, b // any comment\n] = foo;", output: "var [\na, b // any comment\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1838,7 +1838,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a, b /* any comment */] = foo;", output: "var [\na, b /* any comment */\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1858,7 +1858,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a,\nb] = foo;", output: "var [\na,\nb\n] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1880,7 +1880,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [\na] = foo", output: "var [\na\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1896,7 +1896,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a\n] = foo", output: "var [a] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedClosingLinebreak", @@ -1912,7 +1912,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [//\na] = foo", output: "var [//\na\n] = foo", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingClosingLinebreak", @@ -1930,7 +1930,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [\n] = foo;", output: "var [] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedOpeningLinebreak", @@ -1950,7 +1950,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [\na\n] = foo;", output: "var [a] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedOpeningLinebreak", @@ -1970,7 +1970,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a, b] = foo;", output: "var [\na, b\n] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", @@ -1990,7 +1990,7 @@ ruleTester.run("array-bracket-newline", rule, { code: "var [a,\nb] = foo;", output: "var [\na,\nb\n] = foo;", options: [{ minItems: 2 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingOpeningLinebreak", diff --git a/tests/lib/rules/array-bracket-spacing.js b/tests/lib/rules/array-bracket-spacing.js index 33caf088928..2120833114a 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,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [x,y] = y", output: "var [ x,y ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -500,7 +500,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [x,y ] = y", output: "var [ x,y ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -517,7 +517,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [,,,x,,] = y", output: "var [ ,,,x,, ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -545,7 +545,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [ ,,,x,,] = y", output: "var [ ,,,x,, ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceBefore", data: { @@ -562,7 +562,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [...horse] = y", output: "var [ ...horse ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -590,7 +590,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [...horse ] = y", output: "var [ ...horse ] = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpaceAfter", data: { @@ -607,7 +607,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "var [ [ x, y ], z ] = arr;", output: "var [[ x, y ], z ] = arr;", options: ["always", { arraysInArrays: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceAfter", data: { @@ -624,7 +624,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "[ { x, y }, z ] = arr;", output: "[{ x, y }, z ] = arr;", options: ["always", { objectsInArrays: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceAfter", data: { @@ -641,7 +641,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "[ x, { y, z } ] = arr;", output: "[ x, { y, z }] = arr;", options: ["always", { objectsInArrays: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedSpaceBefore", data: { @@ -921,9 +921,9 @@ ruleTester.run("array-bracket-spacing", rule, { code: "([ a, b ]: Array) => {}", output: "([a, b]: Array) => {}", options: ["never"], - parser: parser("flow-destructuring-1"), - parserOptions: { - ecmaVersion: 6 + languageOptions: { + ecmaVersion: 6, + parser: parser("flow-destructuring-1") }, errors: [ { @@ -954,8 +954,8 @@ ruleTester.run("array-bracket-spacing", rule, { code: "([a, b]: Array< any >) => {}", output: "([ a, b ]: Array< any >) => {}", options: ["always"], - parser: parser("flow-destructuring-2"), - parserOptions: { + languageOptions: { + parser: parser("flow-destructuring-2"), ecmaVersion: 6 }, errors: [ @@ -1018,7 +1018,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "function f( [ a, b ] ) {}", output: "function f( [a, b] ) {}", options: ["never"], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ diff --git a/tests/lib/rules/array-callback-return.js b/tests/lib/rules/array-callback-return.js index 39114dbc582..6c78cb8025e 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() {})", 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 }], 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 }], 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, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { 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,7 +212,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(x => x)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -224,7 +224,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(x => (x))", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -236,7 +236,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(val => y += val)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -248,7 +248,7 @@ ruleTester.run("array-callback-return", rule, { { code: "[\"foo\",\"bar\"].forEach(x => ++x)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -260,7 +260,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.bar().forEach(x => x === y)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -276,23 +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, parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" } }] }, + { 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, 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, 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, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -305,7 +305,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(x => !x)", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -318,7 +318,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(x => (x))", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -331,7 +331,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((x) => { return x; })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -343,7 +343,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((x) => { return !x; })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -355,7 +355,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((x) => { return(x); })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -367,7 +367,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((x) => { return (x + 1); })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -379,7 +379,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((x) => { if (a === b) { return x; } })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -391,7 +391,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((x) => { if (a === b) { return !x; } })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -403,7 +403,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((x) => { if (a === b) { return (x + a); } })", options: checkForEachAllowVoid, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -416,7 +416,7 @@ ruleTester.run("array-callback-return", rule, { // full location tests { code: "foo.filter(bar => { baz(); } )", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -429,7 +429,7 @@ ruleTester.run("array-callback-return", rule, { }, { code: "foo.filter(\n() => {} )", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -442,7 +442,7 @@ ruleTester.run("array-callback-return", rule, { }, { code: "foo.filter(bar || ((baz) => {}) )", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -455,7 +455,7 @@ ruleTester.run("array-callback-return", rule, { }, { code: "foo.filter(bar => { return; })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" }, @@ -468,7 +468,7 @@ ruleTester.run("array-callback-return", rule, { }, { code: "Array.from(foo, bar => { bar })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" }, @@ -482,7 +482,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach(bar => bar)", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -496,7 +496,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((function () { return (bar) => bar; })())", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -510,7 +510,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((() => {\n return bar => bar; })())", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -524,7 +524,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.forEach((bar) => { if (bar) { return; } else { return bar ; } })", options: checkForEachOptions, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedNoReturnValue", data: { name: "arrow function", arrayMethodName: "Array.prototype.forEach" }, @@ -660,27 +660,27 @@ ruleTester.run("array-callback-return", rule, { // Optional chaining { code: "foo?.filter(() => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] }, { code: "(foo?.filter)(() => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.prototype.filter" } }] }, { code: "Array?.from([], () => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }] }, { code: "(Array?.from)([], () => { console.log('hello') })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedInside", data: { name: "arrow function", arrayMethodName: "Array.from" } }] }, { code: "foo?.filter((function() { return () => { console.log('hello') } })?.())", - parserOptions: { 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 195b5be45f5..a66ac252499 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,7 +859,7 @@ ruleTester.run("array-element-newline", rule, { code: "var [a, b] = foo;", output: "var [a,\nb] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -872,7 +872,7 @@ ruleTester.run("array-element-newline", rule, { code: "var [a, b, c] = foo;", output: "var [a,\nb,\nc] = foo;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -892,7 +892,7 @@ ruleTester.run("array-element-newline", rule, { code: "var [a,\nb] = foo;", output: "var [a, b] = foo;", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -905,7 +905,7 @@ ruleTester.run("array-element-newline", rule, { code: "var [a, b, c] = foo;", output: "var [a,\nb,\nc] = foo;", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -928,7 +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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -946,7 +946,7 @@ ruleTester.run("array-element-newline", rule, { code: "var [a, b] = [1, 2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -959,7 +959,7 @@ ruleTester.run("array-element-newline", rule, { code: "var [a,\nb] = [1,\n2]", output: "var [a, b] = [1,\n2]", options: [{ ArrayExpression: "always", ArrayPattern: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", 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..4fd45661660 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,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "function a() { for(var b of {}) { var c = b; } c; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -250,7 +252,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "for (var a of []) {} a;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { @@ -265,7 +267,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "{ var a = 0; } a;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "outOfScope", data: { @@ -348,7 +350,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "class C { static { if (bar) { var foo; } foo; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "outOfScope", data: { @@ -377,7 +379,7 @@ ruleTester.run("block-scoped-var", rule, { }, { code: "{ var { foo,\n bar } = baz; } bar;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "outOfScope", data: { diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index 0dfef7ed652..4ec40f87bec 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,7 +181,7 @@ ruleTester.run("block-spacing", rule, { { code: "for (var a of b) {foo();}", output: "for (var a of b) { foo(); }", - parserOptions: { ecmaVersion: 6 }, + 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: "}" } } @@ -266,7 +266,7 @@ ruleTester.run("block-spacing", rule, { { code: "(() => {bar();});", output: "(() => { bar(); });", - parserOptions: { ecmaVersion: 6 }, + 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: "}" } } @@ -275,7 +275,7 @@ ruleTester.run("block-spacing", rule, { { code: "if (a) {/* comment */ foo(); /* comment */}", output: "if (a) { /* comment */ foo(); /* comment */ }", - parserOptions: { ecmaVersion: 6 }, + 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: "}" } } @@ -284,7 +284,7 @@ ruleTester.run("block-spacing", rule, { { code: "if (a) {//comment\n foo(); }", output: "if (a) { //comment\n foo(); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -305,7 +305,7 @@ ruleTester.run("block-spacing", rule, { { code: "class C { static {foo; } }", output: "class C { static { foo; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -324,7 +324,7 @@ ruleTester.run("block-spacing", rule, { { code: "class C { static { foo;} }", output: "class C { static { foo; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -343,7 +343,7 @@ ruleTester.run("block-spacing", rule, { { code: "class C { static {foo;} }", output: "class C { static { foo; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -374,7 +374,7 @@ ruleTester.run("block-spacing", rule, { { code: "class C { static {/* comment */} }", output: "class C { static { /* comment */ } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -405,7 +405,7 @@ ruleTester.run("block-spacing", rule, { { code: "class C { static {/* comment 1 */ foo; /* comment 2 */} }", output: "class C { static { /* comment 1 */ foo; /* comment 2 */ } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -436,7 +436,7 @@ ruleTester.run("block-spacing", rule, { { code: "class C {\n static {foo()\nbar()} }", output: "class C {\n static { foo()\nbar() } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -747,7 +747,7 @@ ruleTester.run("block-spacing", rule, { code: "for (var a of b) { foo(); }", output: "for (var a of b) {foo();}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -884,7 +884,7 @@ ruleTester.run("block-spacing", rule, { code: "(() => { bar(); });", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -935,7 +935,7 @@ ruleTester.run("block-spacing", rule, { code: "(() => { bar();});", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -952,7 +952,7 @@ ruleTester.run("block-spacing", rule, { code: "(() => {bar(); });", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -969,7 +969,7 @@ ruleTester.run("block-spacing", rule, { code: "(() => { bar(); });", output: "(() => {bar();});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "BlockStatement", @@ -997,7 +997,7 @@ ruleTester.run("block-spacing", rule, { code: "class C { static { foo;} }", output: "class C { static {foo;} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1017,7 +1017,7 @@ ruleTester.run("block-spacing", rule, { code: "class C { static {foo; } }", output: "class C { static {foo;} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1037,7 +1037,7 @@ ruleTester.run("block-spacing", rule, { code: "class C { static { foo; } }", output: "class C { static {foo;} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1069,7 +1069,7 @@ ruleTester.run("block-spacing", rule, { code: "class C { static { /* comment */ } }", output: "class C { static {/* comment */} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1101,7 +1101,7 @@ ruleTester.run("block-spacing", rule, { code: "class C { static { /* comment 1 */ foo; /* comment 2 */ } }", output: "class C { static {/* comment 1 */ foo; /* comment 2 */} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", @@ -1133,7 +1133,7 @@ ruleTester.run("block-spacing", rule, { code: "class C { static\n{ foo()\nbar() } }", output: "class C { static\n{foo()\nbar()} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { type: "StaticBlock", diff --git a/tests/lib/rules/brace-style.js b/tests/lib/rules/brace-style.js index 9629f42fc58..e2b47c54705 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,7 +335,7 @@ ruleTester.run("brace-style", rule, { { code: "var foo = () => { return; }", output: "var foo = () => {\n return; \n}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { @@ -411,7 +411,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { @@ -809,7 +809,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } ] @@ -829,7 +829,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } ] @@ -849,7 +849,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } ] @@ -869,7 +869,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, @@ -889,7 +889,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["1tbs"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } ] @@ -911,7 +911,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } ] @@ -931,7 +931,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } ] @@ -951,7 +951,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } ] @@ -971,7 +971,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, @@ -991,7 +991,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["stroustrup"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "nextLineOpen", type: "Punctuator" } ] @@ -1015,7 +1015,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" } ] @@ -1039,7 +1039,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "blockSameLine", type: "Punctuator" } ] @@ -1063,7 +1063,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "singleLineClose", type: "Punctuator" } ] @@ -1085,7 +1085,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, @@ -1107,7 +1107,7 @@ ruleTester.run("brace-style", rule, { } `, options: ["allman"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "sameLineOpen", type: "Punctuator" } ] diff --git a/tests/lib/rules/callback-return.js b/tests/lib/rules/callback-return.js index 1f17ef6cc24..32d136e818d 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,7 +191,7 @@ ruleTester.run("callback-return", rule, { }, { code: "var x = (err) => { if (err) { callback (err); } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, @@ -201,7 +201,7 @@ ruleTester.run("callback-return", rule, { }, { code: "var x = { x(err) { if (err) { callback (err); } } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, @@ -220,7 +220,7 @@ ruleTester.run("callback-return", rule, { }, { code: "var x = { x(err) { if (err) { callback && callback (err); } } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, @@ -257,7 +257,7 @@ ruleTester.run("callback-return", rule, { }, { code: "var a = (err) => { callback (err); callback(); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, @@ -286,7 +286,7 @@ ruleTester.run("callback-return", rule, { }, { code: "class x { horse() { if (err) { callback(); } callback(); } } ", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", line: 1, @@ -324,7 +324,7 @@ ruleTester.run("callback-return", rule, { }, { code: "() => { if (x) { callback(); } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index f634c71b43d..10bc1f61356 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,7 +571,7 @@ ruleTester.run("camelcase", rule, { }, { code: "var { category_id: category_alias } = query;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -586,7 +583,7 @@ ruleTester.run("camelcase", rule, { { code: "var { category_id: category_alias } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -598,7 +595,7 @@ ruleTester.run("camelcase", rule, { { code: "var { [category_id]: categoryId } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -609,7 +606,7 @@ ruleTester.run("camelcase", rule, { }, { code: "var { [category_id]: categoryId } = query;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -621,7 +618,7 @@ ruleTester.run("camelcase", rule, { { code: "var { category_id: categoryId, ...other_props } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "notCamelCase", @@ -632,7 +629,7 @@ ruleTester.run("camelcase", rule, { }, { code: "var { category_id } = query;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -643,7 +640,7 @@ ruleTester.run("camelcase", rule, { }, { code: "var { category_id: category_id } = query;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -654,7 +651,7 @@ ruleTester.run("camelcase", rule, { }, { code: "var { category_id = 1 } = query;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -665,7 +662,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import no_camelcased from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -676,7 +673,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import * as no_camelcased from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -687,7 +684,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import { no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -698,7 +695,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import { no_camelcased as no_camel_cased } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -709,7 +706,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import { camelCased as no_camel_cased } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -720,7 +717,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import { 'snake_cased' as snake_cased } from 'mod'", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -732,7 +729,7 @@ ruleTester.run("camelcase", rule, { { code: "import { 'snake_cased' as another_snake_cased } from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -743,7 +740,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import { camelCased, no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -754,7 +751,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -765,7 +762,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import camelCased, { no_camelcased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -776,7 +773,7 @@ ruleTester.run("camelcase", rule, { }, { code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -788,7 +785,7 @@ ruleTester.run("camelcase", rule, { { code: "import snake_cased from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -800,7 +797,7 @@ ruleTester.run("camelcase", rule, { { code: "import * as snake_cased from 'mod'", options: [{ ignoreImports: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -812,7 +809,7 @@ ruleTester.run("camelcase", rule, { { code: "import snake_cased from 'mod'", options: [{ ignoreImports: false }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -824,7 +821,7 @@ ruleTester.run("camelcase", rule, { { code: "import * as snake_cased from 'mod'", options: [{ ignoreImports: false }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -836,7 +833,7 @@ ruleTester.run("camelcase", rule, { { code: "var camelCased = snake_cased", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -848,7 +845,7 @@ ruleTester.run("camelcase", rule, { { code: "a_global_variable.foo()", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -860,7 +857,7 @@ ruleTester.run("camelcase", rule, { { code: "a_global_variable[undefined]", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -871,7 +868,7 @@ ruleTester.run("camelcase", rule, { }, { code: "var camelCased = snake_cased", - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -883,7 +880,7 @@ ruleTester.run("camelcase", rule, { { code: "var camelCased = snake_cased", options: [{}], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase -- Testing non-CamelCase + languageOptions: { globals: { snake_cased: "readonly" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -895,7 +892,7 @@ ruleTester.run("camelcase", rule, { { code: "foo.a_global_variable = bar", 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 errors: [ { messageId: "notCamelCase", @@ -907,7 +904,7 @@ ruleTester.run("camelcase", rule, { { code: "var foo = { a_global_variable: bar }", 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 errors: [ { messageId: "notCamelCase", @@ -919,7 +916,7 @@ ruleTester.run("camelcase", rule, { { code: "var foo = { a_global_variable: a_global_variable }", 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 errors: [ { messageId: "notCamelCase", @@ -932,8 +929,7 @@ ruleTester.run("camelcase", rule, { { code: "var foo = { a_global_variable() {} }", 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 errors: [ { messageId: "notCamelCase", @@ -945,8 +941,7 @@ ruleTester.run("camelcase", rule, { { code: "class Foo { a_global_variable() {} }", 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 errors: [ { messageId: "notCamelCase", @@ -958,7 +953,7 @@ ruleTester.run("camelcase", rule, { { code: "a_global_variable: for (;;);", 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 errors: [ { messageId: "notCamelCase", @@ -970,8 +965,7 @@ ruleTester.run("camelcase", rule, { { 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 + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -990,8 +984,7 @@ ruleTester.run("camelcase", rule, { { 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 + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1010,7 +1003,7 @@ ruleTester.run("camelcase", rule, { { code: "var a_global_variable", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1022,7 +1015,7 @@ ruleTester.run("camelcase", rule, { { code: "function a_global_variable () {}", options: [{ ignoreGlobals: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1034,8 +1027,7 @@ ruleTester.run("camelcase", rule, { { 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 + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1054,8 +1046,7 @@ ruleTester.run("camelcase", rule, { { 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 + languageOptions: { ecmaVersion: 6, globals: { a_global_variable: "writable" } }, // eslint-disable-line camelcase -- Testing non-CamelCase errors: [ { messageId: "notCamelCase", @@ -1074,8 +1065,7 @@ ruleTester.run("camelcase", rule, { { code: "var foo = { a_global_variable }", 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 errors: [ { messageId: "notCamelCase", @@ -1108,7 +1098,7 @@ ruleTester.run("camelcase", rule, { }, { code: "export * as snake_cased from 'mod'", - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ { messageId: "notCamelCase", @@ -1119,7 +1109,7 @@ ruleTester.run("camelcase", rule, { }, { code: "function foo({ no_camelcased }) {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1130,7 +1120,7 @@ ruleTester.run("camelcase", rule, { }, { code: "function foo({ no_camelcased = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1141,7 +1131,7 @@ ruleTester.run("camelcase", rule, { }, { code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1157,7 +1147,7 @@ ruleTester.run("camelcase", rule, { }, { code: "const { bar: no_camelcased } = foo;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1168,7 +1158,7 @@ ruleTester.run("camelcase", rule, { }, { code: "function foo({ value_1: my_default }) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1179,7 +1169,7 @@ ruleTester.run("camelcase", rule, { }, { code: "function foo({ isCamelcased: no_camelcased }) {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1190,7 +1180,7 @@ ruleTester.run("camelcase", rule, { }, { code: "var { foo: bar_baz = 1 } = quz;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1201,7 +1191,7 @@ ruleTester.run("camelcase", rule, { }, { code: "const { no_camelcased = false } = bar;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1212,7 +1202,7 @@ ruleTester.run("camelcase", rule, { }, { code: "const { no_camelcased = foo_bar } = bar;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1246,7 +1236,7 @@ ruleTester.run("camelcase", rule, { { code: "foo = { [computed_bar]: 0 };", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1257,7 +1247,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({ a: obj.fo_o } = bar);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1269,7 +1259,7 @@ ruleTester.run("camelcase", rule, { { code: "({ a: obj.fo_o } = bar);", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1280,7 +1270,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({ a: obj.fo_o.b_ar } = baz);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1291,7 +1281,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({ a: { b: { c: obj.fo_o } } } = bar);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1302,7 +1292,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({ a: { b: { c: obj.fo_o.b_ar } } } = baz);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1313,7 +1303,7 @@ ruleTester.run("camelcase", rule, { }, { code: "([obj.fo_o] = bar);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1325,7 +1315,7 @@ ruleTester.run("camelcase", rule, { { code: "([obj.fo_o] = bar);", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1337,7 +1327,7 @@ ruleTester.run("camelcase", rule, { { code: "([obj.fo_o = 1] = bar);", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1348,7 +1338,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({ a: [obj.fo_o] } = bar);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1359,7 +1349,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({ a: { b: [obj.fo_o] } } = bar);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1370,7 +1360,7 @@ ruleTester.run("camelcase", rule, { }, { code: "([obj.fo_o.ba_r] = baz);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notCamelCase", @@ -1381,7 +1371,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({...obj.fo_o} = baz);", - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", @@ -1392,7 +1382,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({...obj.fo_o.ba_r} = baz);", - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", @@ -1403,7 +1393,7 @@ ruleTester.run("camelcase", rule, { }, { code: "({c: {...obj.fo_o }} = baz);", - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "notCamelCase", @@ -1417,13 +1407,13 @@ ruleTester.run("camelcase", rule, { { code: "obj.o_k.non_camelcase = 0", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }] }, { code: "(obj?.o_k).non_camelcase = 0", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "notCamelCase", data: { name: "non_camelcase" } }] }, @@ -1431,19 +1421,19 @@ ruleTester.run("camelcase", rule, { { code: "class C { snake_case; }", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "notCamelCase", data: { name: "snake_case" } }] }, { code: "class C { #snake_case; foo() { this.#snake_case; } }", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" }, column: 11 }] }, { code: "class C { #snake_case() {} }", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }] }, @@ -1454,7 +1444,7 @@ ruleTester.run("camelcase", rule, { doSomething({ some_property }); `, options: [{ properties: "always", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1471,7 +1461,7 @@ ruleTester.run("camelcase", rule, { doSomething({ [some_property]: "bar" }); `, options: [{ properties: "never", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", @@ -1496,7 +1486,7 @@ ruleTester.run("camelcase", rule, { }; `, options: [{ properties: "always", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notCamelCase", 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..7d2619f6f4b 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,76 +20,76 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] }, { code: "class A { foo() {/**this**/} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] }, { code: "class A { foo() {var a = function () {this};} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] }, { code: "class A { foo() {var a = function () {var b = function(){this}};} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] }, { code: "class A { foo() {window.this} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] }, { code: "class A { foo() {that.this = 'this';} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] }, { code: "class A { foo() { () => undefined; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] @@ -97,7 +97,7 @@ ruleTester.run("class-methods-use-this", rule, { { code: "class A { foo() {} bar() {} }", options: [{ exceptMethods: ["bar"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method 'foo'" } } ] @@ -105,7 +105,7 @@ ruleTester.run("class-methods-use-this", rule, { { code: "class A { foo() {} hasOwnProperty() {} }", options: [{ exceptMethods: ["foo"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 20, messageId: "missingThis", data: { name: "method 'hasOwnProperty'" } } ] @@ -113,7 +113,7 @@ ruleTester.run("class-methods-use-this", rule, { { code: "class A { [foo]() {} }", options: [{ exceptMethods: ["foo"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", line: 1, column: 11, messageId: "missingThis", data: { name: "method" } } ] @@ -121,7 +121,7 @@ ruleTester.run("class-methods-use-this", rule, { { code: "class A { #foo() { } foo() {} #bar() {} }", options: [{ exceptMethods: ["#foo"] }], - parserOptions: { ecmaVersion: 2022 }, + 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" } } @@ -129,7 +129,7 @@ ruleTester.run("class-methods-use-this", rule, { }, { code: "class A { foo(){} 'bar'(){} 123(){} [`baz`](){} [a](){} [f(a)](){} get quux(){} set[a](b){} *quuux(){} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, type: "FunctionExpression", column: 11 }, { messageId: "missingThis", data: { name: "method 'bar'" }, type: "FunctionExpression", column: 19 }, @@ -144,70 +144,70 @@ ruleTester.run("class-methods-use-this", rule, { }, { code: "class A { foo = function() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 25 } ] }, { code: "class A { foo = () => {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 17 } ] }, { code: "class A { #foo = function() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 26 } ] }, { code: "class A { #foo = () => {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 18 } ] }, { code: "class A { #foo() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private method #foo" }, column: 11, endColumn: 15 } ] }, { code: "class A { get #foo() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private getter #foo" }, column: 11, endColumn: 19 } ] }, { code: "class A { set #foo(x) {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "private setter #foo" }, column: 11, endColumn: 19 } ] }, { code: "class A { foo () { return class { foo = this }; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } ] }, { code: "class A { foo () { return function () { foo = this }; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } ] }, { code: "class A { foo () { return class { static { this; } } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingThis", data: { name: "method 'foo'" }, column: 11, endColumn: 15 } ] diff --git a/tests/lib/rules/comma-dangle.js b/tests/lib/rules/comma-dangle.js index 49cd6c2546b..d7917a8f516 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,7 @@ ruleTester.run("comma-dangle", rule, { code: "var { a, b, } = foo;", output: "var { a, b } = foo;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1053,7 +1104,7 @@ ruleTester.run("comma-dangle", rule, { code: "var { a, b, } = foo;", output: "var { a, b } = foo;", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1067,7 +1118,7 @@ ruleTester.run("comma-dangle", rule, { code: "var [ a, b, ] = foo;", output: "var [ a, b ] = foo;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1081,7 +1132,7 @@ ruleTester.run("comma-dangle", rule, { code: "var [ a, b, ] = foo;", output: "var [ a, b ] = foo;", options: ["only-multiline"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", @@ -1149,91 +1200,91 @@ ruleTester.run("comma-dangle", rule, { code: "import {foo} from 'foo';", output: "import {foo,} from 'foo';", options: ["always"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missing", type: "ExportSpecifier" }] }, @@ -1262,56 +1313,56 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => a", output: "(a) => a", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => (a)", output: "(a) => (a)", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "({foo(a,) {}})", output: "({foo(a) {}})", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "class A {foo(a,) {}}", output: "class A {foo(a) {}}", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, @@ -1319,56 +1370,56 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a) {}", output: "function foo(a,) {}", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(function foo(a) {})", output: "(function foo(a,) {})", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => a", output: "(a,) => a", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => (a)", output: "(a,) => (a)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "({foo(a) {}})", output: "({foo(a,) {}})", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "class A {foo(a) {}}", output: "class A {foo(a,) {}}", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(a)", output: "foo(a,)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(...a)", output: "foo(...a,)", options: [{ functions: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "SpreadElement" }] }, @@ -1376,49 +1427,49 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "always-multiline" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "always-multiline" }], - parserOptions: { 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" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\na,\nb\n)", output: "foo(\na,\nb,\n)", options: [{ functions: "always-multiline" }], - parserOptions: { 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" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "SpreadElement" }] }, @@ -1426,84 +1477,84 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a,) {}", output: "function foo(a) {}", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "only-multiline" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => a", output: "(a) => a", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => (a)", output: "(a) => (a)", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "({foo(a,) {}})", output: "({foo(a) {}})", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "class A {foo(a,) {}}", output: "class A {foo(a) {}}", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, @@ -1511,35 +1562,35 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a) {}", output: "function foo(a,) {}", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(function foo(a) {})", output: "(function foo(a,) {})", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => a", output: "(a,) => a", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => (a)", output: "(a,) => (a)", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "({foo(a) {}})", output: "({foo(a,) {},})", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [ { messageId: "missing", type: "Identifier" }, { messageId: "missing", type: "Property" } @@ -1549,21 +1600,21 @@ ruleTester.run("comma-dangle", rule, { code: "class A {foo(a) {}}", output: "class A {foo(a,) {}}", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(a)", output: "foo(a,)", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(...a)", output: "foo(...a,)", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "SpreadElement" }] }, @@ -1571,49 +1622,49 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: ["always-multiline"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: ["always-multiline"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\na,\nb\n)", output: "foo(\na,\nb,\n)", options: ["always-multiline"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missing", type: "SpreadElement" }] }, @@ -1621,35 +1672,35 @@ ruleTester.run("comma-dangle", rule, { code: "function foo(a,) {}", output: "function foo(a) {}", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: ["only-multiline"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(a) {}", output: "function foo(a,) {}", options: ["always"], - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [{ messageId: "missing", type: "Identifier" }] }, @@ -1672,7 +1723,7 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 1 }, { messageId: "unexpected", line: 1 } @@ -1696,7 +1747,7 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 2 }, { messageId: "unexpected", line: 2 } @@ -1720,7 +1771,7 @@ let d = 0;export {d,}; exports: "ignore", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 3 } ] @@ -1743,7 +1794,7 @@ let d = 0;export {d}; exports: "never", functions: "ignore" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 4 } ] @@ -1766,7 +1817,7 @@ let d = 0;export {d,}; exports: "ignore", functions: "never" }], - parserOptions: { ecmaVersion: 8, sourceType: "module" }, + languageOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ { messageId: "unexpected", line: 5 }, { messageId: "unexpected", line: 5 } @@ -1778,28 +1829,36 @@ let d = 0;export {d,}; code: "function foo({a}: {a: string,}) {}", output: "function foo({a,}: {a: string,}) {}", options: ["always"], - parser: parser("object-pattern-1"), + languageOptions: { + parser: parser("object-pattern-1") + }, errors: [{ messageId: "missing" }] }, { code: "function foo({a,}: {a: string}) {}", output: "function foo({a}: {a: string}) {}", options: ["never"], - parser: parser("object-pattern-2"), + languageOptions: { + parser: parser("object-pattern-2") + }, errors: [{ messageId: "unexpected" }] }, { code: "function foo(a): {b: boolean,} {}", output: "function foo(a,): {b: boolean,} {}", options: [{ functions: "always" }], - parser: parser("return-type-1"), + languageOptions: { + parser: parser("return-type-1") + }, errors: [{ messageId: "missing" }] }, { code: "function foo(a,): {b: boolean} {}", output: "function foo(a): {b: boolean} {}", options: [{ functions: "never" }], - parser: parser("return-type-2"), + languageOptions: { + parser: parser("return-type-2") + }, errors: [{ messageId: "unexpected" }] }, @@ -1807,14 +1866,14 @@ let d = 0;export {d,}; { code: "foo(a,)", output: "foo(a)", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpected" }] }, // 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: 2 }, { 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,50 +1926,11 @@ let d = 0;export {d,}; } from 'react-native'; `, options: [{ imports: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { 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" - } }, - { - 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) {}", diff --git a/tests/lib/rules/comma-spacing.js b/tests/lib/rules/comma-spacing.js index a3b23b62d73..4b73d15da1b 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,7 @@ ruleTester.run("comma-spacing", rule, { code: "var foo = (a,b) => {}", output: "var foo = (a , b) => {}", options: [{ before: true, after: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missing", @@ -459,7 +459,7 @@ ruleTester.run("comma-spacing", rule, { code: "var foo = (a = 1,b) => {}", output: "var foo = (a = 1 , b) => {}", options: [{ before: true, after: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missing", @@ -477,7 +477,7 @@ ruleTester.run("comma-spacing", rule, { code: "function foo(a = 1 ,b = 2) {}", output: "function foo(a = 1, b = 2) {}", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "There should be no space before ','.", @@ -493,7 +493,7 @@ ruleTester.run("comma-spacing", rule, { { code: "{foo(1 ,2)}", output: "{foo(1, 2)}", - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { message: "There should be no space before ','.", diff --git a/tests/lib/rules/comma-style.js b/tests/lib/rules/comma-style.js index e0ac78d6813..e8835bb6e83 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,7 +375,7 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ @@ -417,7 +417,7 @@ ruleTester.run("comma-style", rule, { FunctionExpression: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" }, @@ -434,7 +434,7 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ @@ -450,7 +450,7 @@ ruleTester.run("comma-style", rule, { ArrowFunctionExpression: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ @@ -466,7 +466,7 @@ ruleTester.run("comma-style", rule, { ArrayPattern: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ @@ -482,7 +482,7 @@ ruleTester.run("comma-style", rule, { ImportDeclaration: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" }, @@ -499,7 +499,7 @@ ruleTester.run("comma-style", rule, { ObjectPattern: false } }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ diff --git a/tests/lib/rules/complexity.js b/tests/lib/rules/complexity.js index d6feb8a2f05..3f26629fa45 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], 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], parserOptions: { ecmaVersion: 6 }, errors: 1 }, + { 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], parserOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 2, 1)] }, + { 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,109 +171,109 @@ ruleTester.run("complexity", rule, { { code: "function foo () { a || b; class C { x; } c || d; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { x = c; } d || e; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { [x || y]; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { a || b; class C { [x || y] = c; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y]; } a || b; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y] = a; } b || c; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y]; [z || q]; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "function foo () { class C { [x || y] = a; [z || q] = b; } }", options: [2], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Method 'y'", 3, 2)] }, { code: "class C { x; y() { c || d || e; } z; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Method 'y'", 3, 2)] }, { code: "class C { x = a || b; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class field initializer", 2, 1)] }, { code: "(class { x = a || b; })", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class field initializer", 2, 1)] }, { code: "class C { static x = a || b; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class field initializer", 2, 1)] }, { code: "(class { x = a ? b : c; })", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class field initializer", 2, 1)] }, { code: "class C { x = a || b || c; }", options: [2], - parserOptions: { 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], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class field initializer", 3, 2), line: 1, @@ -285,7 +285,7 @@ ruleTester.run("complexity", rule, { { code: "class C { x = a || b || c; y = d || e; z = f || g || h; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 3, 2), @@ -306,25 +306,25 @@ ruleTester.run("complexity", rule, { { code: "class C { x = () => a || b || c; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Method 'x'", 3, 2)] }, { code: "class C { x = (() => a || b || c) || d; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Arrow function", 3, 2)] }, { code: "class C { x = () => a || b || c; y = d || e; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Method 'x'", 3, 2)] }, { code: "class C { x = () => a || b || c; y = d || e || f; }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ makeError("Method 'x'", 3, 2), { @@ -339,7 +339,7 @@ ruleTester.run("complexity", rule, { { code: "class C { x = function () { a || b }; y = function () { c || d }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ makeError("Method 'x'", 2, 1), makeError("Method 'y'", 2, 1) @@ -348,7 +348,7 @@ ruleTester.run("complexity", rule, { { code: "class C { x = class { [y || z]; }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -362,7 +362,7 @@ ruleTester.run("complexity", rule, { { code: "class C { x = class { [y || z] = a; }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -376,7 +376,7 @@ ruleTester.run("complexity", rule, { { code: "class C { x = class { y = a || b; }; }", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class field initializer", 2, 1), @@ -392,91 +392,91 @@ ruleTester.run("complexity", rule, { { code: "function foo () { a || b; class C { static {} } c || d; }", options: [2], - parserOptions: { 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], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Function 'foo'", 3, 2)] }, { code: "class C { static { a || b; } }", options: [1], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class static block", 2, 1)] }, { code: "class C { static { a || b || c; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class static block", 3, 2)] }, { code: "class C { static { a || b; c || d; } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class static block", 3, 2)] }, { code: "class C { static { a || b; c || d; e || f; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class static block", 4, 3)] }, { code: "class C { static { a || b; c || d; { e || f; } } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [makeError("Class static block", 4, 3)] }, { code: "class C { static { if (a || b) c = d || e; } }", options: [3], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class field initializer", 3, 2), column: 41, @@ -486,7 +486,7 @@ ruleTester.run("complexity", rule, { { code: "class C { static { a || b || c || d; } static { e || f || g; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class static block", 4, 3), column: 11, @@ -496,7 +496,7 @@ ruleTester.run("complexity", rule, { { code: "class C { static { a || b || c; } static { d || e || f || g; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...makeError("Class static block", 4, 3), column: 35, @@ -506,7 +506,7 @@ ruleTester.run("complexity", rule, { { code: "class C { static { a || b || c || d; } static { e || f || g || h; } }", options: [3], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { ...makeError("Class static block", 4, 3), diff --git a/tests/lib/rules/computed-property-spacing.js b/tests/lib/rules/computed-property-spacing.js index 35533d9e686..9a51e2f9dda 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,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[a]: b}", output: "var x = {[ a ]: b}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -580,7 +580,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[a ]: b}", output: "var x = {[ a ]: b}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -597,7 +597,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[ a]: b}", output: "var x = {[ a ]: b}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceBefore", @@ -616,7 +616,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[ a ]: b}", output: "var x = {[a]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -642,7 +642,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[a ]: b}", output: "var x = {[a]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -659,7 +659,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[ a]: b}", output: "var x = {[a]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -676,7 +676,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "var x = {[ a\n]: b}", output: "var x = {[a\n]: b}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -694,7 +694,7 @@ ruleTester.run("computed-property-spacing", rule, { { code: "class A { [ a ](){} }", output: "class A { [a](){} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -720,7 +720,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -836,7 +836,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -952,7 +952,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "A = class { [a](){} }", output: "A = class { [ a ](){} }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -978,7 +978,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1094,7 +1094,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1212,7 +1212,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "class A { [ a](){} }", output: "class A { [a](){} }", options: ["never", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1229,7 +1229,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1246,7 +1246,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1290,7 +1290,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1406,7 +1406,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1464,7 +1464,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "class A { [ a](){} }", output: "class A { [ a ](){} }", options: ["always", { enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceBefore", @@ -1481,7 +1481,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1498,7 +1498,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1542,7 +1542,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1658,7 +1658,7 @@ ruleTester.run("computed-property-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceBefore", @@ -1716,7 +1716,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1750,7 +1750,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1784,7 +1784,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1818,7 +1818,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1852,7 +1852,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1886,7 +1886,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -1938,7 +1938,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1990,7 +1990,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingSpaceAfter", @@ -2033,7 +2033,7 @@ ruleTester.run("computed-property-spacing", rule, { "}" ].join("\n"), options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -2070,7 +2070,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "obj?.[1];", output: "obj?.[ 1 ];", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } @@ -2080,7 +2080,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "obj?.[ 1 ];", output: "obj?.[1];", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } @@ -2092,7 +2092,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "const { [ a]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } } ] @@ -2101,7 +2101,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "const { [a ]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } ] @@ -2110,7 +2110,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "const { [ a ]: someProp } = obj;", output: "const { [a]: someProp } = obj;", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } @@ -2120,7 +2120,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "({ [ a ]: someProp } = obj);", output: "({ [a]: someProp } = obj);", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedSpaceAfter", data: { tokenValue: "[" } }, { messageId: "unexpectedSpaceBefore", data: { tokenValue: "]" } } @@ -2130,7 +2130,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "const { [a]: someProp } = obj;", output: "const { [ a ]: someProp } = obj;", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } @@ -2140,7 +2140,7 @@ ruleTester.run("computed-property-spacing", rule, { code: "({ [a]: someProp } = obj);", output: "({ [ a ]: someProp } = obj);", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingSpaceAfter", data: { tokenValue: "[" } }, { messageId: "missingSpaceBefore", data: { tokenValue: "]" } } diff --git a/tests/lib/rules/consistent-return.js b/tests/lib/rules/consistent-return.js index 16a1ed97a19..2e01eef6fd3 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,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "var foo = () => { if (true) return true; else return; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturnValue", @@ -119,7 +124,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "f(a => { if (true) return; else return false; })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedReturnValue", @@ -194,7 +199,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "if (true) { return 1; } return;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "missingReturnValue", @@ -265,7 +270,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "f(() => { if (a) return true; });", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -280,7 +285,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "var obj = {foo() { if (a) return true; }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -295,7 +300,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "class A {foo() { if (a) return true; }};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -310,7 +315,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "if (a) return true;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "missingReturn", @@ -325,7 +330,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "class A { CapitalizedFunction() { if (a) return true; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -340,7 +345,7 @@ ruleTester.run("consistent-return", rule, { }, { code: "({ constructor() { if (a) return true; } });", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", 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..db23378917b 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,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -575,7 +580,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)}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -591,7 +596,7 @@ ruleTester.run("curly", rule, { { code: "for (a;;) console.log(foo)", output: "for (a;;) {console.log(foo)}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", @@ -607,7 +612,7 @@ ruleTester.run("curly", rule, { { code: "for (a;;) \n console.log(foo)", output: "for (a;;) \n {console.log(foo)}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", @@ -624,7 +629,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -641,7 +646,7 @@ ruleTester.run("curly", rule, { code: "do{foo();} while(bar);", output: "do foo(); while(bar);", options: ["multi"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -849,7 +854,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -1013,7 +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"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -1030,7 +1035,7 @@ ruleTester.run("curly", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -1091,7 +1096,7 @@ ruleTester.run("curly", rule, { code: "if (foo) { let bar; } else baz();", output: "if (foo) { let bar; } else {baz();}", options: ["multi", "consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -1104,7 +1109,7 @@ ruleTester.run("curly", rule, { code: "if (foo) bar(); else { const baz = 'quux' }", output: "if (foo) {bar();} else { const baz = 'quux' }", options: ["multi", "consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfterCondition", @@ -1219,7 +1224,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingCurlyAfter", @@ -1232,7 +1237,7 @@ ruleTester.run("curly", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedCurlyAfter", @@ -1458,7 +1463,7 @@ ruleTester.run("curly", rule, { code: "if (foo) { bar }\n/regex/.test('foo');", output: null, options: ["multi"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { @@ -1495,7 +1500,7 @@ ruleTester.run("curly", rule, { code: "if (foo) { var foo = () => {} } else {}", output: null, options: ["multi"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { @@ -1508,7 +1513,7 @@ ruleTester.run("curly", rule, { code: "if (foo) { var foo = function*() {} } else {}", output: null, options: ["multi"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { @@ -1553,7 +1558,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedCurlyAfter", data: { name: "for-of" }, type: "ForOfStatement" }] }, { @@ -1830,7 +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", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ data: { name: "for-of" }, type: "ForOfStatement", 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..d84fa00626b 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,28 +270,28 @@ ruleTester.run("dot-location", rule, { code: "5_000\n.toExponential()", output: "5_000 .\ntoExponential()", options: ["object"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { @@ -311,7 +316,7 @@ ruleTester.run("dot-location", rule, { code: "`\n`\n.prop", output: "`\n`.\nprop", options: ["object"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 3, column: 1 }] }, @@ -382,21 +387,21 @@ ruleTester.run("dot-location", rule, { code: "obj\n?.prop", output: "obj?.\nprop", options: ["object"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedDotAfterObject" }] }, { code: "10\n?.prop", output: "10?.\nprop", options: ["object"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedDotAfterObject" }] }, { code: "obj?.\nprop", output: "obj\n?.prop", options: ["property"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedDotBeforeProperty" }] }, @@ -405,14 +410,14 @@ 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedDotAfterObject" }] }, { code: "class C { #a; foo() { this.\n#a; } }", output: "class C { #a; foo() { this\n.#a; } }", options: ["property"], - parserOptions: { 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 c2ced102b9c..c03cdc73ee9 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,7 +90,7 @@ ruleTester.run("dot-notation", rule, { { code: "a[`time`];", output: "a.time;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useDot", data: { key: "`time`" } }] }, { @@ -267,25 +272,25 @@ ruleTester.run("dot-notation", rule, { { code: "5_000['prop']", output: "5_000 .prop", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "5_000_00['prop']", output: "5_000_00 .prop", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "5.000_000['prop']", output: "5.000_000.prop", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "0b1010_1010['prop']", output: "0b1010_1010.prop", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, @@ -293,27 +298,27 @@ ruleTester.run("dot-notation", rule, { { code: "obj?.['prop']", output: "obj?.prop", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "0?.['prop']", output: "0?.prop", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, { code: "obj?.true", output: "obj?.[\"true\"]", options: [{ allowKeywords: false }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useBrackets", data: { key: "true" } }] }, { code: "let?.true", output: "let?.[\"true\"]", options: [{ allowKeywords: false }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useBrackets", data: { key: "true" } }] } ] 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..e4c7c0c1372 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,7 +324,7 @@ ruleTester.run("func-call-spacing", rule, { { code: "import (source);", output: "import(source);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] }, @@ -357,7 +357,7 @@ ruleTester.run("func-call-spacing", rule, { { code: "import\n(source);", output: null, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] }, @@ -453,7 +453,7 @@ ruleTester.run("func-call-spacing", rule, { code: "import (source);", output: "import(source);", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", type: "ImportExpression" }] }, @@ -704,7 +704,7 @@ ruleTester.run("func-call-spacing", rule, { code: "import(source);", output: "import (source);", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "missing", type: "ImportExpression" }] }, { @@ -900,70 +900,70 @@ ruleTester.run("func-call-spacing", rule, { code: "func ?.()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func?. ()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func ?. ()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func\n?.()", output: "func?.()", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func\n//comment\n?.()", output: null, // Don't remove comments options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace" }] }, { code: "func?.()", output: null, // Not sure inserting a space into either before/after `?.`. options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "missing" }] }, { code: "func\n ?.()", output: "func ?.()", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedNewline" }] }, { code: "func?.\n ()", output: "func?. ()", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedNewline" }] }, { code: "func ?.\n ()", output: "func ?. ()", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedNewline" }] }, { code: "func\n /*comment*/ ?.()", output: null, // Don't remove comments options: ["always"], - parserOptions: { 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 c020066e752..14b0d72ed8f 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,327 +268,334 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } ] }, { code: "let foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } ] }, { code: "foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } ] }, { code: "foo &&= function bar() {};", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchVariable", data: { funcName: "bar", name: "foo" } } ] }, { code: "obj.foo ||= function bar() {};", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] }, { code: "obj['foo'] ??= function bar() {};", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] }, { code: "obj.foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] }, { code: "obj.bar.foo = function bar() {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] }, { code: "obj['foo'] = function bar() {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] }, { code: "let obj = {foo: function bar() {}};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] }, { code: "let obj = {'foo': function bar() {}};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] }, { code: "({['foo']: function bar() {}})", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] @@ -597,7 +603,7 @@ ruleTester.run("func-name-matching", rule, { { code: "module.exports = function foo(name) {};", options: [{ includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } ] @@ -605,7 +611,7 @@ ruleTester.run("func-name-matching", rule, { { code: "module.exports = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } ] @@ -613,7 +619,7 @@ ruleTester.run("func-name-matching", rule, { { code: "module.exports = function exports(name) {};", options: ["never", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "exports", name: "exports" } } ] @@ -621,7 +627,7 @@ ruleTester.run("func-name-matching", rule, { { code: "module['exports'] = function foo(name) {};", options: [{ includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } ] @@ -629,7 +635,7 @@ ruleTester.run("func-name-matching", rule, { { code: "module['exports'] = function foo(name) {};", options: ["always", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "exports" } } ] @@ -637,7 +643,7 @@ ruleTester.run("func-name-matching", rule, { { code: "module['exports'] = function exports(name) {};", options: ["never", { includeCommonJSModuleExports: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "exports", name: "exports" } } ] @@ -730,7 +736,7 @@ ruleTester.run("func-name-matching", rule, { // Optional chaining { code: "(obj?.aaa).foo = function bar() {};", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "bar", name: "foo" } } ] @@ -738,7 +744,7 @@ ruleTester.run("func-name-matching", rule, { { code: "Object?.defineProperty(foo, 'bar', { value: function baz() {} })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } ] @@ -746,7 +752,7 @@ ruleTester.run("func-name-matching", rule, { { code: "(Object?.defineProperty)(foo, 'bar', { value: function baz() {} })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } ] @@ -754,7 +760,7 @@ ruleTester.run("func-name-matching", rule, { { code: "Object?.defineProperty(foo, 'bar', { value: function bar() {} })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } ] @@ -762,7 +768,7 @@ ruleTester.run("func-name-matching", rule, { { code: "(Object?.defineProperty)(foo, 'bar', { value: function bar() {} })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } ] @@ -770,7 +776,7 @@ ruleTester.run("func-name-matching", rule, { { code: "Object?.defineProperties(foo, { bar: { value: function baz() {} } })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } ] @@ -778,7 +784,7 @@ ruleTester.run("func-name-matching", rule, { { code: "(Object?.defineProperties)(foo, { bar: { value: function baz() {} } })", options: ["always", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "matchProperty", data: { funcName: "baz", name: "bar" } } ] @@ -786,7 +792,7 @@ ruleTester.run("func-name-matching", rule, { { code: "Object?.defineProperties(foo, { bar: { value: function bar() {} } })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } ] @@ -794,7 +800,7 @@ ruleTester.run("func-name-matching", rule, { { code: "(Object?.defineProperties)(foo, { bar: { value: function bar() {} } })", options: ["never", { considerPropertyDescriptor: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "bar", name: "bar" } } ] @@ -804,7 +810,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { x = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } ] @@ -812,7 +818,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { x = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } ] @@ -820,7 +826,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { 'x' = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } ] @@ -828,7 +834,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { 'x' = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } ] @@ -836,7 +842,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { ['x'] = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } ] @@ -844,7 +850,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { ['x'] = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } ] @@ -852,7 +858,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { static x = function y() {}; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } ] @@ -860,7 +866,7 @@ ruleTester.run("func-name-matching", rule, { { code: "class C { static x = function x() {}; }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } ] @@ -868,7 +874,7 @@ ruleTester.run("func-name-matching", rule, { { code: "(class { x = function y() {}; })", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "matchProperty", data: { funcName: "y", name: "x" } } ] @@ -876,40 +882,14 @@ ruleTester.run("func-name-matching", rule, { { code: "(class { x = function x() {}; })", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "notMatchProperty", data: { funcName: "x", name: "x" } } ] }, { 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 - }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "matchProperty", data: { funcName: "foo", name: "\u1885" } } ] diff --git a/tests/lib/rules/func-names.js b/tests/lib/rules/func-names.js index 3341df7f016..c296c61eb0d 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,7 +400,7 @@ ruleTester.run("func-names", rule, { { code: "var {foo} = function(){};", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -412,7 +412,7 @@ ruleTester.run("func-names", rule, { { code: "({ a: obj.prop = function(){} } = foo);", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -424,7 +424,7 @@ ruleTester.run("func-names", rule, { { code: "[obj.prop = function(){}] = foo;", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -436,7 +436,7 @@ ruleTester.run("func-names", rule, { { code: "var { a: [b] = function(){} } = foo;", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -448,7 +448,7 @@ ruleTester.run("func-names", rule, { { code: "function foo({ a } = function(){}) {};", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -498,7 +498,7 @@ ruleTester.run("func-names", rule, { { code: "export default function() {}", options: ["always"], - parserOptions: { sourceType: "module", ecmaVersion: 6 }, + languageOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionDeclaration", @@ -509,7 +509,7 @@ ruleTester.run("func-names", rule, { { code: "export default function() {}", options: ["as-needed"], - parserOptions: { sourceType: "module", ecmaVersion: 6 }, + languageOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionDeclaration", @@ -520,7 +520,7 @@ ruleTester.run("func-names", rule, { { code: "export default (function(){});", options: ["as-needed"], - parserOptions: { sourceType: "module", ecmaVersion: 6 }, + languageOptions: { sourceType: "module", ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -533,7 +533,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -545,7 +545,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = function*() {};", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -557,7 +557,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -569,7 +569,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["always", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -581,7 +581,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = function*() {};", options: ["always", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -593,7 +593,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["always", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -605,7 +605,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["always", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -617,7 +617,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["always", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -629,7 +629,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -641,7 +641,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["as-needed"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -653,7 +653,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["as-needed", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -665,7 +665,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = function*() {};", options: ["as-needed", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -677,7 +677,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["as-needed", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -689,7 +689,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["as-needed", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -701,7 +701,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["as-needed", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -713,7 +713,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["never", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -725,7 +725,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = function*() {};", options: ["never", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -737,7 +737,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["never", { generators: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -749,7 +749,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *() {});", options: ["never", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -761,7 +761,7 @@ ruleTester.run("func-names", rule, { { code: "(function*() {}())", options: ["never", { generators: "as-needed" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnamed", type: "FunctionExpression", @@ -774,7 +774,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *baz() {});", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -787,7 +787,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *baz() {});", options: ["never", { generators: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -800,7 +800,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *baz() {});", options: ["always", { generators: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -813,7 +813,7 @@ ruleTester.run("func-names", rule, { { code: "var foo = bar(function *baz() {});", options: ["as-needed", { generators: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "named", data: { name: "generator function 'baz'" }, @@ -828,7 +828,7 @@ ruleTester.run("func-names", rule, { { code: "class C { foo = function() {} }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "method 'foo'" }, @@ -839,7 +839,7 @@ ruleTester.run("func-names", rule, { { code: "class C { [foo] = function() {} }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "method" }, @@ -850,7 +850,7 @@ ruleTester.run("func-names", rule, { { code: "class C { #foo = function() {} }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "private method #foo" }, @@ -861,7 +861,7 @@ ruleTester.run("func-names", rule, { { code: "class C { foo = bar(function() {}) }", options: ["as-needed"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnamed", data: { name: "function" }, @@ -872,7 +872,7 @@ ruleTester.run("func-names", rule, { { code: "class C { foo = function bar() {} }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "named", data: { name: "method 'foo'" }, diff --git a/tests/lib/rules/func-style.js b/tests/lib/rules/func-style.js index 0017c8627be..8ee8b481f78 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,7 +98,7 @@ ruleTester.run("func-style", rule, { { code: "var foo = () => {};", options: ["declaration"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "declaration", @@ -109,7 +109,7 @@ ruleTester.run("func-style", rule, { { code: "var foo = () => { function foo() { this; } };", options: ["declaration"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "declaration", diff --git a/tests/lib/rules/function-call-argument-newline.js b/tests/lib/rules/function-call-argument-newline.js index 85c908a135d..2e09ae63c29 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,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"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -228,7 +228,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`, b)", output: "fn(`\n`,\nb)", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -343,7 +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"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -379,7 +379,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`,\nb)", output: "fn(`\n`, b)", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -394,7 +394,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(a,/* comment */\nb)", output: "fn(a,/* comment */ b)", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -495,7 +495,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`,\nb, c)", output: "fn(`\n`,\nb,\nc)", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingLineBreak", @@ -510,7 +510,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`, b,\nc)", output: "fn(`\n`, b, c)", options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -525,7 +525,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(a,// comment\n{b, c})", output: null, options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", @@ -554,7 +554,7 @@ ruleTester.run("function-call-argument-newline", rule, { code: "fn(`\n`, b, // comment\nc)", output: null, options: ["consistent"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedLineBreak", diff --git a/tests/lib/rules/function-paren-newline.js b/tests/lib/rules/function-paren-newline.js index a8c7cc85827..322dcab87c7 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,7 +738,7 @@ ruleTester.run("function-paren-newline", rule, { output: ` async (foo, bar) => {}; `, - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { @@ -747,7 +749,7 @@ ruleTester.run("function-paren-newline", rule, { output: ` async (foo, bar) => {}; `, - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [RIGHT_UNEXPECTED_ERROR] }, { @@ -759,7 +761,7 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar\n) => {}; `, - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { @@ -773,13 +775,13 @@ ruleTester.run("function-paren-newline", rule, { foo, bar\n) => {}; `, - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [RIGHT_MISSING_ERROR] }, { code: "import(\n source\n)", output: "import(source)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, @@ -978,7 +980,7 @@ ruleTester.run("function-paren-newline", rule, { async (foo, bar) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [RIGHT_UNEXPECTED_ERROR] }, { @@ -991,7 +993,7 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { @@ -1006,21 +1008,21 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [RIGHT_MISSING_ERROR] }, { code: "import(source\n)", output: "import(source)", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [RIGHT_UNEXPECTED_ERROR] }, { code: "import(\n source)", output: "import(\n source\n)", options: ["multiline-arguments"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [RIGHT_MISSING_ERROR] }, @@ -1109,7 +1111,7 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar\n) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { @@ -1122,7 +1124,7 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { @@ -1137,14 +1139,14 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["always"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [RIGHT_MISSING_ERROR] }, { code: "import(source)", output: "import(\nsource\n)", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, @@ -1280,7 +1282,7 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["never"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { @@ -1294,14 +1296,14 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["never"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_UNEXPECTED_ERROR] }, { code: "import(\n source\n)", output: "import(source)", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, @@ -1356,7 +1358,7 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { @@ -1370,7 +1372,7 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_UNEXPECTED_ERROR] }, { @@ -1381,21 +1383,21 @@ ruleTester.run("function-paren-newline", rule, { async (\nfoo, bar, baz\n) => {}; `, options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, { code: "import(\n source\n)", output: "import(source)", options: [{ minItems: 3 }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] }, { code: "import(source)", output: "import(\nsource\n)", options: [{ minItems: 1 }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [LEFT_MISSING_ERROR, RIGHT_MISSING_ERROR] }, @@ -1439,7 +1441,7 @@ ruleTester.run("function-paren-newline", rule, { bar\n) => {}; `, options: ["consistent"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [RIGHT_MISSING_ERROR] }, { @@ -1453,21 +1455,21 @@ ruleTester.run("function-paren-newline", rule, { bar) => {}; `, options: ["consistent"], - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [RIGHT_UNEXPECTED_ERROR] }, { code: "import(source\n)", output: "import(source)", options: ["consistent"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [RIGHT_UNEXPECTED_ERROR] }, { code: "import(\n source)", output: "import(\n source\n)", options: ["consistent"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [RIGHT_MISSING_ERROR] }, @@ -1492,7 +1494,9 @@ ruleTester.run("function-paren-newline", rule, { method6(3, () => {}); `, options: ["never"], - parser: fixtureParser("function-paren-newline", "arrow-function-return-type"), + languageOptions: { + parser: require(fixtureParser("function-paren-newline", "arrow-function-return-type")) + }, errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] } ] 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..189a9f87073 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,30 +304,30 @@ ruleTester.run("getter-return", rule, { // Optional chaining { code: "Object?.defineProperty(foo, 'bar', { get: function (){} });", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "(Object?.defineProperty)(foo, 'bar', { get: function (){} });", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "Object?.defineProperty(foo, 'bar', { get: function (){} });", options, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "(Object?.defineProperty)(foo, 'bar', { get: function (){} });", options, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expected", data: { name: "method 'get'" } }] }, { code: "(Object?.create)(foo, { bar: { get: function (){} } });", options, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expected", data: { name: "method 'get'" } }] } ] 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..be7ce392351 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,7 +438,7 @@ ruleTester.run("grouped-accessor-pairs", rule, { }, { code: "class A { get a(){} a; set a(foo){} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "notGrouped", data: { formerName: "getter 'a'", latterName: "setter 'a'" }, type: "MethodDefinition", column: 24 }] }, 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..cf2620db210 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) => {};", 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 4d13459acf6..f29afcc6765 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,7 +251,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -246,7 +259,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -254,7 +267,7 @@ ruleTester.run("id-blacklist", rule, { { code: "export * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ error ] @@ -262,7 +275,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -270,7 +283,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -281,7 +294,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -292,7 +305,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -303,7 +316,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -314,7 +327,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -325,7 +338,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import foo, { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -336,7 +349,7 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo; export { foo as bar };", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -347,7 +360,7 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo; export { foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -366,7 +379,7 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo; export { foo as bar };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -387,7 +400,7 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo; export { foo as foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -412,7 +425,7 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo; export { foo as bar };", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -437,7 +450,7 @@ ruleTester.run("id-blacklist", rule, { { code: "export { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -445,7 +458,7 @@ ruleTester.run("id-blacklist", rule, { { code: "export { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -456,7 +469,7 @@ ruleTester.run("id-blacklist", rule, { { code: "export { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -467,7 +480,7 @@ ruleTester.run("id-blacklist", rule, { { code: "export { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -478,7 +491,7 @@ ruleTester.run("id-blacklist", rule, { { code: "export { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -489,7 +502,7 @@ ruleTester.run("id-blacklist", rule, { { code: "export { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -630,7 +643,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const {foo} = baz", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -643,7 +656,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const {foo: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -656,7 +669,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const {[foo]: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -675,7 +688,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -688,7 +701,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const {foo: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -707,7 +720,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const {[foo]: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -732,7 +745,7 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo({ bar: baz }) {}", options: ["bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -745,7 +758,7 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -758,7 +771,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({foo: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -771,7 +784,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -784,7 +797,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({[foo]: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -803,7 +816,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({foo: { a: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -816,7 +829,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({a: obj.bar = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -829,7 +842,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({a: obj.bar.bar.baz = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -842,7 +855,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({a: obj[bar] = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -855,7 +868,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({a: [obj.bar] = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -868,7 +881,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({foo: { a: obj.bar = baz}} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -881,7 +894,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({foo: { [a]: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -894,7 +907,7 @@ ruleTester.run("id-blacklist", rule, { { code: "({...obj.bar} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "restricted", @@ -907,7 +920,7 @@ ruleTester.run("id-blacklist", rule, { { code: "([obj.bar] = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -920,7 +933,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const [bar] = baz;", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -969,7 +982,7 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = { Number() {} };", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -981,7 +994,7 @@ ruleTester.run("id-blacklist", rule, { { code: "class Foo { Number() {} }", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -993,7 +1006,9 @@ ruleTester.run("id-blacklist", rule, { { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1014,7 +1029,7 @@ ruleTester.run("id-blacklist", rule, { { code: "const foo = 1; bar = foo;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1033,7 +1048,7 @@ ruleTester.run("id-blacklist", rule, { { code: "let foo; foo = bar;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1088,7 +1103,7 @@ ruleTester.run("id-blacklist", rule, { { code: "class Foo {} var bar = Foo;", options: ["Foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1109,7 +1124,7 @@ ruleTester.run("id-blacklist", rule, { { code: "let undefined; undefined = 1;", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1164,7 +1179,7 @@ ruleTester.run("id-blacklist", rule, { { code: "class Number {} x = Number.NaN;", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1188,7 +1203,11 @@ ruleTester.run("id-blacklist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], - env: { browser: true }, + languageOptions: { + globals: { + window: "readonly" + } + }, errors: [ { messageId: "restricted", @@ -1203,7 +1222,9 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = undefined;", options: ["undefined"], - globals: { undefined: "off" }, + languageOptions: { + globals: { undefined: "off" } + }, errors: [ { messageId: "restricted", @@ -1239,7 +1260,7 @@ ruleTester.run("id-blacklist", rule, { { code: "if (foo) { let undefined; bar = undefined; }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1276,7 +1297,9 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1295,7 +1318,7 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1314,7 +1337,7 @@ ruleTester.run("id-blacklist", rule, { { code: "import Number from 'myNumber'; const foo = Number.parseInt(bar);", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1346,7 +1369,7 @@ ruleTester.run("id-blacklist", rule, { { code: "var foo = { undefined }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", diff --git a/tests/lib/rules/id-denylist.js b/tests/lib/rules/id-denylist.js index 4e8248399e4..4ffab3ea07a 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,7 +265,7 @@ ruleTester.run("id-denylist", rule, { { code: "import foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -258,7 +273,7 @@ ruleTester.run("id-denylist", rule, { { code: "import * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -266,7 +281,7 @@ ruleTester.run("id-denylist", rule, { { code: "export * as foo from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ error ] @@ -274,7 +289,7 @@ ruleTester.run("id-denylist", rule, { { code: "import { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -282,7 +297,7 @@ ruleTester.run("id-denylist", rule, { { code: "import { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -293,7 +308,7 @@ ruleTester.run("id-denylist", rule, { { code: "import { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -304,7 +319,7 @@ ruleTester.run("id-denylist", rule, { { code: "import { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -315,7 +330,7 @@ ruleTester.run("id-denylist", rule, { { code: "import { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -326,7 +341,7 @@ ruleTester.run("id-denylist", rule, { { code: "import { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -337,7 +352,7 @@ ruleTester.run("id-denylist", rule, { { code: "import foo, { foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -348,7 +363,7 @@ ruleTester.run("id-denylist", rule, { { code: "var foo; export { foo as bar };", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -359,7 +374,7 @@ ruleTester.run("id-denylist", rule, { { code: "var foo; export { foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -378,7 +393,7 @@ ruleTester.run("id-denylist", rule, { { code: "var foo; export { foo as bar };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -399,7 +414,7 @@ ruleTester.run("id-denylist", rule, { { code: "var foo; export { foo as foo };", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -424,7 +439,7 @@ ruleTester.run("id-denylist", rule, { { code: "var foo; export { foo as bar };", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -449,7 +464,7 @@ ruleTester.run("id-denylist", rule, { { code: "export { foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ error ] @@ -457,7 +472,7 @@ ruleTester.run("id-denylist", rule, { { code: "export { foo as bar } from 'mod'", options: ["bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -468,7 +483,7 @@ ruleTester.run("id-denylist", rule, { { code: "export { foo as bar } from 'mod'", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "bar" }, @@ -479,7 +494,7 @@ ruleTester.run("id-denylist", rule, { { code: "export { foo as foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -490,7 +505,7 @@ ruleTester.run("id-denylist", rule, { { code: "export { foo, foo as bar } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -501,7 +516,7 @@ ruleTester.run("id-denylist", rule, { { code: "export { foo as bar, foo } from 'mod'", options: ["foo"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "restricted", data: { name: "foo" }, @@ -642,7 +657,7 @@ ruleTester.run("id-denylist", rule, { { code: "const {foo} = baz", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -655,7 +670,7 @@ ruleTester.run("id-denylist", rule, { { code: "const {foo: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -668,7 +683,7 @@ ruleTester.run("id-denylist", rule, { { code: "const {[foo]: bar} = baz", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -687,7 +702,7 @@ ruleTester.run("id-denylist", rule, { { code: "const {foo: {bar: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -700,7 +715,7 @@ ruleTester.run("id-denylist", rule, { { code: "const {foo: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -719,7 +734,7 @@ ruleTester.run("id-denylist", rule, { { code: "const {[foo]: {[bar]: baz}} = qux", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -744,7 +759,7 @@ ruleTester.run("id-denylist", rule, { { code: "function foo({ bar: baz }) {}", options: ["bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -757,7 +772,7 @@ ruleTester.run("id-denylist", rule, { { code: "function foo({ bar: {baz: qux} }) {}", options: ["bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -770,7 +785,7 @@ ruleTester.run("id-denylist", rule, { { code: "({foo: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -783,7 +798,7 @@ ruleTester.run("id-denylist", rule, { { code: "({foo: obj.bar.bar.bar.baz} = {});", options: ["foo", "bar", "baz"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -796,7 +811,7 @@ ruleTester.run("id-denylist", rule, { { code: "({[foo]: obj.bar} = baz);", options: ["foo", "bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -815,7 +830,7 @@ ruleTester.run("id-denylist", rule, { { code: "({foo: { a: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -828,7 +843,7 @@ ruleTester.run("id-denylist", rule, { { code: "({a: obj.bar = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -841,7 +856,7 @@ ruleTester.run("id-denylist", rule, { { code: "({a: obj.bar.bar.baz = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -854,7 +869,7 @@ ruleTester.run("id-denylist", rule, { { code: "({a: obj[bar] = obj.qux} = obj.qux);", options: ["a", "bar", "baz", "qux"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -867,7 +882,7 @@ ruleTester.run("id-denylist", rule, { { code: "({a: [obj.bar] = baz} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -880,7 +895,7 @@ ruleTester.run("id-denylist", rule, { { code: "({foo: { a: obj.bar = baz}} = qux);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -893,7 +908,7 @@ ruleTester.run("id-denylist", rule, { { code: "({foo: { [a]: obj.bar }} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -906,7 +921,7 @@ ruleTester.run("id-denylist", rule, { { code: "({...obj.bar} = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "restricted", @@ -919,7 +934,7 @@ ruleTester.run("id-denylist", rule, { { code: "([obj.bar] = baz);", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -932,7 +947,7 @@ ruleTester.run("id-denylist", rule, { { code: "const [bar] = baz;", options: ["bar"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -981,7 +996,7 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = { Number() {} };", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -993,7 +1008,7 @@ ruleTester.run("id-denylist", rule, { { code: "class Foo { Number() {} }", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1005,7 +1020,9 @@ ruleTester.run("id-denylist", rule, { { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1026,7 +1043,7 @@ ruleTester.run("id-denylist", rule, { { code: "const foo = 1; bar = foo;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1045,7 +1062,7 @@ ruleTester.run("id-denylist", rule, { { code: "let foo; foo = bar;", options: ["foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1100,7 +1117,7 @@ ruleTester.run("id-denylist", rule, { { code: "class Foo {} var bar = Foo;", options: ["Foo"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1121,7 +1138,7 @@ ruleTester.run("id-denylist", rule, { { code: "let undefined; undefined = 1;", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1176,7 +1193,7 @@ ruleTester.run("id-denylist", rule, { { code: "class Number {} x = Number.NaN;", options: ["Number"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1200,7 +1217,11 @@ ruleTester.run("id-denylist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], - env: { browser: true }, + languageOptions: { + globals: { + window: "readonly" + } + }, errors: [ { messageId: "restricted", @@ -1215,7 +1236,9 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = undefined;", options: ["undefined"], - globals: { undefined: "off" }, + languageOptions: { + globals: { undefined: "off" } + }, errors: [ { messageId: "restricted", @@ -1251,7 +1274,7 @@ ruleTester.run("id-denylist", rule, { { code: "if (foo) { let undefined; bar = undefined; }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1288,7 +1311,9 @@ ruleTester.run("id-denylist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, + languageOptions: { + globals: { myGlobal: "readonly" } + }, errors: [ { messageId: "restricted", @@ -1307,7 +1332,7 @@ ruleTester.run("id-denylist", rule, { { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1326,7 +1351,7 @@ ruleTester.run("id-denylist", rule, { { code: "import Number from 'myNumber'; const foo = Number.parseInt(bar);", options: ["Number"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "restricted", @@ -1358,7 +1383,7 @@ ruleTester.run("id-denylist", rule, { { code: "var foo = { undefined }", options: ["undefined"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "restricted", @@ -1372,7 +1397,7 @@ ruleTester.run("id-denylist", rule, { { code: "class C { camelCase; #camelCase; #camelCase2() {} }", options: ["camelCase"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "restricted", @@ -1390,7 +1415,7 @@ ruleTester.run("id-denylist", rule, { { code: "class C { snake_case; #snake_case() {}; #snake_case2() {} }", options: ["snake_case"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "restricted", diff --git a/tests/lib/rules/id-length.js b/tests/lib/rules/id-length.js index 871db908f92..5dfcb226d54 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;", 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,49 +269,49 @@ ruleTester.run("id-length", rule, { }, { code: "(a) => { a * a };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "function foo(x = 0) { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "class x { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "class Foo { x() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "function foo(...x) { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "function foo({x}) { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "function foo({x: a}) { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -322,7 +322,7 @@ ruleTester.run("id-length", rule, { }, { code: "function foo({x: a, longName}) { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] @@ -330,7 +330,7 @@ ruleTester.run("id-length", rule, { { code: "function foo({ longName: a }) {}", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] @@ -338,7 +338,7 @@ ruleTester.run("id-length", rule, { { code: "function foo({ prop: longName }) {};", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooLongError ] @@ -346,7 +346,7 @@ ruleTester.run("id-length", rule, { { code: "function foo({ a: b }) {};", options: [{ exceptions: ["a"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -372,7 +372,7 @@ ruleTester.run("id-length", rule, { }, { code: "function foo({ a: { b: { c: d, e } } }) { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -392,14 +392,14 @@ ruleTester.run("id-length", rule, { }, { code: "var { x} = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "var { x: a} = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -410,14 +410,14 @@ ruleTester.run("id-length", rule, { }, { code: "var { a: a} = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "var { prop: a } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] @@ -425,21 +425,21 @@ ruleTester.run("id-length", rule, { { code: "var { longName: a } = {};", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "var { prop: [x] } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "var { prop: [[x]] } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] @@ -447,7 +447,7 @@ ruleTester.run("id-length", rule, { { code: "var { prop: longName } = {};", options: [{ min: 3, max: 5 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooLong", @@ -461,7 +461,7 @@ ruleTester.run("id-length", rule, { { code: "var { x: a} = {};", options: [{ exceptions: ["x"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -474,7 +474,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { a: { b: { c: d } } } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -487,7 +487,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { a: { b: { c: d, e } } } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -507,7 +507,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { a: { b: { c, e: longName } } } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -520,7 +520,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { a: { b: { c: d, e: longName } } } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -533,7 +533,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { a, b: { c: d, e: longName } } = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -553,21 +553,21 @@ ruleTester.run("id-length", rule, { }, { code: "import x from 'y';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ tooShortError ] }, { code: "export var x = 0;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ tooShortError ] }, { code: "({ a: obj.x.y.z } = {});", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -580,7 +580,7 @@ ruleTester.run("id-length", rule, { }, { code: "({ prop: obj.x } = {});", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -595,7 +595,7 @@ ruleTester.run("id-length", rule, { { code: "var {prop: x} = foo;", options: [{ properties: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "tooShort", @@ -609,7 +609,7 @@ ruleTester.run("id-length", rule, { { code: "var foo = {x: prop};", options: [{ properties: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] @@ -639,21 +639,21 @@ ruleTester.run("id-length", rule, { // Class Fields { code: "class Foo { #x() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ tooShortErrorPrivate ] }, { code: "class Foo { x = 1 }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ tooShortError ] }, { code: "class Foo { #x = 1 }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ tooShortErrorPrivate ] @@ -661,7 +661,7 @@ ruleTester.run("id-length", rule, { { code: "class Foo { #abcdefg() {} }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ tooLongErrorPrivate ] @@ -669,7 +669,7 @@ ruleTester.run("id-length", rule, { { code: "class Foo { abcdefg = 1 }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ tooLongError ] @@ -677,7 +677,7 @@ ruleTester.run("id-length", rule, { { code: "class Foo { #abcdefg = 1 }", options: [{ max: 3 }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ tooLongErrorPrivate ] @@ -686,21 +686,21 @@ ruleTester.run("id-length", rule, { // Identifier consisting of two code units { code: "var 𠮟 = 2", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "var 葛󠄀 = 2", // 2 code points but only 1 grapheme - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ tooShortError ] }, { code: "var myObj = { 𐌘: 1 };", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -709,7 +709,7 @@ ruleTester.run("id-length", rule, { }, { code: "(𐌘) => { 𐌘 * 𐌘 };", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -718,7 +718,7 @@ ruleTester.run("id-length", rule, { }, { code: "class 𠮟 { }", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -727,7 +727,7 @@ ruleTester.run("id-length", rule, { }, { code: "class Foo { 𐌘() {} }", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -736,7 +736,7 @@ ruleTester.run("id-length", rule, { }, { code: "class Foo1 { #𐌘() {} }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [ @@ -745,7 +745,7 @@ ruleTester.run("id-length", rule, { }, { code: "class Foo2 { 𐌘 = 1 }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [ @@ -754,7 +754,7 @@ ruleTester.run("id-length", rule, { }, { code: "class Foo3 { #𐌘 = 1 }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [ @@ -763,7 +763,7 @@ ruleTester.run("id-length", rule, { }, { code: "function foo1(...𐌘) { }", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -772,7 +772,7 @@ ruleTester.run("id-length", rule, { }, { code: "function foo([𐌘]) { }", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -781,7 +781,7 @@ ruleTester.run("id-length", rule, { }, { code: "var [ 𐌘 ] = arr;", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -790,7 +790,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { prop: [𐌘]} = {};", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -799,7 +799,7 @@ ruleTester.run("id-length", rule, { }, { code: "function foo({𐌘}) { }", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -808,7 +808,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { 𐌘 } = {};", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -817,7 +817,7 @@ ruleTester.run("id-length", rule, { }, { code: "var { prop: 𐌘} = {};", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -826,7 +826,7 @@ ruleTester.run("id-length", rule, { }, { code: "({ prop: obj.𐌘 } = {});", - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ diff --git a/tests/lib/rules/id-match.js b/tests/lib/rules/id-match.js index 7e469bd4d5b..7d4cec1b851 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,7 +407,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_alias' does not match the pattern '^[^_]+$'.", @@ -421,7 +421,7 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_alias' does not match the pattern '^[^_]+$'.", @@ -435,7 +435,7 @@ ruleTester.run("id-match", rule, { properties: true, ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "Identifier 'other_props' does not match the pattern '^[^_]+$'.", @@ -448,7 +448,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_id' does not match the pattern '^[^_]+$'.", @@ -461,7 +461,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'category_id' does not match the pattern '^[^_]+$'.", @@ -474,7 +474,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -487,7 +487,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -498,7 +498,7 @@ ruleTester.run("id-match", rule, { { code: "export * as no_camelcased from \"external-module\";", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -511,7 +511,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -524,7 +524,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camel_cased' does not match the pattern '^[^_]+$'.", @@ -537,7 +537,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camel_cased' does not match the pattern '^[^_]+$'.", @@ -550,7 +550,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -563,7 +563,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'another_no_camelcased' does not match the pattern '^[^_]+$'.", @@ -576,7 +576,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -589,7 +589,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -602,7 +602,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -615,7 +615,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -628,7 +628,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -645,7 +645,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -658,7 +658,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'my_default' does not match the pattern '^[^_]+$'.", @@ -671,7 +671,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -684,7 +684,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'bar_baz' does not match the pattern '^[^_]+$'.", @@ -697,7 +697,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' does not match the pattern '^[^_]+$'.", @@ -723,7 +723,7 @@ ruleTester.run("id-match", rule, { options: ["^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$", { properties: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'foo_variable' does not match the pattern '^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$'.", @@ -780,7 +780,7 @@ ruleTester.run("id-match", rule, { { code: "class x { _foo() {} }", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '_foo' does not match the pattern '^[^_]+$'.", @@ -791,7 +791,7 @@ ruleTester.run("id-match", rule, { { code: "class x { #_foo() {} }", options: ["^[^_]+$"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '#_foo' does not match the pattern '^[^_]+$'.", @@ -806,7 +806,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { classFields: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '_foo' does not match the pattern '^[^_]+$'.", @@ -819,7 +819,7 @@ ruleTester.run("id-match", rule, { options: ["^[^_]+$", { classFields: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier '#_foo' does not match the pattern '^[^_]+$'.", @@ -841,7 +841,7 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.", @@ -865,7 +865,7 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.", @@ -887,7 +887,7 @@ ruleTester.run("id-match", rule, { properties: true, onlyDeclarations: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'a' does not match the pattern '^[^a]'.", @@ -907,7 +907,7 @@ ruleTester.run("id-match", rule, { properties: false, onlyDeclarations: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { message: "Identifier 'a' does not match the pattern '^[^a]'.", diff --git a/tests/lib/rules/implicit-arrow-linebreak.js b/tests/lib/rules/implicit-arrow-linebreak.js index c65d4750a7d..7f081197853 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,7 +399,7 @@ ruleTester.run("implicit-arrow-linebreak", rule, { 'string' `, output: null, - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [UNEXPECTED_LINEBREAK] }, { code: unIndent` @@ -409,7 +409,7 @@ ruleTester.run("implicit-arrow-linebreak", rule, { bar; `, output: null, - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [UNEXPECTED_LINEBREAK] }, { code: unIndent` @@ -418,7 +418,7 @@ ruleTester.run("implicit-arrow-linebreak", rule, { 'string' `, output: null, - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [UNEXPECTED_LINEBREAK] }, { code: unIndent` diff --git a/tests/lib/rules/indent-legacy.js b/tests/lib/rules/indent-legacy.js index e3295e1f3da..923d3e08399 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,7 +2281,7 @@ ruleTester.run("indent-legacy", rule, { " .bar\n" + "}", options: [4, { MemberExpression: 2 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors( [3, 12, 13, "Punctuator"] ) @@ -2297,7 +2302,7 @@ ruleTester.run("indent-legacy", rule, { " });\n" + "};", options: [2, { MemberExpression: 1 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors( [ [3, 4, 6, "Punctuator"] @@ -2432,7 +2437,7 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 2, "ExpressionStatement"] @@ -2449,7 +2454,7 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 2, "ReturnStatement"] @@ -2466,7 +2471,7 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([[2, 4, 0, "Identifier"]]) }, { @@ -2479,7 +2484,7 @@ ruleTester.run("indent-legacy", rule, { " index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "ExpressionStatement"] ]) @@ -2494,7 +2499,7 @@ ruleTester.run("indent-legacy", rule, { " return index;\n" + "});\n", options: [4], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "ReturnStatement"] ]) @@ -2571,7 +2576,7 @@ ruleTester.run("indent-legacy", rule, { " 'c'\n" + "];", options: [4], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 9, "Literal"], [3, 4, 9, "Literal"], @@ -2693,7 +2698,7 @@ ruleTester.run("indent-legacy", rule, { "let geometry,\n" + " rotate;", options: [2, { VariableDeclarator: 2 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 4, 2, "VariableDeclarator"] ]) @@ -2760,7 +2765,7 @@ ruleTester.run("indent-legacy", rule, { " b\n" + "]", options: [2, { VariableDeclarator: { let: 2 }, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [2, 2, 4, "Identifier"], [3, 2, 4, "Identifier"] @@ -2803,7 +2808,7 @@ ruleTester.run("indent-legacy", rule, { " }),\n" + " d = 4;\n", options: [2, { VariableDeclarator: { var: 2 } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([ [6, 4, 6, "Property"], [7, 2, 4, "ObjectExpression"], @@ -2897,7 +2902,7 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "}", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([[2, 4, 2, "MethodDefinition"]]) }, { @@ -2914,7 +2919,7 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + "};", options: [4, { VariableDeclarator: 1, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([[2, 4, 2, "MethodDefinition"], [4, 4, 2, "MethodDefinition"]]) }, { @@ -2933,7 +2938,7 @@ ruleTester.run("indent-legacy", rule, { " get b(){}\n" + " };", options: [2, { VariableDeclarator: 2, SwitchCase: 1 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedErrors([[3, 6, 4, "MethodDefinition"]]) }, { @@ -3681,7 +3686,7 @@ ruleTester.run("indent-legacy", rule, { "return (\n" + " foo\n" + ");", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: expectedErrors([3, 0, 4, "ReturnStatement"]) }, { @@ -3693,7 +3698,7 @@ ruleTester.run("indent-legacy", rule, { "return (\n" + " foo\n" + ")", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: expectedErrors([3, 0, 4, "ReturnStatement"]) }, diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 4880fa5ec02..6f5ca1fae38 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,7 +8816,7 @@ ruleTester.run("indent", rule, { foo ); `, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { @@ -8822,7 +8830,7 @@ ruleTester.run("indent", rule, { foo ) `, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: expectedErrors([3, 0, 4, "Punctuator"]) }, @@ -9301,7 +9309,7 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 2, "Identifier"]]) }, { @@ -9318,7 +9326,7 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [4, { ImportDeclaration: "first" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([[3, 9, 10, "Identifier"]]) }, { @@ -9335,7 +9343,7 @@ ruleTester.run("indent", rule, { } from 'qux'; `, options: [2, { ImportDeclaration: 2 }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([[3, 4, 5, "Identifier"]]) }, { @@ -9355,7 +9363,7 @@ ruleTester.run("indent", rule, { baz }; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]) }, { @@ -9375,7 +9383,7 @@ ruleTester.run("indent", rule, { baz } from 'qux'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]]) }, { @@ -9813,7 +9821,7 @@ ruleTester.run("indent", rule, { baz } `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 8, "Identifier"], [5, 4, 2, "Identifier"]]) }, { @@ -10185,7 +10193,7 @@ ruleTester.run("indent", rule, { import {foo} from 'bar'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([2, 4, 0, "Identifier"]) }, { @@ -10197,7 +10205,7 @@ ruleTester.run("indent", rule, { export {foo} from 'bar'; `, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedErrors([2, 4, 0, "Identifier"]) }, { @@ -10415,7 +10423,7 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-invalid"), + languageOptions: { parser: require(parser("unknown-nodes/namespace-invalid")) }, errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]) }, { @@ -10447,7 +10455,7 @@ ruleTester.run("indent", rule, { } } `, - parser: 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"]]) }, { @@ -10477,7 +10485,7 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/functions-with-abstract-class-invalid"), + languageOptions: { parser: require(parser("unknown-nodes/functions-with-abstract-class-invalid")) }, errors: expectedErrors([ [4, 12, 8, "Keyword"], [5, 16, 8, "Keyword"], @@ -10517,7 +10525,7 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid"), + languageOptions: { parser: require(parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid")) }, errors: expectedErrors([ [3, 8, 4, "Keyword"], [7, 24, 20, "Identifier"] @@ -11322,7 +11330,7 @@ ruleTester.run("indent", rule, { foo }: bar) => baz `, - parser: require.resolve("../../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"]) }, { @@ -11336,7 +11344,7 @@ ruleTester.run("indent", rule, { foo ]: bar) => baz `, - parser: require.resolve("../../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"]) }, { @@ -11350,7 +11358,7 @@ ruleTester.run("indent", rule, { foo }: {}) => baz `, - parser: require.resolve("../../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"]) }, { @@ -11844,7 +11852,7 @@ ruleTester.run("indent", rule, { source ) `, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 0, 4, "Punctuator"] @@ -11875,7 +11883,7 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 4, "Identifier"] ]) @@ -11903,7 +11911,7 @@ ruleTester.run("indent", rule, { }); } `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 8, "Identifier"], [7, 8, 12, "Identifier"], @@ -11949,7 +11957,7 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 12, "Identifier"], [15, 8, 12, "Identifier"], @@ -11995,7 +12003,7 @@ ruleTester.run("indent", rule, { }); } `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [7, 8, 12, "Identifier"], [15, 8, 12, "Identifier"], @@ -12035,7 +12043,7 @@ ruleTester.run("indent", rule, { }); }); `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 4, 0, "Identifier"], [11, 8, 4, "Identifier"] @@ -12068,7 +12076,7 @@ ruleTester.run("indent", rule, { }) }); `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [4, 4, 8, "Identifier"], [5, 4, 0, "Identifier"], @@ -12086,7 +12094,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 8, "Identifier"] ]) @@ -12102,7 +12110,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 0, 4, "Punctuator"] @@ -12123,7 +12131,7 @@ ruleTester.run("indent", rule, { baz(); }) `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 4, 0, "Punctuator"] ]) @@ -12145,7 +12153,7 @@ ruleTester.run("indent", rule, { bar(); }) `, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [5, 8, 0, "Identifier"] ]) @@ -12168,7 +12176,7 @@ ruleTester.run("indent", rule, { }) `, options: [4, { MemberExpression: 0 }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: expectedErrors([ [2, 0, 4, "Punctuator"], [5, 4, 0, "Identifier"], @@ -12193,7 +12201,7 @@ ruleTester.run("indent", rule, { [key] `, options: [4], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 4, 0, "Punctuator"], @@ -12221,7 +12229,7 @@ ruleTester.run("indent", rule, { ?.[key] `, options: [4], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [6, 4, 0, "Punctuator"], [7, 4, 0, "Punctuator"] @@ -12241,7 +12249,7 @@ ruleTester.run("indent", rule, { (arg) `, options: [4], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 4, 0, "Punctuator"], @@ -12268,7 +12276,7 @@ ruleTester.run("indent", rule, { ?.(arg) `, options: [4], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [6, 4, 0, "Punctuator"], [7, 4, 0, "Punctuator"] @@ -12290,7 +12298,7 @@ ruleTester.run("indent", rule, { } `, options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: expectedErrors([ [2, 19, 20, "Identifier"] ]) @@ -12323,7 +12331,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 4, 0, "Keyword"] @@ -12357,7 +12365,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 8, 0, "Punctuator"], @@ -12418,7 +12426,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Punctuator"], [3, 8, 0, "Identifier"], @@ -12459,7 +12467,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 8, 0, "Identifier"], @@ -12484,7 +12492,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "PrivateIdentifier"], [3, 4, 0, "Identifier"], @@ -12510,7 +12518,7 @@ ruleTester.run("indent", rule, { } `, options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 2, 0, "Keyword"], [3, 4, 0, "Identifier"], @@ -12536,7 +12544,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Identifier"], @@ -12562,7 +12570,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 8, "Keyword"], [3, 8, 4, "Identifier"], @@ -12588,7 +12596,7 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 12, 0, "Identifier"], @@ -12614,7 +12622,7 @@ ruleTester.run("indent", rule, { } `, options: [4, { StaticBlock: { body: 0 } }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Identifier"], @@ -12640,7 +12648,7 @@ ruleTester.run("indent", rule, { } `, options: ["tab"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors("tab", [ [2, 1, 0, "Keyword"], [3, 2, 0, "Identifier"], @@ -12666,7 +12674,7 @@ ruleTester.run("indent", rule, { } `, options: ["tab", { StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors("tab", [ [2, 1, 0, "Keyword"], [3, 3, 0, "Identifier"], @@ -12694,7 +12702,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Punctuator"], @@ -12723,7 +12731,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 8, "Punctuator"], [6, 4, 8, "Punctuator"] @@ -12747,7 +12755,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], @@ -12775,7 +12783,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 4, 0, "Punctuator"], @@ -12804,7 +12812,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], @@ -12833,7 +12841,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Punctuator"], @@ -12868,7 +12876,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [4, 4, 0, "Keyword"], @@ -12906,7 +12914,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Keyword"], [4, 8, 4, "Identifier"], @@ -12944,7 +12952,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Identifier"], [5, 4, 0, "Keyword"], @@ -12989,7 +12997,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [3, 4, 0, "Identifier"], [4, 8, 4, "Identifier"], @@ -13024,7 +13032,7 @@ ruleTester.run("indent", rule, { } `, options: [4], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Keyword"], [3, 8, 0, "Keyword"], @@ -13056,7 +13064,7 @@ ruleTester.run("indent", rule, { } `, options: [4, { FunctionExpression: { body: 2 }, StaticBlock: { body: 2 } }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedErrors([ [2, 4, 0, "Identifier"], [3, 12, 0, "Identifier"], diff --git a/tests/lib/rules/init-declarations.js b/tests/lib/rules/init-declarations.js index 556086abac7..40e30269056 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,7 @@ ruleTester.run("init-declarations", rule, { { code: "var foo, bar = false, baz;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -151,7 +151,7 @@ ruleTester.run("init-declarations", rule, { { code: "function foo() { var foo = 0; var bar; }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -163,7 +163,7 @@ ruleTester.run("init-declarations", rule, { { code: "function foo() { var foo; var bar = foo; }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -175,7 +175,7 @@ ruleTester.run("init-declarations", rule, { { code: "let a;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -187,7 +187,7 @@ ruleTester.run("init-declarations", rule, { { code: "function foo() { let a = 1, b; if (a) { let c = 3, d = null; } }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -199,7 +199,7 @@ ruleTester.run("init-declarations", rule, { { code: "function foo() { let a; const b = false; var c; }", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "initialized", @@ -216,7 +216,7 @@ ruleTester.run("init-declarations", rule, { { code: "var foo = bar = 2;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -228,7 +228,7 @@ ruleTester.run("init-declarations", rule, { { code: "var foo = true;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -240,7 +240,7 @@ ruleTester.run("init-declarations", rule, { { code: "var foo, bar = 5, baz = 3;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -257,7 +257,7 @@ ruleTester.run("init-declarations", rule, { { code: "function foo() { var foo; var bar = foo; }", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -270,7 +270,7 @@ ruleTester.run("init-declarations", rule, { { code: "let a = 1;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -282,7 +282,7 @@ ruleTester.run("init-declarations", rule, { { code: "function foo() { let a = 'foo', b; if (a) { let c, d; } }", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -294,7 +294,7 @@ ruleTester.run("init-declarations", rule, { { code: "function foo() { let a; const b = false; var c = 1; }", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", @@ -328,7 +328,7 @@ ruleTester.run("init-declarations", rule, { { code: "for (var foo of []) {}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "notInitialized", 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..e841a069552 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,7 +587,7 @@ ruleTester.run("key-spacing", rule, { afterColon: false } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [] }, { 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,7 +1191,7 @@ ruleTester.run("key-spacing", rule, { code: "var obj = { [ (a + b) ]:value };", output: "var obj = { [ (a + b) ]: value };", options: [{}], - parserOptions: { 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 });", @@ -1310,7 +1310,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, + 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 }, @@ -1506,7 +1506,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" } ] @@ -1526,7 +1526,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 11, type: "Literal" } ] @@ -1546,7 +1546,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" } ] @@ -1566,7 +1566,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 11, type: "Literal" } ] @@ -1594,7 +1594,7 @@ ruleTester.run("key-spacing", rule, { "};" ].join("\n"), options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "baz" }, line: 6, column: 8, type: "Literal" } ] @@ -1742,7 +1742,7 @@ ruleTester.run("key-spacing", rule, { "})" ].join("\n"), options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 2018 }, + 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" } @@ -1960,7 +1960,7 @@ ruleTester.run("key-spacing", rule, { code: "({ a:b, ...object, c : d })", output: "({ a: b, ...object, c: d })", options: [{ align: "colon" }], - parserOptions: { ecmaVersion: 2018 }, + 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" } @@ -1991,7 +1991,7 @@ ruleTester.run("key-spacing", rule, { mode: "strict" } }], - parserOptions: { ecmaVersion: 6 }, + 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" }, @@ -2039,7 +2039,7 @@ ruleTester.run("key-spacing", rule, { mode: "strict" } }], - parserOptions: { ecmaVersion: 6 }, + 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" }, @@ -2088,7 +2088,7 @@ ruleTester.run("key-spacing", rule, { } } }], - parserOptions: { ecmaVersion: 6 }, + 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" }, @@ -2130,7 +2130,7 @@ ruleTester.run("key-spacing", rule, { } } }], - parserOptions: { ecmaVersion: 6 }, + 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" } @@ -2168,7 +2168,7 @@ ruleTester.run("key-spacing", rule, { on: "colon" } }], - parserOptions: { ecmaVersion: 6 }, + 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" } @@ -2413,7 +2413,7 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingValue", data: { computed: "", key: "a" }, line: 3, column: 22, type: "Literal" } ] @@ -2436,7 +2436,7 @@ ruleTester.run("key-spacing", rule, { on: "colon" } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 17, type: "Literal" } ] @@ -2459,7 +2459,7 @@ ruleTester.run("key-spacing", rule, { on: "value" } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "extraValue", data: { computed: "", key: "a" }, line: 3, column: 20, type: "Literal" } ] @@ -2518,7 +2518,7 @@ ruleTester.run("key-spacing", rule, { options: [{ align: "value" }], - parserOptions: { ecmaVersion: 6 }, + 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" }, diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js index 97d198f56fc..c179a8b22cc 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,28 +1527,28 @@ ruleTester.run("keyword-spacing", rule, { { code: "import { \"a\"as b } from \"foo\"", output: "import { \"a\" as b } from \"foo\"", - parserOptions: { 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], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: unexpectedBefore("as") }, @@ -1547,82 +1556,82 @@ ruleTester.run("keyword-spacing", rule, { { code: "let a; export { a as\"b\" };", output: "let a; export { a as \"b\" };", - parserOptions: { 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\";", - parserOptions: { 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\";", - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: unexpectedBeforeAndAfter("as") }, @@ -1630,7 +1639,7 @@ ruleTester.run("keyword-spacing", rule, { { code: "import *as a from \"foo\"", output: "import * as a from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBefore", data: { value: "as" }, @@ -1644,7 +1653,7 @@ ruleTester.run("keyword-spacing", rule, { code: "import* as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBefore", data: { value: "as" }, @@ -1658,7 +1667,7 @@ ruleTester.run("keyword-spacing", rule, { code: "import* as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBefore", data: { value: "as" }, @@ -1672,14 +1681,14 @@ ruleTester.run("keyword-spacing", rule, { code: "import*as a from\"foo\"", output: "import* as a from\"foo\"", options: [override("as", BOTH)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: unexpectedBefore("as") }, @@ -1687,55 +1696,55 @@ ruleTester.run("keyword-spacing", rule, { { code: "export *as a from \"foo\"", output: "export * as a from \"foo\"", - parserOptions: { ecmaVersion: 2020, sourceType: "module" }, + languageOptions: { ecmaVersion: 2020, sourceType: "module" }, errors: expectedBefore("as") }, { code: "export *as\"a\" from \"foo\"", output: "export * as \"a\" from \"foo\"", - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: unexpectedBeforeAndAfter("as") }, @@ -1746,109 +1755,109 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}async function foo() {}", output: "{} async function foo() {}", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBefore("async") }, { code: "{} async function foo() {}", output: "{}async function foo() {}", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedBefore("async") }, { code: "{}async function foo() {}", output: "{} async function foo() {}", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBefore("async") }, { code: "{} async function foo() {}", output: "{}async function foo() {}", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedBefore("async") }, { code: "{}async () => {}", output: "{} async () => {}", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBefore("async") }, { code: "{} async () => {}", output: "{}async () => {}", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedBefore("async") }, { code: "{}async () => {}", output: "{} async () => {}", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBefore("async") }, { code: "{} async () => {}", output: "{}async () => {}", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedBefore("async") }, { code: "({async[b]() {}})", output: "({async [b]() {}})", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedAfter("async") }, { code: "({async [b]() {}})", output: "({async[b]() {}})", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedAfter("async") }, { code: "({async[b]() {}})", output: "({async [b]() {}})", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedAfter("async") }, { code: "({async [b]() {}})", output: "({async[b]() {}})", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedAfter("async") }, { code: "class A {a(){}async[b]() {}}", output: "class A {a(){} async [b]() {}}", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBeforeAndAfter("async") }, { code: "class A {a(){} async [b]() {}}", output: "class A {a(){}async[b]() {}}", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedBeforeAndAfter("async") }, { code: "class A {a(){}async[b]() {}}", output: "class A {a(){} async [b]() {}}", options: [override("async", BOTH)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBeforeAndAfter("async") }, { code: "class A {a(){} async [b]() {}}", output: "class A {a(){}async[b]() {}}", options: [override("async", NEITHER)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedBeforeAndAfter("async") }, @@ -1859,56 +1868,56 @@ ruleTester.run("keyword-spacing", rule, { { code: "async function wrap() { {}await a }", output: "async function wrap() { {} await a }", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBefore("await") }, { code: "async function wrap() { {} await a }", output: "async function wrap() { {}await a }", options: [NEITHER], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: unexpectedBefore("await") }, { code: "async function wrap() { {}await a }", output: "async function wrap() { {} await a }", options: [override("await", BOTH)], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: expectedBefore("await") }, { code: "async function wrap() { {} await a }", output: "async function wrap() { {}await a }", options: [override("await", NEITHER)], - parserOptions: { 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); }", - parserOptions: { 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], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: unexpectedAfter("await") }, @@ -2014,41 +2023,41 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}class Bar {}", output: "{} class Bar {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBefore("class") }, { code: "(class{})", output: "(class {})", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("class") }, { code: "{} class Bar {}", output: "{}class Bar {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBefore("class") }, { code: "(class {})", output: "(class{})", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("class") }, { code: "{}class Bar {}", output: "{} class Bar {}", options: [override("class", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBefore("class") }, { code: "{} class Bar {}", output: "{}class Bar {}", options: [override("class", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBefore("class") }, @@ -2059,55 +2068,55 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}const[a] = b", output: "{} const [a] = b", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("const") }, { code: "{}const{a} = b", output: "{} const {a} = b", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("const") }, { code: "{} const [a] = b", output: "{}const[a] = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("const") }, { code: "{} const {a} = b", output: "{}const{a} = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("const") }, { code: "{}const[a] = b", output: "{} const [a] = b", options: [override("const", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("const") }, { code: "{}const{a} = b", output: "{} const {a} = b", options: [override("const", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("const") }, { code: "{} const [a] = b", output: "{}const[a] = b", options: [override("const", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("const") }, { code: "{} const {a} = b", output: "{}const{a} = b", options: [override("const", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("const") }, @@ -2364,46 +2373,46 @@ ruleTester.run("keyword-spacing", rule, { { code: "var a = 0; {}export{a}", output: "var a = 0; {} export {a}", - parserOptions: { 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", - parserOptions: { 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}", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedAfter("default") }, { code: "{}export* from \"a\"", output: "{} export * from \"a\"", - parserOptions: { 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], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: unexpectedBeforeAndAfter("export") }, @@ -2414,47 +2423,47 @@ ruleTester.run("keyword-spacing", rule, { { code: "class Bar extends[] {}", output: "class Bar extends [] {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("extends") }, { code: "(class extends[] {})", output: "(class extends [] {})", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("extends") }, { code: "class Bar extends [] {}", output: "class Bar extends[] {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("extends") }, { code: "(class extends [] {})", output: "(class extends[] {})", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("extends") }, { code: "class Bar extends[] {}", output: "class Bar extends [] {}", options: [override("extends", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("extends") }, { code: "class Bar extends [] {}", output: "class Bar extends[] {}", options: [override("extends", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("extends") }, { code: "class Bar extends`}` {}", output: "class Bar extends `}` {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("extends") }, @@ -2503,7 +2512,7 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}for(var foo of list) {}", output: "{} for (var foo of list) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("for") }, { @@ -2522,7 +2531,7 @@ ruleTester.run("keyword-spacing", rule, { code: "{} for (var foo of list) {}", output: "{}for(var foo of list) {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("for") }, { @@ -2541,7 +2550,7 @@ ruleTester.run("keyword-spacing", rule, { code: "{}for(var foo of list) {}", output: "{} for (var foo of list) {}", options: [override("for", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("for") }, { @@ -2560,7 +2569,7 @@ ruleTester.run("keyword-spacing", rule, { code: "{} for (var foo of list) {}", output: "{}for(var foo of list) {}", options: [override("for", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("for") }, @@ -2571,123 +2580,123 @@ ruleTester.run("keyword-spacing", rule, { { code: "import {foo}from\"foo\"", output: "import {foo} from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedBeforeAndAfter("from") }, { code: "export {foo}from\"foo\"", output: "export {foo} from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedBeforeAndAfter("from") }, { code: "export *from\"foo\"", output: "export * from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedBeforeAndAfter("from") }, { code: "export * as \"a\"from\"foo\"", output: "export * as \"a\" from \"foo\"", - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: expectedBeforeAndAfter("from") }, { code: "import{foo} from \"foo\"", output: "import{foo}from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: unexpectedBeforeAndAfter("from") }, { code: "export{foo} from \"foo\"", output: "export{foo}from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: unexpectedBeforeAndAfter("from") }, { code: "export* from \"foo\"", output: "export*from\"foo\"", options: [NEITHER], - parserOptions: { 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], - parserOptions: { 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], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedBeforeAndAfter("from") }, { code: "export*from\"foo\"", output: "export* from \"foo\"", options: [override("from", BOTH)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: unexpectedBeforeAndAfter("from") }, { code: "export * from \"foo\"", output: "export *from\"foo\"", options: [override("from", NEITHER)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: unexpectedBeforeAndAfter("from") }, @@ -2726,81 +2735,81 @@ ruleTester.run("keyword-spacing", rule, { { code: "({ get[b]() {} })", output: "({ get [b]() {} })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("get") }, { code: "class A { a() {}get[b]() {} }", output: "class A { a() {} get [b]() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("get") }, { code: "class A { a() {} static get[b]() {} }", output: "class A { a() {} static get [b]() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("get") }, { code: "({ get [b]() {} })", output: "({ get[b]() {} })", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("get") }, { code: "class A { a() {} get [b]() {} }", output: "class A { a() {}get[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("get") }, { code: "class A { a() {}static get [b]() {} }", output: "class A { a() {}static get[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("get") }, { code: "({ get[b]() {} })", output: "({ get [b]() {} })", options: [override("get", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("get") }, { code: "class A { a() {}get[b]() {} }", output: "class A { a() {} get [b]() {} }", options: [override("get", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("get") }, { code: "({ get [b]() {} })", output: "({ get[b]() {} })", options: [override("get", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("get") }, { code: "class A { a() {} get [b]() {} }", output: "class A { a() {}get[b]() {} }", options: [override("get", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("get") }, { code: "class A { a;get#b() {} }", output: "class A { a;get #b() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedAfter("get") }, { code: "class A { a; get #b() {} }", output: "class A { a; get#b() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedAfter("get") }, @@ -2862,7 +2871,7 @@ ruleTester.run("keyword-spacing", rule, { { code: "import* as a from \"foo\"", output: "import * as a from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedAfter", data: { value: "import" }, @@ -2876,7 +2885,7 @@ ruleTester.run("keyword-spacing", rule, { code: "import *as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedAfter", data: { value: "import" }, @@ -2890,7 +2899,7 @@ ruleTester.run("keyword-spacing", rule, { code: "import *as a from\"foo\"", output: "import*as a from\"foo\"", options: [NEITHER], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedAfter", data: { value: "import" }, @@ -2903,61 +2912,61 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}import{a} from \"foo\"", output: "{} import {a} from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedBeforeAndAfter("import") }, { code: "{}import a from \"foo\"", output: "{} import a from \"foo\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedBefore("import") }, { code: "{}import* as a from \"a\"", output: "{} import * as a from \"a\"", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: expectedBeforeAndAfter("import") }, { code: "{} import {a}from\"foo\"", output: "{}import{a}from\"foo\"", options: [NEITHER], - parserOptions: { 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], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: unexpectedBeforeAndAfter("import") }, @@ -2968,28 +2977,28 @@ ruleTester.run("keyword-spacing", rule, { { code: "for ([foo]in{foo: 0}) {}", output: "for ([foo] in {foo: 0}) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("in") }, { code: "for([foo] in {foo: 0}) {}", output: "for([foo]in{foo: 0}) {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("in") }, { code: "for([foo]in{foo: 0}) {}", output: "for([foo] in {foo: 0}) {}", options: [override("in", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("in") }, { code: "for ([foo] in {foo: 0}) {}", output: "for ([foo]in{foo: 0}) {}", options: [override("in", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("in") }, @@ -3006,28 +3015,28 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}let[a] = b", output: "{} let [a] = b", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("let") }, { code: "{} let [a] = b", output: "{}let[a] = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("let") }, { code: "{}let[a] = b", output: "{} let [a] = b", options: [override("let", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("let") }, { code: "{} let [a] = b", output: "{}let[a] = b", options: [override("let", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("let") }, @@ -3066,28 +3075,28 @@ ruleTester.run("keyword-spacing", rule, { { code: "for ([foo]of{foo: 0}) {}", output: "for ([foo] of {foo: 0}) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("of") }, { code: "for([foo] of {foo: 0}) {}", output: "for([foo]of{foo: 0}) {}", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("of") }, { code: "for([foo]of{foo: 0}) {}", output: "for([foo] of {foo: 0}) {}", options: [override("of", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("of") }, { code: "for ([foo] of {foo: 0}) {}", output: "for ([foo]of{foo: 0}) {}", options: [override("of", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("of") }, @@ -3103,7 +3112,7 @@ ruleTester.run("keyword-spacing", rule, { { code: "function foo() { return

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

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

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

; }", options: [{ after: false }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: unexpectedAfter("return") }, { @@ -3139,74 +3148,74 @@ ruleTester.run("keyword-spacing", rule, { { code: "({ set[b](value) {} })", output: "({ set [b](value) {} })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("set") }, { code: "class A { a() {}set[b](value) {} }", output: "class A { a() {} set [b](value) {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("set") }, { code: "class A { a() {} static set[b](value) {} }", output: "class A { a() {} static set [b](value) {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedAfter("set") }, { code: "({ set [b](value) {} })", output: "({ set[b](value) {} })", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedAfter("set") }, { code: "class A { a() {} set [b](value) {} }", output: "class A { a() {}set[b](value) {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("set") }, { code: "({ set[b](value) {} })", output: "({ set [b](value) {} })", options: [override("set", BOTH)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("set") }, { code: "({ set [b](value) {} })", output: "({ set[b](value) {} })", options: [override("set", NEITHER)], - parserOptions: { 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)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("set") }, { code: "class A { a;set#b(x) {} }", output: "class A { a;set #b(x) {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedAfter("set") }, { code: "class A { a; set #b(x) {} }", output: "class A { a; set#b(x) {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedAfter("set") }, @@ -3217,120 +3226,120 @@ ruleTester.run("keyword-spacing", rule, { { code: "class A { a() {}static[b]() {} }", output: "class A { a() {} static [b]() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {}static get [b]() {} }", output: "class A { a() {} static get [b]() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBefore("static") }, { code: "class A { a() {} static [b]() {} }", output: "class A { a() {}static[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a() {} static get[b]() {} }", output: "class A { a() {}static get[b]() {} }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBefore("static") }, { code: "class A { a() {}static[b]() {} }", output: "class A { a() {} static [b]() {} }", options: [override("static", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {} static [b]() {} }", output: "class A { a() {}static[b]() {} }", options: [override("static", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a;static[b]; }", output: "class A { a;static [b]; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedAfter("static") }, { code: "class A { a; static [b]; }", output: "class A { a; static[b]; }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedAfter("static") }, { code: "class A { a;static#b; }", output: "class A { a;static #b; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedAfter("static") }, { code: "class A { a; static #b; }", output: "class A { a; static#b; }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedAfter("static") }, { code: "class A { a() {}static{} }", output: "class A { a() {} static {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {}static{} }", output: "class A { a() {} static {} }", options: [override("static", BOTH)], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedBeforeAndAfter("static") }, { code: "class A { a() {}static {} }", output: "class A { a() {} static {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedBefore("static") }, { code: "class A { a() {} static{} }", output: "class A { a() {} static {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: expectedAfter("static") }, { code: "class A { a() {} static {} }", output: "class A { a() {}static{} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a() {} static {} }", output: "class A { a() {}static{} }", options: [override("static", NEITHER)], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedBeforeAndAfter("static") }, { code: "class A { a() {} static{} }", output: "class A { a() {}static{} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedBefore("static") }, { code: "class A { a() {}static {} }", output: "class A { a() {}static{} }", options: [NEITHER], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: unexpectedAfter("static") }, @@ -3341,28 +3350,28 @@ ruleTester.run("keyword-spacing", rule, { { code: "class A { a() { {}super[b]; } }", output: "class A { a() { {} super[b]; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBefore("super") }, { code: "class A { a() { {} super[b]; } }", output: "class A { a() { {}super[b]; } }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBefore("super") }, { code: "class A { a() { {}super[b]; } }", output: "class A { a() { {} super[b]; } }", options: [override("super", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBefore("super") }, { code: "class A { a() { {} super[b]; } }", output: "class A { a() { {}super[b]; } }", options: [override("super", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBefore("super") }, @@ -3425,13 +3434,17 @@ ruleTester.run("keyword-spacing", rule, { code: " this.blah", output: "this.blah", options: [override("this", { before: false })], - parser: fixtureParser("keyword-spacing", "prefix-cast-operator-space"), + languageOptions: { + parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-space")) + }, errors: unexpectedBefore("this") }, { code: "this.blah", output: " this.blah", - parser: fixtureParser("keyword-spacing", "prefix-cast-operator-no-space"), + languageOptions: { + parser: require(fixtureParser("keyword-spacing", "prefix-cast-operator-no-space")) + }, errors: expectedBefore("this") }, @@ -3526,28 +3539,28 @@ ruleTester.run("keyword-spacing", rule, { { code: "{}var[a] = b", output: "{} var [a] = b", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("var") }, { code: "{} var [a] = b", output: "{}var[a] = b", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("var") }, { code: "{}var[a] = b", output: "{} var [a] = b", options: [override("var", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBeforeAndAfter("var") }, { code: "{} var [a] = b", output: "{}var[a] = b", options: [override("var", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBeforeAndAfter("var") }, @@ -3665,28 +3678,28 @@ ruleTester.run("keyword-spacing", rule, { { code: "function* foo() { {}yield foo }", output: "function* foo() { {} yield foo }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBefore("yield") }, { code: "function* foo() { {} yield foo }", output: "function* foo() { {}yield foo }", options: [NEITHER], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBefore("yield") }, { code: "function* foo() { {}yield foo }", output: "function* foo() { {} yield foo }", options: [override("yield", BOTH)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: expectedBefore("yield") }, { code: "function* foo() { {} yield foo }", output: "function* foo() { {}yield foo }", options: [override("yield", NEITHER)], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: unexpectedBefore("yield") }, @@ -3698,7 +3711,7 @@ 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"), + languageOptions: { parser: require(parser("typescript-parsers/decorator-with-keywords-class-method")) }, errors: expectedAfter("async") } ] 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..8a6cd28e96a 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,7 +1221,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Line", line: 2 }] }, { @@ -1232,7 +1232,7 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: false, beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Line", line: 2 }] }, { @@ -1241,7 +1241,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Line", line: 4 }] }, { @@ -1252,7 +1252,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockEnd: true, allowClassEnd: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Line", line: 4 }] }, { @@ -1291,7 +1291,7 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Line", line: 2 } ] @@ -1318,7 +1318,7 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Block", line: 2 } ] @@ -1346,7 +1346,7 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 3 }, { messageId: "after", type: "Line", line: 3 } @@ -1377,7 +1377,7 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 3 }, { messageId: "after", type: "Block", line: 3 } @@ -1405,7 +1405,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Line", line: 3 } ] @@ -1434,7 +1434,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "after", type: "Block", line: 3 } ] @@ -1461,7 +1461,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 4 } ] @@ -1490,7 +1490,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 4 } ] @@ -1520,7 +1520,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 4 }, { messageId: "after", type: "Line", line: 4 } @@ -1553,7 +1553,7 @@ ruleTester.run("lines-around-comment", rule, { allowBlockStart: true, allowBlockEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 4 }, { messageId: "after", type: "Block", line: 4 } @@ -1579,7 +1579,7 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Line", line: 3 } ] @@ -1606,7 +1606,7 @@ ruleTester.run("lines-around-comment", rule, { allowClassStart: true, allowClassEnd: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "before", type: "Block", line: 3 } ] @@ -1712,7 +1712,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Line", line: 2 }] }, { @@ -1730,7 +1730,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Line", line: 2 }] }, { @@ -1748,7 +1748,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Block", line: 2 }] }, { @@ -1766,7 +1766,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Block", line: 2 }] }, @@ -1874,7 +1874,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Line", line: 3 }] }, { @@ -1892,7 +1892,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Line", line: 3 }] }, { @@ -1912,7 +1912,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Block", line: 4 }] }, { @@ -1932,7 +1932,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Block", line: 4 }] }, @@ -1986,7 +1986,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Line", line: 2 }] }, { @@ -2004,7 +2004,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ beforeBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "before", type: "Block", line: 2 }] }, @@ -2060,7 +2060,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterLineComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Line", line: 3 }] }, { @@ -2080,7 +2080,7 @@ ruleTester.run("lines-around-comment", rule, { options: [{ afterBlockComment: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "after", type: "Block", line: 4 }] }, @@ -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..ff2e7afaa28 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,7 +841,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedAfterStrictError] }, @@ -856,7 +856,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedAfterAsmError] }, @@ -886,7 +886,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterStrictError @@ -896,7 +896,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterStrictError @@ -926,7 +926,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterAsmError @@ -936,7 +936,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, expectedAfterAsmError @@ -1080,7 +1080,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [unexpectedAfterStrictError] }, @@ -1095,7 +1095,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [unexpectedAfterAsmError] }, @@ -1125,7 +1125,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterStrictError @@ -1135,7 +1135,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterStrictError @@ -1165,7 +1165,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterAsmError @@ -1175,7 +1175,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, unexpectedAfterAsmError @@ -1308,14 +1308,14 @@ 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 }, + 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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedAfterStrictError] }, @@ -1336,14 +1336,14 @@ 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 }, + 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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedAfterAsmError] }, @@ -1373,7 +1373,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterStrictError @@ -1383,7 +1383,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterStrictError @@ -1413,7 +1413,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterAsmError @@ -1423,7 +1423,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ unexpectedBeforeStrictError, expectedAfterAsmError @@ -1555,14 +1555,14 @@ 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 }, + 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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [unexpectedAfterStrictError] }, @@ -1583,14 +1583,14 @@ 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 }, + 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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [unexpectedAfterAsmError] }, @@ -1620,7 +1620,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterStrictError @@ -1630,7 +1630,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterStrictError @@ -1660,7 +1660,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterAsmError @@ -1670,7 +1670,7 @@ ruleTester.run("lines-around-directive", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ expectedBeforeStrictError, unexpectedAfterAsmError 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..9fdf7278b83 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,7 +756,7 @@ 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "logical", type: "LogicalExpression", data: { operator: "||=" } }] }, { code: "a['b'] || (a['b'] = c)", @@ -1486,13 +1491,17 @@ 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"), + 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, - parser: parser("typescript-parsers/logical-with-assignment-with-assertion-1"), + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-1")) + }, errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1507,7 +1516,9 @@ ruleTester.run("logical-assignment-operators", rule, { { code: "a.b.c || (a.b.c = (d as number))", output: null, - parser: parser("typescript-parsers/logical-with-assignment-with-assertion-2"), + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-2")) + }, errors: [{ messageId: "logical", type: "LogicalExpression", @@ -1522,7 +1533,9 @@ ruleTester.run("logical-assignment-operators", rule, { { code: "(a.b.c || (a.b.c = d)) as number", output: null, - parser: parser("typescript-parsers/logical-with-assignment-with-assertion-3"), + languageOptions: { + parser: require(parser("typescript-parsers/logical-with-assignment-with-assertion-3")) + }, errors: [{ messageId: "logical", type: "LogicalExpression", 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..0d50184d0f5 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], 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], 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], 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,7 +57,7 @@ ruleTester.run("max-depth", rule, { { code: "class C { static { if (1) { if (2) { if (3) {} } } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, @@ -68,7 +68,7 @@ ruleTester.run("max-depth", rule, { { code: "if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, @@ -79,7 +79,7 @@ ruleTester.run("max-depth", rule, { { code: "function foo() { if (1) { class C { static { if (1) { if (2) { if (3) {} } } } } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, @@ -90,7 +90,7 @@ ruleTester.run("max-depth", rule, { { code: "function foo() { if (1) { class C { static { if (1) { if (2) {} } } } if (2) { if (3) {} } } }", options: [2], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "tooDeeply", data: { depth: 3, maxDepth: 2 }, diff --git a/tests/lib/rules/max-len.js b/tests/lib/rules/max-len.js index 557b5506f89..20d160c87b8 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,7 @@ ruleTester.run("max-len", rule, { { code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string`;", options: [29, { ignoreStrings: false, ignoreTemplateLiterals: false }], - parserOptions, + languageOptions, errors: [ { messageId: "max", @@ -786,7 +786,7 @@ ruleTester.run("max-len", rule, { { 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, + languageOptions, errors: [ { messageId: "max", @@ -811,7 +811,7 @@ ruleTester.run("max-len", rule, { { code: "var foo =
this is a very very very long string
;", options: [29, 4, { ignoreStrings: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -864,7 +864,7 @@ ruleTester.run("max-len", rule, { " { /* this line has 38 characters */}\n" + ")", options: [15, { comments: 37 }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "maxComment", @@ -882,7 +882,7 @@ ruleTester.run("max-len", rule, { "\t\t{ /* this line has 40 characters */}\n" + ")", options: [15, 4, { comments: 40 }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "maxComment", @@ -900,7 +900,7 @@ ruleTester.run("max-len", rule, { "{ 38/* this line has 38 characters */}\n" + ")", options: [15, { comments: 38 }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -918,7 +918,7 @@ ruleTester.run("max-len", rule, { "{ 38/* this line has 38 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -936,7 +936,7 @@ ruleTester.run("max-len", rule, { "{ 38/* this line has 38 characters */}\n" + ")", options: [37, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -954,7 +954,7 @@ ruleTester.run("max-len", rule, { " <> 50 { 50/* this line has 50 characters */}\n" + ")", options: [49, { comments: 100 }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -973,7 +973,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line has 44 characters */}\n" + ")", options: [37, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -991,7 +991,7 @@ ruleTester.run("max-len", rule, { " attr = {a && b/* this line has 57 characters */}\n" + ">
;", options: [56], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1009,7 +1009,7 @@ ruleTester.run("max-len", rule, { " attr = {/* this line has 57 characters */a && b}\n" + ">
;", options: [56], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1027,7 +1027,7 @@ ruleTester.run("max-len", rule, { " attr = {a & b/* this line has 56 characters */}\n" + ">
;", options: [55, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1046,7 +1046,7 @@ ruleTester.run("max-len", rule, { " {a & b /* this line has 51 characters */}\n" + ">
;", options: [30, { comments: 44 }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1065,7 +1065,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 80 characters */}\n" + ")", options: [79], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1083,7 +1083,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 87 characters */} <> \n" + ")", options: [85, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1102,7 +1102,7 @@ ruleTester.run("max-len", rule, { " <> {/* this line with two separate comments */} {/* have 87 characters */} <> \n" + ")", options: [37, { ignoreComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1121,7 +1121,7 @@ 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 } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1140,7 +1140,7 @@ 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 } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1159,7 +1159,7 @@ 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 } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1178,7 +1178,7 @@ ruleTester.run("max-len", rule, { "*/}\n" + ")", options: [14, { ignoreTrailingComments: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", @@ -1197,7 +1197,7 @@ ruleTester.run("max-len", rule, { "this line has 31 characters */}\n" + ")", options: [30, { comments: 100 }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "max", 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..e5cda7b1c89 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,13 +61,13 @@ ruleTester.run("max-nested-callbacks", rule, { { code: "foo(function() { bar(thing, (data) => { baz(function() {}); }); });", options: [2], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }] }, { code: "foo(() => { bar(thing, (data) => { baz( () => {}); }); });", options: [2], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "ArrowFunctionExpression" }] }, { diff --git a/tests/lib/rules/max-params.js b/tests/lib/rules/max-params.js index d5e1bf72e10..1743cb52fb3 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,7 +58,7 @@ ruleTester.run("max-params", rule, { { code: "var test = (a, b, c, d) => {};", options: [3], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { name: "Arrow function", count: 4, max: 3.0 }, diff --git a/tests/lib/rules/max-statements-per-line.js b/tests/lib/rules/max-statements-per-line.js index 2d33891d3f2..18682e2d91d 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 }], 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 }], 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 }], 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 }], 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 }], 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 }], 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 }], 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 decdd8a56dc..649726d6af9 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,7 +70,7 @@ ruleTester.run("max-statements", rule, { { code: "var foo = () => { var bar = 1; var baz = 2; var qux = 3; };", options: [2], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { name: "Arrow function", count: "3", max: 2 } }] }, { @@ -135,7 +135,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 } }] }, @@ -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,7 +152,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 } }] }, { @@ -173,25 +173,25 @@ 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 }, + 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 }], - parserOptions: { 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "exceed", data: { name: "Function 'not_top_level'", count: 3, max: 2 } }] } ] 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..35ee12c6bcb 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,7 @@ ruleTester.run("new-cap", rule, { }, { code: "var a = new b[ ( 'foo' ) ]();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "lower", @@ -286,7 +286,7 @@ ruleTester.run("new-cap", rule, { }, { code: "var a = new b[`foo`];", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "lower", @@ -300,7 +300,7 @@ ruleTester.run("new-cap", rule, { }, { code: "var a = b[`\\\nFoo`]();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "upper", @@ -339,17 +339,17 @@ ruleTester.run("new-cap", rule, { // Optional chaining { code: "new (foo?.bar)();", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "lower", column: 11, endColumn: 14 }] }, { code: "foo?.Bar();", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "upper", column: 6, endColumn: 9 }] }, { code: "(foo?.Bar)();", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "upper", column: 7, endColumn: 10 }] } ] 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..7f638619376 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"], 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"], parserOptions: { ecmaVersion: 6 }, errors: [ALWAYS_ERROR] }, + { 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"], 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"], 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 4923706a986..d0c9769abfb 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,7 +160,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [error] }, { @@ -191,13 +196,13 @@ ruleTester.run("newline-before-return", rule, { { code: "var a;\nreturn;", output: "var a;\n\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [error] }, { code: "var a; return;", output: "var a; \n\nreturn;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [error] }, { diff --git a/tests/lib/rules/newline-per-chained-call.js b/tests/lib/rules/newline-per-chained-call.js index ce7719b7146..b57c27843d8 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,7 +351,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } @@ -361,7 +361,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } @@ -371,7 +371,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.foo2" } }, { messageId: "expected", data: { callee: "?.foo3" } } @@ -381,7 +381,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } @@ -391,7 +391,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } @@ -401,7 +401,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", data: { callee: "?.[foo2]" } }, { messageId: "expected", data: { callee: "?.[foo3]" } } diff --git a/tests/lib/rules/no-alert.js b/tests/lib/rules/no-alert.js index 03fcddb6994..3b4aeed42c0 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,29 +117,29 @@ ruleTester.run("no-alert", rule, { }, { code: "globalThis['alert'](foo)", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "globalThis.alert();", - env: { es2020: true }, + 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();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] }, // Optional chaining { code: "window?.alert(foo)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { name: "alert" } }] }, { code: "(window?.alert)(foo)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { name: "alert" } }] } ] 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..ad2c945d0e7 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,93 +22,93 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { case 1: let x = 1; break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { default: let x = 2; break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { case 1: const x = 1; break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { default: const x = 2; break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "VariableDeclaration" }] }, { code: "switch (a) { case 1: function f() {} break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }] }, { code: "switch (a) { default: function f() {} break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "FunctionDeclaration" }] }, { code: "switch (a) { case 1: class C {} break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "ClassDeclaration" }] }, { code: "switch (a) { default: class C {} break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "ClassDeclaration" }] } ] 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..81cc452c8dc 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,7 @@ ruleTester.run("no-console", rule, { }, { code: "class A { static { console.info(foo) } }", - parserOptions: { ecmaVersion: "latest" }, + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -155,7 +155,7 @@ ruleTester.run("no-console", rule, { }, { code: "a()\nconsole.log(foo);\n[1, 2, 3].forEach(a => doSomething(a))", - parserOptions: { ecmaVersion: "latest" }, + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -164,7 +164,7 @@ ruleTester.run("no-console", rule, { }, { code: "a++\nconsole.log();\n/b/", - parserOptions: { ecmaVersion: "latest" }, + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -173,7 +173,7 @@ ruleTester.run("no-console", rule, { }, { code: "a();\nconsole.log(foo);\n[1, 2, 3].forEach(a => doSomething(a));", - parserOptions: { ecmaVersion: "latest" }, + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -285,7 +285,7 @@ ruleTester.run("no-console", rule, { { code: "class A { static { console.error(foo) } }", options: [{ allow: ["log"] }], - parserOptions: { ecmaVersion: "latest" }, + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -397,7 +397,7 @@ ruleTester.run("no-console", rule, { { code: "class A { static { console.info(foo) } }", options: [{ allow: ["log", "error", "warn"] }], - parserOptions: { ecmaVersion: "latest" }, + languageOptions: { ecmaVersion: "latest" }, errors: [{ messageId: "unexpected", type: "MemberExpression", @@ -412,7 +412,11 @@ ruleTester.run("no-console", rule, { // In case that implicit global variable of 'console' exists { code: "console.log(foo)", - env: { node: true }, + languageOptions: { + globals: { + console: "readonly" + } + }, errors: [{ messageId: "unexpected", type: "MemberExpression", 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..cbf93c77ab3 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()", 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 af7bd355db4..96579ab9e91 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);", 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-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..7db45944c93 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,12 +49,12 @@ 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`var regex = /(?<\u{1d49c}>.)\x1f/`, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { @@ -63,22 +63,22 @@ ruleTester.run("no-control-regex", rule, { }, { code: String.raw`/\u{1111}*\x1F/u`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`new RegExp("\\u{1111}*\\x1F", "u")`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`/\u{1F}/u`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`/\u{1F}/gui`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { @@ -95,12 +95,12 @@ ruleTester.run("no-control-regex", rule, { }, { code: String.raw`/[\u{1F}--B]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, { code: String.raw`/\x11/; RegExp("foo", "uv");`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "unexpected", data: { controlChars: "\\x11" }, type: "Literal", column: 1 }] } ] 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..73310d8880c 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,7 +187,7 @@ ruleTester.run("no-dupe-class-members", rule, { }, { code: "class A { [123n]() {} 123() {} }", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { type: "MethodDefinition", line: 1, column: 23, messageId: "unexpected", data: { name: "123" } } ] 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..20aa29c3454 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 };", 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 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] }, + { 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 };", 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 };", 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() {} };", 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() {} };", 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-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..470e38262a0 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,109 +203,109 @@ 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 }, + 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; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { let a; if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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; } }", - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { var a; if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { var a; return true; } else { let a; } }", output: null, - parserOptions: { 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, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo(a) { if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "BlockStatement" } ] @@ -308,13 +313,13 @@ ruleTester.run("no-else-return", rule, { { code: "function foo(a = 1) { if (bar) { return true; } else { let a; } }", output: null, - parserOptions: { 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, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "BlockStatement" }, { messageId: "unexpected", type: "BlockStatement" } @@ -323,181 +328,181 @@ ruleTester.run("no-else-return", rule, { { code: "function foo(...args) { if (bar) { return true; } else { let args; } }", output: null, - parserOptions: { 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, - parserOptions: { 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; } } }", - parserOptions: { 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, - parserOptions: { 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; }", - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } a; }", output: null, - parserOptions: { 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, - parserOptions: { 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; }", - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function a() { if (foo) { return true; } else { let a; } a(); }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function a() { if (a) { return true; } else { let a; } }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function a() { if (foo) { return a; } else { let a; } }", output: null, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } var a; }", output: null, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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, - parserOptions: { 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; } }", - parserOptions: { 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; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { if (bar) { return true; } else { let a; } function a(){} }", output: null, - parserOptions: { 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, - parserOptions: { 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(){} } }", - parserOptions: { 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(){} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { let a; if (bar) { return true; } else { function a(){} } }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo() { var a; if (bar) { return true; } else { function a(){} } }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { @@ -508,15 +513,13 @@ 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 }, + languageOptions: { ecmaVersion: 6, sourceType: "commonjs" }, errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "let a; if (foo) { return true; } else { let a; }", output: null, - parserOptions: { ecmaVersion: 6 }, - env: { node: true }, + 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 81b66c4b300..4aeab04d1f5 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;", 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-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..ea5086e33d7 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,25 +21,25 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -48,7 +48,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "var [] = foo", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, @@ -57,7 +57,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "var {a: {}} = foo", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -66,7 +66,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "var {a, b: {}} = foo", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -75,7 +75,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "var {a: []} = foo", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, @@ -84,7 +84,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "function foo({}) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -93,7 +93,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "function foo([]) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, @@ -102,7 +102,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "function foo({a: {}}) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -111,7 +111,7 @@ ruleTester.run("no-empty-pattern", rule, { }, { code: "function foo({a: []}) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, @@ -121,7 +121,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "function foo({}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -131,7 +131,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = function({}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -141,7 +141,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = ({}) => {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -151,7 +151,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "function foo({} = {}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -161,7 +161,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = function({} = {}) {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -171,7 +171,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = ({} = {}) => {}", options: [{}], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -181,7 +181,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = ({a: {}}) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -191,7 +191,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = ({} = bar) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -201,7 +201,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = ({} = { bar: 1 }) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "object" }, @@ -211,7 +211,7 @@ ruleTester.run("no-empty-pattern", rule, { { code: "var foo = ([]) => {}", options: [{ allowObjectPatternsAsParameters: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { type: "array" }, 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..64c63731c71 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,81 +101,78 @@ 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')", 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'); }", 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'); }", 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')", 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')", 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')", 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')", 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')", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } }, errors: [{ messageId: "unexpected" }] }, { code: "(window?.eval)('foo')", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } }, errors: [{ messageId: "unexpected" }] }, { code: "(window?.window).eval('foo')", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, + languageOptions: { ecmaVersion: 2020, globals: { window: "readonly" } }, errors: [{ messageId: "unexpected" }] }, // Class fields { code: "class C { [this.eval('foo')] }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected" }] }, { code: "'use strict'; class C { [this.eval('foo')] }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected" }] }, { code: "class A { static {} [this.eval()]; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected" }] }, // in es3, "use strict" directives do not apply { code: "function foo() { 'use strict'; this.eval(); }", - parserOptions: { 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' });", - parserOptions: { ecmaVersion: 2023 }, + languageOptions: { ecmaVersion: 2023 }, errors: [{ messageId: "unexpected" }] }, { diff --git a/tests/lib/rules/no-ex-assign.js b/tests/lib/rules/no-ex-assign.js index 0c00dba65e1..f4d91808478 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] = []; }", 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 4cb4a64b35c..32fcf96a018 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,7 +64,7 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "BigInt.prototype.p = 0", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { builtin: "BigInt" }, @@ -67,7 +72,7 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "WeakRef.prototype.p = 0", - env: { es2021: true }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "WeakRef" }, @@ -75,7 +80,7 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "FinalizationRegistry.prototype.p = 0", - env: { es2021: true }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "FinalizationRegistry" }, @@ -83,7 +88,7 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "AggregateError.prototype.p = 0", - env: { es2021: true }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "AggregateError" }, @@ -167,39 +172,39 @@ ruleTester.run("no-extend-native", rule, { // Optional chaining { code: "(Object?.prototype).p = 0", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, { code: "Object.defineProperty(Object?.prototype, 'p', { value: 0 })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, { code: "Object?.defineProperty(Object.prototype, 'p', { value: 0 })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, { code: "(Object?.defineProperty)(Object.prototype, 'p', { value: 0 })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected", data: { builtin: "Object" } }] }, // Logical assignments { code: "Array.prototype.p &&= 0", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] }, { code: "Array.prototype.p ||= 0", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpected", data: { builtin: "Array" } }] }, { code: "Array.prototype.p ??= 0", - parserOptions: { 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 8422f3de771..d43810e2ab5 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,7 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { return 1; }[`bind`](b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", @@ -73,13 +73,13 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = (() => { return 1; }).bind(b)", output: "var a = (() => { return 1; })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors }, { code: "var a = (() => { return this; }).bind(b)", output: "var a = (() => { return this; })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors }, { @@ -196,37 +196,37 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { return 1; }.bind?.(b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var a = function() { return 1; }?.bind(b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var a = (function() { return 1; }?.bind)(b)", output: "var a = (function() { return 1; })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var a = function() { return 1; }['bind']?.(b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var a = function() { return 1; }?.['bind'](b)", output: "var a = function() { return 1; }", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var a = (function() { return 1; }?.['bind'])(b)", output: "var a = (function() { return 1; })", - parserOptions: { 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 2e95cb740bb..21a68cd8c27 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,7 +279,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "!Boolean(...foo);", output: null, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" @@ -379,7 +379,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield!!a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -388,7 +388,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield!! a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -397,7 +397,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield! !a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -406,7 +406,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield !!a ? b : c }", output: "function *foo() { yield a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -415,7 +415,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield(!!a) ? b : c }", output: "function *foo() { yield(a) ? b : c }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -424,7 +424,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "function *foo() { yield/**/!!a ? b : c }", output: "function *foo() { yield/**/a ? b : c }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -934,7 +934,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(...foo) || bar;", output: null, options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" @@ -1028,7 +1028,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -1038,7 +1038,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -1048,7 +1048,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -1058,7 +1058,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -1068,7 +1068,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" @@ -1371,7 +1371,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression", @@ -2005,25 +2005,25 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "!!!(a ** b)", output: "!(a ** b)", - parserOptions: { ecmaVersion: 2016 }, + languageOptions: { ecmaVersion: 2016 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }] }, { code: "!Boolean(a ** b)", output: "!(a ** b)", - parserOptions: { ecmaVersion: 2016 }, + languageOptions: { ecmaVersion: 2016 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] }, { code: "async function f() { !!!(await a) }", output: "async function f() { !await a }", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }] }, { code: "async function f() { !Boolean(await a) }", output: "async function f() { !await a }", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] }, { @@ -2207,7 +2207,7 @@ 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 }, + languageOptions: { ecmaVersion: 2016 }, errors: [ { messageId: "unexpectedCall", type: "CallExpression" }, { messageId: "unexpectedCall", type: "CallExpression" } @@ -2407,7 +2407,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "if (Boolean(a ?? b) || c) {}", output: "if ((a ?? b) || c) {}", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -2415,14 +2415,14 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "if (Boolean?.(foo)) ;", output: "if (foo) ;", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall" }] }, { code: "if (Boolean?.(a ?? b) || c) {}", output: "if ((a ?? b) || c) {}", options: [{ enforceForLogicalOperands: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall" }] }, @@ -2430,8 +2430,10 @@ ruleTester.run("no-extra-boolean-cast", rule, { { code: "if (!Boolean(a as any)) { }", output: "if (!(a as any)) { }", - parser: parser("typescript-parsers/boolean-cast-with-assertion"), - parserOptions: { ecmaVersion: 2020 }, + 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 e810ef4e320..8d4cc01c02b 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,7 +70,7 @@ ruleTester.run("no-extra-label", rule, { { code: "A: for (a of ary) { break A; }", output: "A: for (a of ary) { break; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index 2d61522cb72..553a2c69433 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,67 +3194,67 @@ ruleTester.run("no-extra-parens", rule, { { code: "var v = ((a ?? b)) || c", output: "var v = (a ?? b) || c", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = a ?? ((b || c))", output: "var v = a ?? (b || c)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = ((a ?? b)) && c", output: "var v = (a ?? b) && c", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = a ?? ((b && c))", output: "var v = a ?? (b && c)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = ((a || b)) ?? c", output: "var v = (a || b) ?? c", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = a || ((b ?? c))", output: "var v = a || (b ?? c)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = ((a && b)) ?? c", output: "var v = (a && b) ?? c", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = a && ((b ?? c))", output: "var v = a && (b ?? c)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = (a ?? b) ? b : c", output: "var v = a ?? b ? b : c", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = (a | b) ?? c | d", output: "var v = a | b ?? c | d", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = a | b ?? (c | d)", output: "var v = a | b ?? c | d", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, @@ -3412,34 +3416,34 @@ ruleTester.run("no-extra-parens", rule, { { code: "var v = (obj?.aaa)?.aaa", output: "var v = obj?.aaa?.aaa", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var v = (obj.aaa)?.aaa", output: "var v = obj.aaa?.aaa", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var foo = (function(){})?.call()", output: "var foo = function(){}?.call()", options: ["all", { enforceForFunctionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "var foo = (function(){}?.call())", output: "var foo = function(){}?.call()", options: ["all", { enforceForFunctionPrototypeMethods: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, { code: "(Object.prototype.toString.call())", output: "Object.prototype.toString.call()", options: ["all"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpected" }] }, diff --git a/tests/lib/rules/no-extra-semi.js b/tests/lib/rules/no-extra-semi.js index 9a2d9a31bee..a69d3412380 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,7 +85,7 @@ ruleTester.run("no-extra-semi", rule, { { code: "for(a of b);;", output: "for(a of b);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "EmptyStatement" }] }, { @@ -116,13 +121,13 @@ ruleTester.run("no-extra-semi", rule, { { code: "class A { static { ; } }", output: "class A { static { } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 20 }] }, { code: "class A { static { a;; } }", output: "class A { static { a; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 22 }] }, @@ -130,37 +135,37 @@ ruleTester.run("no-extra-semi", rule, { { code: "class A { ; }", output: "class A { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }] }, { code: "class A { /*a*/; }", output: "class A { /*a*/ }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 16 }] }, { code: "class A { ; a() {} }", output: "class A { a() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }] }, { code: "class A { a() {}; }", output: "class A { a() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A { a() {}; b() {} }", output: "class A { a() {} b() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A {; a() {}; b() {}; }", output: "class A { a() {} b() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpected", type: "Punctuator", column: 10 }, { messageId: "unexpected", type: "Punctuator", column: 18 }, @@ -170,25 +175,25 @@ ruleTester.run("no-extra-semi", rule, { { code: "class A { a() {}; get b() {} }", output: "class A { a() {} get b() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A { field;; }", output: "class A { field; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A { static {}; }", output: "class A { static {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 20 }] }, { code: "class A { static { a; }; foo(){} }", output: "class A { static { a; } foo(){} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpected", type: "Punctuator", column: 24 }] }, 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..8ad6bb36083 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,7 +54,7 @@ ruleTester.run("no-floating-decimal", rule, { { code: "for(foo of.2);", output: "for(foo of 0.2);", - parserOptions: { 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 85a6bdcc5bb..877cefe01ab 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,7 +55,7 @@ ruleTester.run("no-func-assign", rule, { }, { code: "[foo] = bar; function foo() { };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, @@ -64,7 +64,7 @@ ruleTester.run("no-func-assign", rule, { }, { code: "({x: foo = 0} = bar); function foo() { };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, @@ -73,7 +73,7 @@ ruleTester.run("no-func-assign", rule, { }, { code: "function foo() { [foo] = bar; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, @@ -82,7 +82,7 @@ ruleTester.run("no-func-assign", rule, { }, { code: "(function() { ({x: foo = 0} = bar); function foo() { }; })();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "isAFunction", data: { name: "foo" }, diff --git a/tests/lib/rules/no-global-assign.js b/tests/lib/rules/no-global-assign.js index 41f0ac0f305..ec68a78bfe9 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,7 @@ ruleTester.run("no-global-assign", rule, { }, { code: "({Object = 0, String = 0} = {});", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "globalShouldNotBeModified", @@ -64,7 +70,7 @@ ruleTester.run("no-global-assign", rule, { }, { code: "top = 0;", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "top" }, @@ -73,7 +79,7 @@ ruleTester.run("no-global-assign", rule, { }, { code: "require = 0;", - env: { node: true }, + languageOptions: { sourceType: "commonjs" }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "require" }, @@ -92,7 +98,7 @@ ruleTester.run("no-global-assign", rule, { }, { code: "function f() { b = 1; }", - globals: { b: false }, + languageOptions: { globals: { b: false } }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "b" }, diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index e935081e6f3..f0fa8b728d4 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,7 +205,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "``+foo", output: "String(foo)", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, @@ -224,7 +224,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo+``", output: "String(foo)", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, @@ -243,7 +243,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "``+foo.bar", output: "String(foo.bar)", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo.bar)" }, @@ -262,7 +262,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo.bar+``", output: "String(foo.bar)", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo.bar)" }, @@ -273,7 +273,7 @@ ruleTester.run("no-implicit-coercion", rule, { code: "`${foo}`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, @@ -284,7 +284,7 @@ ruleTester.run("no-implicit-coercion", rule, { code: "`\\\n${foo}`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, @@ -295,7 +295,7 @@ ruleTester.run("no-implicit-coercion", rule, { code: "`${foo}\\\n`", output: "String(foo)", options: [{ disallowTemplateShorthand: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, @@ -314,7 +314,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "foo += ``", output: "foo = String(foo)", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "foo = String(foo)" }, @@ -375,7 +375,7 @@ ruleTester.run("no-implicit-coercion", rule, { code: "var a = `` + foo", output: "var a = String(foo)", options: [{ boolean: true, allow: ["*"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(foo)" }, @@ -403,7 +403,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "let x ='' + 1n;", output: "let x =String(1n);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "String(1n)" }, @@ -415,7 +415,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "~foo?.indexOf(1)", output: null, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "foo?.indexOf(1) >= 0" }, @@ -425,7 +425,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "~(foo?.indexOf)(1)", output: null, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useRecommendation", data: { recommendation: "(foo?.indexOf)(1) !== -1" }, diff --git a/tests/lib/rules/no-implicit-globals.js b/tests/lib/rules/no-implicit-globals.js index 412ba766134..b0c39c3616c 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,7 +552,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "function *foo() {}", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: functionMessage, @@ -536,7 +562,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "async function foo() {}", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [ { message: functionMessage, @@ -546,7 +572,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "async function *foo() {}", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: functionMessage, @@ -574,7 +600,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "var foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, @@ -584,7 +610,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "var foo = function *foo() {};", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, @@ -615,7 +641,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "const a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: constMessage }] @@ -623,7 +649,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "let a;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: letMessage }] @@ -631,7 +657,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "let a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: letMessage }] @@ -639,7 +665,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "class A {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ message: classMessage }] @@ -649,7 +675,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "const a = 1; const b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage } @@ -658,7 +684,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "const a = 1, b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage } @@ -667,7 +693,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "let a, b = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage }, { message: letMessage } @@ -676,7 +702,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "const a = 1; let b; class C {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: letMessage }, @@ -686,7 +712,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "const [a, b, ...c] = [];", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage }, { message: constMessage }, @@ -696,7 +722,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "let { a, foo: b, bar: { c } } = {};", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage }, { message: letMessage }, @@ -729,7 +755,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -766,7 +792,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "for (foo of []);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -778,7 +804,7 @@ ruleTester.run("no-implicit-globals", rule, { // Not implicit strict { code: "window.foo = { bar() { foo = 1 } }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -788,7 +814,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1", - env: { node: true }, + languageOptions: { sourceType: "commonjs" }, errors: [ { message: leakMessage, @@ -798,7 +824,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { message: leakMessage, @@ -898,7 +924,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "[foo, bar] = [];", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -912,7 +938,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/*global foo:writable*/ [foo, bar] = [];", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -922,7 +948,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/*global bar:writable*/ [foo, bar] = [];", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -947,7 +973,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "window = 1;", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [ { message: readonlyAssignmentMessage, @@ -966,7 +992,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1;", - globals: { foo: "readonly" }, + languageOptions: { globals: { foo: "readonly" } }, errors: [ { message: readonlyAssignmentMessage, @@ -985,7 +1011,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/*global foo:readonly*/ for (foo of []);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyAssignmentMessage, @@ -1034,7 +1060,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly*/ const foo = 1", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1045,7 +1071,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly*/ let foo", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1056,7 +1082,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly*/ let foo = 1", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1067,7 +1093,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global Foo:readonly*/ class Foo {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1196,7 +1222,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly, bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1211,7 +1237,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:writable, bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1222,7 +1248,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly, bar: writable*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1233,7 +1259,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1248,7 +1274,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global bar: readonly*/ const foo = 1, bar = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1263,7 +1289,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly, bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1278,7 +1304,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:writable, bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1289,7 +1315,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly, bar: writable*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1300,7 +1326,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global foo:readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: readonlyRedeclarationMessage, @@ -1315,7 +1341,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/*global bar: readonly*/ let foo, bar;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1353,7 +1379,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ function *foo() {}", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: functionMessage, @@ -1363,7 +1389,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ async function foo() {}", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [ { message: functionMessage, @@ -1373,7 +1399,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ async function *foo() {}", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: functionMessage, @@ -1401,7 +1427,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ var foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, @@ -1411,7 +1437,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported bar */ var foo = function *foo() {};", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: varMessage, @@ -1433,7 +1459,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported b */ const a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1444,7 +1470,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported b */ let a;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1455,7 +1481,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported b */ let a = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1466,7 +1492,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported B */ class A {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: classMessage, @@ -1477,7 +1503,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported a */ const a = 1; const b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1488,7 +1514,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported a */ const a = 1, b = 2;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1499,7 +1525,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported a */ let a, b = 1;", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1510,7 +1536,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported a */ const a = 1; let b; class C {}", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1525,7 +1551,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported a */ const [a, b, ...c] = [];", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: constMessage, @@ -1540,7 +1566,7 @@ ruleTester.run("no-implicit-globals", rule, { { code: "/* exported a */ let { a, foo: b, bar: { c } } = {};", options: [{ lexicalBindings: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: letMessage, @@ -1574,7 +1600,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported foo */ foo = function*() {};", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, @@ -1611,7 +1637,7 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "/* exported foo */ for (foo of []);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { message: leakMessage, diff --git a/tests/lib/rules/no-implied-eval.js b/tests/lib/rules/no-implied-eval.js index ce06f662043..b57aff9df8d 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);", languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, + { code: "setTimeout(String('x=1'), 100);", languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, // 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')", 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}`)", 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}`)", 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)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, + { code: "setTimeout(`foo` + bar)", languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, { 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)", 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 { @@ -197,7 +203,7 @@ ruleTester.run("no-implied-eval", rule, { " window.execScript('str');\n" + " return 'bar';\n" + "})())", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [ { messageId: "impliedEval", @@ -220,7 +226,7 @@ ruleTester.run("no-implied-eval", rule, { " global.execScript('str');\n" + " return 'bar';\n" + "})())", - env: { node: true }, + languageOptions: { sourceType: "commonjs" }, errors: [ { messageId: "impliedEval", @@ -240,14 +246,18 @@ ruleTester.run("no-implied-eval", rule, { // Optional chaining { code: "window?.setTimeout('code', 0)", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, + languageOptions: { + ecmaVersion: 2020, + globals: { window: "readonly" } + }, errors: [{ messageId: "impliedEval" }] }, { code: "(window?.setTimeout)('code', 0)", - parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, + 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 babfdfc3445..8d3d68378fc 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,17 +315,17 @@ ruleTester.run("no-import-assign", rule, { // Optional chaining { code: "import * as mod from 'mod'; Object?.defineProperty(mod, key, d)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] }, { code: "import * as mod from 'mod'; (Object?.defineProperty)(mod, key, d)", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] }, { code: "import * as mod from 'mod'; delete mod?.prop", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "readonlyMember", data: { name: "mod" }, column: 29 }] } ] 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..3d42e398001 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,7 @@ ruleTester.run("no-inner-declarations", rule, { }, { code: "const doSomething = () => { if (test) { var foo = 42; } }", options: ["both"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -293,7 +298,7 @@ ruleTester.run("no-inner-declarations", rule, { }, { code: "class C { method() { if(test) { var foo; } } }", options: ["both"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -305,7 +310,7 @@ ruleTester.run("no-inner-declarations", rule, { }, { code: "class C { static { if (test) { function foo() {} } } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -317,7 +322,7 @@ ruleTester.run("no-inner-declarations", rule, { }, { code: "class C { static { if (test) { var foo; } } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { @@ -329,7 +334,7 @@ ruleTester.run("no-inner-declarations", rule, { }, { code: "class C { static { if (test) { if (anotherTest) { var foo; } } } }", options: ["both"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "moveDeclToRoot", data: { 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..85d176fc060 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,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "var any = `\u3000`, other = `\u000B`;", options: [{ skipTemplates: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -560,7 +560,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "`something ${\u3000 10} another thing`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -573,7 +573,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "`something ${10\u3000} another thing`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -586,7 +586,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "\u3000\n`\u3000template`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -599,7 +599,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "\u3000\n`\u3000multiline\ntemplate`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -612,7 +612,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "\u3000`\u3000template`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -625,7 +625,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "\u3000`\u3000multiline\ntemplate`", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -638,7 +638,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "`\u3000template`\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -651,7 +651,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "`\u3000multiline\ntemplate`\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -664,7 +664,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "`\u3000template`\n\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -677,7 +677,7 @@ ruleTester.run("no-irregular-whitespace", rule, { { code: "`\u3000multiline\ntemplate`\n\u3000", options: [{ skipTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noIrregularWhitespace", @@ -1018,9 +1018,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u000B
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1034,9 +1036,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u000C
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1050,9 +1054,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u0085
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1066,9 +1072,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u00A0
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1082,9 +1090,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u180E
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1098,9 +1108,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\ufeff
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1114,9 +1126,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2000
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1130,9 +1144,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2001
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1146,9 +1162,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2002
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1162,9 +1180,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2003
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1178,9 +1198,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2004
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1194,9 +1216,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2005
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1210,9 +1234,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2006
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1226,9 +1252,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2007
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1242,9 +1270,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2008
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1258,9 +1288,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u2009
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1274,9 +1306,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u200A
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1290,9 +1324,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u200B
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1306,9 +1342,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u202F
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1322,9 +1360,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u205f
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -1338,9 +1378,11 @@ ruleTester.run("no-irregular-whitespace", rule, { }, { code: "
\u3000
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ diff --git a/tests/lib/rules/no-iterator.js b/tests/lib/rules/no-iterator.js index 04aa795c179..a3a71841f3b 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,7 +49,7 @@ ruleTester.run("no-iterator", rule, { }, { code: "var a = test[`__iterator__`];", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noIterator", type: "MemberExpression" @@ -57,7 +57,7 @@ ruleTester.run("no-iterator", rule, { }, { code: "test[`__iterator__`] = function () {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noIterator", type: "MemberExpression" 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..8b013756ea9 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,7 +135,7 @@ ruleTester.run("no-lone-blocks", rule, { // Non-block-level bindings, even in ES6 { code: "{ function bar() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement" @@ -138,7 +143,7 @@ ruleTester.run("no-lone-blocks", rule, { }, { code: "{var x = 1;}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement" @@ -147,7 +152,7 @@ ruleTester.run("no-lone-blocks", rule, { { code: "{ \n{var x = 1;}\n let y = 2; } {let z = 1;}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -156,7 +161,7 @@ ruleTester.run("no-lone-blocks", rule, { }, { code: "{ \n{let x = 1;}\n var y = 2; } {let z = 1;}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantBlock", type: "BlockStatement", @@ -165,7 +170,7 @@ ruleTester.run("no-lone-blocks", rule, { }, { code: "{ \n{var x = 1;}\n var y = 2; }\n {var z = 1;}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "redundantBlock", @@ -224,7 +229,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -257,7 +262,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -277,7 +282,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -294,7 +299,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -311,7 +316,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -328,7 +333,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -345,7 +350,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -362,7 +367,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -380,7 +385,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -398,7 +403,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -416,7 +421,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", @@ -434,7 +439,7 @@ ruleTester.run("no-lone-blocks", rule, { } } `, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "redundantNestedBlock", type: "BlockStatement", diff --git a/tests/lib/rules/no-lonely-if.js b/tests/lib/rules/no-lonely-if.js index 9a35184f6f1..ba8731e173b 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,7 +177,7 @@ ruleTester.run("no-lonely-if", rule, { "}\n" + "`template literal`;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors }, { diff --git a/tests/lib/rules/no-loop-func.js b/tests/lib/rules/no-loop-func.js index f1311000f91..3a3efce5636 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,12 +174,12 @@ ruleTester.run("no-loop-func", rule, { }, { code: "for (var i of {}) { (function() { i; }) }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }] }, { code: "for (var i=0; i < l; i++) { (() => { i; }) }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "ArrowFunctionExpression" }] }, { @@ -202,72 +202,72 @@ 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 }, + 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)) { } }", - parserOptions: { 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; }); } }", - parserOptions: { 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; }); } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unsafeRefs", data: { varNames: "'x'" }, type: "FunctionExpression" }] }, { code: "for (var x of xs) { (function() { x; }); }", - parserOptions: { 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; }); }", - parserOptions: { 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; }", - parserOptions: { 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();", - parserOptions: { 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();", - parserOptions: { 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 f268f117e92..cbefdf6ca95 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,32 +121,32 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 900719925474099_3", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 90_0719925_4740.9_93e3", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 9.0_0719925_474099_3e15", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = -9_00719_9254_740993", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 900_719.92_54740_994", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = -900_719.92_5474_0994", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { @@ -174,22 +179,22 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 0b100000000000000000000000000000000000000000000000000001", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0B100000000000000000000000000000000000000000000000000001", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0o400000000000000001", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0O400000000000000001", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noLossOfPrecision" }] }, { @@ -206,67 +211,67 @@ ruleTester.run("no-loss-of-precision", rule, { }, { code: "var x = 5123_00000000000000000000000000_1", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = -5_12300000000000000000000_0000001", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 123_00000000000000000000_00.0_0", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 1.0_00000000000000000_0000123", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 174_980057982_640953949800178169_409709228253554471456994_914061648512796239935950073857881054_1618443059_2", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 2e9_99", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = .1_23000000000000_00000_0000_0", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0b1_0000000000000000000000000000000000000000000000000000_1", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0B10000000000_0000000000000000000000000000_000000000000001", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0o4_00000000000000_001", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0O4_0000000000000000_1", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0x2_0000000000001", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLossOfPrecision" }] }, { code: "var x = 0X200000_0000000_1", - parserOptions: { 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 e168249d117..7f6ea455c7e 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,7 +299,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useConst" }] }, { @@ -307,14 +314,14 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - parserOptions: { + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "useConst" }] }, { code: "var foo = 0n + 1n;", - parserOptions: { + languageOptions: { ecmaVersion: 2020 }, errors: [ @@ -362,6 +369,9 @@ 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" } }, @@ -418,7 +428,7 @@ ruleTester.run("no-magic-numbers", rule, { "function invokeInTen(func) {\n" + "setTimeout(func, 10);\n" + "}\n", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "10" }, line: 7 }, { messageId: "noMagic", data: { raw: "10" }, line: 7 }, @@ -491,7 +501,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "noMagic", data: { raw: "-0b110" }, line: 1 }] @@ -501,7 +511,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "noMagic", data: { raw: "-0o71" }, line: 1 }] @@ -520,6 +530,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], + languageOptions: { sourceType: "script" }, errors: [{ messageId: "noMagic", data: { raw: "-012" }, line: 1 }] @@ -628,7 +639,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-1n" }, line: 1 }] @@ -638,7 +649,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-100n" }, line: 1 }] @@ -648,7 +659,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-0x12n" }, line: 1 }] @@ -658,7 +669,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "4294967295n" }, line: 1 }] @@ -695,7 +706,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "0n" }, line: 1 }] @@ -705,7 +716,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "1n" }, line: 1 }] @@ -715,7 +726,7 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ ignoreArrayIndexes: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "noMagic", data: { raw: "-1n" }, line: 1 }] @@ -740,9 +751,11 @@ ruleTester.run("no-magic-numbers", rule, { }, { code: "var a =
;", - parserOptions: { - ecmaFeatures: { - jsx: true + languageOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true + } } }, errors: [ @@ -763,7 +776,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "f(100n)", options: [{ ignore: [100] }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "100n" }, line: 1 } ] @@ -771,7 +784,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "f(-100n)", options: [{ ignore: ["100n"] }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "-100n" }, line: 1 } ] @@ -779,7 +792,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "f(100n)", options: [{ ignore: ["-100n"] }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "noMagic", data: { raw: "100n" }, line: 1 } ] @@ -794,7 +807,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const func = (param = 123) => {}", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } ] @@ -802,14 +815,14 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const { param = 123 } = sourceObject;", options: [{}], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } ] }, { code: "const { param = 123 } = sourceObject;", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } ] @@ -817,7 +830,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const { param = 123 } = sourceObject;", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } ] @@ -825,7 +838,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } @@ -834,7 +847,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "var one, two; [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } @@ -844,7 +857,7 @@ ruleTester.run("no-magic-numbers", rule, { // ignoreClassFieldInitialValues { code: "class C { foo = 2; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } ] @@ -852,7 +865,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { foo = 2; }", options: [{}], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } ] @@ -860,7 +873,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 } ] @@ -868,7 +881,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { foo = -2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "-2" }, line: 1, column: 17 } ] @@ -876,7 +889,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { static foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 24 } ] @@ -884,7 +897,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { #foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 18 } ] @@ -892,7 +905,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { static #foo = 2; }", options: [{ ignoreClassFieldInitialValues: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 25 } ] @@ -900,7 +913,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { foo = 2 + 3; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 17 }, { messageId: "noMagic", data: { raw: "3" }, line: 1, column: 21 } @@ -909,7 +922,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { 2; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 11 } ] @@ -917,7 +930,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "class C { [2]; }", options: [{ ignoreClassFieldInitialValues: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "noMagic", data: { raw: "2" }, line: 1, column: 12 } ] diff --git a/tests/lib/rules/no-misleading-character-class.js b/tests/lib/rules/no-misleading-character-class.js index 9ee29a4631d..41945f73aee 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,7 +97,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /[👍]/", - parserOptions: { ecmaVersion: 3 }, + languageOptions: { ecmaVersion: 3, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag @@ -106,7 +105,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /[👍]/", - parserOptions: { ecmaVersion: 5 }, + languageOptions: { ecmaVersion: 5, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag @@ -121,7 +120,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /(?<=[👍])/", - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /(?<=[👍])/u" }] @@ -129,7 +128,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: "var r = /(?<=[👍])/", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /(?<=[👍])/u" }] @@ -341,7 +340,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("[👍]", "")`, - parserOptions: { ecmaVersion: 3 }, + languageOptions: { ecmaVersion: 3, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag @@ -349,7 +348,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("[👍]", "")`, - parserOptions: { ecmaVersion: 5 }, + languageOptions: { ecmaVersion: 5, sourceType: "script" }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: null // ecmaVersion doesn't support the 'u' flag @@ -364,7 +363,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("/(?<=[👍])", "")`, - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("/(?<=[👍])", "u")` }] @@ -372,7 +371,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("/(?<=[👍])", "")`, - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("/(?<=[👍])", "u")` }] @@ -513,7 +512,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp("[🇯🇵]",)`, - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp("[🇯🇵]", "u",)` }] @@ -535,7 +534,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new RegExp(("[🇯🇵]"),)`, - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new RegExp(("[🇯🇵]"), "u",)` }] @@ -598,7 +597,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[❇️]", "")`, - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "combiningClass", suggestions: null @@ -606,7 +605,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[👶🏻]", "u")`, - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "emojiModifier", suggestions: null @@ -614,7 +613,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "")`, - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "surrogatePairWithoutUFlag", suggestions: [{ messageId: "suggestUnicodeFlag", output: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "u")` }] @@ -622,7 +621,7 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[\\u{1F468}\\u{200D}\\u{1F469}\\u{200D}\\u{1F466}]", "u")`, - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "zwj", suggestions: null @@ -661,21 +660,12 @@ ruleTester.run("no-misleading-character-class", rule, { // ES2024 { code: "var r = /[[👶🏻]]/v", - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ messageId: "emojiModifier", suggestions: null }] - } - ] -}); - -const flatRuleTester = new FlatRuleTester(); - -flatRuleTester.run("no-misleading-character-class", rule, { - valid: [], - - invalid: [ + }, { code: "var r = /[👍]/", languageOptions: { @@ -697,5 +687,6 @@ flatRuleTester.run("no-misleading-character-class", rule, { suggestions: [{ messageId: "suggestUnicodeFlag", output: "var r = /[👍]/u" }] }] } + ] }); diff --git a/tests/lib/rules/no-mixed-operators.js b/tests/lib/rules/no-mixed-operators.js index 782af07e310..c43044d9650 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,7 @@ ruleTester.run("no-mixed-operators", rule, { { code: "a + b ?? c", options: [{ groups: [["+", "??"]] }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { column: 3, 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..aa3a399e2ab 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,7 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { { code: "`foo${\n \t 5 }bar`;", options: ["smart-tabs"], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -292,7 +292,7 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { }, { code: "`foo${\n\t 5 }bar`;", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "mixedSpacesAndTabs", diff --git a/tests/lib/rules/no-multi-assign.js b/tests/lib/rules/no-multi-assign.js index 94db78ff81d..4c4a9088693 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,7 +75,7 @@ ruleTester.run("no-multi-assign", rule, { }, { code: "let foo = bar = cee = 100;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 11, "AssignmentExpression"), errorAt(1, 17, "AssignmentExpression") @@ -146,7 +146,7 @@ ruleTester.run("no-multi-assign", rule, { { code: "const x = {};\nconst y = x.one = 1;", options: [{ ignoreNonDeclaration: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(2, 11, "AssignmentExpression") ] @@ -155,7 +155,7 @@ ruleTester.run("no-multi-assign", rule, { { code: "let a, b;a = b = 1", options: [{}], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 14, "AssignmentExpression") ] @@ -163,7 +163,7 @@ ruleTester.run("no-multi-assign", rule, { { code: "let x, y;x = y = 'baz'", options: [{ ignoreNonDeclaration: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 14, "AssignmentExpression") ] @@ -171,14 +171,14 @@ ruleTester.run("no-multi-assign", rule, { { code: "const a = b = 1", options: [{ ignoreNonDeclaration: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ errorAt(1, 11, "AssignmentExpression") ] }, { code: "class C { field = foo = 0 }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ errorAt(1, 19, "AssignmentExpression") ] @@ -186,7 +186,7 @@ ruleTester.run("no-multi-assign", rule, { { code: "class C { field = foo = 0 }", options: [{ ignoreNonDeclaration: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ errorAt(1, 19, "AssignmentExpression") ] diff --git a/tests/lib/rules/no-multi-spaces.js b/tests/lib/rules/no-multi-spaces.js index 5534f111548..9d0f588494c 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,7 +121,7 @@ ruleTester.run("no-multi-spaces", rule, { { code: "var foo = (a, b) => {}", output: "var foo = (a, b) => {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "multipleSpaces", data: { displayValue: "b" }, 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..eb0f8a2e2e5 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,14 +301,14 @@ ruleTester.run("no-multiple-empty-lines", rule, { "`bar`;\n" + "`baz`;", options: [{ max: 1 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [getExpectedError(1)] }, { code: "`template ${foo\n\n\n} literal`;", output: "`template ${foo\n\n} literal`;", options: [{ max: 1 }], - parserOptions: { 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 8bb14d70c5d..a85c85d56de 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,7 +36,7 @@ ruleTester.run("no-native-reassign", rule, { { code: "String++;", errors: [{ messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" }] }, { code: "({Object = 0, String = 0} = {});", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "nativeReassign", data: { name: "Object" }, type: "Identifier" }, { messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" } @@ -43,18 +44,18 @@ ruleTester.run("no-native-reassign", rule, { }, { code: "top = 0;", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }] }, { code: "require = 0;", - env: { node: true }, + 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; }", globals: { b: false }, errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, + { 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-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..a92814a0c02 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,7 +96,7 @@ ruleTester.run("no-new-func", rule, { }, { code: "var a = (Function?.call)(null, \"b\", \"c\", \"return b+c\");", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noFunctionConstructor", type: "CallExpression" @@ -104,7 +104,7 @@ ruleTester.run("no-new-func", rule, { }, { code: "const fn = () => { class Function {} }; new Function('', '')", - parserOptions: { + languageOptions: { ecmaVersion: 2015 }, errors: [{ 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..e38156e7a3b 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,7 +62,7 @@ ruleTester.run("no-new-object", rule, { }, { code: "const a = new Object()", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "preferLiteral", type: "NewExpression" }] } ] 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..972e10bbc66 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,7 @@ ruleTester.run("no-new-wrappers", rule, { const b = new String('foo'); } `, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noConstructor", data: { 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..1a786e88751 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,17 +212,17 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Reflect();", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = new Reflect();", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] }, { code: "var x = Reflect();", - env: { es2017: true }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { @@ -228,37 +235,37 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Atomics();", - env: { es2017: true }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = new Atomics();", - env: { es2017: true }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] }, { code: "var x = Atomics();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = Atomics();", - globals: { Atomics: false }, + languageOptions: { globals: { Atomics: false } }, errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = new Atomics();", - globals: { Atomics: "writable" }, + languageOptions: { globals: { Atomics: "writable" } }, errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] }, { code: "var x = Intl();", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] }, { code: "var x = new Intl();", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }] }, { @@ -271,42 +278,42 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = globalThis.Math();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Math();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }] }, { code: "f(globalThis.Math());", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }] }, { code: "globalThis.Math().foo;", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }] }, { code: "new globalThis.Math().foo;", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }] }, { code: "var x = globalThis.JSON();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] }, { code: "x = globalThis.JSON(str);", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] }, { code: "globalThis.Math( globalThis.JSON() );", - env: { es2020: true }, + 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 } @@ -314,37 +321,37 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = globalThis.Reflect();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Reflect;", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] }, { code: "/*globals Reflect: true*/ Reflect();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = globalThis.Atomics();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = globalThis.Intl();", - env: { browser: true, es2020: true }, + languageOptions: { globals: globals.browser, ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Intl;", - env: { browser: true, es2020: true }, + languageOptions: { globals: globals.browser, ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "NewExpression" }] }, { code: "/*globals Intl: true*/ Intl();", - env: { browser: true, es2020: true }, + languageOptions: { globals: globals.browser, ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Intl" }, type: "CallExpression" }] }, { @@ -357,44 +364,44 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var foo = bar ? baz: globalThis.JSON; foo();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }] }, { code: "var foo = bar ? baz: globalThis.JSON; new foo();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }] }, { code: "var foo = window.Atomics; foo();", - env: { es2020: true, browser: true }, + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }] }, { code: "var foo = window.Atomics; new foo;", - env: { es2020: true, browser: true }, + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }] }, { code: "var foo = window.Intl; foo();", - env: { es2020: true, browser: true }, + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "CallExpression" }] }, { code: "var foo = window.Intl; new foo;", - env: { es2020: true, browser: true }, + languageOptions: { ecmaVersion: 2020, globals: globals.browser }, errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Intl" }, type: "NewExpression" }] }, // Optional chaining { code: "var x = globalThis?.Reflect();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = (globalThis?.Reflect)();", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] } ] 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..90101b6d66b 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,7 +154,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo({bar}) { bar = 13; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } @@ -162,7 +162,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo([, {bar}]) { bar = 13; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } @@ -170,7 +170,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(bar) { ({bar} = {}); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } @@ -178,7 +178,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(bar) { ({x: [, bar = 0]} = {}); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } @@ -193,7 +193,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(bar) { for (bar of baz); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "bar" } @@ -243,7 +243,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { for (bar.a of []); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } @@ -260,7 +260,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } @@ -269,7 +269,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsFor: ["a"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } @@ -278,7 +278,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsForRegex: ["^a.*$"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } @@ -287,7 +287,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { [bar.a] = []; }", options: [{ props: true, ignorePropertyModificationsForRegex: ["^B.*$"] }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } @@ -296,7 +296,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(bar) { ({foo: bar.a} = {}); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "bar" } @@ -305,7 +305,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { ({a} = obj); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParam", data: { @@ -315,7 +315,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(a) { ([...a] = obj); }", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "assignmentToFunctionParam", data: { @@ -325,7 +325,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(a) { ({...a} = obj); }", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "assignmentToFunctionParam", data: { @@ -336,7 +336,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { ([...a.b] = obj); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } @@ -345,7 +345,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { ({...a.b} = obj); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } @@ -354,7 +354,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { for ({bar: a.b} in {}); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } @@ -363,7 +363,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { for ([a.b] of []); }", options: [{ props: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } @@ -371,7 +371,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(a) { a &&= b; }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } @@ -379,7 +379,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(a) { a ||= b; }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } @@ -387,7 +387,7 @@ ruleTester.run("no-param-reassign", rule, { }, { code: "function foo(a) { a ??= b; }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParam", data: { name: "a" } @@ -396,7 +396,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { a.b &&= c; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } @@ -405,7 +405,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { a.b.c ||= d; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } @@ -414,7 +414,7 @@ ruleTester.run("no-param-reassign", rule, { { code: "function foo(a) { a[b] ??= c; }", options: [{ props: true }], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "assignmentToFunctionParamProp", data: { name: "a" } 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 74ad523a031..3856480c90d 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,7 +873,7 @@ ruleTester.run("no-promise-executor-return", rule, { }, { code: "() => new Promise(() => async () => 1);", - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, // for async errors: [{ diff --git a/tests/lib/rules/no-proto.js b/tests/lib/rules/no-proto.js index c9b71357156..78698612dfa 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__`];", 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 80755a6d878..27e1f54b0cd 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,7 @@ ruleTester.run("no-prototype-builtins", rule, { }, { code: "foo[`isPrototypeOf`]('bar').baz", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ line: 1, column: 5, @@ -203,28 +203,30 @@ 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')", - globals: { - Object: "off" + languageOptions: { + globals: { + Object: "off" + } }, - errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }], - 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')", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "foo?.bar.hasOwnProperty('baz')", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "foo.hasOwnProperty?.('bar')", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { @@ -234,7 +236,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { @@ -244,7 +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", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, @@ -259,7 +261,7 @@ ruleTester.run("no-prototype-builtins", rule, { { code: "(a,b).hasOwnProperty('bar')", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, @@ -277,25 +279,25 @@ ruleTester.run("no-prototype-builtins", rule, { // No suggestion where no-unsafe-optional-chaining is reported on the call code: "(foo?.hasOwnProperty)('bar')", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "(foo?.hasOwnProperty)?.('bar')", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "prototypeBuildIn", data: { prop: "hasOwnProperty" }, suggestions: [] }] }, { code: "foo?.['hasOwnProperty']('bar')", - parserOptions: { 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')", - parserOptions: { 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 5754d19945f..6bfd974229a 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;", 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" }] }, @@ -144,34 +156,34 @@ 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;", 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; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "class C { static { var a; { var a; } } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "class C { static { { var a; } var a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] }, { code: "class C { static { { var a; } { var a; } } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] @@ -185,13 +197,13 @@ ruleTester.run("no-redeclare", rule, { { code: "var top = 0;", options: [{ builtinGlobals: true }], - env: { browser: true }, + 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 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "'a' is already defined.", type: "Identifier" }, { message: "'Object' is already defined as a built-in global variable.", type: "Identifier" } @@ -200,7 +212,7 @@ ruleTester.run("no-redeclare", rule, { { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { message: "'a' is already defined.", type: "Identifier" } ] @@ -208,7 +220,7 @@ ruleTester.run("no-redeclare", rule, { { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { message: "'a' is already defined.", type: "Identifier" } ] @@ -216,7 +228,7 @@ ruleTester.run("no-redeclare", rule, { { code: "var a; var {a = 0, b: Object = 0} = {};", options: [{ builtinGlobals: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { message: "'a' is already defined.", type: "Identifier" } ] @@ -224,14 +236,13 @@ ruleTester.run("no-redeclare", rule, { { code: "var globalThis = 0;", options: [{ builtinGlobals: true }], - env: { es2020: true }, + 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 }], - parserOptions: { ecmaVersion: 6 }, - env: { es2020: 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" } @@ -294,7 +305,7 @@ ruleTester.run("no-redeclare", rule, { }, { code: "var top = 0;", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [ { message: "'top' is already defined as a built-in global variable.", type: "Identifier" } ] @@ -448,7 +459,7 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */", options: [{ builtinGlobals: true }], - globals: { a: "readonly" }, + languageOptions: { globals: { a: "readonly" } }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -461,7 +472,7 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */", options: [{ builtinGlobals: true }], - globals: { a: "writable" }, + languageOptions: { globals: { a: "writable" } }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -485,7 +496,7 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */ /*globals a */ var a = 0", options: [{ builtinGlobals: true }], - globals: { a: "writable" }, + languageOptions: { globals: { a: "writable" } }, errors: [ { message: "'a' is already defined as a built-in global variable.", diff --git a/tests/lib/rules/no-regex-spaces.js b/tests/lib/rules/no-regex-spaces.js index fdc3eaa1817..c809aec888b 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,7 +148,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "multipleSpaces", @@ -386,7 +386,7 @@ ruleTester.run("no-regex-spaces", rule, { { code: "var foo = /[[ ] ] /v;", output: "var foo = /[[ ] ] {4}/v;", - parserOptions: { + languageOptions: { ecmaVersion: 2024 }, errors: [ 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..79abe9e0b68 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,7 +80,9 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: ["foo"], - globals: { foo: false }, + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, @@ -89,7 +92,7 @@ ruleTester.run("no-restricted-globals", rule, { { code: "event", options: ["foo", "event"], - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, @@ -99,7 +102,9 @@ ruleTester.run("no-restricted-globals", rule, { { code: "foo", options: ["foo"], - globals: { foo: false }, + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, @@ -145,7 +150,9 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo" }], - globals: { foo: false }, + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, @@ -155,7 +162,7 @@ ruleTester.run("no-restricted-globals", rule, { { code: "event", options: ["foo", { name: "event" }], - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, @@ -165,7 +172,9 @@ ruleTester.run("no-restricted-globals", rule, { { code: "foo", options: [{ name: "foo" }], - globals: { foo: false }, + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, @@ -211,7 +220,9 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo", message: customMessage }], - globals: { foo: false }, + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, @@ -221,7 +232,7 @@ ruleTester.run("no-restricted-globals", rule, { { code: "event", options: ["foo", { name: "event", message: "Use local event parameter." }], - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "customMessage", data: { name: "event", customMessage: "Use local event parameter." }, @@ -231,7 +242,9 @@ ruleTester.run("no-restricted-globals", rule, { { code: "foo", options: [{ name: "foo", message: customMessage }], - globals: { foo: false }, + languageOptions: { + globals: { foo: false } + }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, @@ -259,7 +272,7 @@ ruleTester.run("no-restricted-globals", rule, { { code: "var foo = obj => hasOwnProperty(obj, 'name');", options: ["hasOwnProperty"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "defaultMessage", data: { name: "hasOwnProperty" }, diff --git a/tests/lib/rules/no-restricted-imports.js b/tests/lib/rules/no-restricted-imports.js index b756770d686..d12584afb46 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..488849adb8a 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,12 +117,12 @@ ruleTester.run("no-restricted-modules", rule, { }, { code: "require(`fs`)", options: ["fs"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "defaultMessage", data: { name: "fs" }, type: "CallExpression" }] }, { code: "require(`crypt\\o`);", options: ["crypto"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "defaultMessage", data: { name: "crypto" }, type: "CallExpression" }] }, { diff --git a/tests/lib/rules/no-restricted-properties.js b/tests/lib/rules/no-restricted-properties.js index 7c557bcdc06..d470a18da97 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,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "foo[/(?0)/]", options: [{ property: "/(?0)/" }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "restrictedProperty", data: { @@ -381,7 +381,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -394,7 +394,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar: baz} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -407,7 +407,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {'bar': baz} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -420,7 +420,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar: {baz: qux}} = foo;", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -433,7 +433,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar} = foo;", options: [{ object: "foo" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -446,7 +446,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar: baz} = foo;", options: [{ object: "foo" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -459,7 +459,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let {bar} = foo;", options: [{ property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedProperty", data: { @@ -472,7 +472,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let bar; ({bar} = foo);", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -485,7 +485,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "let bar; ({bar: baz = 1} = foo);", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -498,7 +498,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "function qux({bar} = foo) {}", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -511,7 +511,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "function qux({bar: baz} = foo) {}", options: [{ object: "foo", property: "bar" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { @@ -524,7 +524,7 @@ ruleTester.run("no-restricted-properties", rule, { }, { code: "var {['foo']: qux, bar} = baz", options: [{ object: "baz", property: "foo" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedObjectProperty", data: { diff --git a/tests/lib/rules/no-restricted-syntax.js b/tests/lib/rules/no-restricted-syntax.js index d5fb36aa472..7fb4c414664 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,7 +80,7 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "() => {}", options: ["ArrowFunctionExpression > BlockStatement"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ArrowFunctionExpression > BlockStatement' is not allowed." }, type: "BlockStatement" }] }, { @@ -134,13 +134,13 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "var foo = foo?.bar?.();", options: ["ChainExpression"], - parserOptions: { 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]"], - parserOptions: { ecmaVersion: 2020 }, + 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" } @@ -151,7 +151,7 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "a?.b", options: [":nth-child(1)"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using ':nth-child(1)' is not allowed." }, type: "ExpressionStatement" } ] @@ -161,7 +161,7 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "const foo = [
,
]", options: ["* ~ *"], - parserOptions: { ecmaVersion: 2020, ecmaFeatures: { jsx: true } }, + languageOptions: { ecmaVersion: 2020, parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "restrictedSyntax", data: { message: "Using '* ~ *' is not allowed." }, type: "JSXElement" } ] diff --git a/tests/lib/rules/no-return-assign.js b/tests/lib/rules/no-return-assign.js index 600503c2de0..c7d8d6ae9ce 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,7 +138,7 @@ ruleTester.run("no-return-assign", rule, { code: `function doSomething() { return foo = () => a }`, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "returnAssignment", @@ -150,7 +150,7 @@ ruleTester.run("no-return-assign", rule, { code: `function doSomething() { return () => a = () => b }`, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "arrowAssignment", @@ -168,7 +168,7 @@ ruleTester.run("no-return-assign", rule, { }, { code: "const foo = (a) => (b) => a = b", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "arrowAssignment", 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..cb234cf1a2d 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,14 +51,14 @@ ruleTester.run("no-script-url", rule, { }, { code: "var a = `javascript:`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedScriptURL", type: "TemplateLiteral" } ] }, { code: "var a = `JavaScript:`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedScriptURL", type: "TemplateLiteral" } ] diff --git a/tests/lib/rules/no-self-assign.js b/tests/lib/rules/no-self-assign.js index 0fe04040d7a..84864e82628 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]", 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,46 +145,46 @@ 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 }], languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "selfAssignment", data: { name: "a[/(?0)/]" } }] }, // Optional chaining { code: "(a?.b).c = (a?.b).c", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "selfAssignment", data: { name: "(a?.b).c" } }] }, { code: "a.b = a?.b", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "selfAssignment", data: { name: "a?.b" } }] }, // Private members { code: "class C { #field; foo() { this.#field = this.#field; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }] }, { code: "class C { #field; foo() { [this.#field] = [this.#field]; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "selfAssignment", data: { name: "this.#field" } }] }, // logical assignment { code: "a &&= a", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, { code: "a ||= a", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, { code: "a ??= a", - parserOptions: { 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 ad4d30a892f..c078ad8896f 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,7 +50,7 @@ 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 }, + 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 1ac7c4a6c6e..717bf7034f4 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)", 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) }, @@ -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 }], 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 ab5b196b9f3..0cd634df733 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,7 +404,7 @@ ruleTester.run("no-setter-return", rule, { }, { code: "return; ({ set a(val) { return 1; } }); return 2;", - env: { node: true }, + languageOptions: { sourceType: "commonjs" }, errors: [error(25)] }, @@ -416,7 +419,7 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { return 1; } })", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [error()] }, { @@ -435,7 +438,7 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set: val => f(val) })", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [error(50, "CallExpression")] }, { @@ -454,7 +457,7 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { try { return f(val) } catch (e) { return e }; } })", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [error(55), error(83)] }, { @@ -486,7 +489,7 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { 'set'(val) { return 1; } })", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [error()] }, { @@ -511,12 +514,12 @@ ruleTester.run("no-setter-return", rule, { // Optional chaining { code: "Object?.defineProperty(foo, 'bar', { set(val) { return 1; } })", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [error()] }, { code: "(Object?.defineProperty)(foo, 'bar', { set(val) { return 1; } })", - parserOptions: { 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 868cd8220b6..abb3a35c965 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,7 @@ ruleTester.run("no-shadow-restricted-names", rule, { }, { code: "var eval = (eval) => { var eval; !function eval(eval) { try {} catch(eval) {} }; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, @@ -106,14 +111,14 @@ ruleTester.run("no-shadow-restricted-names", rule, { }, { code: "var [undefined] = [1]", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } ] }, { code: "var {undefined} = obj; var {a: undefined} = obj; var {a: {b: {undefined}}} = obj; var {a, ...undefined} = obj;", - parserOptions: { ecmaVersion: 9 }, + languageOptions: { ecmaVersion: 9 }, errors: [ { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, diff --git a/tests/lib/rules/no-shadow.js b/tests/lib/rules/no-shadow.js index 0afcc3ff31b..c95da147132 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,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "var a = (x) => { var b = () => { var x = 'foo'; }; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -199,7 +205,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "var x = 1; { let x = 2; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -212,7 +218,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "let x = 1; { const x = 2; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -225,7 +231,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "{ let a; } function a() {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -238,7 +244,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "{ const a = 0; } function a() {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -251,7 +257,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "function foo() { let a; } function a() {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -264,7 +270,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "function foo() { var a; } function a() {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -277,7 +283,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "function foo(a) { } function a() {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -291,7 +297,7 @@ ruleTester.run("no-shadow", rule, { { code: "{ let a; } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -305,7 +311,7 @@ ruleTester.run("no-shadow", rule, { { code: "{ let a; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -319,7 +325,7 @@ ruleTester.run("no-shadow", rule, { { code: "{ let a; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -333,7 +339,7 @@ ruleTester.run("no-shadow", rule, { { code: "{ const a = 0; } const a = 1;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -347,7 +353,7 @@ ruleTester.run("no-shadow", rule, { { code: "{ const a = 0; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -361,7 +367,7 @@ ruleTester.run("no-shadow", rule, { { code: "{ const a = 0; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -375,7 +381,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { let a; } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -389,7 +395,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { let a; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -403,7 +409,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { let a; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -417,7 +423,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var a; } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -431,7 +437,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var a; } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -445,7 +451,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var a; } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -459,7 +465,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo(a) { } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -473,7 +479,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo(a) { } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -487,7 +493,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo(a) { } function a() {}", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -512,7 +518,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function a() { class a{} })()", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -537,7 +543,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function a() { (class a{}); })()", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -574,7 +580,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function() { var a = function() { class a{} }; })()", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -599,7 +605,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function() { var a = function() { (class a{}); }; })()", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -612,7 +618,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "(function() { var a = class { constructor() { class a {} } }; })()", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -625,7 +631,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "class A { constructor() { var A; } }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -677,7 +683,7 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var top = 0; }", options: [{ builtinGlobals: true }], - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "noShadowGlobal", data: { @@ -689,7 +695,7 @@ ruleTester.run("no-shadow", rule, { { code: "var Object = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "noShadowGlobal", data: { @@ -701,8 +707,11 @@ ruleTester.run("no-shadow", rule, { { code: "var top = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, - env: { browser: true }, + languageOptions: { + ecmaVersion: 6, + sourceType: "module", + globals: globals.browser + }, errors: [{ messageId: "noShadowGlobal", data: { @@ -714,7 +723,7 @@ ruleTester.run("no-shadow", rule, { { code: "var Object = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [{ messageId: "noShadowGlobal", data: { @@ -726,8 +735,10 @@ ruleTester.run("no-shadow", rule, { { code: "var top = 0;", options: [{ builtinGlobals: true }], - parserOptions: { ecmaFeatures: { globalReturn: true } }, - env: { browser: true }, + languageOptions: { + parserOptions: { ecmaFeatures: { globalReturn: true } }, + globals: globals.browser + }, errors: [{ messageId: "noShadowGlobal", data: { @@ -752,7 +763,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "class C { static { let a; { let a; } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -767,7 +778,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "class C { static { var C; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -782,7 +793,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "class C { static { let C; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -797,7 +808,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "var a; class C { static { var a; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -813,7 +824,7 @@ ruleTester.run("no-shadow", rule, { { code: "class C { static { var a; } } var a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -829,7 +840,7 @@ ruleTester.run("no-shadow", rule, { { code: "class C { static { let a; } } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -845,7 +856,7 @@ ruleTester.run("no-shadow", rule, { { code: "class C { static { var a; } } let a;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -860,7 +871,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "class C { static { var a; class D { static { var a; } } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -875,7 +886,7 @@ ruleTester.run("no-shadow", rule, { }, { code: "class C { static { let a; class D { static { let a; } } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noShadow", data: { @@ -891,7 +902,7 @@ ruleTester.run("no-shadow", rule, { { code: "let x = foo((x,y) => {});\nlet y;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noShadow", @@ -916,7 +927,7 @@ ruleTester.run("no-shadow", rule, { { code: "const a = fn(()=>{ class C { fn () { const a = 42; return a } } return new C() })", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -932,7 +943,7 @@ ruleTester.run("no-shadow", rule, { { code: "function a() {}\nfoo(a => {});", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -948,7 +959,7 @@ ruleTester.run("no-shadow", rule, { { code: "const a = fn(()=>{ function C() { this.fn=function() { const a = 42; return a } } return new C() });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -964,7 +975,7 @@ ruleTester.run("no-shadow", rule, { { code: "const x = foo(() => { const bar = () => { return x => {}; }; return bar; });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -980,7 +991,7 @@ ruleTester.run("no-shadow", rule, { { code: "const x = foo(() => { return { bar(x) {} }; });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -996,7 +1007,7 @@ ruleTester.run("no-shadow", rule, { { code: "const x = () => { foo(x => x); }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1012,7 +1023,7 @@ ruleTester.run("no-shadow", rule, { { code: "const foo = () => { let x; bar(x => x); }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1028,7 +1039,7 @@ ruleTester.run("no-shadow", rule, { { code: "foo(() => { const x = x => x; });", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1044,7 +1055,7 @@ ruleTester.run("no-shadow", rule, { { code: "const foo = (x) => { bar(x => {}) }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1060,7 +1071,7 @@ ruleTester.run("no-shadow", rule, { { code: "let x = ((x,y) => {})();\nlet y;", options: [{ hoist: "all" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "noShadow", @@ -1085,7 +1096,7 @@ ruleTester.run("no-shadow", rule, { { code: "const a = (()=>{ class C { fn () { const a = 42; return a } } return new C() })()", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { @@ -1101,7 +1112,7 @@ ruleTester.run("no-shadow", rule, { { code: "const x = () => { (x => x)(); }", options: [{ ignoreOnInitialization: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "noShadow", data: { 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..8712d122a7a 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,17 +174,17 @@ ruleTester.run("no-this-before-super", rule, { }, { code: "class A extends B { constructor() { foo &&= super().a; this.c(); } }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { foo ||= super().a; this.c(); } }", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { foo ??= super().a; this.c(); } }", - parserOptions: { 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 d50b2cea2b6..5ff6b9bda8f 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,7 +129,7 @@ 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 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "object", type: "ThrowStatement" @@ -173,7 +173,7 @@ ruleTester.run("no-throw-literal", rule, { // TemplateLiteral { code: "throw `${err}`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "object", type: "ThrowStatement" diff --git a/tests/lib/rules/no-trailing-spaces.js b/tests/lib/rules/no-trailing-spaces.js index 1275e0708ca..b614fd94009 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,7 +173,7 @@ ruleTester.run("no-trailing-spaces", rule, { " short,\n" + " short2\n" + "}\n", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "trailingSpace", type: "Program" @@ -366,7 +366,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "trailingSpace", type: "Program", @@ -379,7 +379,7 @@ ruleTester.run("no-trailing-spaces", rule, { { code: "let str = `\n${a}\n \n${b}`; \n\t", output: "let str = `\n${a}\n \n${b}`;\n", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -402,7 +402,7 @@ ruleTester.run("no-trailing-spaces", rule, { { code: "let str = ` \n ${a}\n \n${b}`; \n", output: "let str = ` \n ${a}\n \n${b}`;\n", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", @@ -420,7 +420,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ skipBlankLines: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "trailingSpace", diff --git a/tests/lib/rules/no-undef-init.js b/tests/lib/rules/no-undef-init.js index 7f134ba0b3a..6cd38116b6f 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,13 +47,13 @@ ruleTester.run("no-undef-init", rule, { { code: "var [a] = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] }, { code: "var {a} = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }] }, { @@ -64,37 +64,37 @@ ruleTester.run("no-undef-init", rule, { { code: "let a = undefined;", output: "let a;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined, b = 1;", output: "let a, b = 1;", - parserOptions: { 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;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "b" }, type: "VariableDeclarator" }] }, { code: "let [a] = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] }, { code: "let {a} = undefined;", output: null, - parserOptions: { 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]){}}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, @@ -102,55 +102,55 @@ ruleTester.run("no-undef-init", rule, { { code: "let /* comment */a = undefined;", output: "let /* comment */a;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a/**/ = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a /**/ = undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a//\n= undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = /**/undefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = //\nundefined;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined/* comment */;", output: "let a/* comment */;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined/* comment */, b;", output: "let a/* comment */, b;", - parserOptions: { 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;", - parserOptions: { 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 956bbc991ab..5a599658b9d 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, { code: "var a; class C { static {} } a;", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, { code: "a; class C { static {} } var a;", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, { 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,17 +173,17 @@ 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();", 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};", - parserOptions: { + languageOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "undef", data: { name: "b" } }] @@ -180,91 +192,91 @@ ruleTester.run("no-undef", rule, { // class static blocks { code: "class C { static { a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" } }] }, { code: "class C { static { { let a; } a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 31 }] }, { code: "class C { static { { function a() {} } a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 40 }] }, { code: "class C { static { function foo() { var a; } a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 47 }] }, { code: "class C { static { var a; } static { a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }] }, { code: "class C { static { let a; } static { a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 38 }] }, { code: "class C { static { function a(){} } static { a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 46 }] }, { code: "class C { static { var a; } foo() { a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }] }, { code: "class C { static { let a; } foo() { a; } }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 37 }] }, { code: "class C { static { var a; } [a]; }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }] }, { code: "class C { static { let a; } [a]; }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 30 }] }, { code: "class C { static { function a() {} } [a]; }", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "undef", data: { name: "a" }, column: 39 }] }, { code: "class C { static { var a; } } a;", - parserOptions: { + 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..be9cc771a5f 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,22 +93,22 @@ ruleTester.run("no-undefined", rule, { }, { code: "import undefined from 'foo'", - parserOptions: ES6_MODULE, + languageOptions: ES6_MODULE, errors }, { code: "import * as undefined from 'foo'", - parserOptions: ES6_MODULE, + languageOptions: ES6_MODULE, errors }, { code: "import { undefined } from 'foo'", - parserOptions: ES6_MODULE, + languageOptions: ES6_MODULE, errors }, { code: "import { a as undefined } from 'foo'", - parserOptions: ES6_MODULE, + languageOptions: ES6_MODULE, errors }, @@ -116,7 +116,7 @@ ruleTester.run("no-undefined", rule, { * 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..e4c845edc1c 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,73 +95,73 @@ 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; } }", 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 }], 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 }], 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 }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }] }, { code: "const [_foo = 1] = arr", options: [{ allowInArrayDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const [foo, ..._rest] = [1, 2, 3]", options: [{ allowInArrayDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_rest" } }] }, { code: "const [foo, [bar_, baz]] = [1, [2, 3]]", options: [{ allowInArrayDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "bar_" } }] }, { code: "const { _foo, bar } = { _foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { _foo = 1 } = obj", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { bar: _foo = 1 } = obj", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { foo: _foo, bar } = { foo: 1, bar: 2 }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" } }] }, { code: "const { foo, ..._rest} = { foo: 1, bar: 2, baz: 3 }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }, { messageId: "unexpectedUnderscore", data: { identifier: "_a" } } @@ -169,12 +169,12 @@ ruleTester.run("no-underscore-dangle", rule, { }, { code: "const { foo: [_bar, { a: _a, b } ] } = { foo: [1, { a: 'a', b: 'b' }] }", options: [{ allowInArrayDestructuring: true, allowInObjectDestructuring: false }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedUnderscore", data: { identifier: "_bar" } }, { messageId: "unexpectedUnderscore", data: { identifier: "_baz" } } @@ -182,41 +182,41 @@ ruleTester.run("no-underscore-dangle", rule, { }, { code: "const { foo, bar: { baz, _qux } } = { foo: 1, bar: { baz: 3, _qux: 4 } }", options: [{ allowInObjectDestructuring: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_qux" } }] }, { code: "class foo { #_bar() {} }", options: [{ enforceInMethodNames: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_bar" } }] }, { code: "class foo { #bar_() {} }", options: [{ enforceInMethodNames: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#bar_" } }] }, { code: "class foo { _field; }", options: [{ enforceInClassFields: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_field" } }] }, { code: "class foo { #_field; }", options: [{ enforceInClassFields: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "#_field" } }] }, { code: "class foo { field_; }", options: [{ enforceInClassFields: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "field_" } }] }, { code: "class foo { #field_; }", options: [{ enforceInClassFields: true }], - parserOptions: { 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 87044efe2a4..2857572eb7d 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,7 +237,7 @@ ruleTester.run("no-unexpected-multiline", rule, { }, { code: "let x = function() {}\n `hello`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 2, @@ -242,7 +248,7 @@ ruleTester.run("no-unexpected-multiline", rule, { }, { code: "let x = function() {}\nx\n`hello`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 3, column: 1, @@ -253,7 +259,7 @@ ruleTester.run("no-unexpected-multiline", rule, { }, { code: "x\n.y\nz\n`Invalid Test Case`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, @@ -337,7 +343,9 @@ 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"), + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment") + }, errors: [ { line: 5, @@ -352,7 +360,7 @@ ruleTester.run("no-unexpected-multiline", rule, { // Class fields { code: "class C { field1 = obj\n[field2]; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { line: 2, @@ -365,7 +373,7 @@ ruleTester.run("no-unexpected-multiline", rule, { }, { code: "class C { field1 = function() {}\n[field2]; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { line: 2, 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..f1bdcf7738f 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,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -282,7 +282,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -296,7 +296,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = b ? b : c = 0;", output: "var a = b || (c = 0);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -310,7 +310,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -324,7 +324,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = b ? b : (c = 0);", output: "var a = b || (c = 0);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -338,7 +338,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -352,7 +352,7 @@ ruleTester.run("no-unneeded-ternary", rule, { 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -366,7 +366,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = b ? b : (c, d);", output: "var a = b || (c, d);", options: [{ defaultAssignment: false }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -419,7 +419,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", @@ -434,8 +434,10 @@ ruleTester.run("no-unneeded-ternary", rule, { { code: "foo as any ? false : true", output: "!(foo as any)", - parser: parser("typescript-parsers/unneeded-ternary-1"), - parserOptions: { ecmaVersion: 6 }, + languageOptions: { + parser: require(parser("typescript-parsers/unneeded-ternary-1")), + ecmaVersion: 6 + }, errors: [{ messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression" @@ -445,8 +447,10 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "foo ? foo : bar as any", output: "foo || (bar as any)", options: [{ defaultAssignment: false }], - parser: parser("typescript-parsers/unneeded-ternary-2"), - parserOptions: { ecmaVersion: 6 }, + languageOptions: { + parser: require(parser("typescript-parsers/unneeded-ternary-2")), + ecmaVersion: 6 + }, errors: [{ messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression" 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..0cf0cfa4045 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,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() }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unreachableCode", @@ -254,7 +259,7 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -277,7 +282,7 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -301,7 +306,7 @@ ruleTester.run("no-unreachable", rule, { return err; } }`, - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -333,22 +338,22 @@ ruleTester.run("no-unreachable", rule, { */ { code: "class C extends B { foo; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unreachableCode", column: 21, endColumn: 25 }] }, { code: "class C extends B { foo = unreachable + code; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unreachableCode", column: 21, endColumn: 46 }] }, { code: "class C extends B { foo; bar; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unreachableCode", column: 21, endColumn: 30 }] }, { code: "class C extends B { foo; constructor() {} bar; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 21, endColumn: 25 }, { messageId: "unreachableCode", column: 43, endColumn: 47 } @@ -356,7 +361,7 @@ ruleTester.run("no-unreachable", rule, { }, { code: "(class extends B { foo; constructor() {} bar; })", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 20, endColumn: 24 }, { messageId: "unreachableCode", column: 42, endColumn: 46 } @@ -364,21 +369,21 @@ ruleTester.run("no-unreachable", rule, { }, { code: "class B extends A { x; constructor() { class C extends D { [super().x]; constructor() {} } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 60, endColumn: 72 } ] }, { code: "class B extends A { x; constructor() { class C extends super().x { y; constructor() {} } } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 68, endColumn: 70 } ] }, { code: "class B extends A { x; static y; z; static q; constructor() {} }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unreachableCode", column: 21, endColumn: 23 }, { messageId: "unreachableCode", column: 34, endColumn: 36 } 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..ca91156cc19 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,7 +296,7 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { }, { code: "with (obj?.foo) {};", - parserOptions: { + languageOptions: { sourceType: "script" }, errors: [ @@ -310,7 +310,7 @@ ruleTester.run("no-unsafe-optional-chaining", rule, { }, { code: "async function foo() { with ( await obj?.foo) {}; }", - parserOptions: { + languageOptions: { sourceType: "script" }, errors: [ diff --git a/tests/lib/rules/no-unused-expressions.js b/tests/lib/rules/no-unused-expressions.js index 7cf11a9a3ea..b86213e544d 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,12 +120,12 @@ ruleTester.run("no-unused-expressions", rule, { { code: "a ? b() || (c = d) : e", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "`untagged template literal`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression" }] }, { code: "tag`tagged template literal`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression" }] }, { code: "a && b()", options: [{ allowTernary: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, @@ -141,40 +141,40 @@ 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\"; }", languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression" }] }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression" }] }, { code: "tag`tagged template literal`", options: [{ allowTaggedTemplates: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression" }] }, // Optional chaining { code: "obj?.foo", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "obj?.foo.bar", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "obj?.foo().bar", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, @@ -182,25 +182,25 @@ ruleTester.run("no-unused-expressions", rule, { { code: "
", options: [{ enforceForJSX: true }], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "<>", options: [{ enforceForJSX: true }], - 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'; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "class C { static { \n'foo'\n'bar'\n } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unusedExpression", diff --git a/tests/lib/rules/no-unused-labels.js b/tests/lib/rules/no-unused-labels.js index 46b7b1e13e2..42fd69dedd5 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,7 +94,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unused" }] }, { 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..6d98d258d7e 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\";", 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", parserOptions: { ecmaVersion: 6 }, errors: [assignedError("y")] }, + { code: "/*exported x*/ var { x, y } = z", languageOptions: { ecmaVersion: 6 }, errors: [assignedError("y")] }, // ignore pattern { @@ -553,7 +564,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "var [ firstItemIgnored, secondItem ] = items;", options: [{ vars: "all", varsIgnorePattern: "[iI]gnored" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 25, @@ -574,7 +585,7 @@ ruleTester.run("no-unused-vars", rule, { const newArray = [a, c]; `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ // should report only `newArray` @@ -587,7 +598,7 @@ ruleTester.run("no-unused-vars", rule, { const [a, _b, c] = array; `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("a", ". Allowed unused elements of array destructuring patterns must match /^_/u"), @@ -610,7 +621,7 @@ ruleTester.run("no-unused-vars", rule, { const ignoreArray = ['ignore']; `, options: [{ destructuredArrayIgnorePattern: "^_", varsIgnorePattern: "ignore" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("a", ". Allowed unused elements of array destructuring patterns must match /^_/u"), @@ -641,7 +652,7 @@ ruleTester.run("no-unused-vars", rule, { console.log(foo); `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...assignedError("_a"), @@ -658,7 +669,7 @@ ruleTester.run("no-unused-vars", rule, { foo(); `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...definedError("_a"), @@ -676,7 +687,7 @@ ruleTester.run("no-unused-vars", rule, { }); `, options: [{ destructuredArrayIgnorePattern: "^_" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { ...definedError("_a"), @@ -735,7 +746,7 @@ ruleTester.run("no-unused-vars", rule, { // For-of loops { code: "(function(iter) { var name; for ( name of iter ) { i(); return; } })({});", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 35, @@ -749,7 +760,7 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "(function(iter) { var name; for ( name of iter ) { } })({});", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 35, @@ -763,7 +774,7 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "(function(iter) { for ( var name of iter ) { } })({});", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 29, @@ -839,7 +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);", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -858,7 +869,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "const data = { type: 'coords', x: 2, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", options: [{ ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -875,7 +886,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "let type, coords;\n({ type, ...coords } = data);\n console.log(type)", options: [{ ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -893,7 +904,7 @@ ruleTester.run("no-unused-vars", rule, { // 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -911,7 +922,7 @@ ruleTester.run("no-unused-vars", rule, { // 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -929,7 +940,7 @@ ruleTester.run("no-unused-vars", rule, { // 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { line: 2, @@ -948,7 +959,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "(({a, ...rest}) => {})", options: [{ args: "all", ignoreRestSiblings: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [definedError("rest")] }, @@ -1061,7 +1072,7 @@ ruleTester.run("no-unused-vars", rule, { // surrogate pair. { code: "/*global 𠮷𩸽, 𠮷*/\n\\u{20BB7}\\u{29E3D};", - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -1081,32 +1092,32 @@ ruleTester.run("no-unused-vars", rule, { // https://github.com/eslint/eslint/issues/4047 { code: "export default function(a) {}", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("a")] }, { code: "export default function(a, b) { console.log(a); }", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("b")] }, { code: "export default (function(a) {});", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("a")] }, { code: "export default (function(a, b) { console.log(a); });", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("b")] }, { code: "export default (a) => {};", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("a")] }, { code: "export default (a, b) => { console.log(a); };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("b")] }, @@ -1214,7 +1225,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "[cd]" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /[cd]/u"), definedError("b", ". Allowed unused args must match /[cd]/u") @@ -1223,7 +1234,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "c" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /c/u"), definedError("b", ". Allowed unused args must match /c/u"), @@ -1233,7 +1244,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(a, b, {c, d}) {})", options: [{ argsIgnorePattern: "d" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ definedError("a", ". Allowed unused args must match /d/u"), definedError("b", ". Allowed unused args must match /d/u"), @@ -1259,14 +1270,14 @@ ruleTester.run("no-unused-vars", rule, { // https://github.com/eslint/eslint/issues/8442 { code: "(function ({ a }, b ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a") ] }, { code: "(function ({ a }, { b, c } ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") @@ -1277,64 +1288,64 @@ ruleTester.run("no-unused-vars", rule, { { code: `let x = 0; x++, x = 0;`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 2, column: 18 }] }, { code: `let x = 0; x++, x = 0; x=3;`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 3, column: 13 }] }, { code: "let x = 0; x++, 0;", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 12 }] }, { code: "let x = 0; 0, x++;", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 15 }] }, { code: "let x = 0; 0, (1, x++);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = (x++, 0);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = ((0, x++), 0);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 23 }] }, { code: "let x = 0; x += 1, 0;", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 12 }] }, { code: "let x = 0; 0, x += 1;", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 15 }] }, { code: "let x = 0; 0, (1, x += 1);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = (x += 1, 0);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; foo = ((0, x += 1), 0);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 1, column: 23 }] }, @@ -1343,14 +1354,14 @@ ruleTester.run("no-unused-vars", rule, { code: `let z = 0; z = z + 1, z = 2; `, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("z"), line: 2, column: 24 }] }, { code: `let z = 0; z = z+1, z = 2; z = 3;`, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("z"), line: 3, column: 13 }] }, { @@ -1358,37 +1369,37 @@ ruleTester.run("no-unused-vars", rule, { z = z+1, z = 2; z = z+3; `, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("z"), line: 3, column: 13 }] }, { code: "let x = 0; 0, x = x+1;", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("x"), line: 1, column: 15 }] }, { code: "let x = 0; x = x+1, 0;", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("x"), line: 1, column: 12 }] }, { code: "let x = 0; foo = ((0, x = x + 1), 0);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("x"), line: 1, column: 23 }] }, { code: "let x = 0; foo = (x = x+1, 0);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "let x = 0; 0, (1, x=x+1);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("x"), line: 1, column: 19 }] }, { code: "(function ({ a, b }, { c } ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") @@ -1396,14 +1407,14 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "(function ([ a ], b ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a") ] }, { code: "(function ([ a ], [ b, c ] ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") @@ -1411,7 +1422,7 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "(function ([ a, b ], [ c ] ) { return b; })();", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ definedError("a"), definedError("c") @@ -1441,23 +1452,23 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "const a = () => { a(); };", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [assignedError("a")] }, { code: "const a = () => () => { a(); };", - parserOptions: { 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);`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("myArray"), line: 2, column: 5 }] }, { code: "const a = 1; a += 1;", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("a"), line: 1, column: 14 }] }, { @@ -1470,19 +1481,19 @@ ruleTester.run("no-unused-vars", rule, { }, { code: "const a = () => { a(); };", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("a"), line: 1, column: 7 }] }, { code: "const a = () => () => { a(); };", - parserOptions: { 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);", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ ...assignedError("x"), line: 2, column: 1 }] }, { @@ -1495,7 +1506,7 @@ ruleTester.run("no-unused-vars", rule, { a = 13 } }`, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("a"), line: 2, column: 13 }, { ...definedError("foo"), line: 3, column: 22 }] }, { @@ -1505,7 +1516,7 @@ ruleTester.run("no-unused-vars", rule, { function init() { foo = 1; }`, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...assignedError("foo"), line: 3, column: 13 }] }, { @@ -1513,7 +1524,7 @@ ruleTester.run("no-unused-vars", rule, { if (n < 2) return 1; return n * foo(n - 1); }`, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ ...definedError("foo"), line: 1, column: 10 }] }, { @@ -1527,7 +1538,7 @@ function foo1() { } c = foo1`, - parserOptions: { 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 dc858f75287..18ba7c3edf2 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,193 +65,193 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -255,7 +260,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "a++; var a=19;", - parserOptions: { parserOptions: { ecmaVersion: 6 } }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -312,7 +317,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "(() => { alert(a); var a = 42; })();", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -321,7 +326,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "(() => a())(); function a() { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -346,7 +351,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var f = () => a; var a;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -355,7 +360,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "new A(); class A {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, @@ -364,7 +369,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "function foo() { new A(); } class A {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, @@ -373,7 +378,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "new A(); var A = class {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, @@ -382,7 +387,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "function foo() { new A(); } var A = class {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, @@ -393,7 +398,7 @@ ruleTester.run("no-use-before-define", rule, { // Block-level bindings { code: "a++; { var a; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -402,7 +407,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "\"use strict\"; { a(); function a() {} }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -411,7 +416,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "{a; let a = 1}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -420,7 +425,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "switch (foo) { case 1: a();\n default: \n let a;}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -429,7 +434,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "if (true) { function foo() { a; } let a;}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -450,7 +455,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "new A(); class A {};", options: [{ functions: false, classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, @@ -460,7 +465,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "new A(); var A = class {};", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, @@ -470,7 +475,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "function foo() { new A(); } var A = class {};", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "A" }, @@ -489,7 +494,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "let a = a + b;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -498,7 +503,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "const a = foo(a);", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -507,7 +512,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "function foo(a = a) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -516,7 +521,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var {a = a} = [];", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -525,7 +530,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var [a = a] = [];", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -534,7 +539,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var {b = a, a} = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -543,7 +548,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var [b = a, a] = {};", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -552,7 +557,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var {a = 0} = a;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -561,7 +566,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "var [a = 0] = a;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -578,7 +583,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "for (var a of a) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" }, @@ -609,7 +614,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } @@ -617,7 +622,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "for (let x in xs); let xs = []", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "xs" } @@ -625,7 +630,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "for (let x of xs); let xs = []", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "xs" } @@ -633,7 +638,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "try {} catch ({message = x}) {} let x = ''", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } @@ -641,7 +646,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "with (obj) x; let x = {}", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } @@ -651,7 +656,7 @@ ruleTester.run("no-use-before-define", rule, { // WithStatements. { code: "with (x); let x = {}", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } @@ -659,7 +664,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "with (obj) { x } let x = {}", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } @@ -667,7 +672,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "with (obj) { if (a) { x } } let x = {}", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } @@ -675,7 +680,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "with (obj) { (() => { if (a) { x } })() } let x = {}", - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "x" } @@ -686,7 +691,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" } @@ -695,7 +700,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class extends C {};", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -704,7 +709,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" } @@ -713,7 +718,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class extends (class { [C](){} }) {};", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -722,7 +727,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" } @@ -731,7 +736,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class extends (class { static field = C; }) {};", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -740,7 +745,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { [C](){} }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -749,7 +754,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "(class C { [C](){} });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -758,7 +763,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { [C](){} };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -767,7 +772,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static [C](){} }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -776,7 +781,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "(class C { static [C](){} });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -785,7 +790,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static [C](){} };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -794,7 +799,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { [C]; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -803,7 +808,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "(class C { [C]; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -812,7 +817,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { [C]; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -821,7 +826,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { [C] = foo; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -830,7 +835,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "(class C { [C] = foo; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -839,7 +844,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { [C] = foo; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -848,7 +853,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static [C]; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -857,7 +862,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "(class C { static [C]; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -866,7 +871,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static [C]; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -875,7 +880,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static [C] = foo; }", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -884,7 +889,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "(class C { static [C] = foo; });", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -893,7 +898,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static [C] = foo; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -902,7 +907,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static field = C; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -911,7 +916,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static field = class extends C {}; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -920,7 +925,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static field = class { [C]; } };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -929,7 +934,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static field = class { static field = C; }; };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -938,7 +943,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C extends D {} class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } @@ -947,7 +952,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C extends (class { [a](){} }) {} let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -956,7 +961,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C extends (class { static field = a; }) {} let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -965,7 +970,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { [a]() {} } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -974,7 +979,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static [a]() {} } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -983,7 +988,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { [a]; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -992,7 +997,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static [a]; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1001,7 +1006,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { [a] = foo; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1010,7 +1015,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static [a] = foo; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1019,7 +1024,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static field = a; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1028,7 +1033,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static field = D; } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } @@ -1037,7 +1042,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static field = class extends D {}; } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } @@ -1046,7 +1051,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static field = class { [a](){} } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1055,7 +1060,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static field = class { static field = a; }; } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1064,7 +1069,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static { C; } };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -1073,7 +1078,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "const C = class { static { (class extends C {}); } };", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -1082,7 +1087,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static { a; } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1091,7 +1096,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static { D; } } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } @@ -1100,7 +1105,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static { (class extends D {}); } } class D {}", options: [{ classes: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "D" } @@ -1109,7 +1114,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static { (class { [a](){} }); } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1118,7 +1123,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "class C { static { (class { static field = a; }); } } let a;", options: [{ variables: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -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,7 +1164,7 @@ ruleTester.run("no-use-before-define", rule, { // "allowNamedExports" option { code: "export { a }; const a = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1168,7 +1173,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "export { a }; const a = 1;", options: [{}], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1177,7 +1182,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "export { a }; const a = 1;", options: [{ allowNamedExports: false }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1186,7 +1191,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "export { a }; const a = 1;", options: ["nofunc"], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1194,7 +1199,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "export { a as b }; const a = 1;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1202,7 +1207,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "export { a, b }; let a, b;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [ { messageId: "usedBeforeDefined", @@ -1216,7 +1221,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "export { a }; var a;", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1224,7 +1229,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "export { f }; function f() {}", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "f" } @@ -1232,7 +1237,7 @@ ruleTester.run("no-use-before-define", rule, { }, { code: "export { C }; class C {}", - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "C" } @@ -1241,7 +1246,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "export const foo = a; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1250,7 +1255,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "export default a; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1259,7 +1264,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "export function foo() { return a; }; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } @@ -1268,7 +1273,7 @@ ruleTester.run("no-use-before-define", rule, { { code: "export class C { foo() { return a; } }; const a = 1;", options: [{ allowNamedExports: true }], - parserOptions: { ecmaVersion: 2015, sourceType: "module" }, + languageOptions: { ecmaVersion: 2015, sourceType: "module" }, errors: [{ messageId: "usedBeforeDefined", data: { name: "a" } 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..2956adc40a6 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,22 +187,22 @@ ruleTester.run("no-useless-call", rule, { // Optional chaining { code: "foo.call?.(undefined, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] }, { code: "foo?.call(undefined, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] }, { code: "(foo?.call)(undefined, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" } }] }, { code: "obj.foo.call?.(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, @@ -211,7 +211,7 @@ ruleTester.run("no-useless-call", rule, { }, { code: "obj?.foo.call(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, @@ -220,7 +220,7 @@ ruleTester.run("no-useless-call", rule, { }, { code: "(obj?.foo).call(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, @@ -229,7 +229,7 @@ ruleTester.run("no-useless-call", rule, { }, { code: "(obj?.foo.call)(obj, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, @@ -238,7 +238,7 @@ ruleTester.run("no-useless-call", rule, { }, { code: "obj?.foo.bar.call(obj?.foo, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, @@ -247,7 +247,7 @@ ruleTester.run("no-useless-call", rule, { }, { code: "(obj?.foo).bar.call(obj?.foo, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, @@ -256,7 +256,7 @@ ruleTester.run("no-useless-call", rule, { }, { code: "obj.foo?.bar.call(obj.foo, 1, 2);", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unnecessaryCall", data: { name: "call" }, diff --git a/tests/lib/rules/no-useless-catch.js b/tests/lib/rules/no-useless-catch.js index a8b7e342279..99745fbe8c7 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,7 +185,7 @@ ruleTester.run("no-useless-catch", rule, { } } `, - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessaryCatch", type: "TryStatement" diff --git a/tests/lib/rules/no-useless-computed-key.js b/tests/lib/rules/no-useless-computed-key.js index 37f31118878..d97d6fe71ea 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,7 +131,7 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async ['x']() {} })", output: "({ async 'x'() {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "'x'" }, @@ -156,7 +156,7 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async[.2]() {} })", output: "({ async.2() {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: ".2" }, @@ -189,7 +189,7 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async [2]() {} })", output: "({ async 2() {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, @@ -214,7 +214,7 @@ ruleTester.run("no-useless-computed-key", rule, { }, { code: "({ async[2]() {} })", output: "({ async 2() {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, @@ -327,7 +327,7 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async ['x']() {} }", output: "class Foo { async 'x'() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "'x'" }, @@ -355,7 +355,7 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async[.2]() {} }", output: "class Foo { async.2() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: ".2" }, @@ -392,7 +392,7 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async [2]() {} }", output: "class Foo { async 2() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, @@ -420,7 +420,7 @@ ruleTester.run("no-useless-computed-key", rule, { code: "class Foo { async[2]() {} }", output: "class Foo { async 2() {} }", options: [{ enforceForClassMembers: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unnecessarilyComputedProperty", data: { property: "2" }, diff --git a/tests/lib/rules/no-useless-concat.js b/tests/lib/rules/no-useless-concat.js index f19a1965673..807b5092dc7 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,21 +96,21 @@ ruleTester.run("no-useless-concat", rule, { }, { code: "`a` + 'b'", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } ] }, { code: "`a` + `b`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } ] }, { code: "foo + `a` + `b`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedConcat" } ] 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..3fdcfa7b703 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,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "", - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [{ line: 1, column: 13, @@ -477,7 +482,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\\"`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -495,7 +500,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\'`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -513,7 +518,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\#`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -564,7 +569,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\\"${foo}\\\"`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -598,7 +603,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\'${foo}\\'`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -632,7 +637,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\#${foo}`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -650,7 +655,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "let foo = '\\ ';", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -668,7 +673,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "let foo = /\\ /;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 12, @@ -686,7 +691,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\$\\{{${foo}`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -706,7 +711,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `\\$a${foo}`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -726,7 +731,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "var foo = `a\\{{${foo}`;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, @@ -1001,7 +1006,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`multiline template\nliteral with useless \\escape`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 22, @@ -1019,7 +1024,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`multiline template\r\nliteral with useless \\escape`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 22, @@ -1037,7 +1042,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`template literal with line continuation \\\nand useless \\escape`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 13, @@ -1055,7 +1060,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`template literal with line continuation \\\r\nand useless \\escape`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 2, column: 13, @@ -1073,7 +1078,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`template literal with mixed linebreaks \r\r\n\n\\and useless escape`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, @@ -1091,7 +1096,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`template literal with mixed linebreaks in line continuations \\\n\\\r\\\r\n\\and useless escape`", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 4, column: 1, @@ -1109,7 +1114,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "`\\a```", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 2, @@ -1146,7 +1151,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`({ foo() { "foo"; "bar"; "ba\z" } })`, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ line: 1, column: 29, @@ -1185,7 +1190,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[^\^]/u`, - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ line: 1, column: 4, @@ -1207,7 +1212,7 @@ ruleTester.run("no-useless-escape", rule, { // ES2024 { code: String.raw`/[\$]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1228,7 +1233,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\&\&]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1248,7 +1253,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\!\!]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1268,7 +1273,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\#\#]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1288,7 +1293,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\%\%]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1308,7 +1313,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\*\*]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1328,7 +1333,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\+\+]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1348,7 +1353,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\,\,]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1368,7 +1373,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\.\.]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1388,7 +1393,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\:\:]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1408,7 +1413,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\;\;]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1428,7 +1433,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\<\<]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1448,7 +1453,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\=\=]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1468,7 +1473,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\>\>]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1488,7 +1493,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\?\?]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1508,7 +1513,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\@\@]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1528,7 +1533,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: "/[\\`\\`]/v", - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1548,7 +1553,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\~\~]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1568,7 +1573,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[^\^\^]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1588,7 +1593,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[_\^\^]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1608,7 +1613,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\&\&&\&]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1628,7 +1633,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\p{ASCII}--\.]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 14, @@ -1644,7 +1649,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\p{ASCII}&&\.]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 14, @@ -1660,7 +1665,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\.--[.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1676,7 +1681,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\.&&[.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1692,7 +1697,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\.--\.--\.]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1730,7 +1735,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[\.&&\.&&\.]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 3, @@ -1768,7 +1773,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[[\.&]--[\.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, @@ -1803,7 +1808,7 @@ ruleTester.run("no-useless-escape", rule, { }, { code: String.raw`/[[\.&]&&[\.&]]/v`, - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [{ line: 1, column: 4, diff --git a/tests/lib/rules/no-useless-rename.js b/tests/lib/rules/no-useless-rename.js index 262cf2cc5ac..d60ad921b11 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,19 +391,19 @@ ruleTester.run("no-useless-rename", rule, { { code: "const {foo: foo, ...stuff} = myObject;", output: "const {foo, ...stuff} = myObject;", - parserOptions: { 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;", - parserOptions: { 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;", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } @@ -415,7 +417,7 @@ ruleTester.run("no-useless-rename", rule, { { code: "import {'foo' as foo} from 'foo';", output: "import {foo} from 'foo';", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { @@ -459,37 +461,37 @@ ruleTester.run("no-useless-rename", rule, { { code: "var foo = 0; export {foo as 'foo'};", output: "var foo = 0; export {foo};", - parserOptions: { 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';", - parserOptions: { 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';", - parserOptions: { 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';", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "export {' 👍 ' as ' 👍 '} from 'bar';", output: "export {' 👍 '} from 'bar';", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: " 👍 " } }] }, { code: "export {'' as ''} from 'bar';", output: "export {''} from 'bar';", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "" } }] }, { 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; }", diff --git a/tests/lib/rules/no-var.js b/tests/lib/rules/no-var.js index 26b0a8464f4..d035ff097d8 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,7 +36,7 @@ ruleTester.run("no-var", rule, { { code: "var foo = bar;", output: "let foo = bar;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", @@ -47,7 +47,7 @@ ruleTester.run("no-var", rule, { { code: "var foo = bar, toast = most;", output: "let foo = bar, toast = most;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", @@ -58,7 +58,7 @@ ruleTester.run("no-var", rule, { { code: "var foo = bar; let toast = most;", output: "let foo = bar; let toast = most;", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", @@ -69,7 +69,7 @@ ruleTester.run("no-var", rule, { { code: "for (var a of b) { console.log(a); }", output: "for (let a of b) { console.log(a); }", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", @@ -80,7 +80,7 @@ ruleTester.run("no-var", rule, { { code: "for (var a in b) { console.log(a); }", output: "for (let a in b) { console.log(a); }", - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", @@ -91,7 +91,7 @@ ruleTester.run("no-var", rule, { { 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 } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", @@ -102,7 +102,7 @@ ruleTester.run("no-var", rule, { { 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 } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -110,7 +110,7 @@ ruleTester.run("no-var", rule, { { code: "for (var i = 0, i = 0; false;);", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -118,7 +118,7 @@ ruleTester.run("no-var", rule, { { code: "var i = 0; for (var i = 1; false;); console.log(i);", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" }, { messageId: "unexpectedVar", type: "VariableDeclaration" } @@ -129,7 +129,7 @@ ruleTester.run("no-var", rule, { { code: "var a, b, c; var a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } @@ -138,7 +138,7 @@ ruleTester.run("no-var", rule, { { code: "var a; if (b) { var a; }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } @@ -147,7 +147,7 @@ ruleTester.run("no-var", rule, { { code: "if (foo) { var a, b, c; } a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -155,7 +155,7 @@ ruleTester.run("no-var", rule, { { code: "for (var i = 0; i < 10; ++i) {} i;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -163,7 +163,7 @@ ruleTester.run("no-var", rule, { { code: "for (var a in obj) {} a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -171,7 +171,7 @@ ruleTester.run("no-var", rule, { { code: "for (var a of list) {} a;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -179,7 +179,7 @@ ruleTester.run("no-var", rule, { { code: "switch (a) { case 0: var b = 1 }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -189,7 +189,7 @@ ruleTester.run("no-var", rule, { { code: "for (var a of b) { arr.push(() => a); }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -197,7 +197,7 @@ ruleTester.run("no-var", rule, { { code: "for (let a of b) { var c; console.log(c); c = 'hello'; }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -207,7 +207,7 @@ ruleTester.run("no-var", rule, { { code: "var a = a", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -215,7 +215,7 @@ ruleTester.run("no-var", rule, { { code: "var {a = a} = {}", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -223,7 +223,7 @@ ruleTester.run("no-var", rule, { { code: "var {a = b, b} = {}", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -231,7 +231,7 @@ ruleTester.run("no-var", rule, { { code: "var {a, b = a} = {}", output: "let {a, b = a} = {}", - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -239,7 +239,7 @@ ruleTester.run("no-var", rule, { { code: "var a = b, b = 1", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -247,7 +247,7 @@ ruleTester.run("no-var", rule, { { code: "var a = b; var b = 1", output: "let a = b; var b = 1", - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } @@ -261,7 +261,7 @@ ruleTester.run("no-var", rule, { { code: "function foo() { a } var a = 1; foo()", output: null, - parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 2015, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar" } ] @@ -271,7 +271,7 @@ ruleTester.run("no-var", rule, { { code: "if (foo) var bar = 1;", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -296,7 +296,7 @@ ruleTester.run("no-var", rule, { { code: "var foo = 1", output: "let foo = 1", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedVar" }] }, @@ -304,8 +304,11 @@ ruleTester.run("no-var", rule, { { code: "declare var foo = 2;", output: "declare let foo = 2;", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/declare-var"), - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { + ecmaVersion: 6, + sourceType: "module", + parser: require("../../fixtures/parsers/typescript-parsers/declare-var") + }, errors: [{ messageId: "unexpectedVar" }] }, @@ -325,43 +328,43 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = function () { foo() };", output: "let foo = function () { foo() };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = () => foo();", output: "let foo = () => foo();", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = (function () { foo(); })();", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = bar(function () { foo(); });", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedVar" }] }, { code: "var bar = foo, foo = function () { foo(); };", output: null, - parserOptions: { 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(); };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } @@ -370,19 +373,19 @@ ruleTester.run("no-var", rule, { { code: "var { foo = foo } = function () { foo(); };", output: null, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedVar" }] }, { code: "var { bar = foo, foo } = function () { foo(); };", output: null, - parserOptions: { 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() {};", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedVar" }, { messageId: "unexpectedVar" } 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..c3b5aa697ee 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 } } ], @@ -845,6 +845,7 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "08 .toExponential()", output: null, // Not fixed + languageOptions: { sourceType: "script" }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } @@ -853,6 +854,7 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "0192 .toExponential()", output: null, // Not fixed + languageOptions: { sourceType: "script" }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } @@ -861,7 +863,7 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "5_000 .toExponential()", output: null, // Not fixed, - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } @@ -870,7 +872,7 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "5_000_00 .toExponential()", output: null, // Not fixed, - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } @@ -895,7 +897,7 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "5.0_0 .toExponential()", output: "5.0_0.toExponential()", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } @@ -912,7 +914,7 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "0x56_78 .toExponential()", output: "0x56_78.toExponential()", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } @@ -945,6 +947,7 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "05 .toExponential()", output: "05.toExponential()", + languageOptions: { sourceType: "script" }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "toExponential" } @@ -955,49 +958,49 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "obj?. prop", output: "obj?.prop", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "obj ?.prop", output: "obj?.prop", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "obj?. [key]", output: "obj?.[key]", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] }, { code: "obj ?.[key]", output: "obj?.[key]", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] }, { code: "5 ?. prop", output: "5?.prop", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "5 ?. [key]", output: "5?.[key]", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "key" } }] }, { code: "obj/* comment */?. prop", output: null, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] }, { code: "obj ?./* comment */prop", output: null, - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unexpectedWhitespace", data: { propName: "prop" } }] } ] 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..e6c772e5eda 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,7 +690,9 @@ ruleTester.run("object-curly-newline", rule, { "} : MyType) {}" ].join("\n"), options: ["always"], - 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")) + }, errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } @@ -696,7 +706,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-singleline-type-literal"), + 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" } @@ -808,7 +820,9 @@ ruleTester.run("object-curly-newline", rule, { " b} : MyType) {}" ].join("\n"), options: ["never"], - 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")) + }, errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } @@ -826,7 +840,9 @@ 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"), + 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" } @@ -1316,7 +1332,7 @@ ruleTester.run("object-curly-newline", rule, { "let {a} = {a: 1}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] @@ -1330,7 +1346,7 @@ ruleTester.run("object-curly-newline", rule, { "let {a} = {a: 1}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] @@ -1344,7 +1360,7 @@ ruleTester.run("object-curly-newline", rule, { "let {a, b} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] @@ -1358,7 +1374,7 @@ ruleTester.run("object-curly-newline", rule, { "let {a, b} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] @@ -1375,7 +1391,7 @@ ruleTester.run("object-curly-newline", rule, { "} = {a: 1, b: 2}" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 2, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } @@ -1395,7 +1411,7 @@ ruleTester.run("object-curly-newline", rule, { "} = a;" ].join("\n"), options: [{ multiline: true, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } @@ -1442,7 +1458,7 @@ ruleTester.run("object-curly-newline", rule, { "b} = {a: 1, b: 2};" ].join("\n"), options: [{ multiline: false, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] @@ -1458,7 +1474,7 @@ ruleTester.run("object-curly-newline", rule, { "b} = {a: 1, b: 2};" ].join("\n"), options: [{ multiline: false, consistent: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] @@ -1494,7 +1510,7 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ multiline: true, consistent: true, minProperties: 2 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 10, messageId: "expectedLinebreakBeforeClosingBrace" } @@ -1514,7 +1530,7 @@ ruleTester.run("object-curly-newline", rule, { "};" ].join("\n"), options: [{ ObjectExpression: "always", ObjectPattern: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" }, diff --git a/tests/lib/rules/object-curly-spacing.js b/tests/lib/rules/object-curly-spacing.js index f603832cb37..520d11f6915 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,7 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -210,7 +212,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import { bar as y} from 'foo.js';", output: "import { bar as y } from 'foo.js';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -227,7 +229,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import {bar as y} from 'foo.js';", output: "import { bar as y } from 'foo.js';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -253,7 +255,7 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -270,7 +272,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import x, { bar} from 'foo';", output: "import x, { bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -288,7 +290,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import x, { bar/* */} from 'foo';", output: "import x, { bar/* */ } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -305,7 +307,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import x, {/* */bar } from 'foo';", output: "import x, { /* */bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -322,7 +324,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import x, {//\n bar } from 'foo';", output: "import x, { //\n bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -339,7 +341,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import x, { bar, baz} from 'foo';", output: "import x, { bar, baz } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceBefore", @@ -357,7 +359,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import x, {bar} from 'foo';", output: "import x, { bar } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -384,7 +386,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import x, {bar, baz} from 'foo';", output: "import x, { bar, baz } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -410,7 +412,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import {bar,} from 'foo';", output: "import { bar, } from 'foo';", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -437,7 +439,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import { bar, } from 'foo';", output: "import {bar,} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -463,7 +465,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "import { /* */ bar, /* */ } from 'foo';", output: "import {/* */ bar, /* */} from 'foo';", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -489,7 +491,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var bar = 0;\nexport {bar};", output: "var bar = 0;\nexport { bar };", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -513,7 +515,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var bar = 0;\nexport {/* */ bar /* */};", output: "var bar = 0;\nexport { /* */ bar /* */ };", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -539,7 +541,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var bar = 0;\nexport {//\n bar };", output: "var bar = 0;\nexport { //\n bar };", options: ["always"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -556,7 +558,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var bar = 0;\nexport { /* */ bar /* */ };", output: "var bar = 0;\nexport {/* */ bar /* */};", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -652,7 +654,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { a,} = x;", output: "var { a, } = x;", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -669,7 +671,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {a, } = x;", output: "var {a,} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -686,7 +688,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -703,7 +705,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -729,7 +731,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -755,7 +757,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { a:b } = x;", output: "var {a:b} = x;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1134,7 +1136,7 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "requireSpaceAfter", @@ -1153,7 +1155,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {x, y} = y", output: "var { x, y } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1179,7 +1181,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { x, y} = y", output: "var { x, y } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1196,7 +1198,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { x, y/* */} = y", output: "var { x, y/* */ } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1213,7 +1215,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {/* */x, y } = y", output: "var { /* */x, y } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1230,7 +1232,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {//\n x } = y", output: "var { //\n x } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1247,7 +1249,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { x, y } = y", output: "var {x, y} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1273,7 +1275,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {x, y } = y", output: "var {x, y} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1290,7 +1292,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {x, y/* */ } = y", output: "var {x, y/* */} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceBefore", @@ -1307,7 +1309,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { /* */x, y} = y", output: "var {/* */x, y} = y", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedSpaceAfter", @@ -1324,7 +1326,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var { x=10} = y", output: "var { x=10 } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceBefore", @@ -1341,7 +1343,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "var {x=10 } = y", output: "var { x=10 } = y", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "requireSpaceAfter", @@ -1394,7 +1396,9 @@ 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"), + languageOptions: { + parser: require(resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid")) + }, errors: [ { messageId: "unexpectedSpaceBefore", diff --git a/tests/lib/rules/object-property-newline.js b/tests/lib/rules/object-property-newline.js index e6499b9d7d7..16d60c4d03e 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,7 @@ ruleTester.run("object-property-newline", rule, { { code: "var obj = { k1: 'val1', [\nk2]: 'val2' };", output: "var obj = { k1: 'val1',\n[\nk2]: 'val2' };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -246,7 +246,7 @@ ruleTester.run("object-property-newline", rule, { { code: "var obj = { k1: 'val1', ...{} };", output: "var obj = { k1: 'val1',\n...{} };", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -261,7 +261,7 @@ ruleTester.run("object-property-newline", rule, { { code: "var obj = {\nk1: 'val1', ...{}\n};", output: "var obj = {\nk1: 'val1',\n...{}\n};", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -304,7 +304,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({ a, b });", output: "foo({ a,\nb });", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -319,7 +319,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({\na, b\n});", output: "foo({\na,\nb\n});", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -334,7 +334,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({\nbar() {}, baz\n});", output: "foo({\nbar() {},\nbaz\n});", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -349,7 +349,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({\n[bar]: 'baz', baz\n})", output: "foo({\n[bar]: 'baz',\nbaz\n})", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -364,7 +364,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({ k1: 'val1', [\nk2]: 'val2' })", output: "foo({ k1: 'val1',\n[\nk2]: 'val2' })", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewline", @@ -379,7 +379,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({ k1: 'val1', ...{} })", output: "foo({ k1: 'val1',\n...{} })", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -394,7 +394,7 @@ ruleTester.run("object-property-newline", rule, { { code: "foo({\nk1: 'val1', ...{}\n})", output: "foo({\nk1: 'val1',\n...{}\n})", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewline", @@ -560,7 +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 }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -576,7 +576,7 @@ ruleTester.run("object-property-newline", rule, { code: "var obj = {\nk1: 'val1',\nk2: 'val2', ...{}\n};", output: "var obj = {\nk1: 'val1',\nk2: 'val2',\n...{}\n};", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -592,7 +592,7 @@ ruleTester.run("object-property-newline", rule, { code: "var obj = {\n...{},\nk1: 'val1', k2: 'val2'\n};", output: "var obj = {\n...{},\nk1: 'val1',\nk2: 'val2'\n};", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -608,7 +608,7 @@ ruleTester.run("object-property-newline", rule, { code: "foo({ [\nk1]: 'val1', k2: 'val2' })", output: "foo({ [\nk1]: 'val1',\nk2: 'val2' })", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -624,7 +624,7 @@ ruleTester.run("object-property-newline", rule, { code: "foo({\nk1: 'val1',\nk2: 'val2', ...{}\n})", output: "foo({\nk1: 'val1',\nk2: 'val2',\n...{}\n})", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", @@ -640,7 +640,7 @@ ruleTester.run("object-property-newline", rule, { code: "foo({\n...{},\nk1: 'val1', k2: 'val2'\n})", output: "foo({\n...{},\nk1: 'val1',\nk2: 'val2'\n})", options: [{ allowAllPropertiesOnSameLine: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "propertiesOnNewlineAll", diff --git a/tests/lib/rules/object-shorthand.js b/tests/lib/rules/object-shorthand.js index 58bb5708327..1864dc9351d 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,19 +579,19 @@ ruleTester.run("object-shorthand", rule, { { code: "({ foo: async function () {} })", output: "({ async foo () {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, { code: "({ 'foo': async function() {} })", output: "({ async 'foo'() {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, { code: "({ [foo]: async function() {} })", output: "({ async [foo]() {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, { @@ -607,7 +607,7 @@ ruleTester.run("object-shorthand", rule, { { code: "({ [ foo ]: async function() {} })", output: "({ async [ foo ]() {} })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, { @@ -659,7 +659,7 @@ ruleTester.run("object-shorthand", rule, { { code: "({ [(foo)]: async function() { return; } })", output: "({ async [(foo)]() { return; } })", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, { @@ -677,7 +677,7 @@ ruleTester.run("object-shorthand", rule, { code: "({ async [(foo)]() { return; } })", output: "({ [(foo)]: async function() { return; } })", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [LONGFORM_METHOD_ERROR] }, { @@ -708,14 +708,14 @@ ruleTester.run("object-shorthand", rule, { code: "({ async foo() { return; } })", output: "({ foo: async function() { return; } })", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [LONGFORM_METHOD_ERROR] }, { code: "({ *['foo bar']() { return; } })", output: "({ ['foo bar']: function*() { return; } })", options: ["never"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [LONGFORM_METHOD_ERROR] }, { @@ -776,14 +776,14 @@ 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [PROPERTY_ERROR] }, { code: "var x = {foo, bar: baz, ...qux}", output: "var x = {foo: foo, bar: baz, ...qux}", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [LONGFORM_PROPERTY_ERROR] }, @@ -920,7 +920,7 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {foo, bar: baz, ...qux}", output: null, options: ["consistent"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [MIXED_SHORTHAND_ERROR] }, @@ -948,14 +948,14 @@ ruleTester.run("object-shorthand", rule, { code: "var x = {a: a, b: b, ...baz}", output: null, options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ALL_SHORTHAND_ERROR] }, { code: "var x = {foo, bar: bar, ...qux}", output: null, options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [MIXED_SHORTHAND_ERROR] }, @@ -1084,14 +1084,14 @@ 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 }, + languageOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, { code: "({ [ foo ]: async bar => { return; } })", output: "({ async [ foo ](bar) { return; } })", options: ["always", { avoidExplicitReturnArrows: true }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [METHOD_ERROR] }, { @@ -1263,7 +1263,9 @@ ruleTester.run("object-shorthand", rule, { } `, options: ["always", { avoidExplicitReturnArrows: true }], - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props"), + 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 3103ef2d705..b611212673d 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"], 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"], 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"], 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"], 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"], 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 935c464b3d0..37739da1899 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,7 +986,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "var" }, @@ -1093,7 +1093,7 @@ ruleTester.run("one-var", rule, { code: "var {foo} = 1, [bar] = 2;", output: "var {foo} = 1; var [bar] = 2;", options: [{ initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "var" }, @@ -1106,7 +1106,7 @@ ruleTester.run("one-var", rule, { code: "const foo = 1,\n bar = 2;", output: "const foo = 1;\n const bar = 2;", options: [{ initialized: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "const" }, @@ -1273,7 +1273,7 @@ ruleTester.run("one-var", rule, { code: "let a = 1, b; let c;", output: "let a = 1, b, c;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1286,7 +1286,7 @@ ruleTester.run("one-var", rule, { code: "let a = 0, b = 1; let c = 2;", output: "let a = 0, b = 1, c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1299,7 +1299,7 @@ ruleTester.run("one-var", rule, { code: "const a = 0, b = 1; const c = 2;", output: "const a = 0, b = 1, c = 2;", options: ["consecutive"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1312,7 +1312,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "var" }, @@ -1337,7 +1337,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1350,7 +1350,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1394,7 +1394,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1407,7 +1407,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -1427,7 +1427,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1440,7 +1440,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", type: "VariableDeclaration", @@ -1490,7 +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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -1510,7 +1510,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitUninitialized", data: { type: "let" }, @@ -1523,7 +1523,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "const" }, @@ -1543,7 +1543,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitUninitialized", data: { type: "let" }, @@ -1587,7 +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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1607,7 +1607,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -1620,7 +1620,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1640,7 +1640,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineInitialized", data: { type: "const" }, @@ -1684,7 +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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1704,7 +1704,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "let" }, @@ -1717,7 +1717,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combineUninitialized", data: { type: "let" }, @@ -1737,7 +1737,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "splitInitialized", data: { type: "const" }, @@ -1762,7 +1762,7 @@ ruleTester.run("one-var", rule, { code: "let a = 0; let b = 1;", output: "let a = 0, b = 1;", options: [{ let: "consecutive" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1775,7 +1775,7 @@ ruleTester.run("one-var", rule, { code: "const a = 0; const b = 1;", output: "const a = 0, b = 1;", options: [{ const: "consecutive" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1788,7 +1788,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1808,7 +1808,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1821,7 +1821,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1841,7 +1841,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "split", data: { type: "const" }, @@ -1854,7 +1854,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1874,7 +1874,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -1887,7 +1887,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "const" }, @@ -1907,7 +1907,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "split", data: { type: "let" }, @@ -1951,7 +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" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -2040,7 +2040,7 @@ 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" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2051,7 +2051,7 @@ ruleTester.run("one-var", rule, { code: "const foo=1,\n bar=2;", output: "const foo=1;\n const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2062,7 +2062,7 @@ ruleTester.run("one-var", rule, { 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" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2073,7 +2073,7 @@ ruleTester.run("one-var", rule, { 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" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2084,7 +2084,7 @@ ruleTester.run("one-var", rule, { code: "export const foo= a, bar=2;", output: "export const foo= a; export const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2095,7 +2095,7 @@ ruleTester.run("one-var", rule, { code: "export const foo=() => a, bar=2;", output: "export const foo=() => a; export const bar=2;", options: ["never"], - parserOptions: { ecmaVersion: 2021, sourceType: "module" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2106,7 +2106,7 @@ ruleTester.run("one-var", rule, { 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" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2117,7 +2117,7 @@ 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" }, + languageOptions: { ecmaVersion: 2021, sourceType: "module" }, errors: [{ messageId: "split", data: { type: "const" }, @@ -2262,7 +2262,7 @@ 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "split", data: { type: "let" }, @@ -2273,7 +2273,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { var x, y; } }", output: "class C { static { var x; var y; } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "split", data: { type: "var" }, @@ -2284,7 +2284,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { let x; let y; } }", output: "class C { static { let x, y; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -2295,7 +2295,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { var x; var y; } }", output: "class C { static { var x, y; } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, @@ -2306,7 +2306,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { let x; foo; let y; } }", output: null, options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -2317,7 +2317,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { var x; foo; var y; } }", output: null, options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, @@ -2328,7 +2328,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { var x; if (foo) { var y; } } }", output: null, options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, @@ -2339,7 +2339,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { let x; let y; } }", output: "class C { static { let x, y; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "let" }, @@ -2350,7 +2350,7 @@ ruleTester.run("one-var", rule, { code: "class C { static { var x; var y; } }", output: "class C { static { var x, y; } }", options: ["consecutive"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combine", data: { type: "var" }, @@ -2361,7 +2361,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combineInitialized", data: { type: "let" }, @@ -2372,7 +2372,7 @@ ruleTester.run("one-var", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "combineInitialized", data: { type: "var" }, 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..0a1a162208d 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,7 +721,7 @@ ruleTester.run("operator-linebreak", rule, { code: "foo ??\n bar", output: "foo\n ?? bar", options: ["after", { overrides: { "??": "before" } }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "??" } @@ -732,7 +732,7 @@ ruleTester.run("operator-linebreak", rule, { code: "a \n &&= b", output: "a &&= \n b", options: ["after"], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "&&=" }, @@ -747,7 +747,7 @@ ruleTester.run("operator-linebreak", rule, { code: "a ||=\n b", output: "a\n ||= b", options: ["before"], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "||=" }, @@ -762,7 +762,7 @@ ruleTester.run("operator-linebreak", rule, { code: "a ??=\n b", output: "a ??= b", options: ["none"], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLinebreak", data: { operator: "??=" }, @@ -777,7 +777,7 @@ ruleTester.run("operator-linebreak", rule, { code: "a \n &&= b", output: "a &&= b", options: ["before", { overrides: { "&&=": "none" } }], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "noLinebreak", data: { operator: "&&=" }, @@ -792,7 +792,7 @@ ruleTester.run("operator-linebreak", rule, { code: "a ||=\nb", output: "a\n||= b", options: ["after", { overrides: { "||=": "before" } }], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "||=" }, @@ -807,7 +807,7 @@ ruleTester.run("operator-linebreak", rule, { code: "a\n??=b", output: "a??=\nb", options: ["none", { overrides: { "??=": "after" } }], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "??=" }, @@ -824,7 +824,7 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { a\n= 0; }", output: "class C { a =\n0; }", options: ["after"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "=" }, @@ -839,7 +839,7 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { a =\n0; }", output: "class C { a\n= 0; }", options: ["before"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "=" }, @@ -854,7 +854,7 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { a =\n0; }", output: "class C { a =0; }", options: ["none"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noLinebreak", data: { operator: "=" }, @@ -869,7 +869,7 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { [a]\n= 0; }", output: "class C { [a] =\n0; }", options: ["after"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtEnd", data: { operator: "=" }, @@ -884,7 +884,7 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { [a] =\n0; }", output: "class C { [a]\n= 0; }", options: ["before"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "operatorAtBeginning", data: { operator: "=" }, @@ -899,7 +899,7 @@ ruleTester.run("operator-linebreak", rule, { code: "class C { [a]\n =0; }", output: "class C { [a] =0; }", options: ["none"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "noLinebreak", data: { operator: "=" }, diff --git a/tests/lib/rules/padded-blocks.js b/tests/lib/rules/padded-blocks.js index 3dd0dc97e18..8621a65b12e 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,7 @@ ruleTester.run("padded-blocks", rule, { code: "class A {\nconstructor(){}\n}", output: "class A {\n\nconstructor(){}\n\n}", options: ["always"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "alwaysPadBlock", @@ -462,7 +462,7 @@ ruleTester.run("padded-blocks", rule, { code: "class A {\nconstructor(){}\n}", output: "class A {\n\nconstructor(){}\n\n}", options: [{ classes: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "alwaysPadBlock", @@ -728,7 +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"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -764,7 +764,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -786,7 +786,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: [{ blocks: "never", classes: "never" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "neverPadBlock", @@ -857,14 +857,14 @@ ruleTester.run("padded-blocks", rule, { { code: "class A{\nfoo;\n}", output: "class A{\n\nfoo;\n\n}", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] }, { code: "class A{\n\nfoo;\n\n}", output: "class A{\nfoo;\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "neverPadBlock" }, { messageId: "neverPadBlock" }] }, @@ -873,35 +873,35 @@ 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 }, + 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } @@ -911,7 +911,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } @@ -921,7 +921,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } @@ -931,7 +931,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } @@ -941,7 +941,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } @@ -951,7 +951,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" } @@ -961,35 +961,35 @@ ruleTester.run("padded-blocks", rule, { code: "class C {\n static {\n\nfoo;\n} \n}", output: "class C {\n static {\nfoo;\n} \n}", options: ["never"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } @@ -999,7 +999,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } @@ -1009,7 +1009,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } @@ -1019,7 +1019,7 @@ ruleTester.run("padded-blocks", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "neverPadBlock" }, { messageId: "neverPadBlock" } diff --git a/tests/lib/rules/padding-line-between-statements.js b/tests/lib/rules/padding-line-between-statements.js index 0d6e93c437a..f52c4a19d63 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,7 +3534,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -3543,7 +3543,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -3552,7 +3552,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -3561,7 +3561,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -3570,7 +3570,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -3579,7 +3579,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "export", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBlankLine" }] }, @@ -3745,14 +3745,14 @@ 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 }, + 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: "*" }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "expectedBlankLine" }] }, @@ -3766,7 +3766,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -3775,7 +3775,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -3784,7 +3784,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -3793,7 +3793,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -3802,7 +3802,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -3811,7 +3811,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "import", next: "*" } ], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "expectedBlankLine" }] }, @@ -4692,7 +4692,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -4701,7 +4701,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5093,7 +5093,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "expression" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5102,7 +5102,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "let", next: "expression" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -5111,7 +5111,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5120,7 +5120,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -5129,7 +5129,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5138,7 +5138,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "expression", next: "const" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedBlankLine" }] }, { @@ -5148,7 +5148,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: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5157,7 +5157,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5166,7 +5166,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5175,7 +5175,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "block-like" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5184,7 +5184,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "class", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] }, { @@ -5193,7 +5193,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "let" } ], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedBlankLine" }] } ] 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..675b6d22ef9 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,28 +192,28 @@ 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } @@ -213,7 +222,7 @@ ruleTester.run("prefer-const", rule, { { code: "class C { static { let a, b; if (foo) ({ a, b } = foo); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } @@ -222,12 +231,12 @@ ruleTester.run("prefer-const", rule, { { 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,14 +440,16 @@ ruleTester.run("prefer-const", rule, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", output: null, options: [{ destructuring: "any" }], - parserOptions: { 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" }], - parser: fixtureParser("babel-eslint5/destructuring-object-spread"), + languageOptions: { + parser: require(fixtureParser("babel-eslint5/destructuring-object-spread")) + }, errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }] }, @@ -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 } }, + code: "/*eslint custom/use-x:error*/ let x = 1", + output: "/*eslint custom/use-x:error*/ const x = 1", + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }] }, { - 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,7 +500,7 @@ ruleTester.run("prefer-const", rule, { { code: "let predicate; [, {foo:returnType, predicate}] = foo();", output: null, - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } ] @@ -497,7 +508,7 @@ ruleTester.run("prefer-const", rule, { { code: "let predicate; [, {foo:returnType, predicate}, ...bar ] = foo();", output: null, - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } ] @@ -505,7 +516,7 @@ ruleTester.run("prefer-const", rule, { { code: "let predicate; [, {foo:returnType, ...predicate} ] = foo();", output: null, - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { message: "'predicate' is never reassigned. Use 'const' instead.", type: "Identifier" } ] @@ -615,7 +626,7 @@ ruleTester.run("prefer-const", rule, { { code: "let a = 1; class C { static { a; } }", output: "const a = 1; class C { static { a; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { @@ -623,43 +634,43 @@ ruleTester.run("prefer-const", rule, { // 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 }, + 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; } }", - parserOptions: { 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; } } }", - parserOptions: { 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; } } }", - parserOptions: { 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, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }] }, { code: "class C { static { let a; a = 1; } }", output: null, - parserOptions: { 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; } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } @@ -668,7 +679,7 @@ ruleTester.run("prefer-const", rule, { { code: "class C { static { let a, b; ({ a, b } = foo); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } @@ -677,7 +688,7 @@ ruleTester.run("prefer-const", rule, { { code: "class C { static { let a; let b; ({ a, b } = foo); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }, { messageId: "useConst", data: { name: "b" }, type: "Identifier" } @@ -686,7 +697,7 @@ ruleTester.run("prefer-const", rule, { { code: "class C { static { let a; a = 0; console.log(a); } }", output: null, - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "a" }, type: "Identifier" } ] @@ -703,7 +714,7 @@ ruleTester.run("prefer-const", rule, { `, output: null, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, @@ -722,7 +733,7 @@ ruleTester.run("prefer-const", rule, { console.log(itemId, list, obj); `, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, @@ -738,7 +749,7 @@ ruleTester.run("prefer-const", rule, { `, output: null, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" } @@ -756,7 +767,7 @@ ruleTester.run("prefer-const", rule, { console.log(itemId, list, obj); `, options: [{ destructuring: "any", ignoreReadBeforeAssign: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "useConst", data: { name: "itemId" }, type: "Identifier" }, { messageId: "useConst", data: { name: "list" }, type: "Identifier" }, 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..7f1f4b1adfe 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,7 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "globalThis.Math.pow(a, b)", output: "a**b", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useExponentiation", @@ -109,7 +109,7 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "globalThis.Math['pow'](a, b)", output: "a**b", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useExponentiation", @@ -364,7 +364,9 @@ 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"), + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-1")) + }, errors: [ { messageId: "useExponentiation", @@ -375,7 +377,9 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "Math.pow(a as any, b)", output: "(a as any)**b", - parser: parser("typescript-parsers/exponentiation-with-assertion-2"), + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-2")) + }, errors: [ { messageId: "useExponentiation", @@ -386,7 +390,9 @@ 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-3"), + languageOptions: { + parser: require(parser("typescript-parsers/exponentiation-with-assertion-3")) + }, errors: [ { messageId: "useExponentiation", diff --git a/tests/lib/rules/prefer-named-capture-group.js b/tests/lib/rules/prefer-named-capture-group.js index 31dcc70f332..f4477c28387 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,7 @@ ruleTester.run("prefer-named-capture-group", rule, { }, { code: "new globalThis.RegExp('([0-9]{4})')", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "required", type: "NewExpression", @@ -551,7 +551,7 @@ ruleTester.run("prefer-named-capture-group", rule, { }, { code: "globalThis.RegExp('([0-9]{4})')", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "required", type: "CallExpression", @@ -576,7 +576,7 @@ ruleTester.run("prefer-named-capture-group", rule, { function foo() { var globalThis = bar; } new globalThis.RegExp('([0-9]{4})'); `, - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "required", type: "NewExpression", diff --git a/tests/lib/rules/prefer-numeric-literals.js b/tests/lib/rules/prefer-numeric-literals.js index e3cacaa1318..e5e69e96060 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,37 +178,37 @@ ruleTester.run("prefer-numeric-literals", rule, { { code: "function *f(){ yield(Number).parseInt('11', 2) }", output: "function *f(){ yield 0b11 }", - parserOptions: { 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 }", - parserOptions: { 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 }", - parserOptions: { 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 }", - parserOptions: { 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 }", - parserOptions: { 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) }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ message: "Use hexadecimal literals instead of parseInt()." }] }, { 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..4c6da365436 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,7 +347,7 @@ ruleTester.run("prefer-object-spread", rule, { baz: "cats" --> weird }`, - parserOptions: { + languageOptions: { sourceType: "script" }, errors: [ @@ -899,7 +899,7 @@ ruleTester.run("prefer-object-spread", rule, { { code: "globalThis.Object.assign({ });", output: "({});", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -912,7 +912,7 @@ ruleTester.run("prefer-object-spread", rule, { { code: "globalThis.Object.assign({\n});", output: "({});", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -931,7 +931,7 @@ ruleTester.run("prefer-object-spread", rule, { function foo () { var globalThis = bar; } ({}); `, - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -950,7 +950,7 @@ ruleTester.run("prefer-object-spread", rule, { const Foo = require('foo'); ({foo: Foo}); `, - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "useLiteralMessage", @@ -979,7 +979,9 @@ 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"), + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1") + }, errors: [ { messageId: "useSpreadMessage", @@ -992,7 +994,9 @@ ruleTester.run("prefer-object-spread", rule, { { code: "Object.assign<{}, A>({}, foo);", output: "({ ...foo});", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2"), + languageOptions: { + parser: require("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2") + }, errors: [ { messageId: "useSpreadMessage", 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..bc15b9a7d89 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,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('a');", - env: { - es2020: true - }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedRegExp", @@ -551,9 +557,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "globalThis.RegExp('a');", - env: { - es2020: true - }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "unexpectedRegExp", @@ -906,7 +910,7 @@ ruleTester.run("prefer-regex-literals", rule, { disallowRedundantWrapping: true } ], - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1077,8 +1081,9 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('abc', 'u');", - parserOptions: { - ecmaVersion: 3 + languageOptions: { + ecmaVersion: 3, + sourceType: "script" }, errors: [ { @@ -1089,7 +1094,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new RegExp('abc', 'd');", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1101,7 +1106,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('abc', 'd');", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [ @@ -1132,7 +1137,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('\\n', '');", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [ @@ -1344,8 +1349,10 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('\\\\W', '');", - globals: { - globalThis: "readonly" + languageOptions: { + globals: { + globalThis: "readonly" + } }, errors: [ { @@ -1389,8 +1396,10 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "globalThis.RegExp('\\\\d', '');", - globals: { - globalThis: "readonly" + languageOptions: { + globals: { + globalThis: "readonly" + } }, errors: [ { @@ -1406,8 +1415,10 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "globalThis.RegExp('\\\\D', '')", - globals: { - globalThis: "readonly" + languageOptions: { + globals: { + globalThis: "readonly" + } }, errors: [ { @@ -1423,8 +1434,10 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "globalThis.RegExp('\\\\\\\\\\\\D', '')", - globals: { - globalThis: "readonly" + languageOptions: { + globals: { + globalThis: "readonly" + } }, errors: [ { @@ -1454,8 +1467,10 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('\\\\0\\\\0', '');", - globals: { - globalThis: "writable" + languageOptions: { + globals: { + globalThis: "writable" + } }, errors: [ { @@ -1508,7 +1523,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "RegExp('\\\\78\\\\126\\\\5934', '')", - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [ @@ -1525,8 +1540,10 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new window['RegExp']('\\\\x56\\\\x78\\\\x45', '');", - env: { - browser: true + languageOptions: { + globals: { + window: "readonly" + } }, errors: [ { @@ -1748,7 +1765,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "async function abc(){await new RegExp(\"foo\")}", - parserOptions: { + languageOptions: { ecmaVersion: 8, sourceType: "module" }, @@ -1886,7 +1903,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ == new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1903,7 +1920,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ === new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1920,7 +1937,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ != new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1937,7 +1954,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ !== new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1954,7 +1971,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ > new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1971,7 +1988,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ < new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -1988,7 +2005,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ >= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2005,7 +2022,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ <= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2022,7 +2039,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ << new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2039,7 +2056,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ >> new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2056,7 +2073,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ >>> new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2073,7 +2090,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ ^ new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2090,7 +2107,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ & new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2107,7 +2124,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n /abc/ | new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2124,7 +2141,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n null ?? new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2141,7 +2158,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc *= new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2158,7 +2175,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n console.log({a: new RegExp('sup')})\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2175,7 +2192,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n console.log(() => {new RegExp('sup')})\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2192,7 +2209,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n function abc() {new RegExp('sup')}\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2209,7 +2226,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n function abc() {return new RegExp('sup')}\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2226,7 +2243,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc <<= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2243,7 +2260,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc >>= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2260,7 +2277,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc >>>= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2277,7 +2294,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc ^= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2294,7 +2311,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc &= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2311,7 +2328,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc |= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2328,7 +2345,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc ??= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2345,7 +2362,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc &&= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2362,7 +2379,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc ||= new RegExp('cba');\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2379,7 +2396,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc **= new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2396,7 +2413,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc /= new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2413,7 +2430,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc += new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2430,7 +2447,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc -= new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2447,7 +2464,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n abc %= new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2464,7 +2481,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "\n () => new RegExp('blah')\n ", - parserOptions: { + languageOptions: { ecmaVersion: 2021 }, errors: [ @@ -2588,7 +2605,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "(async function(){for await (value of new RegExp('something being searched')) { console.log(value) }})()", - parserOptions: { + languageOptions: { ecmaVersion: 2018 }, errors: [ @@ -2816,7 +2833,7 @@ ruleTester.run("prefer-regex-literals", rule, { // ES2024 { code: "new RegExp('[[A--B]]', 'v')", - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", @@ -2831,7 +2848,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new RegExp('[[A--B]]', 'v')", - parserOptions: { ecmaVersion: 2023 }, + languageOptions: { ecmaVersion: 2023 }, errors: [ { messageId: "unexpectedRegExp", @@ -2841,7 +2858,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new RegExp('[[A&&&]]', 'v')", - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", @@ -2851,7 +2868,7 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new RegExp('a', 'uv')", - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRegExp", @@ -2862,7 +2879,7 @@ ruleTester.run("prefer-regex-literals", rule, { { code: "new RegExp(/a/, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2881,7 +2898,7 @@ ruleTester.run("prefer-regex-literals", rule, { { code: "new RegExp(/a/, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2023 }, + languageOptions: { ecmaVersion: 2023 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2892,7 +2909,7 @@ ruleTester.run("prefer-regex-literals", rule, { { code: "new RegExp(/a/g, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2918,7 +2935,7 @@ ruleTester.run("prefer-regex-literals", rule, { { code: "new RegExp(/[[A--B]]/v, 'g')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2939,7 +2956,7 @@ ruleTester.run("prefer-regex-literals", rule, { { code: "new RegExp(/a/u, 'v')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2960,7 +2977,7 @@ ruleTester.run("prefer-regex-literals", rule, { { code: "new RegExp(/a/v, 'u')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", @@ -2981,23 +2998,14 @@ ruleTester.run("prefer-regex-literals", rule, { { code: "new RegExp(/[[A--B]]/v, 'u')", options: [{ disallowRedundantWrapping: true }], - parserOptions: { ecmaVersion: 2024 }, + languageOptions: { ecmaVersion: 2024 }, errors: [ { messageId: "unexpectedRedundantRegExpWithFlags", suggestions: null } ] - } - ] -}); - -const flatRuleTester = new FlatRuleTester(); - -flatRuleTester.run("prefer-regex-literals", rule, { - valid: [], - - invalid: [ + }, { code: "var regex = new RegExp('foo', 'u');", languageOptions: { @@ -3013,5 +3021,6 @@ flatRuleTester.run("prefer-regex-literals", rule, { ] }] } + ] }); 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..3b3ea58ac68 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,7 +182,7 @@ ruleTester.run("quote-props", rule, { code: "({ 'a': 0, [x]: 0 })", output: "({ a: 0, [x]: 0 })", options: ["consistent-as-needed"], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "redundantQuoting", type: "Property" } ] @@ -190,7 +190,7 @@ ruleTester.run("quote-props", rule, { code: "({ 'a': 0, x })", output: "({ a: 0, x })", options: ["consistent-as-needed"], - env: { es6: true }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "redundantQuoting", type: "Property" }] @@ -375,7 +375,7 @@ ruleTester.run("quote-props", rule, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "1" } @@ -385,7 +385,7 @@ ruleTester.run("quote-props", rule, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["as-needed", { numbers: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "unquotedNumericProperty", data: { property: "1" } @@ -394,7 +394,7 @@ ruleTester.run("quote-props", rule, { code: "({ 1_0: 1 })", output: "({ \"10\": 1 })", options: ["as-needed", { numbers: true }], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedNumericProperty", data: { property: "10" } @@ -403,7 +403,7 @@ ruleTester.run("quote-props", rule, { code: "({ 1_2.3_4e0_2: 1 })", output: "({ \"1234\": 1 })", options: ["always"], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "1234" } @@ -412,7 +412,7 @@ ruleTester.run("quote-props", rule, { code: "({ 0b1_000: 1 })", output: "({ \"8\": 1 })", options: ["always"], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "unquotedPropertyFound", data: { property: "8" } @@ -421,7 +421,7 @@ ruleTester.run("quote-props", rule, { code: "({ 1_000: a, '1_000': b })", output: "({ \"1000\": a, '1_000': b })", options: ["consistent-as-needed"], - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "inconsistentlyQuotedProperty", data: { key: "1000" } diff --git a/tests/lib/rules/quotes.js b/tests/lib/rules/quotes.js index 11ae90248b7..549275e1d2a 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,7 +122,7 @@ ruleTester.run("quotes", rule, { code: "var foo = `bar`;", output: "var foo = 'bar';", options: ["single"], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ @@ -168,7 +173,7 @@ ruleTester.run("quotes", rule, { code: "var foo = `bar`;", output: "var foo = \"bar\";", options: ["double"], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [{ @@ -231,7 +236,7 @@ ruleTester.run("quotes", rule, { code: "var foo = 'bar';", output: "var foo = `bar`;", options: ["backtick"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -242,7 +247,7 @@ ruleTester.run("quotes", rule, { code: "var foo = 'b${x}a$r';", output: "var foo = `b\\${x}a$r`;", options: ["backtick"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -253,7 +258,7 @@ ruleTester.run("quotes", rule, { code: "var foo = \"bar\";", output: "var foo = `bar`;", options: ["backtick"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -264,7 +269,7 @@ ruleTester.run("quotes", rule, { code: "var foo = \"bar\";", output: "var foo = `bar`;", options: ["backtick", { avoidEscape: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -275,7 +280,7 @@ ruleTester.run("quotes", rule, { code: "var foo = 'bar';", output: "var foo = `bar`;", options: ["backtick", { avoidEscape: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -288,7 +293,7 @@ ruleTester.run("quotes", rule, { code: "var foo = `backtick`; \"use strict\";", output: "var foo = `backtick`; `use strict`;", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -299,7 +304,7 @@ ruleTester.run("quotes", rule, { code: "{ \"use strict\"; var foo = `backtick`; }", output: "{ `use strict`; var foo = `backtick`; }", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -310,7 +315,7 @@ ruleTester.run("quotes", rule, { code: "if (1) { \"use strict\"; var foo = `backtick`; }", output: "if (1) { `use strict`; var foo = `backtick`; }", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -323,7 +328,7 @@ ruleTester.run("quotes", rule, { code: "var obj = {[\"key0\"]: 0, ['key1']: 1};", output: "var obj = {[`key0`]: 0, [`key1`]: 1};", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -341,7 +346,7 @@ ruleTester.run("quotes", rule, { code: "class Foo { ['a'](){} static ['b'](){} }", output: "class Foo { [`a`](){} static [`b`](){} }", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -361,7 +366,7 @@ ruleTester.run("quotes", rule, { code: "
", output: "
", options: ["single"], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "wrongQuotes", @@ -374,7 +379,7 @@ ruleTester.run("quotes", rule, { code: "
", output: "
", options: ["double"], - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, errors: [ { messageId: "wrongQuotes", @@ -387,7 +392,7 @@ ruleTester.run("quotes", rule, { code: "
", output: "
", options: ["backtick"], - parserOptions: { ecmaFeatures: { jsx: true }, ecmaVersion: 2015 }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } }, ecmaVersion: 2015 }, errors: [ { messageId: "wrongQuotes", @@ -401,7 +406,7 @@ ruleTester.run("quotes", rule, { { code: "`use strict`;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -411,7 +416,7 @@ ruleTester.run("quotes", rule, { { code: "function foo() { `use strict`; foo(); }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -421,7 +426,7 @@ ruleTester.run("quotes", rule, { { code: "foo = function() { `use strict`; foo(); }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -431,7 +436,7 @@ ruleTester.run("quotes", rule, { { code: "() => { `use strict`; foo(); }", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -441,7 +446,7 @@ ruleTester.run("quotes", rule, { { code: "() => { foo(); `use strict`; }", output: null, // no autofix - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -451,7 +456,7 @@ ruleTester.run("quotes", rule, { { code: "foo(); `use strict`;", output: null, // no autofix - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -463,7 +468,7 @@ ruleTester.run("quotes", rule, { { code: "var foo = `foo\\nbar`;", output: "var foo = \"foo\\nbar\";", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -473,7 +478,7 @@ ruleTester.run("quotes", rule, { { code: "var foo = `foo\\\nbar`;", // 1 backslash followed by a newline output: "var foo = \"foo\\\nbar\";", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -483,7 +488,7 @@ ruleTester.run("quotes", rule, { { code: "var foo = `foo\\\\\\\nbar`;", // 3 backslashes followed by a newline output: "var foo = \"foo\\\\\\\nbar\";", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -493,7 +498,7 @@ ruleTester.run("quotes", rule, { { code: "````", output: "\"\"``", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -532,7 +537,7 @@ ruleTester.run("quotes", rule, { code: "var notoctal = '\\0'", output: "var notoctal = `\\0`", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -545,7 +550,7 @@ ruleTester.run("quotes", rule, { code: "var foo = '\\1'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -558,7 +563,7 @@ ruleTester.run("quotes", rule, { code: "var foo = \"\\1\"", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -571,7 +576,7 @@ ruleTester.run("quotes", rule, { code: "var foo = '\\01'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -584,7 +589,7 @@ ruleTester.run("quotes", rule, { code: "var foo = '\\0\\1'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -597,7 +602,7 @@ ruleTester.run("quotes", rule, { code: "var foo = '\\08'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -610,7 +615,7 @@ ruleTester.run("quotes", rule, { code: "var foo = 'prefix \\33'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -623,7 +628,7 @@ ruleTester.run("quotes", rule, { code: "var foo = 'prefix \\75 suffix'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -636,7 +641,7 @@ ruleTester.run("quotes", rule, { code: "var nonOctalDecimalEscape = '\\8'", output: null, options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "wrongQuotes", @@ -652,7 +657,7 @@ ruleTester.run("quotes", rule, { code: "class C { 'foo'; }", output: "class C { \"foo\"; }", options: ["double"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", @@ -665,7 +670,7 @@ ruleTester.run("quotes", rule, { code: "class C { 'foo'() {} }", output: "class C { \"foo\"() {} }", options: ["double"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", @@ -678,7 +683,7 @@ ruleTester.run("quotes", rule, { code: "class C { \"foo\"; }", output: "class C { 'foo'; }", options: ["single"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", @@ -691,7 +696,7 @@ ruleTester.run("quotes", rule, { code: "class C { \"foo\"() {} }", output: "class C { 'foo'() {} }", options: ["single"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", @@ -704,7 +709,7 @@ ruleTester.run("quotes", rule, { code: "class C { [\"foo\"]; }", output: "class C { [`foo`]; }", options: ["backtick"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", @@ -717,7 +722,7 @@ ruleTester.run("quotes", rule, { code: "class C { foo = \"foo\"; }", output: "class C { foo = `foo`; }", options: ["backtick"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "wrongQuotes", @@ -731,7 +736,7 @@ ruleTester.run("quotes", rule, { { code: "() => { foo(); (`use strict`); }", output: "() => { foo(); (\"use strict\"); }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -742,7 +747,7 @@ ruleTester.run("quotes", rule, { code: "('foo'); \"bar\";", output: "(`foo`); `bar`;", options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "backtick" }, @@ -765,7 +770,7 @@ ruleTester.run("quotes", rule, { { code: "{ `foobar`; }", output: "{ \"foobar\"; }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, @@ -775,7 +780,7 @@ ruleTester.run("quotes", rule, { { code: "foo(() => `bar`);", output: "foo(() => \"bar\");", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrongQuotes", data: { description: "doublequote" }, diff --git a/tests/lib/rules/radix.js b/tests/lib/rules/radix.js index 437d2465350..c5acd6f254b 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,7 +90,7 @@ ruleTester.run("radix", rule, { }, { code: "parseInt(\"10\",);", // Function parameter with trailing comma - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "missingRadix", type: "CallExpression", @@ -107,7 +107,7 @@ ruleTester.run("radix", rule, { }, { code: "parseInt((0, \"10\"),);", // Sequence expression (with trailing comma). - parserOptions: { ecmaVersion: 2017 }, + languageOptions: { ecmaVersion: 2017 }, errors: [{ messageId: "missingRadix", type: "CallExpression", @@ -226,7 +226,7 @@ ruleTester.run("radix", rule, { // Optional chaining { code: "parseInt?.(\"10\");", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", @@ -237,7 +237,7 @@ ruleTester.run("radix", rule, { }, { code: "Number.parseInt?.(\"10\");", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", @@ -248,7 +248,7 @@ ruleTester.run("radix", rule, { }, { code: "Number?.parseInt(\"10\");", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", @@ -259,7 +259,7 @@ ruleTester.run("radix", rule, { }, { code: "(Number?.parseInt)(\"10\");", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "missingRadix", diff --git a/tests/lib/rules/require-atomic-updates.js b/tests/lib/rules/require-atomic-updates.js index 53d85b75289..25dfb277279 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,7 @@ ruleTester.run("require-atomic-updates", rule, { } }; `, - env: { node: true }, + languageOptions: { sourceType: "commonjs", globals: { process: "readonly" } }, errors: [ { messageId: "nonAtomicObjectUpdate", 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..0ad2fb15f41 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,7 +256,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "FunctionExpression" @@ -279,7 +279,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" @@ -302,7 +302,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" @@ -325,7 +325,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" @@ -348,7 +348,7 @@ ruleTester.run("require-jsdoc", rule, { ClassDeclaration: true } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingJSDocComment", type: "ClassDeclaration" @@ -361,7 +361,7 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ArrowFunctionExpression" @@ -374,7 +374,7 @@ ruleTester.run("require-jsdoc", rule, { ArrowFunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "ArrowFunctionExpression" @@ -399,7 +399,7 @@ ruleTester.run("require-jsdoc", rule, { FunctionExpression: true } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingJSDocComment", type: "FunctionExpression" diff --git a/tests/lib/rules/require-unicode-regexp.js b/tests/lib/rules/require-unicode-regexp.js index eab11b70fed..ff9bfb41ce5 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,7 @@ ruleTester.run("require-unicode-regexp", rule, { }, { code: "new window.RegExp('foo')", - env: { browser: true }, + languageOptions: { globals: globals.browser }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -278,7 +279,7 @@ ruleTester.run("require-unicode-regexp", rule, { }, { code: "new global.RegExp('foo')", - env: { node: true }, + languageOptions: { sourceType: "commonjs" }, errors: [{ messageId: "requireUFlag", suggestions: [ @@ -291,7 +292,7 @@ ruleTester.run("require-unicode-regexp", rule, { }, { code: "new globalThis.RegExp('foo')", - env: { es2020: true }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "requireUFlag", suggestions: [ 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..6962813dcf8 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,7 @@ ruleTester.run("rest-spread-spacing", rule, { { code: "let n = { x, y, ... z };", output: "let n = { x, y, ...z };", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -517,7 +517,7 @@ ruleTester.run("rest-spread-spacing", rule, { { code: "let n = { x, y, ...\tz };", output: "let n = { x, y, ...z };", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -531,7 +531,7 @@ ruleTester.run("rest-spread-spacing", rule, { { code: "let n = { x, y, ...\nz };", output: "let n = { x, y, ...z };", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -546,7 +546,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ... z };", output: "let n = { x, y, ...z };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -561,7 +561,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ...\tz };", output: "let n = { x, y, ...z };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -576,7 +576,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ...\nz };", output: "let n = { x, y, ...z };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -591,7 +591,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ...z };", output: "let n = { x, y, ... z };", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -606,7 +606,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ... (z) };", output: "let n = { x, y, ...(z) };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -621,7 +621,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ... ( z ) };", output: "let n = { x, y, ...( z ) };", options: ["never"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 20, @@ -636,7 +636,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ...(z) };", output: "let n = { x, y, ... (z) };", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -651,7 +651,7 @@ ruleTester.run("rest-spread-spacing", rule, { code: "let n = { x, y, ...( z ) };", output: "let n = { x, y, ... ( z ) };", options: ["always"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 17, @@ -665,7 +665,7 @@ ruleTester.run("rest-spread-spacing", rule, { { 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -679,7 +679,7 @@ ruleTester.run("rest-spread-spacing", rule, { { 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -693,7 +693,7 @@ ruleTester.run("rest-spread-spacing", rule, { { 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -708,7 +708,7 @@ ruleTester.run("rest-spread-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -723,7 +723,7 @@ ruleTester.run("rest-spread-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -738,7 +738,7 @@ ruleTester.run("rest-spread-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 16, @@ -753,7 +753,7 @@ ruleTester.run("rest-spread-spacing", rule, { 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [{ line: 1, column: 13, diff --git a/tests/lib/rules/semi-spacing.js b/tests/lib/rules/semi-spacing.js index ffd67854abc..972bc78e928 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,7 +280,7 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 22 } ] @@ -289,7 +289,7 @@ ruleTester.run("semi-spacing", rule, { code: "import * as foo from 'bar' ;", output: "import * as foo from 'bar';", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 27 } ] @@ -298,7 +298,7 @@ ruleTester.run("semi-spacing", rule, { code: "var foo = 0; export {foo} ;", output: "var foo = 0; export {foo};", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportNamedDeclaration", line: 1, column: 26 } ] @@ -307,7 +307,7 @@ ruleTester.run("semi-spacing", rule, { code: "export * from 'foo' ;", output: "export * from 'foo';", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportAllDeclaration", line: 1, column: 20 } ] @@ -316,7 +316,7 @@ ruleTester.run("semi-spacing", rule, { code: "export default foo ;", output: "export default foo;", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "unexpectedWhitespaceBefore", type: "ExportDefaultDeclaration", line: 1, column: 19 } ] @@ -325,7 +325,7 @@ ruleTester.run("semi-spacing", rule, { code: "while(foo) {continue ;}", output: "while(foo) {continue;}", options: [{ before: false, after: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -341,7 +341,7 @@ ruleTester.run("semi-spacing", rule, { code: "if(foo) {throw new Error() ; }", output: "if(foo) {throw new Error(); }", options: [{ before: false, after: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -357,7 +357,7 @@ ruleTester.run("semi-spacing", rule, { code: "for(a ; ; );", output: "for(a;; );", options: [{ before: false, after: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ type: "ForStatement", messageId: "unexpectedWhitespaceBefore", @@ -379,7 +379,7 @@ ruleTester.run("semi-spacing", rule, { code: "for(a ; \n ; );", output: "for(a; \n ; );", options: [{ before: false, after: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ type: "ForStatement", messageId: "unexpectedWhitespaceBefore", @@ -440,7 +440,7 @@ ruleTester.run("semi-spacing", rule, { { code: "class C { foo ;bar;}", output: "class C { foo; bar;}", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "unexpectedWhitespaceBefore", @@ -464,7 +464,7 @@ ruleTester.run("semi-spacing", rule, { code: "class C { foo; bar ; }", output: "class C { foo ;bar ; }", options: [{ before: true, after: false }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [ { messageId: "missingWhitespaceBefore", @@ -487,7 +487,7 @@ ruleTester.run("semi-spacing", rule, { { code: "class C { foo;static {}}", output: "class C { foo; static {}}", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingWhitespaceAfter", type: "PropertyDefinition", diff --git a/tests/lib/rules/semi-style.js b/tests/lib/rules/semi-style.js index 7ab8f223fe8..428487c88e9 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,7 +591,7 @@ ruleTester.run("semi-style", rule, { code: "class C { foo\n;bar }", output: "class C { foo;\nbar }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { @@ -603,7 +603,7 @@ ruleTester.run("semi-style", rule, { code: "class C { foo;\nbar }", output: "class C { foo\n;bar }", options: ["first"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { @@ -617,7 +617,7 @@ ruleTester.run("semi-style", rule, { code: "class C { static { foo\n; } }", output: "class C { static { foo;\n} }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { @@ -629,7 +629,7 @@ ruleTester.run("semi-style", rule, { code: "class C { static { foo\n ;bar } }", output: "class C { static { foo;\nbar } }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { @@ -641,7 +641,7 @@ ruleTester.run("semi-style", rule, { code: "class C { static { foo;\nbar\n ; } }", output: "class C { static { foo;\nbar;\n} }", options: ["last"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { @@ -653,7 +653,7 @@ ruleTester.run("semi-style", rule, { code: "class C { static { foo;\nbar } }", output: "class C { static { foo\n;bar } }", options: ["first"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "expectedSemiColon", data: { diff --git a/tests/lib/rules/semi.js b/tests/lib/rules/semi.js index 1811e14ee7b..3d8e88371a4 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,79 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -595,7 +595,7 @@ ruleTester.run("semi", rule, { { code: "import { square, diag } from 'lib'", output: "import { square, diag } from 'lib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -608,7 +608,7 @@ ruleTester.run("semi", rule, { { code: "import { default as foo } from 'lib'", output: "import { default as foo } from 'lib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -621,7 +621,7 @@ ruleTester.run("semi", rule, { { code: "import 'src/mylib'", output: "import 'src/mylib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -634,7 +634,7 @@ ruleTester.run("semi", rule, { { code: "import theDefault, { named1, named2 } from 'src/mylib'", output: "import theDefault, { named1, named2 } from 'src/mylib';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ImportDeclaration", @@ -683,7 +683,7 @@ ruleTester.run("semi", rule, { { code: "let x = 5", output: "let x = 5;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -975,7 +975,7 @@ ruleTester.run("semi", rule, { code: "let x = 5;", output: "let x = 5", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1106,7 +1106,7 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ImportDeclaration", @@ -1132,7 +1132,7 @@ ruleTester.run("semi", rule, { { code: "class C { static { foo() } }", output: "class C { static { foo(); } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1146,7 +1146,7 @@ ruleTester.run("semi", rule, { code: "class C { static { foo() } }", output: "class C { static { foo(); } }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1159,7 +1159,7 @@ ruleTester.run("semi", rule, { { code: "class C { static { foo(); bar() } }", output: "class C { static { foo(); bar(); } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1172,7 +1172,7 @@ ruleTester.run("semi", rule, { { code: "class C { static { foo()\nbar(); } }", output: "class C { static { foo();\nbar(); } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1185,7 +1185,7 @@ ruleTester.run("semi", rule, { { code: "class C { static { foo(); bar()\nbaz(); } }", output: "class C { static { foo(); bar();\nbaz(); } }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "ExpressionStatement", @@ -1199,7 +1199,7 @@ ruleTester.run("semi", rule, { code: "class C { static { foo(); } }", output: "class C { static { foo() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1213,7 +1213,7 @@ ruleTester.run("semi", rule, { code: "class C { static { foo();\nbar() } }", output: "class C { static { foo()\nbar() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1227,7 +1227,7 @@ ruleTester.run("semi", rule, { code: "class C { static { foo()\nbar(); } }", output: "class C { static { foo()\nbar() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1241,7 +1241,7 @@ ruleTester.run("semi", rule, { code: "class C { static { foo()\nbar();\nbaz() } }", output: "class C { static { foo()\nbar()\nbaz() } }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "ExpressionStatement", @@ -1255,7 +1255,7 @@ ruleTester.run("semi", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", type: "DoWhileStatement", @@ -1269,7 +1269,7 @@ ruleTester.run("semi", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", type: "DoWhileStatement", @@ -1381,7 +1381,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", line: 2, @@ -1394,7 +1394,7 @@ ruleTester.run("semi", rule, { code: "class C {\nfoo() \n{ bar(); baz(); }\n}", output: "class C {\nfoo() \n{ bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "extraSemi", line: 3, @@ -1407,7 +1407,7 @@ ruleTester.run("semi", rule, { code: "class C {\nfoo() {\n bar(); baz() }\n}", output: "class C {\nfoo() {\n bar(); baz(); }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", line: 3, @@ -1420,7 +1420,7 @@ ruleTester.run("semi", rule, { code: "class C {\nfoo() { bar(); baz() \n}\n}", output: "class C {\nfoo() { bar(); baz(); \n}\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSemi", line: 2, @@ -1433,7 +1433,7 @@ ruleTester.run("semi", rule, { code: "class C {\nstatic { bar(); baz(); }\n}", output: "class C {\nstatic { bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 2, @@ -1446,7 +1446,7 @@ ruleTester.run("semi", rule, { code: "class C {\nstatic \n{ bar(); baz(); }\n}", output: "class C {\nstatic \n{ bar(); baz() }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 3, @@ -1459,7 +1459,7 @@ ruleTester.run("semi", rule, { code: "class C {\nstatic {\n bar(); baz() }\n}", output: "class C {\nstatic {\n bar(); baz(); }\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 3, @@ -1472,7 +1472,7 @@ ruleTester.run("semi", rule, { code: "class C {\nfoo() { bar(); baz() \n}\n}", output: "class C {\nfoo() { bar(); baz(); \n}\n}", options: ["always", { omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 2, @@ -1487,7 +1487,7 @@ ruleTester.run("semi", rule, { { code: "export * from 'foo'", output: "export * from 'foo';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportAllDeclaration", @@ -1500,7 +1500,7 @@ ruleTester.run("semi", rule, { { code: "export { foo } from 'foo'", output: "export { foo } from 'foo';", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportNamedDeclaration", @@ -1513,7 +1513,7 @@ ruleTester.run("semi", rule, { { code: "var foo = 0;export { foo }", output: "var foo = 0;export { foo };", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportNamedDeclaration", @@ -1526,7 +1526,7 @@ ruleTester.run("semi", rule, { { code: "export var foo", output: "export var foo;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1539,7 +1539,7 @@ ruleTester.run("semi", rule, { { code: "export let foo", output: "export let foo;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1552,7 +1552,7 @@ ruleTester.run("semi", rule, { { code: "export const FOO = 42", output: "export const FOO = 42;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "VariableDeclaration", @@ -1565,7 +1565,7 @@ ruleTester.run("semi", rule, { { code: "export default foo || bar", output: "export default foo || bar;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1578,7 +1578,7 @@ ruleTester.run("semi", rule, { { code: "export default (foo) => foo.bar()", output: "export default (foo) => foo.bar();", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1591,7 +1591,7 @@ ruleTester.run("semi", rule, { { code: "export default foo = 42", output: "export default foo = 42;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1604,7 +1604,7 @@ ruleTester.run("semi", rule, { { code: "export default foo += 42", output: "export default foo += 42;", - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", type: "ExportDefaultDeclaration", @@ -1620,7 +1620,7 @@ ruleTester.run("semi", rule, { code: "export * from 'foo';", output: "export * from 'foo'", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportAllDeclaration", @@ -1634,7 +1634,7 @@ ruleTester.run("semi", rule, { code: "export { foo } from 'foo';", output: "export { foo } from 'foo'", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportNamedDeclaration", @@ -1648,7 +1648,7 @@ ruleTester.run("semi", rule, { code: "var foo = 0;export { foo };", output: "var foo = 0;export { foo }", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportNamedDeclaration", @@ -1662,7 +1662,7 @@ ruleTester.run("semi", rule, { code: "export var foo;", output: "export var foo", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1676,7 +1676,7 @@ ruleTester.run("semi", rule, { code: "export let foo;", output: "export let foo", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1690,7 +1690,7 @@ ruleTester.run("semi", rule, { code: "export const FOO = 42;", output: "export const FOO = 42", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "VariableDeclaration", @@ -1704,7 +1704,7 @@ ruleTester.run("semi", rule, { code: "export default foo || bar;", output: "export default foo || bar", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1718,7 +1718,7 @@ ruleTester.run("semi", rule, { code: "export default (foo) => foo.bar();", output: "export default (foo) => foo.bar()", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1732,7 +1732,7 @@ ruleTester.run("semi", rule, { code: "export default foo = 42;", output: "export default foo = 42", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1746,7 +1746,7 @@ ruleTester.run("semi", rule, { code: "export default foo += 42;", output: "export default foo += 42", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", type: "ExportDefaultDeclaration", @@ -1811,7 +1811,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", line: 2, @@ -1830,7 +1830,7 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "missingSemi", line: 2, @@ -1853,7 +1853,7 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "missingSemi", line: 3, @@ -1934,7 +1934,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "always" }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "missingSemi", line: 2, @@ -1953,7 +1953,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 2, @@ -1972,7 +1972,7 @@ ruleTester.run("semi", rule, { [a] = b `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 2, @@ -1995,7 +1995,7 @@ ruleTester.run("semi", rule, { } `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 3, @@ -2076,7 +2076,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 2, @@ -2095,7 +2095,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 3, @@ -2114,7 +2114,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "extraSemi", line: 3, @@ -2217,7 +2217,7 @@ ruleTester.run("semi", rule, { [1,2,3].forEach(doSomething) `, options: ["never", { beforeStatementContinuationChars: "never" }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [{ messageId: "extraSemi", line: 3, @@ -2231,7 +2231,7 @@ ruleTester.run("semi", rule, { { code: "class C { foo }", output: "class C { foo; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, @@ -2244,7 +2244,7 @@ ruleTester.run("semi", rule, { code: "class C { foo }", output: "class C { foo; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, @@ -2257,7 +2257,7 @@ ruleTester.run("semi", rule, { code: "class C { foo; }", output: "class C { foo }", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2270,7 +2270,7 @@ ruleTester.run("semi", rule, { code: "class C { foo\n[bar]; }", output: "class C { foo;\n[bar]; }", options: ["always"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSemi", line: 1, @@ -2285,7 +2285,7 @@ ruleTester.run("semi", rule, { code: "class C { [get];\nfoo\n}", output: "class C { [get]\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2298,7 +2298,7 @@ ruleTester.run("semi", rule, { code: "class C { [set];\nfoo\n}", output: "class C { [set]\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2311,7 +2311,7 @@ ruleTester.run("semi", rule, { code: "class C { #get;\nfoo\n}", output: "class C { #get\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2324,7 +2324,7 @@ ruleTester.run("semi", rule, { code: "class C { #set;\nfoo\n}", output: "class C { #set\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2337,7 +2337,7 @@ ruleTester.run("semi", rule, { code: "class C { #static;\nfoo\n}", output: "class C { #static\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2350,7 +2350,7 @@ ruleTester.run("semi", rule, { code: "class C { get=1;\nfoo\n}", output: "class C { get=1\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2363,7 +2363,7 @@ ruleTester.run("semi", rule, { code: "class C { static static;\nfoo\n}", output: "class C { static static\nfoo\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2376,7 +2376,7 @@ ruleTester.run("semi", rule, { code: "class C { static;\n}", output: "class C { static\n}", options: ["never"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "extraSemi", line: 1, @@ -2407,7 +2407,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1;} `, options: ["always", { omitLastInOneLineClassBody: false }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2438,7 +2438,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1;} `, options: ["always", { omitLastInOneLineClassBody: false, omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", @@ -2469,7 +2469,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1} `, options: ["always", { omitLastInOneLineClassBody: true, omitLastInOneLineBlock: false }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "extraSemi", @@ -2502,7 +2502,7 @@ ruleTester.run("semi", rule, { export class Variant1 extends SomeClass{type=1; anotherType=2;} `, options: ["always", { omitLastInOneLineClassBody: false, omitLastInOneLineBlock: true }], - parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + languageOptions: { ecmaVersion: 2022, sourceType: "module" }, errors: [ { messageId: "missingSemi", 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..4577ac9840f 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,7 @@ ruleTester.run("sort-keys", rule, { }, { code: "var obj = {a:1, [``]:2} // default", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -501,7 +501,7 @@ ruleTester.run("sort-keys", rule, { }, { code: "var obj = { null: 1, [/(?0)/]: 2 }", - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -520,7 +520,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {...z, c:1, b:1}", options: [], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -537,7 +537,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {...z, ...c, d:4, b:1, ...y, ...f, e:2, a:1}", options: [], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -564,7 +564,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {c:1, b:1, ...a}", options: [], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -581,7 +581,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {...z, ...a, c:1, b:1}", options: [], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -598,7 +598,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {...z, b:1, a:1, ...d, ...c}", options: [], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -615,7 +615,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {...z, a:2, b:0, ...x, ...c}", options: ["desc"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -632,7 +632,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {...z, a:2, b:0, ...x}", options: ["desc"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -649,7 +649,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {...z, '':1, a:2}", options: ["desc"], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", @@ -667,7 +667,7 @@ ruleTester.run("sort-keys", rule, { // 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -684,7 +684,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {'':1, [b+c]:2, a:3}", options: ["desc"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -701,7 +701,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {b:1, [f()]:2, '':3, a:4}", options: ["desc"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -719,7 +719,7 @@ ruleTester.run("sort-keys", rule, { // not ignore simple computed properties. { code: "var obj = {a:1, b:3, [a]: -1, c:2}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -1277,7 +1277,7 @@ ruleTester.run("sort-keys", rule, { { code: "var obj = {[``]:1, a:'2'} // desc", options: ["desc"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -1990,7 +1990,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2017,7 +2017,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2044,7 +2044,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2069,7 +2069,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2092,7 +2092,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2119,7 +2119,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2153,7 +2153,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2207,7 +2207,7 @@ ruleTester.run("sort-keys", rule, { }; `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "sortKeys", @@ -2233,7 +2233,7 @@ ruleTester.run("sort-keys", rule, { } `, options: ["asc", { allowLineSeparatedGroups: true }], - parserOptions: { ecmaVersion: 2018 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "sortKeys", diff --git a/tests/lib/rules/sort-vars.js b/tests/lib/rules/sort-vars.js index fb12b1fc33d..782ef1c40a5 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,21 +189,21 @@ ruleTester.run("sort-vars", rule, { code: "var d, a, [b, c] = {};", output: "var a, d, [b, c] = {};", options: ignoreCaseArgs, - parserOptions: { 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, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, { code: "var {} = 1, b, a", output: "var {} = 1, a, b", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, { @@ -220,13 +219,13 @@ ruleTester.run("sort-vars", rule, { { code: "var b = 0, a = `${b}`;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, { code: "var b = 0, a = `${f()}`", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, { @@ -247,7 +246,7 @@ ruleTester.run("sort-vars", rule, { { code: "var b = `${f()}`, c, d, a;", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedError] }, { diff --git a/tests/lib/rules/space-before-blocks.js b/tests/lib/rules/space-before-blocks.js index 49af9611650..4dd25219303 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,76 +430,76 @@ 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [expectedNoSpacingError] }, { code: "export function a(){ if(b){} }", output: "export function a(){ if(b) {} }", options: keywordOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [expectedSpacingError] }, { code: "export function a(){}", output: "export function a() {}", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [expectedSpacingError] }, { code: "export default function (a) {}", output: "export default function (a){}", options: keywordOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [expectedNoSpacingError] }, { code: "export function a() {}", output: "export function a(){}", options: keywordOnlyArgs, - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [expectedNoSpacingError] }, { code: "class test{}", output: "class test {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedSpacingError] }, { code: "class test{}", output: "class test {}", options: classesOnlyArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedSpacingError] }, { code: "class test{ constructor(){} }", output: "class test{ constructor() {} }", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedSpacingError] }, { code: "class test { constructor() {} }", output: "class test { constructor(){} }", options: classesOnlyArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedNoSpacingError] }, { code: "class test {}", output: "class test{}", options: functionsOnlyArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedNoSpacingError] }, { code: "class test {}", output: "class test{}", options: neverArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedNoSpacingError] }, { @@ -530,14 +530,14 @@ ruleTester.run("space-before-blocks", rule, { code: "class test{ constructor(){} }", output: "class test { constructor(){} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedSpacingError] }, { code: "class test{ constructor() {} }", output: "class test { constructor() {} }", options: classesAlwaysOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedSpacingError] }, { @@ -568,14 +568,14 @@ ruleTester.run("space-before-blocks", rule, { code: "class test { constructor(){} }", output: "class test{ constructor(){} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedNoSpacingError] }, { code: "class test { constructor() {} }", output: "class test{ constructor() {} }", options: classesNeverOthersOffArgs, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [expectedNoSpacingError] }, @@ -583,14 +583,18 @@ ruleTester.run("space-before-blocks", rule, { { code: "class A { foo(bar: string): void{} }", output: "class A { foo(bar: string): void {} }", - parser: fixtureParser("space-before-blocks", "return-type-keyword-1"), + languageOptions: { + parser: require(fixtureParser("space-before-blocks", "return-type-keyword-1")) + }, errors: [expectedSpacingError] }, { code: "function foo(): null {}", output: "function foo(): null{}", options: neverArgs, - parser: fixtureParser("space-before-blocks", "return-type-keyword-2"), + languageOptions: { + parser: require(fixtureParser("space-before-blocks", "return-type-keyword-2")) + }, errors: [expectedNoSpacingError] }, diff --git a/tests/lib/rules/space-before-function-paren.js b/tests/lib/rules/space-before-function-paren.js index 09187fad6d9..6eec7d8d2d2 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,7 @@ ruleTester.run("space-before-function-paren", rule, { { code: "var obj = { foo() {} };", output: "var obj = { foo () {} };", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -212,7 +214,7 @@ ruleTester.run("space-before-function-paren", rule, { { code: "function* foo() {}", output: "function* foo () {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -381,7 +383,7 @@ ruleTester.run("space-before-function-paren", rule, { code: "var obj = { foo () {} };", output: "var obj = { foo() {} };", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -395,7 +397,7 @@ ruleTester.run("space-before-function-paren", rule, { code: "function* foo () {}", output: "function* foo() {}", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionDeclaration", @@ -418,7 +420,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 }, errors: [ { type: "FunctionDeclaration", @@ -456,7 +458,7 @@ ruleTester.run("space-before-function-paren", rule, { code: "class Foo { constructor () {} *method () {} }", output: "class Foo { constructor() {} *method() {} }", options: [{ named: "never", anonymous: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -476,7 +478,7 @@ ruleTester.run("space-before-function-paren", rule, { code: "var foo = { bar () {} }", output: "var foo = { bar() {} }", options: [{ named: "never", anonymous: "always" }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { type: "FunctionExpression", @@ -498,7 +500,7 @@ 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 }, errors: [ { type: "FunctionDeclaration", @@ -590,34 +592,34 @@ ruleTester.run("space-before-function-paren", rule, { code: "async() => 1", output: "async () => 1", options: [{ asyncArrow: "always" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: ["Missing space before function parentheses."] }, { code: "async () => 1", output: "async() => 1", options: [{ asyncArrow: "never" }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: ["Unexpected space before function parentheses."] }, { code: "async() => 1", output: "async () => 1", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] }, { code: "async() => 1", output: "async () => 1", options: ["always"], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] }, { code: "async () => 1", output: "async() => 1", options: ["never"], - parserOptions: { 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 e304fb78858..6e0e2041c46 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,7 +552,7 @@ ruleTester.run("space-in-parens", rule, { code: "var foo = `(bar ${( 1 + 2 )})`;", output: "var foo = `(bar ${(1 + 2)})`;", options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "rejectedOpeningSpace", line: 1, column: 20 }, { messageId: "rejectedClosingSpace", line: 1, column: 26 } @@ -562,7 +562,7 @@ ruleTester.run("space-in-parens", rule, { code: "var foo = `(bar ${(1 + 2 )})`;", output: "var foo = `(bar ${( 1 + 2 )})`;", options: ["always"], - parserOptions: { 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 c2a5c554649..8212c7c6352 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,7 +403,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "const my_object={key: 'value'}", output: "const my_object = {key: 'value'}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -415,7 +415,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "var {a=0}=bar;", output: "var {a = 0} = bar;", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -433,7 +433,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "function foo(a=0) { }", output: "function foo(a = 0) { }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -445,7 +445,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "a**b", output: "a ** b", - parserOptions: { ecmaVersion: 7 }, + languageOptions: { ecmaVersion: 7 }, errors: [{ messageId: "missingSpace", data: { operator: "**" }, @@ -481,7 +481,9 @@ 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"), + languageOptions: { + parser: require(parser("type-annotations/variable-declaration-init-type-annotation-no-space")) + }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -493,8 +495,10 @@ ruleTester.run("space-infix-ops", rule, { { 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 }, + languageOptions: { + ecmaVersion: 6, + parser: require(parser("type-annotations/function-declaration-type-annotation-no-space")) + }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -508,7 +512,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "a&&=b", output: "a &&= b", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "&&=" }, @@ -522,7 +526,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "a ||=b", output: "a ||= b", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "||=" }, @@ -536,7 +540,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "a??= b", output: "a ??= b", - parserOptions: { ecmaVersion: 2021 }, + languageOptions: { ecmaVersion: 2021 }, errors: [{ messageId: "missingSpace", data: { operator: "??=" }, @@ -552,7 +556,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "class C { a=b; }", output: "class C { a = b; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, @@ -566,7 +570,7 @@ ruleTester.run("space-infix-ops", rule, { { code: "class C { [a ]= b; }", output: "class C { [a ] = b; }", - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "missingSpace", data: { operator: "=" }, diff --git a/tests/lib/rules/space-unary-ops.js b/tests/lib/rules/space-unary-ops.js index 9969bbc64e3..76c851059f1 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,7 +628,7 @@ ruleTester.run("space-unary-ops", rule, { { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, @@ -641,7 +641,7 @@ ruleTester.run("space-unary-ops", rule, { code: "function *foo() { yield (0) }", output: "function *foo() { yield(0) }", options: [{ words: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "yield" }, @@ -653,7 +653,7 @@ ruleTester.run("space-unary-ops", rule, { { code: "function *foo() { yield+0 }", output: "function *foo() { yield +0 }", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, @@ -738,7 +738,7 @@ 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, @@ -751,7 +751,7 @@ ruleTester.run("space-unary-ops", rule, { code: "function *foo() { yield(0) }", output: "function *foo() { yield (0) }", options: [{ words: false, overrides: { yield: true } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wordOperator", data: { word: "yield" }, @@ -763,7 +763,7 @@ ruleTester.run("space-unary-ops", rule, { { code: "async function foo() { await{foo: 'bar'} }", output: "async function foo() { await {foo: 'bar'} }", - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "wordOperator", data: { word: "await" }, @@ -776,7 +776,7 @@ ruleTester.run("space-unary-ops", rule, { code: "async function foo() { await{baz: 'qux'} }", output: "async function foo() { await {baz: 'qux'} }", options: [{ words: false, overrides: { await: true } }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "wordOperator", data: { word: "await" }, @@ -789,7 +789,7 @@ ruleTester.run("space-unary-ops", rule, { code: "async function foo() { await {foo: 1} }", output: "async function foo() { await{foo: 1} }", options: [{ words: false }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "await" }, @@ -802,7 +802,7 @@ ruleTester.run("space-unary-ops", rule, { code: "async function foo() { await {bar: 2} }", output: "async function foo() { await{bar: 2} }", options: [{ words: true, overrides: { await: false } }], - parserOptions: { ecmaVersion: 8 }, + languageOptions: { ecmaVersion: 8 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "await" }, @@ -815,7 +815,7 @@ ruleTester.run("space-unary-ops", rule, { 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 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unexpectedAfterWord", data: { word: "yield" }, 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..5fa646c6413 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,7 +165,7 @@ ruleTester.run("strict", rule, { code: "\"use strict\"; foo();", output: " foo();", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } ] @@ -156,7 +173,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["never"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } @@ -165,7 +182,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["never"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } @@ -200,7 +217,7 @@ ruleTester.run("strict", rule, { code: "var foo = () => { 'use strict'; return () => 1; }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } @@ -230,7 +247,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; foo();", output: " foo();", options: ["global"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } ] @@ -238,7 +255,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["global"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } @@ -247,7 +264,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["global"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } @@ -287,7 +304,7 @@ ruleTester.run("strict", rule, { code: "(() => { return true; })();", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "function", type: "ArrowFunctionExpression" } ] @@ -295,7 +312,7 @@ ruleTester.run("strict", rule, { code: "(() => true)();", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ { messageId: "function", type: "ArrowFunctionExpression" } ] @@ -325,7 +342,7 @@ ruleTester.run("strict", rule, { code: "var foo = function() { 'use strict'; return; }", output: "var foo = function() { return; }", options: ["function"], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "module", type: "ExpressionStatement" } ] @@ -333,7 +350,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["function"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } @@ -342,7 +359,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["function"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } @@ -396,7 +413,7 @@ ruleTester.run("strict", rule, { code: "var foo = () => { return; };", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "function", type: "ArrowFunctionExpression" }] }, @@ -405,35 +422,35 @@ ruleTester.run("strict", rule, { code: "class A { constructor() { \"use strict\"; } }", output: "class A { constructor() { } }", options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, { code: "class A { foo() { \"use strict\"; } }", output: "class A { foo() { } }", options: ["function"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, { code: "class A { field = () => { \"use strict\"; } }", output: "class A { field = () => { } }", options: ["function"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, { code: "class A { field = function() { \"use strict\"; } }", output: "class A { field = function() { } }", options: ["function"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }] }, @@ -451,7 +468,7 @@ ruleTester.run("strict", rule, { code: "function foo() { 'use strict'; return; }", output: null, options: ["safe"], - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } @@ -461,7 +478,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["safe"], - parserOptions: { ecmaFeatures: { impliedStrict: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } @@ -471,7 +488,7 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", options: ["safe"], - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } @@ -495,7 +512,7 @@ ruleTester.run("strict", rule, { { code: "function foo() { 'use strict'; return; }", output: null, - parserOptions: { ecmaFeatures: { globalReturn: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ { messageId: "global", type: "Program" }, { messageId: "global", type: "ExpressionStatement" } @@ -504,7 +521,7 @@ ruleTester.run("strict", rule, { { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", - parserOptions: { ecmaFeatures: { impliedStrict: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "implied", type: "ExpressionStatement" }, { messageId: "implied", type: "ExpressionStatement" } @@ -513,7 +530,7 @@ ruleTester.run("strict", rule, { { code: "'use strict'; function foo() { 'use strict'; return; }", output: " function foo() { return; }", - parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { impliedStrict: true } }, + languageOptions: { ecmaVersion: 6, sourceType: "module", parserOptions: { ecmaFeatures: { impliedStrict: true } } }, errors: [ { messageId: "module", type: "ExpressionStatement" }, { messageId: "module", type: "ExpressionStatement" } @@ -525,21 +542,21 @@ ruleTester.run("strict", rule, { code: "function foo(a = 0) { 'use strict' }", output: null, options: [], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())", output: null, options: [], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: [], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [ "Use the global form of 'use strict'.", { messageId: "nonSimpleParameterList" } @@ -549,21 +566,21 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo(a = 0) { 'use strict' }", output: null, options: [], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } }, + languageOptions: { ecmaVersion: 6, parserOptions: { ecmaFeatures: { globalReturn: true } } }, errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["never"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [ "Use the global form of 'use strict'.", { messageId: "nonSimpleParameterList" } @@ -573,35 +590,35 @@ ruleTester.run("strict", rule, { code: "'use strict'; function foo(a = 0) { 'use strict' }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { 'use strict' }", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "nonSimpleParameterList" }] }, { code: "function foo(a = 0) { }", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "wrap", data: { name: "function 'foo'" } }] }, { code: "(function() { function foo(a = 0) { } }())", output: null, options: ["function"], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: ["Use the function form of 'use strict'."] }, @@ -610,80 +627,57 @@ ruleTester.run("strict", rule, { code: "'use strict'; class C { static { function foo() { \n'use strict'; } } }", output: null, options: ["global"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "global", line: 2 }] }, { code: "class C { static { function foo() { \n'use strict'; } } }", output: null, options: ["never"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 2022, 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"], - parserOptions: { 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"], - parserOptions: { 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"], - parserOptions: { ecmaVersion: 2022 }, + languageOptions: { 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" - } }, - { - code: "'use strict'; module.exports = function identity (value) { return value; }", - options: ["safe"], - languageOptions: { - sourceType: "commonjs" - } - } - ], - - invalid: [ { code: "module.exports = function identity (value) { return value; }", + output: null, options: ["safe"], languageOptions: { sourceType: "commonjs" @@ -694,6 +688,7 @@ flatRuleTester.run("strict", rule, { }, { code: "module.exports = function identity (value) { return value; }", + output: null, languageOptions: { sourceType: "commonjs" }, 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..a23e9e202ec 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,7 +477,7 @@ ruleTester.run("use-isnan", rule, { }, { code: "x === Number?.NaN;", - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [comparisonError] }, { @@ -685,19 +685,19 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf?.(NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "foo?.indexOf(NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "(foo?.indexOf)(NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { @@ -733,19 +733,19 @@ ruleTester.run("use-isnan", rule, { { code: "foo.indexOf?.(Number.NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "foo?.indexOf(Number.NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }] }, { code: "(foo?.indexOf)(Number.NaN)", options: [{ enforceForIndexOf: true }], - parserOptions: { 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 325064fc189..1f2cd367336 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,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" } }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1311,7 +1311,7 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: true, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -1346,7 +1346,7 @@ ruleTester.run("valid-jsdoc", rule, { { code: "/**\n* Foo\n* @returns {string} something \n*/\nvar foo = \nfunction foo(a = 1){}", output: null, - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingParam", data: { name: "a" }, @@ -1356,7 +1356,7 @@ ruleTester.run("valid-jsdoc", rule, { { 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 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expected", data: { name: "b", jsdocName: "a" }, @@ -1470,7 +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" } }], - parserOptions: { ecmaVersion: 6, sourceType: "module" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1485,7 +1485,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 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" }, + languageOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "use", data: { name: "returns" }, @@ -1500,7 +1500,7 @@ ruleTester.run("valid-jsdoc", rule, { code: "/** foo */ var foo = () => bar();", output: null, options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, @@ -1511,7 +1511,7 @@ ruleTester.run("valid-jsdoc", rule, { code: "/** foo */ var foo = () => { return bar(); };", output: null, options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingReturn", data: { returns: "returns" }, @@ -1522,7 +1522,7 @@ ruleTester.run("valid-jsdoc", rule, { code: "/** @returns {object} foo */ var foo = () => { bar(); };", output: null, options: [{ requireReturn: false }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedTag", data: { title: "returns" }, @@ -1611,7 +1611,7 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: false, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -1644,7 +1644,7 @@ ruleTester.run("valid-jsdoc", rule, { requireReturn: true, matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$" }], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -1682,7 +1682,7 @@ ruleTester.run("valid-jsdoc", rule, { "}", output: null, options: [], - parserOptions: { + languageOptions: { ecmaVersion: 6 }, errors: [ @@ -1736,7 +1736,7 @@ ruleTester.run("valid-jsdoc", rule, { "async function a() {}", output: null, options: [{ requireReturn: true }], - parserOptions: { + languageOptions: { ecmaVersion: 2017 }, errors: [{ diff --git a/tests/lib/rules/valid-typeof.js b/tests/lib/rules/valid-typeof.js index 35a52f0a6c0..608ea04bc2e 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,7 +129,7 @@ ruleTester.run("valid-typeof", rule, { }, { code: "if (typeof bar === `umdefined`) {}", - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "invalidValue", type: "TemplateLiteral" }] }, { @@ -208,13 +208,13 @@ ruleTester.run("valid-typeof", rule, { { code: "typeof foo === `undefined${foo}`", options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [{ messageId: "notString", type: "TemplateLiteral" }] }, { code: "typeof foo === `${string}`", options: [{ requireStringLiterals: true }], - parserOptions: { 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 e2b1bb689c5..c793b334db8 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,7 +430,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { ecmaVersion: 6 }, + languageOptions: { ecmaVersion: 6 }, errors: [error] }, { @@ -454,7 +454,7 @@ ruleTester.run("vars-on-top", rule, { "export function f() {}", "var x;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" }, @@ -466,7 +466,7 @@ ruleTester.run("vars-on-top", rule, { "export function f() {}", "var y;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" }, @@ -478,7 +478,7 @@ ruleTester.run("vars-on-top", rule, { "export {foo};", "var test = 1;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" }, @@ -489,7 +489,7 @@ ruleTester.run("vars-on-top", rule, { "export {foo} from 'foo';", "var test = 1;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" }, @@ -500,7 +500,7 @@ ruleTester.run("vars-on-top", rule, { "export * from 'foo';", "var test = 1;" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 6, sourceType: "module" }, @@ -515,7 +515,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [error] @@ -529,7 +529,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [error] @@ -544,7 +544,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [{ ...error, line: 5 }] @@ -559,7 +559,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [error] @@ -573,7 +573,7 @@ ruleTester.run("vars-on-top", rule, { " }", "}" ].join("\n"), - parserOptions: { + languageOptions: { ecmaVersion: 2022 }, errors: [error] diff --git a/tests/lib/rules/wrap-iife.js b/tests/lib/rules/wrap-iife.js index 642e29b26df..18a22762caf 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,7 +483,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [wrapExpressionError] }, { @@ -601,7 +606,7 @@ 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 }, + languageOptions: { ecmaVersion: 2020 }, errors: [wrapExpressionError] }, @@ -610,28 +615,28 @@ 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 }, + 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 }], - parserOptions: { 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 }], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [wrapInvocationError] }, { code: "new (function () {} ?.());", output: "new ((function () {}) ?.());", options: ["inside"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [wrapExpressionError] } ] 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..e7e938e99a1 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,7 +371,7 @@ ruleTester.run("yoda", rule, { code: "if (5n != value) {}", output: "if (value != 5n) {}", options: ["never"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", @@ -408,7 +408,7 @@ ruleTester.run("yoda", rule, { code: "if (`red` <= value) {}", output: "if (value >= `red`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -421,7 +421,7 @@ ruleTester.run("yoda", rule, { code: "if (`red` <= `${foo}`) {}", output: "if (`${foo}` >= `red`) {}", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -434,7 +434,7 @@ ruleTester.run("yoda", rule, { code: 'if (`red` <= `${"red"}`) {}', output: 'if (`${"red"}` >= `red`) {}', options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -507,7 +507,7 @@ ruleTester.run("yoda", rule, { code: "if (value == `red`) {}", output: "if (`red` == value) {}", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -532,7 +532,7 @@ ruleTester.run("yoda", rule, { code: "if (value === 5n) {}", output: "if (5n === value) {}", options: ["always"], - parserOptions: { ecmaVersion: 2020 }, + languageOptions: { ecmaVersion: 2020 }, errors: [ { messageId: "expected", @@ -545,7 +545,7 @@ ruleTester.run("yoda", rule, { code: 'if (`${"red"}` <= `red`) {}', output: 'if (`red` >= `${"red"}`) {}', options: ["always"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -642,7 +642,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -655,7 +655,7 @@ ruleTester.run("yoda", rule, { code: "if (`green` < x.y && x.y < `blue`) {}", output: "if (x.y > `green` && x.y < `blue`) {}", options: ["never", { exceptRange: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -680,7 +680,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -693,7 +693,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -754,7 +754,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -791,7 +791,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -816,7 +816,7 @@ 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 }, + languageOptions: { ecmaVersion: 2018 }, errors: [ { messageId: "expected", @@ -865,7 +865,7 @@ ruleTester.run("yoda", rule, { code: "foo(a === `3`);", output: "foo(`3` === a);", options: ["always", { onlyEquality: true }], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1001,7 +1001,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield(1) < a }", output: "function *foo() { yield a > (1) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1014,7 +1014,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield((1)) < a }", output: "function *foo() { yield a > ((1)) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1027,7 +1027,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield 1 < a }", output: "function *foo() { yield a > 1 }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1040,7 +1040,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield/**/1 < a }", output: "function *foo() { yield/**/a > 1 }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1053,7 +1053,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield(1) < ++a }", output: "function *foo() { yield++a > (1) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1066,7 +1066,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield(1) < (a) }", output: "function *foo() { yield(a) > (1) }", options: ["never"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1091,7 +1091,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield++a < 1 }", output: "function *foo() { yield 1 > ++a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1104,7 +1104,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield(a) < 1 }", output: "function *foo() { yield 1 > (a) }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1117,7 +1117,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield a < 1 }", output: "function *foo() { yield 1 > a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1130,7 +1130,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield/**/a < 1 }", output: "function *foo() { yield/**/1 > a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1143,7 +1143,7 @@ ruleTester.run("yoda", rule, { code: "function *foo() { yield++a < (1) }", output: "function *foo() { yield(1) > ++a }", options: ["always"], - parserOptions: { ecmaVersion: 2015 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected", @@ -1312,7 +1312,7 @@ 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 }, + languageOptions: { ecmaVersion: 2015 }, errors: [ { messageId: "expected",