From c19d46837a1a4169dbfe3ba5cab280c376c725de Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 14 Jun 2021 11:18:04 -0700 Subject: [PATCH 1/5] Breaking: Strict package exports (refs #13654) --- .eslintrc.js | 1 + lib/api.js | 24 ++-- lib/unsupported-api.js | 23 ++++ package.json | 5 + tests/lib/api.js | 20 +++- tests/lib/rules/array-bracket-spacing.js | 12 +- tests/lib/rules/camelcase.js | 64 +++++------ tests/lib/rules/comma-dangle.js | 16 +-- tests/lib/rules/id-blacklist.js | 16 +-- tests/lib/rules/id-denylist.js | 16 +-- tests/lib/rules/indent.js | 28 ++--- tests/lib/rules/keyword-spacing.js | 4 +- tests/lib/rules/no-alert.js | 12 +- tests/lib/rules/no-console.js | 2 +- tests/lib/rules/no-else-return.js | 8 +- tests/lib/rules/no-eval.js | 40 +++---- tests/lib/rules/no-extend-native.js | 16 +-- tests/lib/rules/no-global-assign.js | 12 +- tests/lib/rules/no-implicit-globals.js | 12 +- tests/lib/rules/no-implied-eval.js | 72 ++++++------ tests/lib/rules/no-magic-numbers.js | 32 +++--- .../rules/no-misleading-character-class.js | 16 +-- tests/lib/rules/no-mixed-spaces-and-tabs.js | 8 +- tests/lib/rules/no-native-reassign.js | 10 +- tests/lib/rules/no-obj-calls.js | 104 +++++++++--------- tests/lib/rules/no-redeclare.js | 28 ++--- tests/lib/rules/no-restricted-globals.js | 36 +++--- tests/lib/rules/no-sequences.js | 4 +- tests/lib/rules/no-setter-return.js | 20 ++-- tests/lib/rules/no-shadow.js | 12 +- tests/lib/rules/no-unexpected-multiline.js | 4 +- tests/lib/rules/no-unused-vars.js | 4 +- tests/lib/rules/no-var.js | 4 +- tests/lib/rules/object-curly-newline.js | 16 +-- tests/lib/rules/object-curly-spacing.js | 4 +- tests/lib/rules/object-shorthand.js | 4 +- tests/lib/rules/prefer-const.js | 4 +- .../rules/prefer-exponentiation-operator.js | 8 +- tests/lib/rules/prefer-named-capture-group.js | 12 +- tests/lib/rules/prefer-object-spread.js | 24 ++-- tests/lib/rules/prefer-regex-literals.js | 8 +- tests/lib/rules/quote-props.js | 8 +- tests/lib/rules/require-unicode-regexp.js | 12 +- tests/lib/rules/space-before-blocks.js | 8 +- tests/lib/rules/space-infix-ops.js | 18 +-- tests/lib/unsupported-api.js | 30 +++++ 46 files changed, 452 insertions(+), 389 deletions(-) create mode 100644 lib/unsupported-api.js create mode 100644 tests/lib/unsupported-api.js diff --git a/.eslintrc.js b/.eslintrc.js index 668bc2747c5..a1f013f2d2c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -105,6 +105,7 @@ module.exports = { // Restrict relative path imports { files: ["lib/*"], + excludedFiles: ["lib/unsupported-api.js"], rules: { "node/no-restricted-require": ["error", [ ...createInternalFilesPatterns() diff --git a/lib/api.js b/lib/api.js index e4b6643b447..3dde0985505 100644 --- a/lib/api.js +++ b/lib/api.js @@ -5,30 +5,22 @@ "use strict"; -const { CLIEngine } = require("./cli-engine"); +//----------------------------------------------------------------------------- +// Requirements +//----------------------------------------------------------------------------- + const { ESLint } = require("./eslint"); const { Linter } = require("./linter"); const { RuleTester } = require("./rule-tester"); const { SourceCode } = require("./source-code"); +//----------------------------------------------------------------------------- +// Exports +//----------------------------------------------------------------------------- + module.exports = { Linter, - CLIEngine, ESLint, RuleTester, SourceCode }; - -// DOTO: remove deprecated API. -let deprecatedLinterInstance = null; - -Object.defineProperty(module.exports, "linter", { - enumerable: false, - get() { - if (!deprecatedLinterInstance) { - deprecatedLinterInstance = new Linter(); - } - - return deprecatedLinterInstance; - } -}); diff --git a/lib/unsupported-api.js b/lib/unsupported-api.js new file mode 100644 index 00000000000..110b35a47a4 --- /dev/null +++ b/lib/unsupported-api.js @@ -0,0 +1,23 @@ +/** + * @fileoverview APIs that are not officially supported by ESLint. + * These APIs may change or be removed at any time. Use at your + * own risk. + * @author Nicholas C. Zakas + */ + +"use strict"; + +//----------------------------------------------------------------------------- +// Requirements +//----------------------------------------------------------------------------- + +const { FileEnumerator } = require("./cli-engine/file-enumerator"); + +//----------------------------------------------------------------------------- +// Exports +//----------------------------------------------------------------------------- + +module.exports = { + builtinRules: require("./rules"), + FileEnumerator +}; diff --git a/package.json b/package.json index 601033eb44e..c189740a645 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,11 @@ "eslint": "./bin/eslint.js" }, "main": "./lib/api.js", + "exports": { + "./package.json": "./package.json", + ".": "./lib/api.js", + "./use-at-your-own-risk": "./lib/unsupported-api.js" + }, "scripts": { "test": "node Makefile.js test", "test:cli": "mocha", diff --git a/tests/lib/api.js b/tests/lib/api.js index f943f526c73..074d206e52e 100644 --- a/tests/lib/api.js +++ b/tests/lib/api.js @@ -5,21 +5,33 @@ "use strict"; +//----------------------------------------------------------------------------- +// Requirements +//----------------------------------------------------------------------------- + const assert = require("chai").assert, api = require("../../lib/api"); +//----------------------------------------------------------------------------- +// Tests +//----------------------------------------------------------------------------- + describe("api", () => { it("should have RuleTester exposed", () => { assert.isFunction(api.RuleTester); }); - it("should have CLIEngine exposed", () => { - assert.isFunction(api.CLIEngine); + it("should not have CLIEngine exposed", () => { + assert.isUndefined(api.CLIEngine); + }); + + it("should not have linter exposed", () => { + assert.isUndefined(api.linter); }); - it("should have linter exposed", () => { - assert.isObject(api.linter); + it("should have Linter exposed", () => { + assert.isFunction(api.Linter); }); it("should have SourceCode exposed", () => { diff --git a/tests/lib/rules/array-bracket-spacing.js b/tests/lib/rules/array-bracket-spacing.js index 33caf088928..4b5f5f051d4 100644 --- a/tests/lib/rules/array-bracket-spacing.js +++ b/tests/lib/rules/array-bracket-spacing.js @@ -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"], parserOptions: { ecmaVersion: 6 }, parser: parser("flow-destructuring-1") }, + { code: "([a, b]: Array< any >) => {}", options: ["never"], parserOptions: { ecmaVersion: 6 }, parser: parser("flow-destructuring-2") } ], invalid: [ @@ -921,7 +921,6 @@ ruleTester.run("array-bracket-spacing", rule, { code: "([ a, b ]: Array) => {}", output: "([a, b]: Array) => {}", options: ["never"], - parser: parser("flow-destructuring-1"), parserOptions: { ecmaVersion: 6 }, @@ -948,13 +947,13 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 9 } - ] + ], + parser: parser("flow-destructuring-1") }, { code: "([a, b]: Array< any >) => {}", output: "([ a, b ]: Array< any >) => {}", options: ["always"], - parser: parser("flow-destructuring-2"), parserOptions: { ecmaVersion: 6 }, @@ -981,7 +980,8 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 8 } - ] + ], + parser: parser("flow-destructuring-2") }, // multiple spaces diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index 4f9cdca78fe..110be8acdfa 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -753,90 +753,89 @@ ruleTester.run("camelcase", rule, { { code: "var camelCased = snake_cased", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { snake_cased: "readonly" } }, { code: "a_global_variable.foo()", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { snake_cased: "readonly" } }, { code: "a_global_variable[undefined]", options: [{ ignoreGlobals: false }], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { snake_cased: "readonly" } }, { code: "var camelCased = snake_cased", - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { snake_cased: "readonly" } }, { code: "var camelCased = snake_cased", options: [{}], - globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { snake_cased: "readonly" } }, { code: "foo.a_global_variable = bar", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "var foo = { a_global_variable: bar }", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "var foo = { a_global_variable: a_global_variable }", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", @@ -844,51 +843,51 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 13 } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "var foo = { a_global_variable() {} }", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "class Foo { a_global_variable() {} }", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "a_global_variable: for (;;);", options: [{ ignoreGlobals: true }], - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { 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 errors: [ { messageId: "notCamelCase", @@ -902,13 +901,13 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 35 } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { 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 errors: [ { messageId: "notCamelCase", @@ -922,7 +921,8 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 41 } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "var a_global_variable", @@ -952,7 +952,6 @@ 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 errors: [ { messageId: "notCamelCase", @@ -966,13 +965,13 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 38 } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "bar = a_global_variable; var a_global_variable;", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", @@ -986,20 +985,21 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 30 } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "writable" } }, { code: "var foo = { a_global_variable }", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, - globals: { a_global_variable: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ] + ], // eslint-disable-line camelcase + globals: { a_global_variable: "readonly" } }, { code: "export * as snake_cased from 'mod'", diff --git a/tests/lib/rules/comma-dangle.js b/tests/lib/rules/comma-dangle.js index 2ef7a008e2e..6b85c2fa73d 100644 --- a/tests/lib/rules/comma-dangle.js +++ b/tests/lib/rules/comma-dangle.js @@ -1735,29 +1735,29 @@ let d = 0;export {d,}; code: "function foo({a}: {a: string,}) {}", output: "function foo({a,}: {a: string,}) {}", options: ["always"], - parser: parser("object-pattern-1"), - errors: [{ messageId: "missing" }] + errors: [{ messageId: "missing" }], + parser: parser("object-pattern-1") }, { code: "function foo({a,}: {a: string}) {}", output: "function foo({a}: {a: string}) {}", options: ["never"], - parser: parser("object-pattern-2"), - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + parser: parser("object-pattern-2") }, { code: "function foo(a): {b: boolean,} {}", output: "function foo(a,): {b: boolean,} {}", options: [{ functions: "always" }], - parser: parser("return-type-1"), - errors: [{ messageId: "missing" }] + errors: [{ messageId: "missing" }], + parser: parser("return-type-1") }, { code: "function foo(a,): {b: boolean} {}", output: "function foo(a): {b: boolean} {}", options: [{ functions: "never" }], - parser: parser("return-type-2"), - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + parser: parser("return-type-2") }, // https://github.com/eslint/eslint/issues/11502 diff --git a/tests/lib/rules/id-blacklist.js b/tests/lib/rules/id-blacklist.js index 4d13459acf6..bea7ad3e1dc 100644 --- a/tests/lib/rules/id-blacklist.js +++ b/tests/lib/rules/id-blacklist.js @@ -993,7 +993,6 @@ ruleTester.run("id-blacklist", rule, { { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1007,7 +1006,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 30 } - ] + ], + globals: { myGlobal: "readonly" } }, // globals declared in the given source code are not excluded from consideration @@ -1188,7 +1188,6 @@ ruleTester.run("id-blacklist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], - env: { browser: true }, errors: [ { messageId: "restricted", @@ -1196,21 +1195,22 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 31 } - ] + ], + env: { browser: true } }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], - globals: { undefined: "off" }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ] + ], + globals: { undefined: "off" } }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1276,7 +1276,6 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1290,7 +1289,8 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 36 } - ] + ], + globals: { myGlobal: "readonly" } }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", diff --git a/tests/lib/rules/id-denylist.js b/tests/lib/rules/id-denylist.js index 6da179d99ff..eea9211166c 100644 --- a/tests/lib/rules/id-denylist.js +++ b/tests/lib/rules/id-denylist.js @@ -993,7 +993,6 @@ ruleTester.run("id-denylist", rule, { { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1007,7 +1006,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 30 } - ] + ], + globals: { myGlobal: "readonly" } }, // globals declared in the given source code are not excluded from consideration @@ -1188,7 +1188,6 @@ ruleTester.run("id-denylist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], - env: { browser: true }, errors: [ { messageId: "restricted", @@ -1196,21 +1195,22 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 31 } - ] + ], + env: { browser: true } }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], - globals: { undefined: "off" }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ] + ], + globals: { undefined: "off" } }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1276,7 +1276,6 @@ ruleTester.run("id-denylist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], - globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1290,7 +1289,8 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 36 } - ] + ], + globals: { myGlobal: "readonly" } }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 02517ffaeeb..42f1701661e 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -9734,8 +9734,8 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-invalid"), - errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]) + errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]), + parser: parser("unknown-nodes/namespace-invalid") }, { code: unIndent` @@ -9766,8 +9766,8 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/abstract-class-invalid"), - errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]) + errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]), + parser: parser("unknown-nodes/abstract-class-invalid") }, { code: unIndent` @@ -9796,14 +9796,14 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/functions-with-abstract-class-invalid"), errors: expectedErrors([ [4, 12, 8, "Keyword"], [5, 16, 8, "Keyword"], [6, 20, 8, "Identifier"], [7, 16, 8, "Punctuator"], [8, 12, 8, "Punctuator"] - ]) + ]), + parser: parser("unknown-nodes/functions-with-abstract-class-invalid") }, { code: unIndent` @@ -9836,11 +9836,11 @@ ruleTester.run("indent", rule, { } } `, - parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid"), errors: expectedErrors([ [3, 8, 4, "Keyword"], [7, 24, 20, "Identifier"] - ]) + ]), + parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid") }, //---------------------------------------------------------------------- @@ -10641,8 +10641,8 @@ ruleTester.run("indent", rule, { foo }: bar) => baz `, - parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation"), - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation") }, { code: unIndent` @@ -10655,8 +10655,8 @@ ruleTester.run("indent", rule, { foo ]: bar) => baz `, - parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation"), - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation") }, { code: unIndent` @@ -10669,8 +10669,8 @@ ruleTester.run("indent", rule, { foo }: {}) => baz `, - parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation"), - errors: expectedErrors([3, 0, 4, "Punctuator"]) + errors: expectedErrors([3, 0, 4, "Punctuator"]), + parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation") }, { code: unIndent` diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js index 64ee5a43474..602e646da04 100644 --- a/tests/lib/rules/keyword-spacing.js +++ b/tests/lib/rules/keyword-spacing.js @@ -3230,8 +3230,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }", output: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }", - parser: parser("typescript-parsers/decorator-with-keywords-class-method"), - errors: expectedAfter("async") + errors: expectedAfter("async"), + parser: parser("typescript-parsers/decorator-with-keywords-class-method") } ] diff --git a/tests/lib/rules/no-alert.js b/tests/lib/rules/no-alert.js index 03fcddb6994..70e3605eea0 100644 --- a/tests/lib/rules/no-alert.js +++ b/tests/lib/rules/no-alert.js @@ -112,18 +112,18 @@ ruleTester.run("no-alert", rule, { }, { code: "globalThis['alert'](foo)", - env: { es2020: true }, - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], + env: { es2020: true } }, { code: "globalThis.alert();", - env: { es2020: true }, - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], + env: { es2020: true } }, { code: "function foo() { var globalThis = bar; globalThis.alert(); }\nglobalThis.alert();", - env: { es2020: true }, - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }], + env: { es2020: true } }, // Optional chaining diff --git a/tests/lib/rules/no-console.js b/tests/lib/rules/no-console.js index d1c9176d0ff..49efa5408b2 100644 --- a/tests/lib/rules/no-console.js +++ b/tests/lib/rules/no-console.js @@ -58,6 +58,6 @@ ruleTester.run("no-console", rule, { { code: "console.warn(foo)", options: [{ allow: ["info", "log"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, // In case that implicit global variable of 'console' exists - { code: "console.log(foo)", env: { node: true }, errors: [{ messageId: "unexpected", type: "MemberExpression" }] } + { code: "console.log(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { node: true } } ] }); diff --git a/tests/lib/rules/no-else-return.js b/tests/lib/rules/no-else-return.js index 5486bbbdc3a..3daccca7fc8 100644 --- a/tests/lib/rules/no-else-return.js +++ b/tests/lib/rules/no-else-return.js @@ -509,15 +509,15 @@ ruleTester.run("no-else-return", rule, { code: "if (foo) { return true; } else { let a; }", output: "if (foo) { return true; } let a; ", parserOptions: { ecmaVersion: 6 }, - env: { node: true }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + env: { node: true } }, { code: "let a; if (foo) { return true; } else { let a; }", output: null, parserOptions: { ecmaVersion: 6 }, - env: { node: true }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }], + env: { node: true } } ] }); diff --git a/tests/lib/rules/no-eval.js b/tests/lib/rules/no-eval.js index bc8d38471bb..f03d37cc970 100644 --- a/tests/lib/rules/no-eval.js +++ b/tests/lib/rules/no-eval.js @@ -85,44 +85,44 @@ ruleTester.run("no-eval", rule, { // Indirect eval { code: "(0, eval)('foo')", errors: [{ messageId: "unexpected", type: "Identifier", column: 5, endColumn: 9 }] }, - { code: "(0, window.eval)('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 16 }] }, - { code: "(0, window['eval'])('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 18 }] }, + { code: "(0, window.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 16 }], env: { browser: true } }, + { code: "(0, window['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 18 }], env: { browser: true } }, { 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: "(function(exe){ exe('foo') })(eval);", errors: [{ messageId: "unexpected", type: "Identifier", column: 31, endColumn: 35 }] }, - { code: "window.eval('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }] }, - { code: "window.window.eval('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }] }, - { code: "window.window['eval']('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }] }, - { code: "global.eval('foo')", env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }] }, - { code: "global.global.eval('foo')", env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }] }, - { code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }] }, + { code: "window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], env: { browser: true } }, + { code: "window.window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], env: { browser: true } }, + { code: "window.window['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], env: { browser: true } }, + { code: "global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], env: { node: true } }, + { code: "global.global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], env: { node: true } }, + { code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], env: { node: true } }, { code: "this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 6, endColumn: 10 }] }, { code: "function foo() { this.eval('foo') }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }] }, - { code: "var EVAL = globalThis.eval; EVAL('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 23, endColumn: 27 }] }, - { code: "globalThis.eval('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 12, endColumn: 16 }] }, - { code: "globalThis.globalThis.eval('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }] }, - { code: "globalThis.globalThis['eval']('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 29 }] }, - { code: "(0, globalThis.eval)('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 20 }] }, - { code: "(0, globalThis['eval'])('foo')", env: { es2020: true }, errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 22 }] }, + { code: "var EVAL = globalThis.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 23, endColumn: 27 }], env: { es2020: true } }, + { code: "globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 12, endColumn: 16 }], env: { es2020: true } }, + { code: "globalThis.globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }], env: { es2020: true } }, + { code: "globalThis.globalThis['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 29 }], env: { es2020: true } }, + { code: "(0, globalThis.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 20 }], env: { es2020: true } }, + { code: "(0, globalThis['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 22 }], env: { es2020: true } }, // Optional chaining { code: "window?.eval('foo')", parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + globals: { window: "readonly" } }, { code: "(window?.eval)('foo')", parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + globals: { window: "readonly" } }, { code: "(window?.window).eval('foo')", parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "unexpected" }] + errors: [{ messageId: "unexpected" }], + globals: { window: "readonly" } } ] }); diff --git a/tests/lib/rules/no-extend-native.js b/tests/lib/rules/no-extend-native.js index 4cb4a64b35c..2ccdf780ff6 100644 --- a/tests/lib/rules/no-extend-native.js +++ b/tests/lib/rules/no-extend-native.js @@ -59,36 +59,36 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "BigInt.prototype.p = 0", - env: { es2020: true }, errors: [{ messageId: "unexpected", data: { builtin: "BigInt" }, type: "AssignmentExpression" - }] + }], + env: { es2020: true } }, { code: "WeakRef.prototype.p = 0", - env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "WeakRef" }, type: "AssignmentExpression" - }] + }], + env: { es2021: true } }, { code: "FinalizationRegistry.prototype.p = 0", - env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "FinalizationRegistry" }, type: "AssignmentExpression" - }] + }], + env: { es2021: true } }, { code: "AggregateError.prototype.p = 0", - env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "AggregateError" }, type: "AssignmentExpression" - }] + }], + env: { es2021: true } }, { code: "Function.prototype['p'] = 0", errors: [{ diff --git a/tests/lib/rules/no-global-assign.js b/tests/lib/rules/no-global-assign.js index 41f0ac0f305..daa5c0f11b3 100644 --- a/tests/lib/rules/no-global-assign.js +++ b/tests/lib/rules/no-global-assign.js @@ -64,21 +64,21 @@ ruleTester.run("no-global-assign", rule, { }, { code: "top = 0;", - env: { browser: true }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "top" }, type: "Identifier" - }] + }], + env: { browser: true } }, { code: "require = 0;", - env: { node: true }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "require" }, type: "Identifier" - }] + }], + env: { node: true } }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 @@ -92,12 +92,12 @@ ruleTester.run("no-global-assign", rule, { }, { code: "function f() { b = 1; }", - globals: { b: false }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "b" }, type: "Identifier" - }] + }], + globals: { b: false } }, { code: "/*global b:false*/ function f() { b++; }", diff --git a/tests/lib/rules/no-implicit-globals.js b/tests/lib/rules/no-implicit-globals.js index 348ef6feb55..54d6f7c7e8d 100644 --- a/tests/lib/rules/no-implicit-globals.js +++ b/tests/lib/rules/no-implicit-globals.js @@ -703,13 +703,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1", - env: { node: true }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ] + ], + env: { node: true } }, { code: "foo = 1;", @@ -862,13 +862,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "window = 1;", - env: { browser: true }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ] + ], + env: { browser: true } }, { code: "/*global foo:readonly*/ foo = 1", @@ -881,13 +881,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1;", - globals: { foo: "readonly" }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ] + ], + globals: { foo: "readonly" } }, { code: "/*global foo:readonly*/ for (foo in {});", diff --git a/tests/lib/rules/no-implied-eval.js b/tests/lib/rules/no-implied-eval.js index ce06f662043..f31f8c02ed8 100644 --- a/tests/lib/rules/no-implied-eval.js +++ b/tests/lib/rules/no-implied-eval.js @@ -129,43 +129,43 @@ ruleTester.run("no-implied-eval", rule, { { code: "setTimeout(String('x=1'), 100);", parserOptions: { 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')", errors: [expectedError], env: { browser: true } }, + { code: "window.setInterval('foo')", errors: [expectedError], env: { browser: true } }, + { code: "window['setTimeout']('foo')", errors: [expectedError], env: { browser: true } }, + { code: "window['setInterval']('foo')", errors: [expectedError], env: { browser: true } }, + { code: "window[`setInterval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, + { code: "window.window['setInterval']('foo')", errors: [expectedError], env: { browser: true } }, + { code: "global.setTimeout('foo')", errors: [expectedError], env: { node: true } }, + { code: "global.setInterval('foo')", errors: [expectedError], env: { node: true } }, + { code: "global['setTimeout']('foo')", errors: [expectedError], env: { node: true } }, + { code: "global['setInterval']('foo')", errors: [expectedError], env: { node: true } }, + { code: "global[`setInterval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { node: true } }, + { code: "global.global['setInterval']('foo')", errors: [expectedError], env: { node: true } }, + { code: "globalThis.setTimeout('foo')", errors: [expectedError], env: { es2020: true } }, + { code: "globalThis.setInterval('foo')", errors: [expectedError], env: { es2020: true } }, // 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: "window.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, + { code: "window.window.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, + { code: "global.global.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { node: true } }, // 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(1 + ';' + 1)", errors: [expectedError] }, - { code: "window.setTimeout('foo' + bar)", env: { browser: true }, errors: [expectedError] }, - { code: "window.setTimeout(foo + 'bar')", env: { browser: true }, errors: [expectedError] }, - { code: "window.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, env: { browser: true }, errors: [expectedError] }, - { code: "window.setTimeout(1 + ';' + 1)", env: { browser: true }, errors: [expectedError] }, - { code: "window.window.setTimeout(1 + ';' + 1)", env: { browser: true }, errors: [expectedError] }, - { code: "global.setTimeout('foo' + bar)", env: { node: true }, errors: [expectedError] }, - { code: "global.setTimeout(foo + 'bar')", env: { node: true }, errors: [expectedError] }, - { code: "global.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, env: { node: true }, errors: [expectedError] }, - { code: "global.setTimeout(1 + ';' + 1)", env: { node: true }, errors: [expectedError] }, - { code: "global.global.setTimeout(1 + ';' + 1)", env: { node: true }, errors: [expectedError] }, - { code: "globalThis.setTimeout('foo' + bar)", env: { es2020: true }, errors: [expectedError] }, + { code: "window.setTimeout('foo' + bar)", errors: [expectedError], env: { browser: true } }, + { code: "window.setTimeout(foo + 'bar')", errors: [expectedError], env: { browser: true } }, + { code: "window.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, + { code: "window.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { browser: true } }, + { code: "window.window.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { browser: true } }, + { code: "global.setTimeout('foo' + bar)", errors: [expectedError], env: { node: true } }, + { code: "global.setTimeout(foo + 'bar')", errors: [expectedError], env: { node: true } }, + { code: "global.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { node: true } }, + { code: "global.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { node: true } }, + { code: "global.global.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { node: true } }, + { code: "globalThis.setTimeout('foo' + bar)", errors: [expectedError], env: { es2020: true } }, // gives the correct node when dealing with nesting { @@ -197,7 +197,6 @@ ruleTester.run("no-implied-eval", rule, { " window.execScript('str');\n" + " return 'bar';\n" + "})())", - env: { browser: true }, errors: [ { messageId: "impliedEval", @@ -211,7 +210,8 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ] + ], + env: { browser: true } }, { code: @@ -220,7 +220,6 @@ ruleTester.run("no-implied-eval", rule, { " global.execScript('str');\n" + " return 'bar';\n" + "})())", - env: { node: true }, errors: [ { messageId: "impliedEval", @@ -234,21 +233,22 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ] + ], + env: { node: true } }, // Optional chaining { code: "window?.setTimeout('code', 0)", parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "impliedEval" }] + errors: [{ messageId: "impliedEval" }], + globals: { window: "readonly" } }, { code: "(window?.setTimeout)('code', 0)", parserOptions: { ecmaVersion: 2020 }, - globals: { window: "readonly" }, - errors: [{ messageId: "impliedEval" }] + errors: [{ messageId: "impliedEval" }], + globals: { window: "readonly" } } ] }); diff --git a/tests/lib/rules/no-magic-numbers.js b/tests/lib/rules/no-magic-numbers.js index bbdf8ca984f..62efeacd936 100644 --- a/tests/lib/rules/no-magic-numbers.js +++ b/tests/lib/rules/no-magic-numbers.js @@ -265,8 +265,8 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - env: { es6: true }, - errors: [{ messageId: "useConst" }] + errors: [{ messageId: "useConst" }], + env: { es6: true } }, { code: "var foo = 0 + 1;", @@ -391,7 +391,6 @@ ruleTester.run("no-magic-numbers", rule, { "function invokeInTen(func) {\n" + "setTimeout(func, 10);\n" + "}\n", - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "10" }, line: 7 }, { messageId: "noMagic", data: { raw: "10" }, line: 7 }, @@ -399,7 +398,8 @@ ruleTester.run("no-magic-numbers", rule, { { messageId: "noMagic", data: { raw: "1000" }, line: 15 }, { messageId: "noMagic", data: { raw: "0" }, line: 19 }, { messageId: "noMagic", data: { raw: "10" }, line: 22 } - ] + ], + env: { es6: true } }, { code: "var data = ['foo', 'bar', 'baz']; var third = data[3];", @@ -767,51 +767,51 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const func = (param = 123) => {}", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + env: { es6: true } }, { code: "const { param = 123 } = sourceObject;", options: [{}], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + env: { es6: true } }, { code: "const { param = 123 } = sourceObject;", - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + env: { es6: true } }, { code: "const { param = 123 } = sourceObject;", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ] + ], + env: { es6: true } }, { code: "const [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ] + ], + env: { es6: true } }, { code: "var one, two; [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], - env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ] + ], + env: { es6: true } } ] }); diff --git a/tests/lib/rules/no-misleading-character-class.js b/tests/lib/rules/no-misleading-character-class.js index a7bc04ef415..83d43806586 100644 --- a/tests/lib/rules/no-misleading-character-class.js +++ b/tests/lib/rules/no-misleading-character-class.js @@ -276,23 +276,23 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[❇️]", "")`, - env: { es2020: true }, - errors: [{ messageId: "combiningClass" }] + errors: [{ messageId: "combiningClass" }], + env: { es2020: true } }, { code: String.raw`var r = new globalThis.RegExp("[👶🏻]", "u")`, - env: { es2020: true }, - errors: [{ messageId: "emojiModifier" }] + errors: [{ messageId: "emojiModifier" }], + env: { es2020: true } }, { code: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "")`, - env: { es2020: true }, - errors: [{ messageId: "surrogatePairWithoutUFlag" }] + errors: [{ messageId: "surrogatePairWithoutUFlag" }], + env: { es2020: true } }, { code: String.raw`var r = new globalThis.RegExp("[\\u{1F468}\\u{200D}\\u{1F469}\\u{200D}\\u{1F466}]", "u")`, - env: { es2020: true }, - errors: [{ messageId: "zwj" }] + errors: [{ messageId: "zwj" }], + env: { es2020: true } } ] }); diff --git a/tests/lib/rules/no-mixed-spaces-and-tabs.js b/tests/lib/rules/no-mixed-spaces-and-tabs.js index 4dd475d4b60..b23826a52ea 100644 --- a/tests/lib/rules/no-mixed-spaces-and-tabs.js +++ b/tests/lib/rules/no-mixed-spaces-and-tabs.js @@ -278,7 +278,6 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { { code: "`foo${\n \t 5 }bar`;", options: ["smart-tabs"], - env: { es6: true }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -288,11 +287,11 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ] + ], + env: { es6: true } }, { code: "`foo${\n\t 5 }bar`;", - env: { es6: true }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -302,7 +301,8 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ] + ], + env: { es6: true } }, { code: " \t'';", diff --git a/tests/lib/rules/no-native-reassign.js b/tests/lib/rules/no-native-reassign.js index 8bb14d70c5d..6df55fe2db4 100644 --- a/tests/lib/rules/no-native-reassign.js +++ b/tests/lib/rules/no-native-reassign.js @@ -43,18 +43,18 @@ ruleTester.run("no-native-reassign", rule, { }, { code: "top = 0;", - env: { browser: true }, - errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }] + errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }], + env: { browser: true } }, { code: "require = 0;", - env: { node: true }, - errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }] + errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }], + env: { node: true } }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 { code: "/*global b:false*/ function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, - { code: "function f() { b = 1; }", globals: { b: false }, errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, + { code: "function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }], globals: { b: false } }, { code: "/*global b:false*/ function f() { b++; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, { code: "/*global b*/ b = 1;", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, { code: "Array = 1;", errors: [{ messageId: "nativeReassign", data: { name: "Array" }, type: "Identifier" }] } diff --git a/tests/lib/rules/no-obj-calls.js b/tests/lib/rules/no-obj-calls.js index 6270e7a7280..61aa6ca1dbc 100644 --- a/tests/lib/rules/no-obj-calls.js +++ b/tests/lib/rules/no-obj-calls.js @@ -179,18 +179,18 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Reflect();", - env: { es6: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + env: { es6: true } }, { code: "var x = new Reflect();", - env: { es6: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], + env: { es6: true } }, { code: "var x = Reflect();", - env: { es2017: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + env: { es2017: true } }, { code: "/*globals Reflect: true*/ Reflect();", @@ -202,91 +202,91 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Atomics();", - env: { es2017: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + env: { es2017: true } }, { code: "var x = new Atomics();", - env: { es2017: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], + env: { es2017: true } }, { code: "var x = Atomics();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "var x = Atomics();", - globals: { Atomics: false }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + globals: { Atomics: false } }, { code: "var x = new Atomics();", - globals: { Atomics: "writable" }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], + globals: { Atomics: "writable" } }, { code: "var x = globalThis.Math();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "var x = new globalThis.Math();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }], + env: { es2020: true } }, { code: "f(globalThis.Math());", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }], + env: { es2020: true } }, { code: "globalThis.Math().foo;", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }], + env: { es2020: true } }, { code: "new globalThis.Math().foo;", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }], + env: { es2020: true } }, { code: "var x = globalThis.JSON();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "x = globalThis.JSON(str);", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "globalThis.Math( globalThis.JSON() );", - env: { es2020: true }, errors: [ { messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 37 }, { messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression", column: 18, endColumn: 35 } - ] + ], + env: { es2020: true } }, { code: "var x = globalThis.Reflect();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "var x = new globalThis.Reflect;", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], + env: { es2020: true } }, { code: "/*globals Reflect: true*/ Reflect();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "var x = globalThis.Atomics();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "var foo = bar ? baz: JSON; foo();", @@ -298,35 +298,35 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var foo = bar ? baz: globalThis.JSON; foo();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "var foo = bar ? baz: globalThis.JSON; new foo();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }], + env: { es2020: true } }, { code: "var foo = window.Atomics; foo();", - env: { es2020: true, browser: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }], + env: { es2020: true, browser: true } }, { code: "var foo = window.Atomics; new foo;", - env: { es2020: true, browser: true }, - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }] + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }], + env: { es2020: true, browser: true } }, // Optional chaining { code: "var x = globalThis?.Reflect();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + env: { es2020: true } }, { code: "var x = (globalThis?.Reflect)();", - env: { es2020: true }, - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], + env: { es2020: true } } ] }); diff --git a/tests/lib/rules/no-redeclare.js b/tests/lib/rules/no-redeclare.js index f89d6853fa3..da46f15d6e0 100644 --- a/tests/lib/rules/no-redeclare.js +++ b/tests/lib/rules/no-redeclare.js @@ -88,8 +88,8 @@ ruleTester.run("no-redeclare", rule, { { code: "var top = 0;", options: [{ builtinGlobals: true }], - env: { browser: true }, - errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }] + errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }], + env: { browser: true } }, { code: "var a; var {a = 0, b: Object = 0} = {};", @@ -127,18 +127,18 @@ ruleTester.run("no-redeclare", rule, { { code: "var globalThis = 0;", options: [{ builtinGlobals: true }], - env: { es2020: true }, - errors: [{ message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" }] + errors: [{ message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" }], + env: { es2020: true } }, { code: "var a; var {a = 0, b: globalThis = 0} = {};", options: [{ builtinGlobals: true }], parserOptions: { ecmaVersion: 6 }, - env: { es2020: true }, errors: [ { message: "'a' is already defined.", type: "Identifier" }, { message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" } - ] + ], + env: { es2020: true } }, { code: "/*global b:false*/ var b = 1;", @@ -197,10 +197,10 @@ ruleTester.run("no-redeclare", rule, { }, { code: "var top = 0;", - env: { browser: true }, errors: [ { message: "'top' is already defined as a built-in global variable.", type: "Identifier" } - ] + ], + env: { browser: true } }, // Comments and built-ins. @@ -351,7 +351,6 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */", options: [{ builtinGlobals: true }], - globals: { a: "readonly" }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -359,12 +358,12 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }] + }], + globals: { a: "readonly" } }, { code: "/*globals a */", options: [{ builtinGlobals: true }], - globals: { a: "writable" }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -372,7 +371,8 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }] + }], + globals: { a: "writable" } }, { code: "/*globals a */ /*globals a */", @@ -388,7 +388,6 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */ /*globals a */ var a = 0", options: [{ builtinGlobals: true }], - globals: { a: "writable" }, errors: [ { message: "'a' is already defined as a built-in global variable.", @@ -414,7 +413,8 @@ ruleTester.run("no-redeclare", rule, { endLine: 1, endColumn: 36 } - ] + ], + globals: { a: "writable" } } ] }); diff --git a/tests/lib/rules/no-restricted-globals.js b/tests/lib/rules/no-restricted-globals.js index c8b5232e8ef..ac84b341b1d 100644 --- a/tests/lib/rules/no-restricted-globals.js +++ b/tests/lib/rules/no-restricted-globals.js @@ -79,32 +79,32 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: ["foo"], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + globals: { foo: false } }, { code: "event", options: ["foo", "event"], - env: { browser: true }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }] + }], + env: { browser: true } }, { code: "foo", options: ["foo"], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + globals: { foo: false } }, { code: "foo()", @@ -145,32 +145,32 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo" }], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + globals: { foo: false } }, { code: "event", options: ["foo", { name: "event" }], - env: { browser: true }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }] + }], + env: { browser: true } }, { code: "foo", options: [{ name: "foo" }], - globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }] + }], + globals: { foo: false } }, { code: "foo()", @@ -211,32 +211,32 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo", message: customMessage }], - globals: { foo: false }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }] + }], + globals: { foo: false } }, { code: "event", options: ["foo", { name: "event", message: "Use local event parameter." }], - env: { browser: true }, errors: [{ messageId: "customMessage", data: { name: "event", customMessage: "Use local event parameter." }, type: "Identifier" - }] + }], + env: { browser: true } }, { code: "foo", options: [{ name: "foo", message: customMessage }], - globals: { foo: false }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }] + }], + globals: { foo: false } }, { code: "foo()", diff --git a/tests/lib/rules/no-sequences.js b/tests/lib/rules/no-sequences.js index 1ac7c4a6c6e..e39a9b7b213 100644 --- a/tests/lib/rules/no-sequences.js +++ b/tests/lib/rules/no-sequences.js @@ -86,7 +86,7 @@ ruleTester.run("no-sequences", rule, { { code: "switch (doSomething(), val) {}", errors: errors(22) }, { code: "while (doSomething(), !!test);", errors: errors(21) }, { code: "with (doSomething(), val) {}", errors: errors(20) }, - { code: "a => (doSomething(), a)", env: { es6: true }, errors: errors(20) }, + { code: "a => (doSomething(), a)", errors: errors(20), env: { es6: true } }, { code: "(1), 2", errors: errors(4) }, { code: "((1)) , (2)", errors: errors(7) }, { code: "while((1) , 2);", errors: errors(11) }, @@ -101,6 +101,6 @@ ruleTester.run("no-sequences", rule, { { code: "switch ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(23) }, { code: "while ((doSomething(), !!test));", options: [{ allowInParentheses: false }], errors: errors(22) }, { code: "with ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(21) }, - { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], env: { es6: true }, errors: errors(21) } + { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], errors: errors(21), env: { es6: true } } ] }); diff --git a/tests/lib/rules/no-setter-return.js b/tests/lib/rules/no-setter-return.js index 0c64e8b4811..f0b9c5bf244 100644 --- a/tests/lib/rules/no-setter-return.js +++ b/tests/lib/rules/no-setter-return.js @@ -400,8 +400,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "return; ({ set a(val) { return 1; } }); return 2;", - env: { node: true }, - errors: [error(25)] + errors: [error(25)], + env: { node: true } }, //------------------------------------------------------------------------------ @@ -415,8 +415,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { return 1; } })", - env: { es6: true }, - errors: [error()] + errors: [error()], + env: { es6: true } }, { code: "Object.defineProperties(foo, { baz: { set(val) { return 1; } } })", @@ -434,8 +434,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set: val => f(val) })", - env: { es6: true }, - errors: [error(50, "CallExpression")] + errors: [error(50, "CallExpression")], + env: { es6: true } }, { code: "Object.defineProperties(foo, { baz: { set: val => a + b } })", @@ -453,8 +453,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { try { return f(val) } catch (e) { return e }; } })", - env: { es6: true }, - errors: [error(55), error(83)] + errors: [error(55), error(83)], + env: { es6: true } }, { code: "Object.defineProperties(foo, { bar: { get(){ return null; }, set(val) { return null; } } })", @@ -485,8 +485,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { 'set'(val) { return 1; } })", - env: { es6: true }, - errors: [error()] + errors: [error()], + env: { es6: true } }, { code: "Object[`defineProperties`](foo, { baz: { ['set'](val) { return 1; } } })", diff --git a/tests/lib/rules/no-shadow.js b/tests/lib/rules/no-shadow.js index dc2cc63c4de..fb5b3d8c13b 100644 --- a/tests/lib/rules/no-shadow.js +++ b/tests/lib/rules/no-shadow.js @@ -643,14 +643,14 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var top = 0; }", options: [{ builtinGlobals: true }], - env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }] + }], + env: { browser: true } }, { code: "var Object = 0;", @@ -668,14 +668,14 @@ ruleTester.run("no-shadow", rule, { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }] + }], + env: { browser: true } }, { code: "var Object = 0;", @@ -693,14 +693,14 @@ ruleTester.run("no-shadow", rule, { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaFeatures: { globalReturn: true } }, - env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }] + }], + env: { browser: true } }, { code: "function foo(cb) { (function (cb) { cb(42); })(cb); }", diff --git a/tests/lib/rules/no-unexpected-multiline.js b/tests/lib/rules/no-unexpected-multiline.js index 83c7bf67570..b9f0cdf140f 100644 --- a/tests/lib/rules/no-unexpected-multiline.js +++ b/tests/lib/rules/no-unexpected-multiline.js @@ -311,7 +311,6 @@ ruleTester.run("no-unexpected-multiline", rule, { "test", "*/`foo`" ].join("\n"), - parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment"), errors: [ { line: 5, @@ -320,7 +319,8 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 4, messageId: "taggedTemplate" } - ] + ], + parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment") } ] }); diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js index 48ccdb1d42f..97cc8c9e7e5 100644 --- a/tests/lib/rules/no-unused-vars.js +++ b/tests/lib/rules/no-unused-vars.js @@ -788,7 +788,6 @@ ruleTester.run("no-unused-vars", rule, { // surrogate pair. { code: "/*global 𠮷𩸽, 𠮷*/\n\\u{20BB7}\\u{29E3D};", - env: { es6: true }, errors: [ { line: 1, @@ -802,7 +801,8 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ] + ], + env: { es6: true } }, // https://github.com/eslint/eslint/issues/4047 diff --git a/tests/lib/rules/no-var.js b/tests/lib/rules/no-var.js index 84e14ae19c9..c29697cfc3c 100644 --- a/tests/lib/rules/no-var.js +++ b/tests/lib/rules/no-var.js @@ -304,9 +304,9 @@ 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" }, - errors: [{ messageId: "unexpectedVar" }] + errors: [{ messageId: "unexpectedVar" }], + parser: require.resolve("../../fixtures/parsers/typescript-parsers/declare-var") }, // https://github.com/eslint/eslint/issues/11830 diff --git a/tests/lib/rules/object-curly-newline.js b/tests/lib/rules/object-curly-newline.js index 86e95609920..e26976384b1 100644 --- a/tests/lib/rules/object-curly-newline.js +++ b/tests/lib/rules/object-curly-newline.js @@ -682,11 +682,11 @@ ruleTester.run("object-curly-newline", rule, { "} : MyType) {}" ].join("\n"), options: ["always"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline"), errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline") }, { code: "function foo({ a, b } : { a : string, b : string }) {}", @@ -696,11 +696,11 @@ ruleTester.run("object-curly-newline", rule, { "} : { a : string, b : string }) {}" ].join("\n"), options: ["always"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal"), errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ] + ], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal") }, // "never" ------------------------------------------------------------ @@ -808,11 +808,11 @@ ruleTester.run("object-curly-newline", rule, { " b} : MyType) {}" ].join("\n"), options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline"), errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ] + ], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline") }, { code: [ @@ -826,11 +826,11 @@ ruleTester.run("object-curly-newline", rule, { " b} : { a : string, b : string }) {}" ].join("\n"), options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal"), errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ] + ], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal") }, // "multiline" --------------------------------------------------------- diff --git a/tests/lib/rules/object-curly-spacing.js b/tests/lib/rules/object-curly-spacing.js index f603832cb37..42b47eb9b28 100644 --- a/tests/lib/rules/object-curly-spacing.js +++ b/tests/lib/rules/object-curly-spacing.js @@ -1394,7 +1394,6 @@ ruleTester.run("object-curly-spacing", rule, { code: "function foo ({a, b }: Props) {\n}", output: "function foo ({a, b}: Props) {\n}", options: ["never"], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid"), errors: [ { messageId: "unexpectedSpaceBefore", @@ -1405,7 +1404,8 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 21 } - ] + ], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid") } ] }); diff --git a/tests/lib/rules/object-shorthand.js b/tests/lib/rules/object-shorthand.js index 01a72f4e6f0..9e0d43f07e1 100644 --- a/tests/lib/rules/object-shorthand.js +++ b/tests/lib/rules/object-shorthand.js @@ -1173,8 +1173,8 @@ ruleTester.run("object-shorthand", rule, { } `, options: ["always", { avoidExplicitReturnArrows: true }], - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props"), - errors: Array(18).fill(METHOD_ERROR) + errors: Array(18).fill(METHOD_ERROR), + parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props") } ] }); diff --git a/tests/lib/rules/prefer-const.js b/tests/lib/rules/prefer-const.js index c591d236583..14ee7abab3c 100644 --- a/tests/lib/rules/prefer-const.js +++ b/tests/lib/rules/prefer-const.js @@ -383,8 +383,8 @@ ruleTester.run("prefer-const", rule, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", output: null, options: [{ destructuring: "any" }], - parser: fixtureParser("babel-eslint5/destructuring-object-spread"), - errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }] + errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }], + parser: fixtureParser("babel-eslint5/destructuring-object-spread") }, // Warnings are located at declaration if there are reading references before assignments. diff --git a/tests/lib/rules/prefer-exponentiation-operator.js b/tests/lib/rules/prefer-exponentiation-operator.js index 7bccdd64b43..68ec4451eb2 100644 --- a/tests/lib/rules/prefer-exponentiation-operator.js +++ b/tests/lib/rules/prefer-exponentiation-operator.js @@ -91,7 +91,6 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "globalThis.Math.pow(a, b)", output: "a**b", - env: { es2020: true }, errors: [ { messageId: "useExponentiation", @@ -101,12 +100,12 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 26 } - ] + ], + env: { es2020: true } }, { code: "globalThis.Math['pow'](a, b)", output: "a**b", - env: { es2020: true }, errors: [ { messageId: "useExponentiation", @@ -116,7 +115,8 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 29 } - ] + ], + env: { es2020: true } }, // able to catch some workarounds diff --git a/tests/lib/rules/prefer-named-capture-group.js b/tests/lib/rules/prefer-named-capture-group.js index 0faf1d6be65..5561f34a912 100644 --- a/tests/lib/rules/prefer-named-capture-group.js +++ b/tests/lib/rules/prefer-named-capture-group.js @@ -222,7 +222,6 @@ ruleTester.run("prefer-named-capture-group", rule, { }, { code: "new globalThis.RegExp('([0-9]{4})')", - env: { es2020: true }, errors: [{ messageId: "required", type: "NewExpression", @@ -230,11 +229,11 @@ ruleTester.run("prefer-named-capture-group", rule, { line: 1, column: 1, endColumn: 36 - }] + }], + env: { es2020: true } }, { code: "globalThis.RegExp('([0-9]{4})')", - env: { es2020: true }, errors: [{ messageId: "required", type: "CallExpression", @@ -242,14 +241,14 @@ ruleTester.run("prefer-named-capture-group", rule, { line: 1, column: 1, endColumn: 32 - }] + }], + env: { es2020: true } }, { code: ` function foo() { var globalThis = bar; } new globalThis.RegExp('([0-9]{4})'); `, - env: { es2020: true }, errors: [{ messageId: "required", type: "NewExpression", @@ -257,7 +256,8 @@ ruleTester.run("prefer-named-capture-group", rule, { line: 3, column: 17, endColumn: 52 - }] + }], + env: { es2020: true } } ] }); diff --git a/tests/lib/rules/prefer-object-spread.js b/tests/lib/rules/prefer-object-spread.js index 91bf08a2f74..33541f437c0 100644 --- a/tests/lib/rules/prefer-object-spread.js +++ b/tests/lib/rules/prefer-object-spread.js @@ -889,7 +889,6 @@ ruleTester.run("prefer-object-spread", rule, { { code: "globalThis.Object.assign({ });", output: "({});", - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -897,12 +896,12 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ] + ], + env: { es2020: true } }, { code: "globalThis.Object.assign({\n});", output: "({});", - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -910,7 +909,8 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ] + ], + env: { es2020: true } }, { code: ` @@ -921,7 +921,6 @@ ruleTester.run("prefer-object-spread", rule, { function foo () { var globalThis = bar; } ({}); `, - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -929,7 +928,8 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ] + ], + env: { es2020: true } }, { code: ` @@ -940,7 +940,6 @@ ruleTester.run("prefer-object-spread", rule, { const Foo = require('foo'); ({foo: Foo}); `, - env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -948,7 +947,8 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ] + ], + env: { es2020: true } }, // report Object.assign() with getters/setters if the function call has only 1 argument @@ -969,7 +969,6 @@ ruleTester.run("prefer-object-spread", rule, { { code: "const obj = Object.assign<{}, Record>({}, getObject());", output: "const obj = { ...getObject()};", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1"), errors: [ { messageId: "useSpreadMessage", @@ -977,12 +976,12 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 13 } - ] + ], + parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1") }, { code: "Object.assign<{}, A>({}, foo);", output: "({ ...foo});", - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2"), errors: [ { messageId: "useSpreadMessage", @@ -990,7 +989,8 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ] + ], + parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2") } ] }); diff --git a/tests/lib/rules/prefer-regex-literals.js b/tests/lib/rules/prefer-regex-literals.js index 0ddaa8dae3d..acba15ab925 100644 --- a/tests/lib/rules/prefer-regex-literals.js +++ b/tests/lib/rules/prefer-regex-literals.js @@ -214,13 +214,13 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('a');", - env: { es2020: true }, - errors: [{ messageId: "unexpectedRegExp", type: "NewExpression" }] + errors: [{ messageId: "unexpectedRegExp", type: "NewExpression" }], + env: { es2020: true } }, { code: "globalThis.RegExp('a');", - env: { es2020: true }, - errors: [{ messageId: "unexpectedRegExp", type: "CallExpression" }] + errors: [{ messageId: "unexpectedRegExp", type: "CallExpression" }], + env: { es2020: true } }, { diff --git a/tests/lib/rules/quote-props.js b/tests/lib/rules/quote-props.js index 5186f87d140..8f10f9233cb 100644 --- a/tests/lib/rules/quote-props.js +++ b/tests/lib/rules/quote-props.js @@ -178,18 +178,18 @@ ruleTester.run("quote-props", rule, { code: "({ 'a': 0, [x]: 0 })", output: "({ a: 0, [x]: 0 })", options: ["consistent-as-needed"], - env: { es6: true }, errors: [ { messageId: "redundantQuoting", type: "Property" } - ] + ], + env: { es6: true } }, { code: "({ 'a': 0, x })", output: "({ a: 0, x })", options: ["consistent-as-needed"], - env: { es6: true }, errors: [{ messageId: "redundantQuoting", type: "Property" - }] + }], + env: { es6: true } }, { code: "({ 'true': 0, 'null': 0 })", output: "({ true: 0, null: 0 })", diff --git a/tests/lib/rules/require-unicode-regexp.js b/tests/lib/rules/require-unicode-regexp.js index 6033d44ca32..2cbf0b5b4ec 100644 --- a/tests/lib/rules/require-unicode-regexp.js +++ b/tests/lib/rules/require-unicode-regexp.js @@ -85,18 +85,18 @@ ruleTester.run("require-unicode-regexp", rule, { }, { code: "new window.RegExp('foo')", - env: { browser: true }, - errors: [{ messageId: "requireUFlag" }] + errors: [{ messageId: "requireUFlag" }], + env: { browser: true } }, { code: "new global.RegExp('foo')", - env: { node: true }, - errors: [{ messageId: "requireUFlag" }] + errors: [{ messageId: "requireUFlag" }], + env: { node: true } }, { code: "new globalThis.RegExp('foo')", - env: { es2020: true }, - errors: [{ messageId: "requireUFlag" }] + errors: [{ messageId: "requireUFlag" }], + env: { es2020: true } } ] }); diff --git a/tests/lib/rules/space-before-blocks.js b/tests/lib/rules/space-before-blocks.js index 7424aec8458..65b6e4bf713 100644 --- a/tests/lib/rules/space-before-blocks.js +++ b/tests/lib/rules/space-before-blocks.js @@ -562,15 +562,15 @@ 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"), - errors: [expectedSpacingError] + errors: [expectedSpacingError], + parser: fixtureParser("space-before-blocks", "return-type-keyword-1") }, { code: "function foo(): null {}", output: "function foo(): null{}", options: neverArgs, - parser: fixtureParser("space-before-blocks", "return-type-keyword-2"), - errors: [expectedNoSpacingError] + errors: [expectedNoSpacingError], + parser: fixtureParser("space-before-blocks", "return-type-keyword-2") } ] }); diff --git a/tests/lib/rules/space-infix-ops.js b/tests/lib/rules/space-infix-ops.js index 2e6f423e919..4f8363abf58 100644 --- a/tests/lib/rules/space-infix-ops.js +++ b/tests/lib/rules/space-infix-ops.js @@ -41,13 +41,13 @@ ruleTester.run("space-infix-ops", rule, { { 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) { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-parameter-type-annotation") }, + { code: "function foo(): Bar { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-return-type-annotation") }, + { code: "var foo: Bar = '';", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/variable-declaration-init-type-annotation") }, + { code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: 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;", parserOptions: { ecmaVersion: 6 }, parser: parser("typescript-parsers/type-alias") }, { code: "a &&= b", parserOptions: { ecmaVersion: 2021 } }, { code: "a ||= b", parserOptions: { ecmaVersion: 2021 } }, @@ -469,19 +469,18 @@ ruleTester.run("space-infix-ops", rule, { { code: "var a: Foo= b;", output: "var a: Foo = b;", - parser: parser("type-annotations/variable-declaration-init-type-annotation-no-space"), errors: [{ messageId: "missingSpace", data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 11 - }] + }], + parser: parser("type-annotations/variable-declaration-init-type-annotation-no-space") }, { code: "function foo(a: number=0): Foo { }", output: "function foo(a: number = 0): Foo { }", - parser: parser("type-annotations/function-declaration-type-annotation-no-space"), parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", @@ -489,7 +488,8 @@ ruleTester.run("space-infix-ops", rule, { line: 1, column: 23, type: "AssignmentPattern" - }] + }], + parser: parser("type-annotations/function-declaration-type-annotation-no-space") }, { diff --git a/tests/lib/unsupported-api.js b/tests/lib/unsupported-api.js new file mode 100644 index 00000000000..dd88be5e69b --- /dev/null +++ b/tests/lib/unsupported-api.js @@ -0,0 +1,30 @@ +/** + * @fileoverview Tests for unsupported-api. + * @author Nicholas C. Zakas + */ + +"use strict"; + +//----------------------------------------------------------------------------- +// Requirements +//----------------------------------------------------------------------------- + +const assert = require("chai").assert, + { LazyLoadingRuleMap } = require("../../lib/rules/utils/lazy-loading-rule-map"), + api = require("../../lib/unsupported-api"); + +//----------------------------------------------------------------------------- +// Tests +//----------------------------------------------------------------------------- + +describe("unsupported-api", () => { + + it("should have FileEnumerator exposed", () => { + assert.isFunction(api.FileEnumerator); + }); + + it("should have builtinRules exposed", () => { + assert.instanceOf(api.builtinRules, LazyLoadingRuleMap); + }); + +}); From 08b169804b4c0cb2a6d9b4525b49d0565f7debab Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 14 Jun 2021 11:26:55 -0700 Subject: [PATCH 2/5] Update docs --- docs/developer-guide/nodejs-api.md | 518 +---------------------------- 1 file changed, 2 insertions(+), 516 deletions(-) diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index f1e21584e32..b032a9e1171 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -30,8 +30,6 @@ While ESLint is designed to be run on the command line, it's possible to use ESL * [getRules()](#lintergetrules) * [defineParser()](#linterdefineparser) * [version](#linterversionlinterversion) -* [linter (deprecated)](#linter-1) -* [CLIEngine (deprecated)](#cliengine) * [RuleTester](#ruletester) * [Customizing RuleTester](#customizing-ruletester) * [Deprecated APIs](#deprecated-apis) @@ -460,8 +458,8 @@ Those run on `linter2` will get `process.cwd()` if the global `process` object i The most important method on `Linter` is `verify()`, which initiates linting of the given text. This method accepts three arguments: * `code` - the source code to lint (a string or instance of `SourceCode`). -* `config` - a configuration object that has been processed and normalized by CLIEngine using eslintrc files and/or other configuration arguments. - * **Note**: If you want to lint text and have your configuration be read and processed, use CLIEngine's [`executeOnFiles`](#cliengineexecuteonfiles) or [`executeOnText`](#cliengineexecuteontext) instead. +* `config` - a configuration object that has been processed and normalized by `ESLint`` using eslintrc files and/or other configuration arguments. + * **Note**: If you want to lint text and have your configuration be read and processed, use [`ESLint#lintFiles()`](#eslint-lintfiles) or [`ESLint#lintText()`](#eslint-linttext) instead. * `options` - (optional) Additional options for this run. * `filename` - (optional) the filename to associate with the source code. * `preprocess` - (optional) A function that [Processors in Plugins](/docs/developer-guide/working-with-plugins.md#processors-in-plugins) documentation describes as the `preprocess` method. @@ -678,510 +676,6 @@ const Linter = require("eslint").Linter; Linter.version; // => '4.5.0' ``` - -## linter - -The `eslint.linter` object (deprecated) is an instance of the `Linter` class as defined [above](#linter). `eslint.linter` exists for backwards compatibility, but we do not recommend using it because any mutations to it are shared among every module that uses `eslint`. Instead, please create your own instance of `eslint.Linter`. - -```js -const linter = require("eslint").linter; - -const messages = linter.verify("var foo;", { - rules: { - semi: 2 - } -}, { filename: "foo.js" }); -``` - -Note: This API is deprecated as of 4.0.0. - ---- - -## CLIEngine - -⚠️ The `CLIEngine` class has been deprecated in favor of the `ESLint` class as of v7.0.0. - -The primary Node.js API is `CLIEngine`, which is the underlying utility that runs the ESLint command line interface. This object will read the filesystem for configuration and file information but will not output any results. Instead, it allows you direct access to the important information so you can deal with the output yourself. - -You can get a reference to the `CLIEngine` by doing the following: - -```js -const CLIEngine = require("eslint").CLIEngine; -``` - -The `CLIEngine` is a constructor, and you can create a new instance by passing in the options you want to use. The available options are: - -* `allowInlineConfig` - Set to `false` to disable the use of configuration comments (such as `/*eslint-disable*/`). Corresponds to `--no-inline-config`. -* `baseConfig` - Can optionally be set to a config object that has the same schema as `.eslintrc.*`. This will used as a default config, and will be merged with any configuration defined in `.eslintrc.*` files, with the `.eslintrc.*` files having precedence. -* `cache` - Operate only on changed files (default: `false`). Corresponds to `--cache`. -* `cacheFile` - Name of the file where the cache will be stored (default: `.eslintcache`). Corresponds to `--cache-file`. Deprecated: use `cacheLocation` instead. -* `cacheLocation` - Name of the file or directory where the cache will be stored (default: `.eslintcache`). Corresponds to `--cache-location`. -* `configFile` - The configuration file to use (default: null). If `useEslintrc` is true or not specified, this configuration will be merged with any configuration defined in `.eslintrc.*` files, with options in this configuration having precedence. Corresponds to `-c`. -* `cwd` - Path to a directory that should be considered as the current working directory. -* `envs` - An array of environments to load (default: empty array). Corresponds to `--env`. Note: This differs from `.eslintrc.*` / `baseConfig`, where instead the option is called `env` and is an object. -* `errorOnUnmatchedPattern` - Set to `false` to prevent errors when pattern is unmatched. Corresponds to `--no-error-on-unmatched-pattern`. -* `extensions` - An array of filename extensions that should be checked for code. The default is an array containing just `".js"`. Corresponds to `--ext`. It is only used in conjunction with directories, not with filenames, glob patterns or when using `executeOnText()`. -* `fix` - A boolean or a function (default: `false`). If a function, it will be passed each linting message and should return a boolean indicating whether the fix should be included with the output report (errors and warnings will not be listed if fixed). Files on disk are never changed regardless of the value of `fix`. To persist changes to disk, call [`outputFixes()`](#cliengineoutputfixes). -* `fixTypes` - An array of rule types for which fixes should be applied (default: `null`). This array acts like a filter, only allowing rules of the given types to apply fixes. Possible array values are `"problem"`, `"suggestion"`, and `"layout"`. -* `globals` - An array of global variables to declare (default: empty array). Corresponds to `--global`, and similarly supports passing `'name:true'` to denote a writeable global. Note: This differs from `.eslintrc.*` / `baseConfig`, where `globals` is an object. -* `ignore` - False disables use of `.eslintignore`, `ignorePath` and `ignorePattern` (default: true). Corresponds to `--no-ignore`. -* `ignorePath` - The ignore file to use instead of `.eslintignore` (default: null). Corresponds to `--ignore-path`. -* `ignorePattern` - Glob patterns for paths to ignore. String or array of strings. -* `parser` - Specify the parser to be used (default: `espree`). Corresponds to `--parser`. -* `parserOptions` - An object containing parser options (default: empty object). Corresponds to `--parser-options`. -* `plugins` - An array of plugins to load (default: empty array). Corresponds to `--plugin`. -* `reportUnusedDisableDirectives` - When set to `true`, adds reported errors for unused `eslint-disable` directives when no problems would be reported in the disabled area anyway (default: false). Corresponds to `--report-unused-disable-directives`. -* `resolvePluginsRelativeTo` - Determines the folder where plugins should be resolved from. Should be used when an integration installs plugins and uses those plugins to lint code on behalf of the end user. Corresponds to `--resolve-plugins-relative-to`. -* `rulePaths` - An array of directories to load custom rules from (default: empty array). Corresponds to `--rulesdir`. -* `rules` - An object of rules to use (default: null). Corresponds to `--rule`. -* `useEslintrc` - Set to false to disable use of `.eslintrc` files (default: true). Corresponds to `--no-eslintrc`. -* `globInputPaths` - Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file. - -To programmatically set `.eslintrc.*` options not supported above (such as `extends`, -`overrides` and `settings`), define them in a config object passed to `baseConfig` instead. - -For example: - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - baseConfig: { - extends: ["eslint-config-shared"], - settings: { - sharedData: "Hello" - } - }, - envs: ["browser", "mocha"], - useEslintrc: false, - rules: { - semi: 2 - } -}); -``` - -In this example, a new `CLIEngine` instance is created that extends a configuration called -`"eslint-config-shared"`, a setting named `"sharedData"` and two environments (`"browser"` -and `"mocha"`) are defined, loading of `.eslintrc` and `package.json` files are disabled, -and the `semi` rule enabled as an error. You can then call methods on `cli` and these options -will be used to perform the correct action. - -Note: Currently `CLIEngine` does not validate options passed to it, but may start doing so in the future. - -### CLIEngine#executeOnFiles() - -If you want to lint one or more files, use the `executeOnFiles()` method. This method accepts a single argument, which is an array of files and/or directories to traverse for files. You can pass the same values as you would using the ESLint command line interface, such as `"."` to search all JavaScript files in the current directory. Here's an example: - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - useEslintrc: false, - rules: { - semi: 2 - } -}); - -// lint myfile.js and all files in lib/ -const report = cli.executeOnFiles(["myfile.js", "lib/"]); -``` - -The return value is an object containing the results of the linting operation. Here's an example of a report object: - -```js -{ - results: [ - { - filePath: "/Users/eslint/project/myfile.js", - messages: [{ - ruleId: "semi", - severity: 2, - message: "Missing semicolon.", - line: 1, - column: 13, - nodeType: "ExpressionStatement", - fix: { range: [12, 12], text: ";" } - }, { - ruleId: "no-useless-escape", - severity: 1, - message: "disallow unnecessary escape characters", - line: 1, - column: 10, - nodeType: "ExpressionStatement", - suggestions: [{ - desc: "Remove unnecessary escape. This maintains the current functionality.", - fix: { range: [9, 10], text: "" } - }, { - desc: "Escape backslash to include it in the RegExp.", - fix: { range: [9, 9], text: "\\" } - }] - }], - errorCount: 1, - warningCount: 1, - fixableErrorCount: 1, - fixableWarningCount: 0, - source: "\"use strict\"\n" - } - ], - errorCount: 1, - warningCount: 0, - fixableErrorCount: 1, - fixableWarningCount: 0, - usedDeprecatedRules: [] -} -``` - -You can also pass `fix: true` when instantiating the `CLIEngine` in order to have it figure out what fixes can be applied. - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - fix: true, // difference from last example - useEslintrc: false, - rules: { - semi: 2, - quotes: [2, "double"] - } -}); - -// lint myfile.js and all files in lib/ -const report = cli.executeOnFiles(["myfile.js", "lib/"]); -``` - -```js -{ - results: [ - { - filePath: "/Users/eslint/project/myfile.js", - messages: [ - { - ruleId: "semi", - severity: 2, - message: "Missing semicolon.", - line: 1, - column: 13, - nodeType: "ExpressionStatement", - fix: { range: [12, 12], text: ";" } - }, - { - ruleId: "func-name-matching", - severity: 2, - message: "Function name `bar` should match variable name `foo`", - line: 2, - column: 5, - nodeType: "VariableDeclarator" - } - ], - errorCount: 2, - warningCount: 0, - fixableErrorCount: 1, - fixableWarningCount: 0, - output: "\"use strict\";\nvar foo = function bar() {};\nfoo();\n" - } - ], - errorCount: 2, - warningCount: 0, - fixableErrorCount: 1, - fixableWarningCount: 0, - usedDeprecatedRules: [] -} -``` - -If the operation ends with a parsing error, you will get a single message for this file, with `fatal: true` added as an extra property. - -```js -{ - results: [ - { - filePath: "./myfile.js", - messages: [ - { - ruleId: null, - fatal: true, - severity: 2, - message: "Parsing error: Unexpected token foo", - line: 1, - column: 10 - } - ], - errorCount: 1, - warningCount: 0, - fixableErrorCount: 0, - fixableWarningCount: 0, - source: "function foo() {}" - } - ], - errorCount: 1, - warningCount: 0, - fixableErrorCount: 0, - fixableWarningCount: 0, - usedDeprecatedRules: [] -} -``` - -The top-level report object has a `results` array containing all linting results for files that had warnings or errors (any files that did not produce a warning or error are omitted). Each file result includes: - -* `filePath` - Path to the given file. -* `messages` - Array containing the result of calling `linter.verify()` on the given file. -* `errorCount` and `warningCount` - The exact number of errors and warnings respectively on the given file. -* `source` - The source code for the given file. This property is omitted if this file has no errors/warnings or if the `output` property is present. -* `output` - The source code for the given file with as many fixes applied as possible, so you can use that to rewrite the files if necessary. This property is omitted if no fix is available. - -The top-level report object also has `errorCount` and `warningCount` which give the exact number of errors and warnings respectively on all the files. Additionally, `usedDeprecatedRules` signals any deprecated rules used and their replacement (if available). Specifically, it is an array of objects with properties like so: - -* `ruleId` - The name of the rule (e.g. `indent-legacy`). -* `replacedBy` - An array of rules that replace the deprecated rule (e.g. `["indent"]`). - -Once you get a report object, it's up to you to determine how to output the results. Fixes will not be automatically applied to the files, even if you set `fix: true` when constructing the `CLIEngine` instance. To apply fixes to the files, call [`outputFixes`](#cliengineoutputfixes). - -### CLIEngine#resolveFileGlobPatterns() - -You can pass filesystem-style or glob patterns to ESLint and have it function properly. In order to achieve this, ESLint must resolve non-glob patterns into glob patterns before determining which files to execute on. The `resolveFileGlobPatterns()` methods uses the current settings from `CLIEngine` to resolve non-glob patterns into glob patterns. Pass an array of patterns that might be passed to the ESLint CLI and it will return an array of glob patterns that mean the same thing. Here's an example: - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ -}); - -// pass an array of patterns -const globPatterns = cli.resolveFileGlobPatterns(["."]); -console.log(globPatterns[i]); // ["**/*.js"] -``` - -### CLIEngine#getConfigForFile() - -If you want to retrieve a configuration object for a given file, use the `getConfigForFile()` method. This method accepts one argument, a file path, and returns an object represented the calculated configuration of the file. Here's an example: - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - useEslintrc: false, - rules: { - semi: 2 - } -}); - -const config = cli.getConfigForFile("myfile.js"); -``` - -Once you have the configuration information, you can pass it into the `linter` object: - -```js -const CLIEngine = require("eslint").CLIEngine, - Linter = require("eslint").Linter; - -const linter = new Linter(); -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - useEslintrc: false, - rules: { - semi: 2 - } -}); - -const config = cli.getConfigForFile("myfile.js"); - -const messages = linter.verify('var foo;', config); -``` - -### CLIEngine#executeOnText() - -If you already have some text to lint, then you can use the `executeOnText()` method to lint that text. The linter will assume that the text is a file in the current working directory, and so will still obey any `.eslintrc` and `.eslintignore` files that may be present. Here's an example: - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - useEslintrc: false, - rules: { - semi: 2 - } -}); - -// Lint the supplied text and optionally set a filename that is displayed in the report -const report = cli.executeOnText("var foo = 'bar';", "foo.js"); - -// In addition to the above, warn if the resolved file name is ignored. -const reportAndWarnOnIgnoredFile = cli.executeOnText("var foo = 'bar';", "foo.js", true); -``` - -The `report` returned from `executeOnText()` is in the same format as from `executeOnFiles()`, but there is only ever one result in `report.results`. - -If a filename in the optional second parameter matches a file that is configured to be ignored, then this function returns no errors or warnings. The method includes an additional optional boolean third parameter. When `true`, a resolved file name that is ignored will return a warning. - -### CLIEngine#addPlugin() - -Loads a plugin from configuration object with specified name. Name can include plugin prefix ("eslint-plugin-") - -```js -const CLIEngine = require("eslint").CLIEngine; -const cli = new CLIEngine({ - ignore: true -}); -cli.addPlugin("eslint-plugin-processor", { - processors: { - ".txt": { - preprocess: function(text) { - return [text]; - }, - postprocess: function(messages) { - return messages[0]; - } - } - } -}); -``` - -### CLIEngine#isPathIgnored() - -Checks if a given path is ignored by ESLint. - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - ignore: true, - ignorePath: ".customIgnoreFile" -}); - -const isIgnored = cli.isPathIgnored("foo/bar.js"); -``` - -### CLIEngine#getFormatter() - -Retrieves a formatter, which you can then use to format a report object. The argument is either the name of a built-in formatter: - -* "[checkstyle](../user-guide/formatters#checkstyle)" -* "[codeframe](../user-guide/formatters#codeframe)" -* "[compact](../user-guide/formatters#compact)" -* "[html](../user-guide/formatters#html)" -* "[jslint-xml](../user-guide/formatters#jslint-xml)" -* "[json](../user-guide/formatters#json)" -* "[junit](../user-guide/formatters#junit)" -* "[stylish](../user-guide/formatters#stylish)" (the default) -* "[table](../user-guide/formatters#table)" -* "[tap](../user-guide/formatters#tap)" -* "[unix](../user-guide/formatters#unix)" -* "[visualstudio](../user-guide/formatters#visualstudio)" - -or the full path to a JavaScript file containing a custom formatter. You can also omit the argument to retrieve the default formatter. - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - useEslintrc: false, - rules: { - semi: 2 - } -}); - -// lint myfile.js and all files in lib/ -const report = cli.executeOnFiles(["myfile.js", "lib/"]); - -// get the default formatter -const formatter = cli.getFormatter(); - -// Also could do... -// const formatter = cli.getFormatter("compact"); -// const formatter = cli.getFormatter("./my/formatter.js"); - -// output to console -console.log(formatter(report.results)); -``` - -**Note:** Also available as a static function on `CLIEngine`. - -```js -// get the default formatter by calling the static function -const formatter = CLIEngine.getFormatter(); -``` - -**Important:** You must pass in the `results` property of the report. Passing in `report` directly will result in an error. - -### CLIEngine#getErrorResults() - -This is a static function on `CLIEngine`. It can be used to filter out all the non error messages from the report object. - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - useEslintrc: false, - rules: { - semi: 2 - } -}); - -// lint myfile.js and all files in lib/ -const report = cli.executeOnFiles(["myfile.js", "lib/"]); - -// only get the error messages -const errorReport = CLIEngine.getErrorResults(report.results) -``` - -**Important:** You must pass in the `results` property of the report. Passing in `report` directly will result in an error. - -### CLIEngine#outputFixes() - -This is a static function on `CLIEngine` that is used to output fixes from `report` to disk. It does by looking for files that have an `output` property in their results. Here's an example: - -```js -const CLIEngine = require("eslint").CLIEngine; - -const cli = new CLIEngine({ - envs: ["browser", "mocha"], - fix: true, - useEslintrc: false, - rules: { - semi: 2 - } -}); - -// lint myfile.js and all files in lib/ -const report = cli.executeOnFiles(["myfile.js", "lib/"]); - -// output fixes to disk -CLIEngine.outputFixes(report); -``` - -### CLIEngine#getRules() - -This method returns a map of all loaded rules. Under the hood, it calls [Linter#getRules](#lintergetrules). - -```js -const CLIEngine = require("eslint").CLIEngine; -const cli = new CLIEngine(); - -cli.getRules(); - -/* -Map { - 'accessor-pairs' => { meta: { docs: [Object], schema: [Array] }, create: [Function: create] }, - 'array-bracket-newline' => { meta: { docs: [Object], schema: [Array] }, create: [Function: create] }, - ... -} -*/ -``` - - -### CLIEngine.version - -`CLIEngine` has a static `version` property containing the semantic version number of ESLint that it comes from. - -```js -require("eslint").CLIEngine.version; // '4.5.0' -``` - --- ## RuleTester @@ -1374,14 +868,6 @@ ruleTester.run("my-rule", myRule, { --- -## Deprecated APIs - -* `cli` - the `cli` object has been deprecated in favor of `CLIEngine`. As of v1.0.0, `cli` is no longer exported and should not be used by external tools. -* `linter` - the `linter` object has been deprecated in favor of `Linter` as of v4.0.0. -* `CLIEngine` - the `CLIEngine` class has been deprecated in favor of the `ESLint` class as of v7.0.0. - ---- - [configuration object]: ../user-guide/configuring [builtin-formatters]: https://eslint.org/docs/user-guide/formatters/ [thirdparty-formatters]: https://www.npmjs.com/search?q=eslintformatter From 465ef9598d5eac64d1ae950d477185149888266f Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 14 Jun 2021 18:24:15 -0700 Subject: [PATCH 3/5] Fix linting errors --- docs/developer-guide/nodejs-api.md | 1 + tests/lib/rules/array-bracket-spacing.js | 12 +- tests/lib/rules/camelcase.js | 64 +++++------ tests/lib/rules/comma-dangle.js | 16 +-- tests/lib/rules/id-blacklist.js | 16 +-- tests/lib/rules/id-denylist.js | 16 +-- tests/lib/rules/indent.js | 28 ++--- tests/lib/rules/keyword-spacing.js | 4 +- tests/lib/rules/no-alert.js | 12 +- tests/lib/rules/no-console.js | 2 +- tests/lib/rules/no-else-return.js | 8 +- tests/lib/rules/no-eval.js | 40 +++---- tests/lib/rules/no-extend-native.js | 16 +-- tests/lib/rules/no-global-assign.js | 12 +- tests/lib/rules/no-implicit-globals.js | 12 +- tests/lib/rules/no-implied-eval.js | 72 ++++++------ tests/lib/rules/no-magic-numbers.js | 32 +++--- .../rules/no-misleading-character-class.js | 16 +-- tests/lib/rules/no-mixed-spaces-and-tabs.js | 8 +- tests/lib/rules/no-native-reassign.js | 10 +- tests/lib/rules/no-obj-calls.js | 104 +++++++++--------- tests/lib/rules/no-redeclare.js | 28 ++--- tests/lib/rules/no-restricted-globals.js | 36 +++--- tests/lib/rules/no-sequences.js | 4 +- tests/lib/rules/no-setter-return.js | 20 ++-- tests/lib/rules/no-shadow.js | 12 +- tests/lib/rules/no-unexpected-multiline.js | 4 +- tests/lib/rules/no-unused-vars.js | 4 +- tests/lib/rules/no-var.js | 4 +- tests/lib/rules/object-curly-newline.js | 16 +-- tests/lib/rules/object-curly-spacing.js | 4 +- tests/lib/rules/object-shorthand.js | 4 +- tests/lib/rules/prefer-const.js | 4 +- .../rules/prefer-exponentiation-operator.js | 8 +- tests/lib/rules/prefer-named-capture-group.js | 12 +- tests/lib/rules/prefer-object-spread.js | 24 ++-- tests/lib/rules/prefer-regex-literals.js | 8 +- tests/lib/rules/quote-props.js | 8 +- tests/lib/rules/require-unicode-regexp.js | 12 +- tests/lib/rules/space-before-blocks.js | 8 +- tests/lib/rules/space-infix-ops.js | 18 +-- 41 files changed, 370 insertions(+), 369 deletions(-) diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index b032a9e1171..42ca9add4db 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -676,6 +676,7 @@ const Linter = require("eslint").Linter; Linter.version; // => '4.5.0' ``` + --- ## RuleTester diff --git a/tests/lib/rules/array-bracket-spacing.js b/tests/lib/rules/array-bracket-spacing.js index 4b5f5f051d4..33caf088928 100644 --- a/tests/lib/rules/array-bracket-spacing.js +++ b/tests/lib/rules/array-bracket-spacing.js @@ -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"], parserOptions: { ecmaVersion: 6 }, parser: parser("flow-destructuring-1") }, - { code: "([a, b]: Array< any >) => {}", options: ["never"], parserOptions: { ecmaVersion: 6 }, parser: parser("flow-destructuring-2") } + { 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 } } ], invalid: [ @@ -921,6 +921,7 @@ ruleTester.run("array-bracket-spacing", rule, { code: "([ a, b ]: Array) => {}", output: "([a, b]: Array) => {}", options: ["never"], + parser: parser("flow-destructuring-1"), parserOptions: { ecmaVersion: 6 }, @@ -947,13 +948,13 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 9 } - ], - parser: parser("flow-destructuring-1") + ] }, { code: "([a, b]: Array< any >) => {}", output: "([ a, b ]: Array< any >) => {}", options: ["always"], + parser: parser("flow-destructuring-2"), parserOptions: { ecmaVersion: 6 }, @@ -980,8 +981,7 @@ ruleTester.run("array-bracket-spacing", rule, { endLine: 1, endColumn: 8 } - ], - parser: parser("flow-destructuring-2") + ] }, // multiple spaces diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index 110be8acdfa..4f9cdca78fe 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -753,89 +753,90 @@ ruleTester.run("camelcase", rule, { { code: "var camelCased = snake_cased", options: [{ ignoreGlobals: false }], + globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { snake_cased: "readonly" } + ] }, { code: "a_global_variable.foo()", options: [{ ignoreGlobals: false }], + globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { snake_cased: "readonly" } + ] }, { code: "a_global_variable[undefined]", options: [{ ignoreGlobals: false }], + globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { snake_cased: "readonly" } + ] }, { code: "var camelCased = snake_cased", + globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { snake_cased: "readonly" } + ] }, { code: "var camelCased = snake_cased", options: [{}], + globals: { snake_cased: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "snake_cased" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { snake_cased: "readonly" } + ] }, { code: "foo.a_global_variable = bar", options: [{ ignoreGlobals: true }], + globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "var foo = { a_global_variable: bar }", options: [{ ignoreGlobals: true }], + globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "var foo = { a_global_variable: a_global_variable }", options: [{ ignoreGlobals: true }], + globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", @@ -843,51 +844,51 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 13 } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "var foo = { a_global_variable() {} }", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, + globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "class Foo { a_global_variable() {} }", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, + globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "a_global_variable: for (;;);", options: [{ ignoreGlobals: true }], + globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { 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 errors: [ { messageId: "notCamelCase", @@ -901,13 +902,13 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 35 } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { 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 errors: [ { messageId: "notCamelCase", @@ -921,8 +922,7 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 41 } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "var a_global_variable", @@ -952,6 +952,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 errors: [ { messageId: "notCamelCase", @@ -965,13 +966,13 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 38 } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "bar = a_global_variable; var a_global_variable;", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, + globals: { a_global_variable: "writable" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", @@ -985,21 +986,20 @@ ruleTester.run("camelcase", rule, { type: "Identifier", column: 30 } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "writable" } + ] }, { code: "var foo = { a_global_variable }", options: [{ ignoreGlobals: true }], parserOptions: { ecmaVersion: 6 }, + globals: { a_global_variable: "readonly" }, // eslint-disable-line camelcase errors: [ { messageId: "notCamelCase", data: { name: "a_global_variable" }, type: "Identifier" } - ], // eslint-disable-line camelcase - globals: { a_global_variable: "readonly" } + ] }, { code: "export * as snake_cased from 'mod'", diff --git a/tests/lib/rules/comma-dangle.js b/tests/lib/rules/comma-dangle.js index 6b85c2fa73d..2ef7a008e2e 100644 --- a/tests/lib/rules/comma-dangle.js +++ b/tests/lib/rules/comma-dangle.js @@ -1735,29 +1735,29 @@ let d = 0;export {d,}; code: "function foo({a}: {a: string,}) {}", output: "function foo({a,}: {a: string,}) {}", options: ["always"], - errors: [{ messageId: "missing" }], - parser: parser("object-pattern-1") + parser: parser("object-pattern-1"), + errors: [{ messageId: "missing" }] }, { code: "function foo({a,}: {a: string}) {}", output: "function foo({a}: {a: string}) {}", options: ["never"], - errors: [{ messageId: "unexpected" }], - parser: parser("object-pattern-2") + parser: parser("object-pattern-2"), + errors: [{ messageId: "unexpected" }] }, { code: "function foo(a): {b: boolean,} {}", output: "function foo(a,): {b: boolean,} {}", options: [{ functions: "always" }], - errors: [{ messageId: "missing" }], - parser: parser("return-type-1") + parser: parser("return-type-1"), + errors: [{ messageId: "missing" }] }, { code: "function foo(a,): {b: boolean} {}", output: "function foo(a): {b: boolean} {}", options: [{ functions: "never" }], - errors: [{ messageId: "unexpected" }], - parser: parser("return-type-2") + parser: parser("return-type-2"), + errors: [{ messageId: "unexpected" }] }, // https://github.com/eslint/eslint/issues/11502 diff --git a/tests/lib/rules/id-blacklist.js b/tests/lib/rules/id-blacklist.js index bea7ad3e1dc..4d13459acf6 100644 --- a/tests/lib/rules/id-blacklist.js +++ b/tests/lib/rules/id-blacklist.js @@ -993,6 +993,7 @@ ruleTester.run("id-blacklist", rule, { { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], + globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1006,8 +1007,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 30 } - ], - globals: { myGlobal: "readonly" } + ] }, // globals declared in the given source code are not excluded from consideration @@ -1188,6 +1188,7 @@ ruleTester.run("id-blacklist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], + env: { browser: true }, errors: [ { messageId: "restricted", @@ -1195,22 +1196,21 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 31 } - ], - env: { browser: true } + ] }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], + globals: { undefined: "off" }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ], - globals: { undefined: "off" } + ] }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1276,6 +1276,7 @@ ruleTester.run("id-blacklist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], + globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1289,8 +1290,7 @@ ruleTester.run("id-blacklist", rule, { type: "Identifier", column: 36 } - ], - globals: { myGlobal: "readonly" } + ] }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", diff --git a/tests/lib/rules/id-denylist.js b/tests/lib/rules/id-denylist.js index eea9211166c..6da179d99ff 100644 --- a/tests/lib/rules/id-denylist.js +++ b/tests/lib/rules/id-denylist.js @@ -993,6 +993,7 @@ ruleTester.run("id-denylist", rule, { { code: "myGlobal: while(foo) { break myGlobal; } ", options: ["myGlobal"], + globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1006,8 +1007,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 30 } - ], - globals: { myGlobal: "readonly" } + ] }, // globals declared in the given source code are not excluded from consideration @@ -1188,6 +1188,7 @@ ruleTester.run("id-denylist", rule, { { code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;", options: ["myGlobal"], + env: { browser: true }, errors: [ { messageId: "restricted", @@ -1195,22 +1196,21 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 31 } - ], - env: { browser: true } + ] }, // disabled global variables { code: "var foo = undefined;", options: ["undefined"], + globals: { undefined: "off" }, errors: [ { messageId: "restricted", data: { name: "undefined" }, type: "Identifier" } - ], - globals: { undefined: "off" } + ] }, { code: "/* globals Number: off */ Number.parseInt()", @@ -1276,6 +1276,7 @@ ruleTester.run("id-denylist", rule, { { code: "function foo() { var myGlobal; x = myGlobal; }", options: ["myGlobal"], + globals: { myGlobal: "readonly" }, errors: [ { messageId: "restricted", @@ -1289,8 +1290,7 @@ ruleTester.run("id-denylist", rule, { type: "Identifier", column: 36 } - ], - globals: { myGlobal: "readonly" } + ] }, { code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;", diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 42f1701661e..02517ffaeeb 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -9734,8 +9734,8 @@ ruleTester.run("indent", rule, { } } `, - errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]), - parser: parser("unknown-nodes/namespace-invalid") + parser: parser("unknown-nodes/namespace-invalid"), + errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]) }, { code: unIndent` @@ -9766,8 +9766,8 @@ ruleTester.run("indent", rule, { } } `, - errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]), - parser: parser("unknown-nodes/abstract-class-invalid") + parser: parser("unknown-nodes/abstract-class-invalid"), + errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]) }, { code: unIndent` @@ -9796,14 +9796,14 @@ ruleTester.run("indent", rule, { } } `, + parser: parser("unknown-nodes/functions-with-abstract-class-invalid"), errors: expectedErrors([ [4, 12, 8, "Keyword"], [5, 16, 8, "Keyword"], [6, 20, 8, "Identifier"], [7, 16, 8, "Punctuator"], [8, 12, 8, "Punctuator"] - ]), - parser: parser("unknown-nodes/functions-with-abstract-class-invalid") + ]) }, { code: unIndent` @@ -9836,11 +9836,11 @@ ruleTester.run("indent", rule, { } } `, + parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid"), errors: expectedErrors([ [3, 8, 4, "Keyword"], [7, 24, 20, "Identifier"] - ]), - parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid") + ]) }, //---------------------------------------------------------------------- @@ -10641,8 +10641,8 @@ ruleTester.run("indent", rule, { foo }: bar) => baz `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation") + parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation"), + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { code: unIndent` @@ -10655,8 +10655,8 @@ ruleTester.run("indent", rule, { foo ]: bar) => baz `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation") + parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation"), + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { code: unIndent` @@ -10669,8 +10669,8 @@ ruleTester.run("indent", rule, { foo }: {}) => baz `, - errors: expectedErrors([3, 0, 4, "Punctuator"]), - parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation") + parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation"), + errors: expectedErrors([3, 0, 4, "Punctuator"]) }, { code: unIndent` diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js index 602e646da04..64ee5a43474 100644 --- a/tests/lib/rules/keyword-spacing.js +++ b/tests/lib/rules/keyword-spacing.js @@ -3230,8 +3230,8 @@ ruleTester.run("keyword-spacing", rule, { { code: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }", output: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }", - errors: expectedAfter("async"), - parser: parser("typescript-parsers/decorator-with-keywords-class-method") + parser: parser("typescript-parsers/decorator-with-keywords-class-method"), + errors: expectedAfter("async") } ] diff --git a/tests/lib/rules/no-alert.js b/tests/lib/rules/no-alert.js index 70e3605eea0..03fcddb6994 100644 --- a/tests/lib/rules/no-alert.js +++ b/tests/lib/rules/no-alert.js @@ -112,18 +112,18 @@ ruleTester.run("no-alert", rule, { }, { code: "globalThis['alert'](foo)", - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "globalThis.alert();", - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "function foo() { var globalThis = bar; globalThis.alert(); }\nglobalThis.alert();", - errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] }, // Optional chaining diff --git a/tests/lib/rules/no-console.js b/tests/lib/rules/no-console.js index 49efa5408b2..d1c9176d0ff 100644 --- a/tests/lib/rules/no-console.js +++ b/tests/lib/rules/no-console.js @@ -58,6 +58,6 @@ ruleTester.run("no-console", rule, { { code: "console.warn(foo)", options: [{ allow: ["info", "log"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, // In case that implicit global variable of 'console' exists - { code: "console.log(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { node: true } } + { code: "console.log(foo)", env: { node: true }, errors: [{ messageId: "unexpected", type: "MemberExpression" }] } ] }); diff --git a/tests/lib/rules/no-else-return.js b/tests/lib/rules/no-else-return.js index 3daccca7fc8..5486bbbdc3a 100644 --- a/tests/lib/rules/no-else-return.js +++ b/tests/lib/rules/no-else-return.js @@ -509,15 +509,15 @@ ruleTester.run("no-else-return", rule, { code: "if (foo) { return true; } else { let a; }", output: "if (foo) { return true; } let a; ", parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - env: { node: true } + env: { node: true }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "let a; if (foo) { return true; } else { let a; }", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ messageId: "unexpected", type: "BlockStatement" }], - env: { node: true } + env: { node: true }, + errors: [{ messageId: "unexpected", type: "BlockStatement" }] } ] }); diff --git a/tests/lib/rules/no-eval.js b/tests/lib/rules/no-eval.js index f03d37cc970..bc8d38471bb 100644 --- a/tests/lib/rules/no-eval.js +++ b/tests/lib/rules/no-eval.js @@ -85,44 +85,44 @@ ruleTester.run("no-eval", rule, { // Indirect eval { code: "(0, eval)('foo')", errors: [{ messageId: "unexpected", type: "Identifier", column: 5, endColumn: 9 }] }, - { code: "(0, window.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 16 }], env: { browser: true } }, - { code: "(0, window['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 12, endColumn: 18 }], env: { browser: true } }, + { 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: "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: "(function(exe){ exe('foo') })(eval);", errors: [{ messageId: "unexpected", type: "Identifier", column: 31, endColumn: 35 }] }, - { code: "window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], env: { browser: true } }, - { code: "window.window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], env: { browser: true } }, - { code: "window.window['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], env: { browser: true } }, - { code: "global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 8, endColumn: 12 }], env: { node: true } }, - { code: "global.global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 19 }], env: { node: true } }, - { code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression", column: 15, endColumn: 21 }], env: { node: true } }, + { 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: "this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 6, endColumn: 10 }] }, { code: "function foo() { this.eval('foo') }", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }] }, - { code: "var EVAL = globalThis.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 23, endColumn: 27 }], env: { es2020: true } }, - { code: "globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 12, endColumn: 16 }], env: { es2020: true } }, - { code: "globalThis.globalThis.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 27 }], env: { es2020: true } }, - { code: "globalThis.globalThis['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression", column: 23, endColumn: 29 }], env: { es2020: true } }, - { code: "(0, globalThis.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 20 }], env: { es2020: true } }, - { code: "(0, globalThis['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression", column: 16, endColumn: 22 }], env: { es2020: true } }, + { 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 }] }, // Optional chaining { code: "window?.eval('foo')", parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }], - globals: { window: "readonly" } + globals: { window: "readonly" }, + errors: [{ messageId: "unexpected" }] }, { code: "(window?.eval)('foo')", parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }], - globals: { window: "readonly" } + globals: { window: "readonly" }, + errors: [{ messageId: "unexpected" }] }, { code: "(window?.window).eval('foo')", parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "unexpected" }], - globals: { window: "readonly" } + globals: { window: "readonly" }, + errors: [{ messageId: "unexpected" }] } ] }); diff --git a/tests/lib/rules/no-extend-native.js b/tests/lib/rules/no-extend-native.js index 2ccdf780ff6..4cb4a64b35c 100644 --- a/tests/lib/rules/no-extend-native.js +++ b/tests/lib/rules/no-extend-native.js @@ -59,36 +59,36 @@ ruleTester.run("no-extend-native", rule, { }] }, { code: "BigInt.prototype.p = 0", + env: { es2020: true }, errors: [{ messageId: "unexpected", data: { builtin: "BigInt" }, type: "AssignmentExpression" - }], - env: { es2020: true } + }] }, { code: "WeakRef.prototype.p = 0", + env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "WeakRef" }, type: "AssignmentExpression" - }], - env: { es2021: true } + }] }, { code: "FinalizationRegistry.prototype.p = 0", + env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "FinalizationRegistry" }, type: "AssignmentExpression" - }], - env: { es2021: true } + }] }, { code: "AggregateError.prototype.p = 0", + env: { es2021: true }, errors: [{ messageId: "unexpected", data: { builtin: "AggregateError" }, type: "AssignmentExpression" - }], - env: { es2021: true } + }] }, { code: "Function.prototype['p'] = 0", errors: [{ diff --git a/tests/lib/rules/no-global-assign.js b/tests/lib/rules/no-global-assign.js index daa5c0f11b3..41f0ac0f305 100644 --- a/tests/lib/rules/no-global-assign.js +++ b/tests/lib/rules/no-global-assign.js @@ -64,21 +64,21 @@ ruleTester.run("no-global-assign", rule, { }, { code: "top = 0;", + env: { browser: true }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "top" }, type: "Identifier" - }], - env: { browser: true } + }] }, { code: "require = 0;", + env: { node: true }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "require" }, type: "Identifier" - }], - env: { node: true } + }] }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 @@ -92,12 +92,12 @@ ruleTester.run("no-global-assign", rule, { }, { code: "function f() { b = 1; }", + globals: { b: false }, errors: [{ messageId: "globalShouldNotBeModified", data: { name: "b" }, type: "Identifier" - }], - globals: { b: false } + }] }, { code: "/*global b:false*/ function f() { b++; }", diff --git a/tests/lib/rules/no-implicit-globals.js b/tests/lib/rules/no-implicit-globals.js index 54d6f7c7e8d..348ef6feb55 100644 --- a/tests/lib/rules/no-implicit-globals.js +++ b/tests/lib/rules/no-implicit-globals.js @@ -703,13 +703,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1", + env: { node: true }, errors: [ { message: leakMessage, type: "AssignmentExpression" } - ], - env: { node: true } + ] }, { code: "foo = 1;", @@ -862,13 +862,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "window = 1;", + env: { browser: true }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ], - env: { browser: true } + ] }, { code: "/*global foo:readonly*/ foo = 1", @@ -881,13 +881,13 @@ ruleTester.run("no-implicit-globals", rule, { }, { code: "foo = 1;", + globals: { foo: "readonly" }, errors: [ { message: readonlyAssignmentMessage, type: "AssignmentExpression" } - ], - globals: { foo: "readonly" } + ] }, { code: "/*global foo:readonly*/ for (foo in {});", diff --git a/tests/lib/rules/no-implied-eval.js b/tests/lib/rules/no-implied-eval.js index f31f8c02ed8..ce06f662043 100644 --- a/tests/lib/rules/no-implied-eval.js +++ b/tests/lib/rules/no-implied-eval.js @@ -129,43 +129,43 @@ ruleTester.run("no-implied-eval", rule, { { code: "setTimeout(String('x=1'), 100);", parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, // member expressions - { code: "window.setTimeout('foo')", errors: [expectedError], env: { browser: true } }, - { code: "window.setInterval('foo')", errors: [expectedError], env: { browser: true } }, - { code: "window['setTimeout']('foo')", errors: [expectedError], env: { browser: true } }, - { code: "window['setInterval']('foo')", errors: [expectedError], env: { browser: true } }, - { code: "window[`setInterval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, - { code: "window.window['setInterval']('foo')", errors: [expectedError], env: { browser: true } }, - { code: "global.setTimeout('foo')", errors: [expectedError], env: { node: true } }, - { code: "global.setInterval('foo')", errors: [expectedError], env: { node: true } }, - { code: "global['setTimeout']('foo')", errors: [expectedError], env: { node: true } }, - { code: "global['setInterval']('foo')", errors: [expectedError], env: { node: true } }, - { code: "global[`setInterval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { node: true } }, - { code: "global.global['setInterval']('foo')", errors: [expectedError], env: { node: true } }, - { code: "globalThis.setTimeout('foo')", errors: [expectedError], env: { es2020: true } }, - { code: "globalThis.setInterval('foo')", errors: [expectedError], env: { es2020: true } }, + { 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] }, // template literals { code: "setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, - { code: "window.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, - { code: "window.window.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, - { code: "global.global.setTimeout(`foo${bar}`)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { node: true } }, + { 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] }, // 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(1 + ';' + 1)", errors: [expectedError] }, - { code: "window.setTimeout('foo' + bar)", errors: [expectedError], env: { browser: true } }, - { code: "window.setTimeout(foo + 'bar')", errors: [expectedError], env: { browser: true } }, - { code: "window.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { browser: true } }, - { code: "window.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { browser: true } }, - { code: "window.window.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { browser: true } }, - { code: "global.setTimeout('foo' + bar)", errors: [expectedError], env: { node: true } }, - { code: "global.setTimeout(foo + 'bar')", errors: [expectedError], env: { node: true } }, - { code: "global.setTimeout(`foo` + bar)", parserOptions: { ecmaVersion: 6 }, errors: [expectedError], env: { node: true } }, - { code: "global.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { node: true } }, - { code: "global.global.setTimeout(1 + ';' + 1)", errors: [expectedError], env: { node: true } }, - { code: "globalThis.setTimeout('foo' + bar)", errors: [expectedError], env: { es2020: true } }, + { 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] }, // gives the correct node when dealing with nesting { @@ -197,6 +197,7 @@ ruleTester.run("no-implied-eval", rule, { " window.execScript('str');\n" + " return 'bar';\n" + "})())", + env: { browser: true }, errors: [ { messageId: "impliedEval", @@ -210,8 +211,7 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ], - env: { browser: true } + ] }, { code: @@ -220,6 +220,7 @@ ruleTester.run("no-implied-eval", rule, { " global.execScript('str');\n" + " return 'bar';\n" + "})())", + env: { node: true }, errors: [ { messageId: "impliedEval", @@ -233,22 +234,21 @@ ruleTester.run("no-implied-eval", rule, { type: "CallExpression", line: 3 } - ], - env: { node: true } + ] }, // Optional chaining { code: "window?.setTimeout('code', 0)", parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "impliedEval" }], - globals: { window: "readonly" } + globals: { window: "readonly" }, + errors: [{ messageId: "impliedEval" }] }, { code: "(window?.setTimeout)('code', 0)", parserOptions: { ecmaVersion: 2020 }, - errors: [{ messageId: "impliedEval" }], - globals: { window: "readonly" } + globals: { window: "readonly" }, + errors: [{ messageId: "impliedEval" }] } ] }); diff --git a/tests/lib/rules/no-magic-numbers.js b/tests/lib/rules/no-magic-numbers.js index 62efeacd936..bbdf8ca984f 100644 --- a/tests/lib/rules/no-magic-numbers.js +++ b/tests/lib/rules/no-magic-numbers.js @@ -265,8 +265,8 @@ ruleTester.run("no-magic-numbers", rule, { options: [{ enforceConst: true }], - errors: [{ messageId: "useConst" }], - env: { es6: true } + env: { es6: true }, + errors: [{ messageId: "useConst" }] }, { code: "var foo = 0 + 1;", @@ -391,6 +391,7 @@ ruleTester.run("no-magic-numbers", rule, { "function invokeInTen(func) {\n" + "setTimeout(func, 10);\n" + "}\n", + env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "10" }, line: 7 }, { messageId: "noMagic", data: { raw: "10" }, line: 7 }, @@ -398,8 +399,7 @@ ruleTester.run("no-magic-numbers", rule, { { messageId: "noMagic", data: { raw: "1000" }, line: 15 }, { messageId: "noMagic", data: { raw: "0" }, line: 19 }, { messageId: "noMagic", data: { raw: "10" }, line: 22 } - ], - env: { es6: true } + ] }, { code: "var data = ['foo', 'bar', 'baz']; var third = data[3];", @@ -767,51 +767,51 @@ ruleTester.run("no-magic-numbers", rule, { { code: "const func = (param = 123) => {}", options: [{ ignoreDefaultValues: false }], + env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - env: { es6: true } + ] }, { code: "const { param = 123 } = sourceObject;", options: [{}], + env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - env: { es6: true } + ] }, { code: "const { param = 123 } = sourceObject;", + env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - env: { es6: true } + ] }, { code: "const { param = 123 } = sourceObject;", options: [{ ignoreDefaultValues: false }], + env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "123" }, line: 1 } - ], - env: { es6: true } + ] }, { code: "const [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], + env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ], - env: { es6: true } + ] }, { code: "var one, two; [one = 1, two = 2] = []", options: [{ ignoreDefaultValues: false }], + env: { es6: true }, errors: [ { messageId: "noMagic", data: { raw: "1" }, line: 1 }, { messageId: "noMagic", data: { raw: "2" }, line: 1 } - ], - env: { es6: true } + ] } ] }); diff --git a/tests/lib/rules/no-misleading-character-class.js b/tests/lib/rules/no-misleading-character-class.js index 83d43806586..a7bc04ef415 100644 --- a/tests/lib/rules/no-misleading-character-class.js +++ b/tests/lib/rules/no-misleading-character-class.js @@ -276,23 +276,23 @@ ruleTester.run("no-misleading-character-class", rule, { }, { code: String.raw`var r = new globalThis.RegExp("[❇️]", "")`, - errors: [{ messageId: "combiningClass" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "combiningClass" }] }, { code: String.raw`var r = new globalThis.RegExp("[👶🏻]", "u")`, - errors: [{ messageId: "emojiModifier" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "emojiModifier" }] }, { code: String.raw`var r = new globalThis.RegExp("[🇯🇵]", "")`, - errors: [{ messageId: "surrogatePairWithoutUFlag" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "surrogatePairWithoutUFlag" }] }, { code: String.raw`var r = new globalThis.RegExp("[\\u{1F468}\\u{200D}\\u{1F469}\\u{200D}\\u{1F466}]", "u")`, - errors: [{ messageId: "zwj" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "zwj" }] } ] }); diff --git a/tests/lib/rules/no-mixed-spaces-and-tabs.js b/tests/lib/rules/no-mixed-spaces-and-tabs.js index b23826a52ea..4dd475d4b60 100644 --- a/tests/lib/rules/no-mixed-spaces-and-tabs.js +++ b/tests/lib/rules/no-mixed-spaces-and-tabs.js @@ -278,6 +278,7 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { { code: "`foo${\n \t 5 }bar`;", options: ["smart-tabs"], + env: { es6: true }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -287,11 +288,11 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ], - env: { es6: true } + ] }, { code: "`foo${\n\t 5 }bar`;", + env: { es6: true }, errors: [ { messageId: "mixedSpacesAndTabs", @@ -301,8 +302,7 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, { endLine: 2, endColumn: 3 } - ], - env: { es6: true } + ] }, { code: " \t'';", diff --git a/tests/lib/rules/no-native-reassign.js b/tests/lib/rules/no-native-reassign.js index 6df55fe2db4..8bb14d70c5d 100644 --- a/tests/lib/rules/no-native-reassign.js +++ b/tests/lib/rules/no-native-reassign.js @@ -43,18 +43,18 @@ ruleTester.run("no-native-reassign", rule, { }, { code: "top = 0;", - errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }], - env: { browser: true } + env: { browser: true }, + errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }] }, { code: "require = 0;", - errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }], - env: { node: true } + env: { node: true }, + errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }] }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 { code: "/*global b:false*/ function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, - { code: "function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }], globals: { b: false } }, + { code: "function f() { b = 1; }", 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-obj-calls.js b/tests/lib/rules/no-obj-calls.js index 61aa6ca1dbc..6270e7a7280 100644 --- a/tests/lib/rules/no-obj-calls.js +++ b/tests/lib/rules/no-obj-calls.js @@ -179,18 +179,18 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - env: { es6: true } + env: { es6: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = new Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], - env: { es6: true } + env: { es6: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] }, { code: "var x = Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - env: { es2017: true } + env: { es2017: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "/*globals Reflect: true*/ Reflect();", @@ -202,91 +202,91 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var x = Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - env: { es2017: true } + env: { es2017: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = new Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], - env: { es2017: true } + env: { es2017: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] }, { code: "var x = Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - globals: { Atomics: false } + globals: { Atomics: false }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var x = new Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }], - globals: { Atomics: "writable" } + globals: { Atomics: "writable" }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "NewExpression" }] }, { code: "var x = globalThis.Math();", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Math();", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression" }] }, { code: "f(globalThis.Math());", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 3, endColumn: 20 }] }, { code: "globalThis.Math().foo;", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 18 }] }, { code: "new globalThis.Math().foo;", - errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "NewExpression", column: 1, endColumn: 22 }] }, { code: "var x = globalThis.JSON();", - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] }, { code: "x = globalThis.JSON(str);", - errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression" }] }, { code: "globalThis.Math( globalThis.JSON() );", + env: { es2020: true }, errors: [ { messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression", column: 1, endColumn: 37 }, { messageId: "unexpectedCall", data: { name: "JSON" }, type: "CallExpression", column: 18, endColumn: 35 } - ], - env: { es2020: true } + ] }, { code: "var x = globalThis.Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = new globalThis.Reflect;", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "NewExpression" }] }, { code: "/*globals Reflect: true*/ Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = globalThis.Atomics();", - errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Atomics" }, type: "CallExpression" }] }, { code: "var foo = bar ? baz: JSON; foo();", @@ -298,35 +298,35 @@ ruleTester.run("no-obj-calls", rule, { }, { code: "var foo = bar ? baz: globalThis.JSON; foo();", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "CallExpression" }] }, { code: "var foo = bar ? baz: globalThis.JSON; new foo();", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "JSON" }, type: "NewExpression" }] }, { code: "var foo = window.Atomics; foo();", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }], - env: { es2020: true, browser: true } + env: { es2020: true, browser: true }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "CallExpression" }] }, { code: "var foo = window.Atomics; new foo;", - errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }], - env: { es2020: true, browser: true } + env: { es2020: true, browser: true }, + errors: [{ messageId: "unexpectedRefCall", data: { name: "foo", ref: "Atomics" }, type: "NewExpression" }] }, // Optional chaining { code: "var x = globalThis?.Reflect();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] }, { code: "var x = (globalThis?.Reflect)();", - errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedCall", data: { name: "Reflect" }, type: "CallExpression" }] } ] }); diff --git a/tests/lib/rules/no-redeclare.js b/tests/lib/rules/no-redeclare.js index da46f15d6e0..f89d6853fa3 100644 --- a/tests/lib/rules/no-redeclare.js +++ b/tests/lib/rules/no-redeclare.js @@ -88,8 +88,8 @@ ruleTester.run("no-redeclare", rule, { { code: "var top = 0;", options: [{ builtinGlobals: true }], - errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }], - env: { browser: true } + env: { browser: true }, + errors: [{ message: "'top' is already defined as a built-in global variable.", type: "Identifier" }] }, { code: "var a; var {a = 0, b: Object = 0} = {};", @@ -127,18 +127,18 @@ ruleTester.run("no-redeclare", rule, { { code: "var globalThis = 0;", options: [{ builtinGlobals: true }], - errors: [{ message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" }], - env: { es2020: true } + env: { es2020: true }, + 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 }, errors: [ { message: "'a' is already defined.", type: "Identifier" }, { message: "'globalThis' is already defined as a built-in global variable.", type: "Identifier" } - ], - env: { es2020: true } + ] }, { code: "/*global b:false*/ var b = 1;", @@ -197,10 +197,10 @@ ruleTester.run("no-redeclare", rule, { }, { code: "var top = 0;", + env: { browser: true }, errors: [ { message: "'top' is already defined as a built-in global variable.", type: "Identifier" } - ], - env: { browser: true } + ] }, // Comments and built-ins. @@ -351,6 +351,7 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */", options: [{ builtinGlobals: true }], + globals: { a: "readonly" }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -358,12 +359,12 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }], - globals: { a: "readonly" } + }] }, { code: "/*globals a */", options: [{ builtinGlobals: true }], + globals: { a: "writable" }, errors: [{ message: "'a' is already defined as a built-in global variable.", type: "Block", @@ -371,8 +372,7 @@ ruleTester.run("no-redeclare", rule, { column: 11, endLine: 1, endColumn: 12 - }], - globals: { a: "writable" } + }] }, { code: "/*globals a */ /*globals a */", @@ -388,6 +388,7 @@ ruleTester.run("no-redeclare", rule, { { code: "/*globals a */ /*globals a */ var a = 0", options: [{ builtinGlobals: true }], + globals: { a: "writable" }, errors: [ { message: "'a' is already defined as a built-in global variable.", @@ -413,8 +414,7 @@ ruleTester.run("no-redeclare", rule, { endLine: 1, endColumn: 36 } - ], - globals: { a: "writable" } + ] } ] }); diff --git a/tests/lib/rules/no-restricted-globals.js b/tests/lib/rules/no-restricted-globals.js index ac84b341b1d..c8b5232e8ef 100644 --- a/tests/lib/rules/no-restricted-globals.js +++ b/tests/lib/rules/no-restricted-globals.js @@ -79,32 +79,32 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: ["foo"], + globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - globals: { foo: false } + }] }, { code: "event", options: ["foo", "event"], + env: { browser: true }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }], - env: { browser: true } + }] }, { code: "foo", options: ["foo"], + globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - globals: { foo: false } + }] }, { code: "foo()", @@ -145,32 +145,32 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo" }], + globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - globals: { foo: false } + }] }, { code: "event", options: ["foo", { name: "event" }], + env: { browser: true }, errors: [{ messageId: "defaultMessage", data: { name: "event" }, type: "Identifier" - }], - env: { browser: true } + }] }, { code: "foo", options: [{ name: "foo" }], + globals: { foo: false }, errors: [{ messageId: "defaultMessage", data: { name: "foo" }, type: "Identifier" - }], - globals: { foo: false } + }] }, { code: "foo()", @@ -211,32 +211,32 @@ ruleTester.run("no-restricted-globals", rule, { { code: "function fn() { foo; }", options: [{ name: "foo", message: customMessage }], + globals: { foo: false }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }], - globals: { foo: false } + }] }, { code: "event", options: ["foo", { name: "event", message: "Use local event parameter." }], + env: { browser: true }, errors: [{ messageId: "customMessage", data: { name: "event", customMessage: "Use local event parameter." }, type: "Identifier" - }], - env: { browser: true } + }] }, { code: "foo", options: [{ name: "foo", message: customMessage }], + globals: { foo: false }, errors: [{ messageId: "customMessage", data: { name: "foo", customMessage }, type: "Identifier" - }], - globals: { foo: false } + }] }, { code: "foo()", diff --git a/tests/lib/rules/no-sequences.js b/tests/lib/rules/no-sequences.js index e39a9b7b213..1ac7c4a6c6e 100644 --- a/tests/lib/rules/no-sequences.js +++ b/tests/lib/rules/no-sequences.js @@ -86,7 +86,7 @@ ruleTester.run("no-sequences", rule, { { code: "switch (doSomething(), val) {}", errors: errors(22) }, { code: "while (doSomething(), !!test);", errors: errors(21) }, { code: "with (doSomething(), val) {}", errors: errors(20) }, - { code: "a => (doSomething(), a)", errors: errors(20), env: { es6: true } }, + { code: "a => (doSomething(), a)", env: { es6: true }, errors: errors(20) }, { code: "(1), 2", errors: errors(4) }, { code: "((1)) , (2)", errors: errors(7) }, { code: "while((1) , 2);", errors: errors(11) }, @@ -101,6 +101,6 @@ ruleTester.run("no-sequences", rule, { { code: "switch ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(23) }, { code: "while ((doSomething(), !!test));", options: [{ allowInParentheses: false }], errors: errors(22) }, { code: "with ((doSomething(), val)) {}", options: [{ allowInParentheses: false }], errors: errors(21) }, - { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], errors: errors(21), env: { es6: true } } + { code: "a => ((doSomething(), a))", options: [{ allowInParentheses: false }], env: { es6: true }, errors: errors(21) } ] }); diff --git a/tests/lib/rules/no-setter-return.js b/tests/lib/rules/no-setter-return.js index f0b9c5bf244..0c64e8b4811 100644 --- a/tests/lib/rules/no-setter-return.js +++ b/tests/lib/rules/no-setter-return.js @@ -400,8 +400,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "return; ({ set a(val) { return 1; } }); return 2;", - errors: [error(25)], - env: { node: true } + env: { node: true }, + errors: [error(25)] }, //------------------------------------------------------------------------------ @@ -415,8 +415,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { return 1; } })", - errors: [error()], - env: { es6: true } + env: { es6: true }, + errors: [error()] }, { code: "Object.defineProperties(foo, { baz: { set(val) { return 1; } } })", @@ -434,8 +434,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set: val => f(val) })", - errors: [error(50, "CallExpression")], - env: { es6: true } + env: { es6: true }, + errors: [error(50, "CallExpression")] }, { code: "Object.defineProperties(foo, { baz: { set: val => a + b } })", @@ -453,8 +453,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { set(val) { try { return f(val) } catch (e) { return e }; } })", - errors: [error(55), error(83)], - env: { es6: true } + env: { es6: true }, + errors: [error(55), error(83)] }, { code: "Object.defineProperties(foo, { bar: { get(){ return null; }, set(val) { return null; } } })", @@ -485,8 +485,8 @@ ruleTester.run("no-setter-return", rule, { }, { code: "Reflect.defineProperty(foo, 'bar', { 'set'(val) { return 1; } })", - errors: [error()], - env: { es6: true } + env: { es6: true }, + errors: [error()] }, { code: "Object[`defineProperties`](foo, { baz: { ['set'](val) { return 1; } } })", diff --git a/tests/lib/rules/no-shadow.js b/tests/lib/rules/no-shadow.js index fb5b3d8c13b..dc2cc63c4de 100644 --- a/tests/lib/rules/no-shadow.js +++ b/tests/lib/rules/no-shadow.js @@ -643,14 +643,14 @@ ruleTester.run("no-shadow", rule, { { code: "function foo() { var top = 0; }", options: [{ builtinGlobals: true }], + env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }], - env: { browser: true } + }] }, { code: "var Object = 0;", @@ -668,14 +668,14 @@ ruleTester.run("no-shadow", rule, { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, + env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }], - env: { browser: true } + }] }, { code: "var Object = 0;", @@ -693,14 +693,14 @@ ruleTester.run("no-shadow", rule, { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaFeatures: { globalReturn: true } }, + env: { browser: true }, errors: [{ messageId: "noShadowGlobal", data: { name: "top" }, type: "Identifier" - }], - env: { browser: true } + }] }, { code: "function foo(cb) { (function (cb) { cb(42); })(cb); }", diff --git a/tests/lib/rules/no-unexpected-multiline.js b/tests/lib/rules/no-unexpected-multiline.js index b9f0cdf140f..83c7bf67570 100644 --- a/tests/lib/rules/no-unexpected-multiline.js +++ b/tests/lib/rules/no-unexpected-multiline.js @@ -311,6 +311,7 @@ ruleTester.run("no-unexpected-multiline", rule, { "test", "*/`foo`" ].join("\n"), + parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment"), errors: [ { line: 5, @@ -319,8 +320,7 @@ ruleTester.run("no-unexpected-multiline", rule, { endColumn: 4, messageId: "taggedTemplate" } - ], - parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-and-comment") + ] } ] }); diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js index 97cc8c9e7e5..48ccdb1d42f 100644 --- a/tests/lib/rules/no-unused-vars.js +++ b/tests/lib/rules/no-unused-vars.js @@ -788,6 +788,7 @@ ruleTester.run("no-unused-vars", rule, { // surrogate pair. { code: "/*global 𠮷𩸽, 𠮷*/\n\\u{20BB7}\\u{29E3D};", + env: { es6: true }, errors: [ { line: 1, @@ -801,8 +802,7 @@ ruleTester.run("no-unused-vars", rule, { additional: "" } } - ], - env: { es6: true } + ] }, // https://github.com/eslint/eslint/issues/4047 diff --git a/tests/lib/rules/no-var.js b/tests/lib/rules/no-var.js index c29697cfc3c..84e14ae19c9 100644 --- a/tests/lib/rules/no-var.js +++ b/tests/lib/rules/no-var.js @@ -304,9 +304,9 @@ 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" }, - errors: [{ messageId: "unexpectedVar" }], - parser: require.resolve("../../fixtures/parsers/typescript-parsers/declare-var") + errors: [{ messageId: "unexpectedVar" }] }, // https://github.com/eslint/eslint/issues/11830 diff --git a/tests/lib/rules/object-curly-newline.js b/tests/lib/rules/object-curly-newline.js index e26976384b1..86e95609920 100644 --- a/tests/lib/rules/object-curly-newline.js +++ b/tests/lib/rules/object-curly-newline.js @@ -682,11 +682,11 @@ ruleTester.run("object-curly-newline", rule, { "} : MyType) {}" ].join("\n"), options: ["always"], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline"), errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline") + ] }, { code: "function foo({ a, b } : { a : string, b : string }) {}", @@ -696,11 +696,11 @@ ruleTester.run("object-curly-newline", rule, { "} : { a : string, b : string }) {}" ].join("\n"), options: ["always"], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal"), errors: [ { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } - ], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal") + ] }, // "never" ------------------------------------------------------------ @@ -808,11 +808,11 @@ ruleTester.run("object-curly-newline", rule, { " b} : MyType) {}" ].join("\n"), options: ["never"], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline"), errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline") + ] }, { code: [ @@ -826,11 +826,11 @@ ruleTester.run("object-curly-newline", rule, { " b} : { a : string, b : string }) {}" ].join("\n"), options: ["never"], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal"), errors: [ { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } - ], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal") + ] }, // "multiline" --------------------------------------------------------- diff --git a/tests/lib/rules/object-curly-spacing.js b/tests/lib/rules/object-curly-spacing.js index 42b47eb9b28..f603832cb37 100644 --- a/tests/lib/rules/object-curly-spacing.js +++ b/tests/lib/rules/object-curly-spacing.js @@ -1394,6 +1394,7 @@ ruleTester.run("object-curly-spacing", rule, { code: "function foo ({a, b }: Props) {\n}", output: "function foo ({a, b}: Props) {\n}", options: ["never"], + parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid"), errors: [ { messageId: "unexpectedSpaceBefore", @@ -1404,8 +1405,7 @@ ruleTester.run("object-curly-spacing", rule, { endLine: 1, endColumn: 21 } - ], - parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid") + ] } ] }); diff --git a/tests/lib/rules/object-shorthand.js b/tests/lib/rules/object-shorthand.js index 9e0d43f07e1..01a72f4e6f0 100644 --- a/tests/lib/rules/object-shorthand.js +++ b/tests/lib/rules/object-shorthand.js @@ -1173,8 +1173,8 @@ ruleTester.run("object-shorthand", rule, { } `, options: ["always", { avoidExplicitReturnArrows: true }], - errors: Array(18).fill(METHOD_ERROR), - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props") + parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-with-arrow-fn-props"), + errors: Array(18).fill(METHOD_ERROR) } ] }); diff --git a/tests/lib/rules/prefer-const.js b/tests/lib/rules/prefer-const.js index 14ee7abab3c..c591d236583 100644 --- a/tests/lib/rules/prefer-const.js +++ b/tests/lib/rules/prefer-const.js @@ -383,8 +383,8 @@ ruleTester.run("prefer-const", rule, { code: "let { name, ...otherStuff } = obj; otherStuff = {};", output: null, options: [{ destructuring: "any" }], - errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }], - parser: fixtureParser("babel-eslint5/destructuring-object-spread") + parser: fixtureParser("babel-eslint5/destructuring-object-spread"), + errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }] }, // Warnings are located at declaration if there are reading references before assignments. diff --git a/tests/lib/rules/prefer-exponentiation-operator.js b/tests/lib/rules/prefer-exponentiation-operator.js index 68ec4451eb2..7bccdd64b43 100644 --- a/tests/lib/rules/prefer-exponentiation-operator.js +++ b/tests/lib/rules/prefer-exponentiation-operator.js @@ -91,6 +91,7 @@ ruleTester.run("prefer-exponentiation-operator", rule, { { code: "globalThis.Math.pow(a, b)", output: "a**b", + env: { es2020: true }, errors: [ { messageId: "useExponentiation", @@ -100,12 +101,12 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 26 } - ], - env: { es2020: true } + ] }, { code: "globalThis.Math['pow'](a, b)", output: "a**b", + env: { es2020: true }, errors: [ { messageId: "useExponentiation", @@ -115,8 +116,7 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endLine: 1, endColumn: 29 } - ], - env: { es2020: true } + ] }, // able to catch some workarounds diff --git a/tests/lib/rules/prefer-named-capture-group.js b/tests/lib/rules/prefer-named-capture-group.js index 5561f34a912..0faf1d6be65 100644 --- a/tests/lib/rules/prefer-named-capture-group.js +++ b/tests/lib/rules/prefer-named-capture-group.js @@ -222,6 +222,7 @@ ruleTester.run("prefer-named-capture-group", rule, { }, { code: "new globalThis.RegExp('([0-9]{4})')", + env: { es2020: true }, errors: [{ messageId: "required", type: "NewExpression", @@ -229,11 +230,11 @@ ruleTester.run("prefer-named-capture-group", rule, { line: 1, column: 1, endColumn: 36 - }], - env: { es2020: true } + }] }, { code: "globalThis.RegExp('([0-9]{4})')", + env: { es2020: true }, errors: [{ messageId: "required", type: "CallExpression", @@ -241,14 +242,14 @@ ruleTester.run("prefer-named-capture-group", rule, { line: 1, column: 1, endColumn: 32 - }], - env: { es2020: true } + }] }, { code: ` function foo() { var globalThis = bar; } new globalThis.RegExp('([0-9]{4})'); `, + env: { es2020: true }, errors: [{ messageId: "required", type: "NewExpression", @@ -256,8 +257,7 @@ ruleTester.run("prefer-named-capture-group", rule, { line: 3, column: 17, endColumn: 52 - }], - env: { es2020: true } + }] } ] }); diff --git a/tests/lib/rules/prefer-object-spread.js b/tests/lib/rules/prefer-object-spread.js index 33541f437c0..91bf08a2f74 100644 --- a/tests/lib/rules/prefer-object-spread.js +++ b/tests/lib/rules/prefer-object-spread.js @@ -889,6 +889,7 @@ ruleTester.run("prefer-object-spread", rule, { { code: "globalThis.Object.assign({ });", output: "({});", + env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -896,12 +897,12 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ], - env: { es2020: true } + ] }, { code: "globalThis.Object.assign({\n});", output: "({});", + env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -909,8 +910,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ], - env: { es2020: true } + ] }, { code: ` @@ -921,6 +921,7 @@ ruleTester.run("prefer-object-spread", rule, { function foo () { var globalThis = bar; } ({}); `, + env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -928,8 +929,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ], - env: { es2020: true } + ] }, { code: ` @@ -940,6 +940,7 @@ ruleTester.run("prefer-object-spread", rule, { const Foo = require('foo'); ({foo: Foo}); `, + env: { es2020: true }, errors: [ { messageId: "useLiteralMessage", @@ -947,8 +948,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 3, column: 17 } - ], - env: { es2020: true } + ] }, // report Object.assign() with getters/setters if the function call has only 1 argument @@ -969,6 +969,7 @@ ruleTester.run("prefer-object-spread", rule, { { code: "const obj = Object.assign<{}, Record>({}, getObject());", output: "const obj = { ...getObject()};", + parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1"), errors: [ { messageId: "useSpreadMessage", @@ -976,12 +977,12 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 13 } - ], - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-1") + ] }, { code: "Object.assign<{}, A>({}, foo);", output: "({ ...foo});", + parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2"), errors: [ { messageId: "useSpreadMessage", @@ -989,8 +990,7 @@ ruleTester.run("prefer-object-spread", rule, { line: 1, column: 1 } - ], - parser: require.resolve("../../fixtures/parsers/typescript-parsers/object-assign-with-generic/object-assign-with-generic-2") + ] } ] }); diff --git a/tests/lib/rules/prefer-regex-literals.js b/tests/lib/rules/prefer-regex-literals.js index acba15ab925..0ddaa8dae3d 100644 --- a/tests/lib/rules/prefer-regex-literals.js +++ b/tests/lib/rules/prefer-regex-literals.js @@ -214,13 +214,13 @@ ruleTester.run("prefer-regex-literals", rule, { }, { code: "new globalThis.RegExp('a');", - errors: [{ messageId: "unexpectedRegExp", type: "NewExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedRegExp", type: "NewExpression" }] }, { code: "globalThis.RegExp('a');", - errors: [{ messageId: "unexpectedRegExp", type: "CallExpression" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "unexpectedRegExp", type: "CallExpression" }] }, { diff --git a/tests/lib/rules/quote-props.js b/tests/lib/rules/quote-props.js index 8f10f9233cb..5186f87d140 100644 --- a/tests/lib/rules/quote-props.js +++ b/tests/lib/rules/quote-props.js @@ -178,18 +178,18 @@ ruleTester.run("quote-props", rule, { code: "({ 'a': 0, [x]: 0 })", output: "({ a: 0, [x]: 0 })", options: ["consistent-as-needed"], + env: { es6: true }, errors: [ { messageId: "redundantQuoting", type: "Property" } - ], - env: { es6: true } + ] }, { code: "({ 'a': 0, x })", output: "({ a: 0, x })", options: ["consistent-as-needed"], + env: { es6: true }, errors: [{ messageId: "redundantQuoting", type: "Property" - }], - env: { es6: true } + }] }, { code: "({ 'true': 0, 'null': 0 })", output: "({ true: 0, null: 0 })", diff --git a/tests/lib/rules/require-unicode-regexp.js b/tests/lib/rules/require-unicode-regexp.js index 2cbf0b5b4ec..6033d44ca32 100644 --- a/tests/lib/rules/require-unicode-regexp.js +++ b/tests/lib/rules/require-unicode-regexp.js @@ -85,18 +85,18 @@ ruleTester.run("require-unicode-regexp", rule, { }, { code: "new window.RegExp('foo')", - errors: [{ messageId: "requireUFlag" }], - env: { browser: true } + env: { browser: true }, + errors: [{ messageId: "requireUFlag" }] }, { code: "new global.RegExp('foo')", - errors: [{ messageId: "requireUFlag" }], - env: { node: true } + env: { node: true }, + errors: [{ messageId: "requireUFlag" }] }, { code: "new globalThis.RegExp('foo')", - errors: [{ messageId: "requireUFlag" }], - env: { es2020: true } + env: { es2020: true }, + errors: [{ messageId: "requireUFlag" }] } ] }); diff --git a/tests/lib/rules/space-before-blocks.js b/tests/lib/rules/space-before-blocks.js index 65b6e4bf713..7424aec8458 100644 --- a/tests/lib/rules/space-before-blocks.js +++ b/tests/lib/rules/space-before-blocks.js @@ -562,15 +562,15 @@ ruleTester.run("space-before-blocks", rule, { { code: "class A { foo(bar: string): void{} }", output: "class A { foo(bar: string): void {} }", - errors: [expectedSpacingError], - parser: fixtureParser("space-before-blocks", "return-type-keyword-1") + parser: fixtureParser("space-before-blocks", "return-type-keyword-1"), + errors: [expectedSpacingError] }, { code: "function foo(): null {}", output: "function foo(): null{}", options: neverArgs, - errors: [expectedNoSpacingError], - parser: fixtureParser("space-before-blocks", "return-type-keyword-2") + parser: fixtureParser("space-before-blocks", "return-type-keyword-2"), + errors: [expectedNoSpacingError] } ] }); diff --git a/tests/lib/rules/space-infix-ops.js b/tests/lib/rules/space-infix-ops.js index 4f8363abf58..2e6f423e919 100644 --- a/tests/lib/rules/space-infix-ops.js +++ b/tests/lib/rules/space-infix-ops.js @@ -41,13 +41,13 @@ ruleTester.run("space-infix-ops", rule, { { code: "a |0", options: [{ int32Hint: true }] }, // Type Annotations - { code: "function foo(a: number = 0) { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-parameter-type-annotation") }, - { code: "function foo(): Bar { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-return-type-annotation") }, - { code: "var foo: Bar = '';", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/variable-declaration-init-type-annotation") }, - { code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-expression-type-annotation") }, + { 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 } }, // TypeScript Type Aliases - { code: "type Foo = T;", parserOptions: { ecmaVersion: 6 }, parser: parser("typescript-parsers/type-alias") }, + { code: "type Foo = T;", parser: parser("typescript-parsers/type-alias"), parserOptions: { ecmaVersion: 6 } }, { code: "a &&= b", parserOptions: { ecmaVersion: 2021 } }, { code: "a ||= b", parserOptions: { ecmaVersion: 2021 } }, @@ -469,18 +469,19 @@ ruleTester.run("space-infix-ops", rule, { { code: "var a: Foo= b;", output: "var a: Foo = b;", + parser: parser("type-annotations/variable-declaration-init-type-annotation-no-space"), errors: [{ messageId: "missingSpace", data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 11 - }], - parser: parser("type-annotations/variable-declaration-init-type-annotation-no-space") + }] }, { code: "function foo(a: number=0): Foo { }", output: "function foo(a: number = 0): Foo { }", + parser: parser("type-annotations/function-declaration-type-annotation-no-space"), parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "missingSpace", @@ -488,8 +489,7 @@ ruleTester.run("space-infix-ops", rule, { line: 1, column: 23, type: "AssignmentPattern" - }], - parser: parser("type-annotations/function-declaration-type-annotation-no-space") + }] }, { From 3e0afa04f37deeb56f9c75bbe4577f831ec2b0e4 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 16 Jun 2021 17:27:16 -0700 Subject: [PATCH 4/5] Update docs/developer-guide/nodejs-api.md Co-authored-by: Milos Djermanovic --- docs/developer-guide/nodejs-api.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index 42ca9add4db..a7560252a8f 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -32,7 +32,6 @@ While ESLint is designed to be run on the command line, it's possible to use ESL * [version](#linterversionlinterversion) * [RuleTester](#ruletester) * [Customizing RuleTester](#customizing-ruletester) -* [Deprecated APIs](#deprecated-apis) --- From 4eecb432bf07921aa5c001e77e4c42a33cc2d55d Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 16 Jun 2021 17:27:36 -0700 Subject: [PATCH 5/5] Update docs/developer-guide/nodejs-api.md Co-authored-by: Milos Djermanovic --- docs/developer-guide/nodejs-api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index a7560252a8f..f39dbc5fcbf 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -457,8 +457,8 @@ Those run on `linter2` will get `process.cwd()` if the global `process` object i The most important method on `Linter` is `verify()`, which initiates linting of the given text. This method accepts three arguments: * `code` - the source code to lint (a string or instance of `SourceCode`). -* `config` - a configuration object that has been processed and normalized by `ESLint`` using eslintrc files and/or other configuration arguments. - * **Note**: If you want to lint text and have your configuration be read and processed, use [`ESLint#lintFiles()`](#eslint-lintfiles) or [`ESLint#lintText()`](#eslint-linttext) instead. +* `config` - a configuration object that has been processed and normalized by `ESLint` using eslintrc files and/or other configuration arguments. + * **Note**: If you want to lint text and have your configuration be read and processed, use [`ESLint#lintFiles()`][eslint-lintfiles] or [`ESLint#lintText()`][eslint-linttext] instead. * `options` - (optional) Additional options for this run. * `filename` - (optional) the filename to associate with the source code. * `preprocess` - (optional) A function that [Processors in Plugins](/docs/developer-guide/working-with-plugins.md#processors-in-plugins) documentation describes as the `preprocess` method.