diff --git a/eslint/babel-eslint-config-internal/.npmignore b/eslint/babel-eslint-config-internal/.npmignore new file mode 100644 index 0000000000..ad69326ce8 --- /dev/null +++ b/eslint/babel-eslint-config-internal/.npmignore @@ -0,0 +1,4 @@ +src +test +.* +*.log diff --git a/eslint/babel-eslint-parser/.gitignore b/eslint/babel-eslint-parser/.gitignore deleted file mode 100644 index 93f1361991..0000000000 --- a/eslint/babel-eslint-parser/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -npm-debug.log diff --git a/eslint/babel-eslint-parser/.npmignore b/eslint/babel-eslint-parser/.npmignore new file mode 100644 index 0000000000..c3aafe7a77 --- /dev/null +++ b/eslint/babel-eslint-parser/.npmignore @@ -0,0 +1,4 @@ +src +test +.* +*.log \ No newline at end of file diff --git a/eslint/babel-eslint-parser/.npmrc b/eslint/babel-eslint-parser/.npmrc deleted file mode 100644 index c1ca392fea..0000000000 --- a/eslint/babel-eslint-parser/.npmrc +++ /dev/null @@ -1 +0,0 @@ -package-lock = false diff --git a/eslint/babel-eslint-parser/.travis.yml b/eslint/babel-eslint-parser/.travis.yml deleted file mode 100644 index 8ece2fc212..0000000000 --- a/eslint/babel-eslint-parser/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -sudo: false -language: node_js -node_js: - - "12" - - "10" - - "8" - -matrix: - fast_finish: true - include: - - node_js: "node" - env: LINT=true - -script: - - 'if [ -n "${LINT-}" ]; then npm run lint ; fi' - - 'if [ -z "${LINT-}" ]; then npm test ; fi' diff --git a/eslint/babel-eslint-parser/Makefile b/eslint/babel-eslint-parser/Makefile deleted file mode 100644 index d35bcfa016..0000000000 --- a/eslint/babel-eslint-parser/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -.PHONY: publish-patch - -publish-patch: - ./node_modules/.bin/mocha - npm version patch - npm publish - git push --follow-tags diff --git a/eslint/babel-eslint-parser/package.json b/eslint/babel-eslint-parser/package.json index 6cb74e76f2..ebbcbdb79d 100644 --- a/eslint/babel-eslint-parser/package.json +++ b/eslint/babel-eslint-parser/package.json @@ -20,9 +20,6 @@ "node": ">=6" }, "main": "lib/index.js", - "files": [ - "lib" - ], "peerDependencies": { "@babel/core": ">=7.2.0", "eslint": ">= 4.12.1" diff --git a/eslint/babel-eslint-plugin-development/.npmignore b/eslint/babel-eslint-plugin-development/.npmignore index 7810671790..c3aafe7a77 100644 --- a/eslint/babel-eslint-plugin-development/.npmignore +++ b/eslint/babel-eslint-plugin-development/.npmignore @@ -1,2 +1,4 @@ -tests/ -.* \ No newline at end of file +src +test +.* +*.log \ No newline at end of file diff --git a/eslint/babel-eslint-plugin-development/package.json b/eslint/babel-eslint-plugin-development/package.json index 1cb2805898..68d877ba3c 100644 --- a/eslint/babel-eslint-plugin-development/package.json +++ b/eslint/babel-eslint-plugin-development/package.json @@ -13,7 +13,7 @@ "email": "nicolo.ribaudo@gmail.com", "url": "https://github.com/nicolo-ribaudo" }, - "main": "src/index.js", + "main": "lib/index.js", "devDependencies": { "eslint": "^5.9.0" }, diff --git a/eslint/babel-eslint-plugin/.npmignore b/eslint/babel-eslint-plugin/.npmignore new file mode 100644 index 0000000000..ad69326ce8 --- /dev/null +++ b/eslint/babel-eslint-plugin/.npmignore @@ -0,0 +1,4 @@ +src +test +.* +*.log diff --git a/eslint/babel-eslint-plugin/.travis.yml b/eslint/babel-eslint-plugin/.travis.yml deleted file mode 100644 index 068a0122c8..0000000000 --- a/eslint/babel-eslint-plugin/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -git: - depth: 1 -sudo: false -language: node_js -node_js: - - 6 - - 8 - - 10 diff --git a/eslint/babel-eslint-plugin/package.json b/eslint/babel-eslint-plugin/package.json index b4780d73d6..653ebcaf43 100644 --- a/eslint/babel-eslint-plugin/package.json +++ b/eslint/babel-eslint-plugin/package.json @@ -2,7 +2,7 @@ "name": "eslint-plugin-babel", "version": "5.3.0", "description": "an eslint rule plugin companion to babel-eslint", - "main": "index.js", + "main": "lib/index.js", "repository": { "type": "git", "url": "git+https://github.com/babel/eslint-plugin-babel.git" diff --git a/eslint/babel-eslint-plugin/index.js b/eslint/babel-eslint-plugin/src/index.js similarity index 100% rename from eslint/babel-eslint-plugin/index.js rename to eslint/babel-eslint-plugin/src/index.js diff --git a/eslint/babel-eslint-plugin/rules/array-bracket-spacing.js b/eslint/babel-eslint-plugin/src/rules/array-bracket-spacing.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/array-bracket-spacing.js rename to eslint/babel-eslint-plugin/src/rules/array-bracket-spacing.js diff --git a/eslint/babel-eslint-plugin/rules/arrow-parens.js b/eslint/babel-eslint-plugin/src/rules/arrow-parens.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/arrow-parens.js rename to eslint/babel-eslint-plugin/src/rules/arrow-parens.js diff --git a/eslint/babel-eslint-plugin/rules/camelcase.js b/eslint/babel-eslint-plugin/src/rules/camelcase.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/camelcase.js rename to eslint/babel-eslint-plugin/src/rules/camelcase.js diff --git a/eslint/babel-eslint-plugin/rules/flow-object-type.js b/eslint/babel-eslint-plugin/src/rules/flow-object-type.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/flow-object-type.js rename to eslint/babel-eslint-plugin/src/rules/flow-object-type.js diff --git a/eslint/babel-eslint-plugin/rules/func-params-comma-dangle.js b/eslint/babel-eslint-plugin/src/rules/func-params-comma-dangle.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/func-params-comma-dangle.js rename to eslint/babel-eslint-plugin/src/rules/func-params-comma-dangle.js diff --git a/eslint/babel-eslint-plugin/rules/generator-star-spacing.js b/eslint/babel-eslint-plugin/src/rules/generator-star-spacing.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/generator-star-spacing.js rename to eslint/babel-eslint-plugin/src/rules/generator-star-spacing.js diff --git a/eslint/babel-eslint-plugin/rules/new-cap.js b/eslint/babel-eslint-plugin/src/rules/new-cap.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/new-cap.js rename to eslint/babel-eslint-plugin/src/rules/new-cap.js diff --git a/eslint/babel-eslint-plugin/rules/no-await-in-loop.js b/eslint/babel-eslint-plugin/src/rules/no-await-in-loop.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/no-await-in-loop.js rename to eslint/babel-eslint-plugin/src/rules/no-await-in-loop.js diff --git a/eslint/babel-eslint-plugin/rules/no-invalid-this.js b/eslint/babel-eslint-plugin/src/rules/no-invalid-this.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/no-invalid-this.js rename to eslint/babel-eslint-plugin/src/rules/no-invalid-this.js diff --git a/eslint/babel-eslint-plugin/rules/no-unused-expressions.js b/eslint/babel-eslint-plugin/src/rules/no-unused-expressions.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/no-unused-expressions.js rename to eslint/babel-eslint-plugin/src/rules/no-unused-expressions.js diff --git a/eslint/babel-eslint-plugin/rules/object-curly-spacing.js b/eslint/babel-eslint-plugin/src/rules/object-curly-spacing.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/object-curly-spacing.js rename to eslint/babel-eslint-plugin/src/rules/object-curly-spacing.js diff --git a/eslint/babel-eslint-plugin/rules/object-shorthand.js b/eslint/babel-eslint-plugin/src/rules/object-shorthand.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/object-shorthand.js rename to eslint/babel-eslint-plugin/src/rules/object-shorthand.js diff --git a/eslint/babel-eslint-plugin/rules/quotes.js b/eslint/babel-eslint-plugin/src/rules/quotes.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/quotes.js rename to eslint/babel-eslint-plugin/src/rules/quotes.js diff --git a/eslint/babel-eslint-plugin/rules/semi.js b/eslint/babel-eslint-plugin/src/rules/semi.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/semi.js rename to eslint/babel-eslint-plugin/src/rules/semi.js diff --git a/eslint/babel-eslint-plugin/rules/valid-typeof.js b/eslint/babel-eslint-plugin/src/rules/valid-typeof.js similarity index 100% rename from eslint/babel-eslint-plugin/rules/valid-typeof.js rename to eslint/babel-eslint-plugin/src/rules/valid-typeof.js diff --git a/eslint/babel-eslint-plugin/test/rules/camelcase.js b/eslint/babel-eslint-plugin/test/rules/camelcase.js index af399b4133..f6d1d9249b 100644 --- a/eslint/babel-eslint-plugin/test/rules/camelcase.js +++ b/eslint/babel-eslint-plugin/test/rules/camelcase.js @@ -9,7 +9,7 @@ // Requirements //------------------------------------------------------------------------------ -const rule = require("../../rules/camelcase"), +const rule = require("../../src/rules/camelcase"), RuleTester = require("../helpers/RuleTester"); //------------------------------------------------------------------------------ @@ -21,10 +21,10 @@ const ruleTester = new RuleTester(); ruleTester.run("camelcase", rule, { valid: [ // Original test cases. - "firstName = \"Nicholas\"", - "FIRST_NAME = \"Nicholas\"", - "__myPrivateVariable = \"Patrick\"", - "myPrivateVariable_ = \"Patrick\"", + 'firstName = "Nicholas"', + 'FIRST_NAME = "Nicholas"', + '__myPrivateVariable = "Patrick"', + 'myPrivateVariable_ = "Patrick"', "function doSomething(){}", "do_something()", "new do_something", @@ -42,175 +42,175 @@ ruleTester.run("camelcase", rule, { "if (foo.bar_baz === boom.bam_pow) { [foo.baz_boom] }", { code: "var o = {key: 1}", - options: [{ properties: "always" }] + options: [{ properties: "always" }], }, { code: "var o = {_leading: 1}", - options: [{ properties: "always" }] + options: [{ properties: "always" }], }, { code: "var o = {trailing_: 1}", - options: [{ properties: "always" }] + options: [{ properties: "always" }], }, { code: "var o = {bar_baz: 1}", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "var o = {_leading: 1}", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "var o = {trailing_: 1}", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "obj.a_b = 2;", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "obj._a = 2;", - options: [{ properties: "always" }] + options: [{ properties: "always" }], }, { code: "obj.a_ = 2;", - options: [{ properties: "always" }] + options: [{ properties: "always" }], }, { code: "obj._a = 2;", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "obj.a_ = 2;", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "var obj = {\n a_a: 1 \n};\n obj.a_b = 2;", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "obj.foo_bar = function(){};", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, { code: "var { category_id } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "var { category_id: category_id } = query;", options: [{ ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "var { category_id = 1 } = query;", options: [{ ignoreDestructuring: true }], parserOptions: { ecmaVersion: 6 }, - }, { code: "var { category_id: category } = query;", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "var { _leading } = query;", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "var { trailing_ } = query;", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { - code: "import { camelCased } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + code: 'import { camelCased } from "external module";', + parserOptions: { ecmaVersion: 6, sourceType: "module" }, }, { - code: "import { _leading } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + code: 'import { _leading } from "external module";', + parserOptions: { ecmaVersion: 6, sourceType: "module" }, }, { - code: "import { trailing_ } from \"external module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + code: 'import { trailing_ } from "external module";', + parserOptions: { ecmaVersion: 6, sourceType: "module" }, }, { - code: "import { no_camelcased as camelCased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + code: 'import { no_camelcased as camelCased } from "external-module";', + parserOptions: { ecmaVersion: 6, sourceType: "module" }, }, { - code: "import { no_camelcased as _leading } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + code: 'import { no_camelcased as _leading } from "external-module";', + parserOptions: { ecmaVersion: 6, sourceType: "module" }, }, { - code: "import { no_camelcased as trailing_ } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + code: 'import { no_camelcased as trailing_ } from "external-module";', + parserOptions: { ecmaVersion: 6, sourceType: "module" }, }, { - code: "import { no_camelcased as camelCased, anoterCamelCased } from \"external-module\";", - parserOptions: { ecmaVersion: 6, sourceType: "module" } + code: + 'import { no_camelcased as camelCased, anoterCamelCased } from "external-module";', + parserOptions: { ecmaVersion: 6, sourceType: "module" }, }, { code: "function foo({ no_camelcased: camelCased }) {};", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ no_camelcased: _leading }) {};", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ no_camelcased: trailing_ }) {};", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ camelCased = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ _leading = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ trailing_ = 'default value' }) {};", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ camelCased }) {};", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ _leading }) {}", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, { code: "function foo({ trailing_ }) {}", - parserOptions: { ecmaVersion: 6 } + parserOptions: { ecmaVersion: 6 }, }, // Babel-specific test cases { code: "var foo = bar?.a_b;", - options: [{ properties: "never" }] + options: [{ properties: "never" }], }, ], invalid: [ { - code: "first_name = \"Nicholas\"", + code: 'first_name = "Nicholas"', errors: [ { messageId: "notCamelCase", data: { name: "first_name" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "__private_first_name = \"Patrick\"", + code: '__private_first_name = "Patrick"', errors: [ { messageId: "notCamelCase", data: { name: "__private_first_name" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "function foo_bar(){}", @@ -218,9 +218,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "foo_bar" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "obj.foo_bar = function(){};", @@ -228,9 +228,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "foo_bar" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "bar_baz.foo = function(){};", @@ -238,9 +238,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "bar_baz" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "[foo_bar.baz]", @@ -248,9 +248,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "foo_bar" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }", @@ -258,9 +258,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "foo_bar" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "foo.bar_baz = boom.bam_pow", @@ -268,9 +268,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "bar_baz" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var foo = { bar_baz: boom.bam_pow }", @@ -278,9 +278,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "bar_baz" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "foo.qux.boom_pow = { bar: boom.bam_pow }", @@ -288,9 +288,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "boom_pow" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var o = {bar_baz: 1}", @@ -299,9 +299,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "bar_baz" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "obj.a_b = 2;", @@ -310,9 +310,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "a_b" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var { category_id: category_alias } = query;", @@ -321,9 +321,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "category_alias" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var { category_id: category_alias } = query;", @@ -333,9 +333,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "category_alias" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var { category_id: categoryId, ...other_props } = query;", @@ -345,9 +345,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "other_props" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var { category_id } = query;", @@ -356,9 +356,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "category_id" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var { category_id: category_id } = query;", @@ -367,9 +367,9 @@ ruleTester.run("camelcase", rule, { { messageId: "notCamelCase", data: { name: "category_id" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var { category_id = 1 } = query;", @@ -377,108 +377,111 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'category_id' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import no_camelcased from \"external-module\";", + code: 'import no_camelcased from "external-module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import * as no_camelcased from \"external-module\";", + code: 'import * as no_camelcased from "external-module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import { no_camelcased } from \"external-module\";", + code: 'import { no_camelcased } from "external-module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import { no_camelcased as no_camel_cased } from \"external module\";", + code: + 'import { no_camelcased as no_camel_cased } from "external module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camel_cased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import { camelCased as no_camel_cased } from \"external module\";", + code: 'import { camelCased as no_camel_cased } from "external module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camel_cased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import { camelCased, no_camelcased } from \"external-module\";", + code: 'import { camelCased, no_camelcased } from "external-module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";", + code: + 'import { no_camelcased as camelCased, another_no_camelcased } from "external-module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "another_no_camelcased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import camelCased, { no_camelcased } from \"external-module\";", + code: 'import camelCased, { no_camelcased } from "external-module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";", + code: + 'import no_camelcased, { another_no_camelcased as camelCased } from "external-module";', parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { messageId: "notCamelCase", data: { name: "no_camelcased" }, - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "function foo({ no_camelcased }) {};", @@ -486,9 +489,9 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'no_camelcased' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "function foo({ no_camelcased = 'default value' }) {};", @@ -496,23 +499,24 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'no_camelcased' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { - code: "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}", + code: + "const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}", parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Identifier 'no_camelcased' is not in camel case.", - type: "Identifier" + type: "Identifier", }, { message: "Identifier 'camelcased_value' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "const { bar: no_camelcased } = foo;", @@ -520,9 +524,9 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'no_camelcased' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "function foo({ value_1: my_default }) {}", @@ -530,9 +534,9 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'my_default' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "function foo({ isCamelcased: no_camelcased }) {};", @@ -540,9 +544,9 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'no_camelcased' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "var { foo: bar_baz = 1 } = quz;", @@ -550,9 +554,9 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'bar_baz' is not in camel case.", - type: "Identifier" - } - ] + type: "Identifier", + }, + ], }, { code: "const { no_camelcased = false } = bar;", @@ -560,9 +564,9 @@ ruleTester.run("camelcase", rule, { errors: [ { message: "Identifier 'no_camelcased' is not in camel case.", - type: "Identifier" - } - ] - } - ] + type: "Identifier", + }, + ], + }, + ], }); diff --git a/eslint/babel-eslint-plugin/test/rules/new-cap.js b/eslint/babel-eslint-plugin/test/rules/new-cap.js index 225867e597..1dc8d3069a 100644 --- a/eslint/babel-eslint-plugin/test/rules/new-cap.js +++ b/eslint/babel-eslint-plugin/test/rules/new-cap.js @@ -3,155 +3,298 @@ * @author Nicholas C. Zakas */ -var rule = require('../../rules/new-cap'), - RuleTester = require("../helpers/RuleTester"); +var rule = require("../../src/rules/new-cap"), + RuleTester = require("../helpers/RuleTester"); var ruleTester = new RuleTester(); -ruleTester.run('babel/new-cap', rule, { - valid: [ - // Original test cases. - "var x = new Constructor();", - "var x = new a.b.Constructor();", - "var x = new a.b['Constructor']();", - "var x = new a.b[Constructor]();", - "var x = new a.b[constructor]();", - "var x = new function(){};", - "var x = new _;", - "var x = new $;", - "var x = new Σ;", - "var x = new _x;", - "var x = new $x;", - "var x = new this;", - "var x = Array(42)", - "var x = Boolean(42)", - "var x = Date(42)", - "var x = Date.UTC(2000, 0)", - "var x = Error('error')", - "var x = Function('return 0')", - "var x = Number(42)", - "var x = Object(null)", - "var x = RegExp(42)", - "var x = String(42)", - "var x = Symbol('symbol')", - "var x = _();", - "var x = $();", - { code: "var x = Foo(42)", options: [{ capIsNew: false }] }, - { code: "var x = bar.Foo(42)", options: [{ capIsNew: false }] }, - { code: "var x = Foo.bar(42)", options: [{ capIsNew: false }] }, - "var x = bar[Foo](42)", - { code: "var x = bar['Foo'](42)", options: [{ capIsNew: false }] }, - "var x = Foo.bar(42)", - { code: "var x = new foo(42)", options: [{ newIsCap: false }] }, - "var o = { 1: function() {} }; o[1]();", - "var o = { 1: function() {} }; new o[1]();", - { code: "var x = Foo(42);", options: [{ capIsNew: true, capIsNewExceptions: ["Foo"] }] }, - { code: "var x = Foo(42);", options: [{ capIsNewExceptionPattern: "^Foo" }] }, - { code: "var x = new foo(42);", options: [{ newIsCap: true, newIsCapExceptions: ["foo"] }] }, - { code: "var x = new foo(42);", options: [{ newIsCapExceptionPattern: "^foo" }] }, - { code: "var x = Object(42);", options: [{ capIsNewExceptions: ["Foo"] }] }, +ruleTester.run("babel/new-cap", rule, { + valid: [ + // Original test cases. + "var x = new Constructor();", + "var x = new a.b.Constructor();", + "var x = new a.b['Constructor']();", + "var x = new a.b[Constructor]();", + "var x = new a.b[constructor]();", + "var x = new function(){};", + "var x = new _;", + "var x = new $;", + "var x = new Σ;", + "var x = new _x;", + "var x = new $x;", + "var x = new this;", + "var x = Array(42)", + "var x = Boolean(42)", + "var x = Date(42)", + "var x = Date.UTC(2000, 0)", + "var x = Error('error')", + "var x = Function('return 0')", + "var x = Number(42)", + "var x = Object(null)", + "var x = RegExp(42)", + "var x = String(42)", + "var x = Symbol('symbol')", + "var x = _();", + "var x = $();", + { code: "var x = Foo(42)", options: [{ capIsNew: false }] }, + { code: "var x = bar.Foo(42)", options: [{ capIsNew: false }] }, + { code: "var x = Foo.bar(42)", options: [{ capIsNew: false }] }, + "var x = bar[Foo](42)", + { code: "var x = bar['Foo'](42)", options: [{ capIsNew: false }] }, + "var x = Foo.bar(42)", + { code: "var x = new foo(42)", options: [{ newIsCap: false }] }, + "var o = { 1: function() {} }; o[1]();", + "var o = { 1: function() {} }; new o[1]();", + { + code: "var x = Foo(42);", + options: [{ capIsNew: true, capIsNewExceptions: ["Foo"] }], + }, + { + code: "var x = Foo(42);", + options: [{ capIsNewExceptionPattern: "^Foo" }], + }, + { + code: "var x = new foo(42);", + options: [{ newIsCap: true, newIsCapExceptions: ["foo"] }], + }, + { + code: "var x = new foo(42);", + options: [{ newIsCapExceptionPattern: "^foo" }], + }, + { code: "var x = Object(42);", options: [{ capIsNewExceptions: ["Foo"] }] }, - { code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptions: ["Bar"] }] }, - { code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptions: ["Foo.Bar"] }] }, + { + code: "var x = Foo.Bar(42);", + options: [{ capIsNewExceptions: ["Bar"] }], + }, + { + code: "var x = Foo.Bar(42);", + options: [{ capIsNewExceptions: ["Foo.Bar"] }], + }, - { code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptionPattern: "^Foo\\.." }] }, - { code: "var x = new foo.bar(42);", options: [{ newIsCapExceptions: ["bar"] }] }, - { code: "var x = new foo.bar(42);", options: [{ newIsCapExceptions: ["foo.bar"] }] }, + { + code: "var x = Foo.Bar(42);", + options: [{ capIsNewExceptionPattern: "^Foo\\.." }], + }, + { + code: "var x = new foo.bar(42);", + options: [{ newIsCapExceptions: ["bar"] }], + }, + { + code: "var x = new foo.bar(42);", + options: [{ newIsCapExceptions: ["foo.bar"] }], + }, - { code: "var x = new foo.bar(42);", options: [{ newIsCapExceptionPattern: "^foo\\.." }] }, - { code: "var x = new foo.bar(42);", options: [{ properties: false }] }, - { code: "var x = Foo.bar(42);", options: [{ properties: false }] }, - { code: "var x = foo.Bar(42);", options: [{ capIsNew: false, properties: false }] }, + { + code: "var x = new foo.bar(42);", + options: [{ newIsCapExceptionPattern: "^foo\\.." }], + }, + { code: "var x = new foo.bar(42);", options: [{ properties: false }] }, + { code: "var x = Foo.bar(42);", options: [{ properties: false }] }, + { + code: "var x = foo.Bar(42);", + options: [{ capIsNew: false, properties: false }], + }, - // Babel-specific test cases. - { code: "@MyDecorator(123) class MyClass{}", parser: "babel-eslint" }, - ], - invalid: [ - { code: "var x = new c();", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, - { code: "var x = new φ;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, - { code: "var x = new a.b.c;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, - { code: "var x = new a.b['c'];", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, - { code: "var b = Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, - { code: "var b = a.Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, - { code: "var b = a['Foo']();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, - { code: "var b = a.Date.UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, - { code: "var b = UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, + // Babel-specific test cases. + { code: "@MyDecorator(123) class MyClass{}", parser: "babel-eslint" }, + ], + invalid: [ + { + code: "var x = new c();", + errors: [ { - code: "var a = B.C();", - errors: [ - { - message: "A function with a name starting with an uppercase letter should only be used as a constructor.", - type: "CallExpression", - line: 1, - column: 11 - } - ] + message: + "A constructor name should not start with a lowercase letter.", + type: "NewExpression", }, + ], + }, + { + code: "var x = new φ;", + errors: [ { - code: "var a = B\n.C();", - errors: [ - { - message: "A function with a name starting with an uppercase letter should only be used as a constructor.", - type: "CallExpression", - line: 2, - column: 2 - } - ] + message: + "A constructor name should not start with a lowercase letter.", + type: "NewExpression", }, + ], + }, + { + code: "var x = new a.b.c;", + errors: [ { - code: "var a = new B.c();", - errors: [ - { - message: "A constructor name should not start with a lowercase letter.", - type: "NewExpression", - line: 1, - column: 15 - } - ] + message: + "A constructor name should not start with a lowercase letter.", + type: "NewExpression", }, + ], + }, + { + code: "var x = new a.b['c'];", + errors: [ { - code: "var a = new B.\nc();", - errors: [ - { - message: "A constructor name should not start with a lowercase letter.", - type: "NewExpression", - line: 2, - column: 1 - } - ] + message: + "A constructor name should not start with a lowercase letter.", + type: "NewExpression", }, + ], + }, + { + code: "var b = Foo();", + errors: [ { - code: "var a = new c();", - errors: [ - { - message: "A constructor name should not start with a lowercase letter.", - type: "NewExpression", - line: 1, - column: 13 - } - ] + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", + type: "CallExpression", }, + ], + }, + { + code: "var b = a.Foo();", + errors: [ + { + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", + type: "CallExpression", + }, + ], + }, + { + code: "var b = a['Foo']();", + errors: [ + { + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", + type: "CallExpression", + }, + ], + }, + { + code: "var b = a.Date.UTC();", + errors: [ + { + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", + type: "CallExpression", + }, + ], + }, + { + code: "var b = UTC();", + errors: [ + { + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", + type: "CallExpression", + }, + ], + }, + { + code: "var a = B.C();", + errors: [ + { + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", + type: "CallExpression", + line: 1, + column: 11, + }, + ], + }, + { + code: "var a = B\n.C();", + errors: [ + { + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", + type: "CallExpression", + line: 2, + column: 2, + }, + ], + }, + { + code: "var a = new B.c();", + errors: [ + { + message: + "A constructor name should not start with a lowercase letter.", + type: "NewExpression", + line: 1, + column: 15, + }, + ], + }, + { + code: "var a = new B.\nc();", + errors: [ + { + message: + "A constructor name should not start with a lowercase letter.", + type: "NewExpression", + line: 2, + column: 1, + }, + ], + }, + { + code: "var a = new c();", + errors: [ + { + message: + "A constructor name should not start with a lowercase letter.", + type: "NewExpression", + line: 1, + column: 13, + }, + ], + }, + { + code: "var x = Foo.Bar(42);", + options: [{ capIsNewExceptions: ["Foo"] }], + errors: [ { - code: "var x = Foo.Bar(42);", - options: [{ capIsNewExceptions: ["Foo"] }], - errors: [{ type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor." }] + type: "CallExpression", + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", }, - { - code: "var x = Bar.Foo(42);", + ], + }, + { + code: "var x = Bar.Foo(42);", - options: [{ capIsNewExceptionPattern: "^Foo\\.." }], - errors: [{ type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor." }] - }, + options: [{ capIsNewExceptionPattern: "^Foo\\.." }], + errors: [ { - code: "var x = new foo.bar(42);", - options: [{ newIsCapExceptions: ["foo"] }], - errors: [{ type: "NewExpression", message: "A constructor name should not start with a lowercase letter." }] + type: "CallExpression", + message: + "A function with a name starting with an uppercase letter should only be used as a constructor.", }, + ], + }, + { + code: "var x = new foo.bar(42);", + options: [{ newIsCapExceptions: ["foo"] }], + errors: [ { - code: "var x = new bar.foo(42);", + type: "NewExpression", + message: + "A constructor name should not start with a lowercase letter.", + }, + ], + }, + { + code: "var x = new bar.foo(42);", - options: [{ newIsCapExceptionPattern: "^foo\\.." }], - errors: [{ type: "NewExpression", message: "A constructor name should not start with a lowercase letter." }] - } - ] + options: [{ newIsCapExceptionPattern: "^foo\\.." }], + errors: [ + { + type: "NewExpression", + message: + "A constructor name should not start with a lowercase letter.", + }, + ], + }, + ], }); diff --git a/eslint/babel-eslint-plugin/test/rules/no-invalid-this.js b/eslint/babel-eslint-plugin/test/rules/no-invalid-this.js index b4c385b466..7264a030f0 100644 --- a/eslint/babel-eslint-plugin/test/rules/no-invalid-this.js +++ b/eslint/babel-eslint-plugin/test/rules/no-invalid-this.js @@ -10,8 +10,8 @@ //------------------------------------------------------------------------------ const cloneDeep = require("lodash.clonedeep"); -const rule = require("../../rules/no-invalid-this"), - RuleTester = require("../helpers/RuleTester"); +const rule = require("../../src/rules/no-invalid-this"), + RuleTester = require("../helpers/RuleTester"); //------------------------------------------------------------------------------ // Helpers @@ -22,7 +22,7 @@ const rule = require("../../rules/no-invalid-this"), * @returns {void} */ function NORMAL(pattern) { - pattern.parserOptions.sourceType = "script"; + pattern.parserOptions.sourceType = "script"; } /** @@ -32,7 +32,7 @@ function NORMAL(pattern) { * @returns {void} */ function USE_STRICT(pattern) { - pattern.code = "\"use strict\"; " + pattern.code; + pattern.code = '"use strict"; ' + pattern.code; } /** @@ -42,9 +42,9 @@ function USE_STRICT(pattern) { * @returns {void} */ function IMPLIED_STRICT(pattern) { - pattern.code = "/* implied strict mode */ " + pattern.code; - pattern.parserOptions.ecmaFeatures = pattern.parserOptions.ecmaFeatures || {}; - pattern.parserOptions.ecmaFeatures.impliedStrict = true; + pattern.code = "/* implied strict mode */ " + pattern.code; + pattern.parserOptions.ecmaFeatures = pattern.parserOptions.ecmaFeatures || {}; + pattern.parserOptions.ecmaFeatures.impliedStrict = true; } /** @@ -54,7 +54,7 @@ function IMPLIED_STRICT(pattern) { * @returns {void} */ function MODULES(pattern) { - pattern.code = "/* modules */ " + pattern.code; + pattern.code = "/* modules */ " + pattern.code; } /** @@ -64,564 +64,625 @@ function MODULES(pattern) { * @returns {Object[]} Test patterns. */ function extractPatterns(patterns, type) { + // Clone and apply the pattern environment. + const patternsList = patterns.map(function(pattern) { + return pattern[type].map(function(applyCondition) { + const thisPattern = cloneDeep(pattern); - // Clone and apply the pattern environment. - const patternsList = patterns.map(function(pattern) { - return pattern[type].map(function(applyCondition) { - const thisPattern = cloneDeep(pattern); + applyCondition(thisPattern); - applyCondition(thisPattern); + if (type === "valid") { + thisPattern.errors = []; + } else { + thisPattern.code += " /* should error */"; + } - if (type === "valid") { - thisPattern.errors = []; - } else { - thisPattern.code += " /* should error */"; - } + delete thisPattern.invalid; + delete thisPattern.valid; - delete thisPattern.invalid; - delete thisPattern.valid; - - return thisPattern; - }); + return thisPattern; }); + }); - // Flatten. - return Array.prototype.concat.apply([], patternsList); + // Flatten. + return Array.prototype.concat.apply([], patternsList); } - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ const errors = [ - {message: "Unexpected 'this'.", type: "ThisExpression"}, - {message: "Unexpected 'this'.", type: "ThisExpression"} + { message: "Unexpected 'this'.", type: "ThisExpression" }, + { message: "Unexpected 'this'.", type: "ThisExpression" }, ]; const patterns = [ + // Global. + { + code: "console.log(this); z(x => console.log(x, this));", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: "console.log(this); z(x => console.log(x, this));", + parserOptions: { + ecmaVersion: 6, + ecmaFeatures: { globalReturn: true }, + }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, - // Global. - { - code: "console.log(this); z(x => console.log(x, this));", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "console.log(this); z(x => console.log(x, this));", - parserOptions: { - ecmaVersion: 6, - ecmaFeatures: {globalReturn: true} - }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, + // IIFE. + { + code: + "(function() { console.log(this); z(x => console.log(x, this)); })();", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, - // IIFE. - { - code: "(function() { console.log(this); z(x => console.log(x, this)); })();", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] + // Just functions. + { + code: "function foo() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + 'function foo() { "use strict"; console.log(this); z(x => console.log(x, this)); }', + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [], + invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "return function() { console.log(this); z(x => console.log(x, this)); };", + parserOptions: { + ecmaVersion: 6, + ecmaFeatures: { globalReturn: true }, }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT], // modules cannot return on global. + }, + { + code: + "var foo = (function() { console.log(this); z(x => console.log(x, this)); }).bar(obj);", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, - // Just functions. - { - code: "function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "function foo() { \"use strict\"; console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [], - invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "return function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { - ecmaVersion: 6, - ecmaFeatures: {globalReturn: true} - }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT] // modules cannot return on global. - }, - { - code: "var foo = (function() { console.log(this); z(x => console.log(x, this)); }).bar(obj);", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, + // Functions in methods. + { + code: + "var obj = {foo: function() { function foo() { console.log(this); z(x => console.log(x, this)); } foo(); }};", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "var obj = {foo() { function foo() { console.log(this); z(x => console.log(x, this)); } foo(); }};", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "var obj = {foo: function() { return function() { console.log(this); z(x => console.log(x, this)); }; }};", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + 'var obj = {foo: function() { "use strict"; return function() { console.log(this); z(x => console.log(x, this)); }; }};', + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [], + invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "obj.foo = function() { return function() { console.log(this); z(x => console.log(x, this)); }; };", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + 'obj.foo = function() { "use strict"; return function() { console.log(this); z(x => console.log(x, this)); }; };', + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [], + invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "class A { foo() { return function() { console.log(this); z(x => console.log(x, this)); }; } }", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [], + invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + }, - // Functions in methods. - { - code: "var obj = {foo: function() { function foo() { console.log(this); z(x => console.log(x, this)); } foo(); }};", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "var obj = {foo() { function foo() { console.log(this); z(x => console.log(x, this)); } foo(); }};", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "var obj = {foo: function() { return function() { console.log(this); z(x => console.log(x, this)); }; }};", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "var obj = {foo: function() { \"use strict\"; return function() { console.log(this); z(x => console.log(x, this)); }; }};", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [], - invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "obj.foo = function() { return function() { console.log(this); z(x => console.log(x, this)); }; };", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "obj.foo = function() { \"use strict\"; return function() { console.log(this); z(x => console.log(x, this)); }; };", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [], - invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "class A { foo() { return function() { console.log(this); z(x => console.log(x, this)); }; } }", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [], - invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES] - }, + // Class Static methods. + { + code: + "class A {static foo() { console.log(this); z(x => console.log(x, this)); }};", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // Class Static methods. - { - code: "class A {static foo() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // Constructors. + { + code: "function Foo() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "var Foo = function Foo() { console.log(this); z(x => console.log(x, this)); };", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "class A {constructor() { console.log(this); z(x => console.log(x, this)); }};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // Constructors. - { - code: "function Foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "var Foo = function Foo() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "class A {constructor() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // On a property. + { + code: + "var obj = {foo: function() { console.log(this); z(x => console.log(x, this)); }};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "var obj = {foo() { console.log(this); z(x => console.log(x, this)); }};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "var obj = {foo: foo || function() { console.log(this); z(x => console.log(x, this)); }};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "var obj = {foo: hasNative ? foo : function() { console.log(this); z(x => console.log(x, this)); }};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "var obj = {foo: (function() { return function() { console.log(this); z(x => console.log(x, this)); }; })()};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + 'Object.defineProperty(obj, "foo", {value: function() { console.log(this); z(x => console.log(x, this)); }})', + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "Object.defineProperties(obj, {foo: {value: function() { console.log(this); z(x => console.log(x, this)); }}})", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // On a property. - { - code: "var obj = {foo: function() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "var obj = {foo() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "var obj = {foo: foo || function() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "var obj = {foo: hasNative ? foo : function() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "var obj = {foo: (function() { return function() { console.log(this); z(x => console.log(x, this)); }; })()};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "Object.defineProperty(obj, \"foo\", {value: function() { console.log(this); z(x => console.log(x, this)); }})", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "Object.defineProperties(obj, {foo: {value: function() { console.log(this); z(x => console.log(x, this)); }}})", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // Assigns to a property. + { + code: + "obj.foo = function() { console.log(this); z(x => console.log(x, this)); };", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "obj.foo = foo || function() { console.log(this); z(x => console.log(x, this)); };", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "obj.foo = foo ? bar : function() { console.log(this); z(x => console.log(x, this)); };", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "obj.foo = (function() { return function() { console.log(this); z(x => console.log(x, this)); }; })();", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // Assigns to a property. - { - code: "obj.foo = function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "obj.foo = foo || function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "obj.foo = foo ? bar : function() { console.log(this); z(x => console.log(x, this)); };", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "obj.foo = (function() { return function() { console.log(this); z(x => console.log(x, this)); }; })();", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // Class Instance Methods. + { + code: + "class A {foo() { console.log(this); z(x => console.log(x, this)); }};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // Class Instance Methods. - { - code: "class A {foo() { console.log(this); z(x => console.log(x, this)); }};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // Bind/Call/Apply + { + code: + "var foo = function() { console.log(this); z(x => console.log(x, this)); }.bind(obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "var foo = function() { console.log(this); z(x => console.log(x, this)); }.bind(null);", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "(function() { console.log(this); z(x => console.log(x, this)); }).call(obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "(function() { console.log(this); z(x => console.log(x, this)); }).call(undefined);", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "(function() { console.log(this); z(x => console.log(x, this)); }).apply(obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "(function() { console.log(this); z(x => console.log(x, this)); }).apply(void 0);", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "Reflect.apply(function() { console.log(this); z(x => console.log(x, this)); }, obj, []);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // Bind/Call/Apply - { - code: "var foo = function() { console.log(this); z(x => console.log(x, this)); }.bind(obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "var foo = function() { console.log(this); z(x => console.log(x, this)); }.bind(null);", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "(function() { console.log(this); z(x => console.log(x, this)); }).call(obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "(function() { console.log(this); z(x => console.log(x, this)); }).call(undefined);", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "(function() { console.log(this); z(x => console.log(x, this)); }).apply(obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "(function() { console.log(this); z(x => console.log(x, this)); }).apply(void 0);", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "Reflect.apply(function() { console.log(this); z(x => console.log(x, this)); }, obj, []);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // Array methods. + { + code: + "Array.from([], function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo.every(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo.filter(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo.find(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo.findIndex(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo.forEach(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo.map(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo.some(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "Array.from([], function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.every(function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.filter(function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.find(function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.findIndex(function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.forEach(function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.map(function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.some(function() { console.log(this); z(x => console.log(x, this)); }, obj);", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "foo.forEach(function() { console.log(this); z(x => console.log(x, this)); }, null);", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, - // Array methods. - { - code: "Array.from([], function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo.every(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo.filter(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo.find(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo.findIndex(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo.forEach(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo.map(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo.some(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "Array.from([], function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.every(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.filter(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.find(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.findIndex(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.forEach(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.map(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.some(function() { console.log(this); z(x => console.log(x, this)); }, obj);", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "foo.forEach(function() { console.log(this); z(x => console.log(x, this)); }, null);", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, + // @this tag. + { + code: + "/** @this Obj */ function foo() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "/**\n * @returns {void}\n * @this Obj\n */\nfunction foo() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "/** @returns {void} */ function foo() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "/** @this Obj */ foo(function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "foo(/* @this Obj */ function() { console.log(this); z(x => console.log(x, this)); });", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // @this tag. - { - code: "/** @this Obj */ function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "/**\n * @returns {void}\n * @this Obj\n */\nfunction foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "/** @returns {void} */ function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "/** @this Obj */ foo(function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "foo(/* @this Obj */ function() { console.log(this); z(x => console.log(x, this)); });", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // https://github.com/eslint/eslint/issues/3254 + { + code: "function foo() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, - // https://github.com/eslint/eslint/issues/3254 - { - code: "function foo() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, + // https://github.com/eslint/eslint/issues/3287 + { + code: + "function foo() { /** @this Obj*/ return function bar() { console.log(this); z(x => console.log(x, this)); }; }", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // https://github.com/eslint/eslint/issues/3287 - { - code: "function foo() { /** @this Obj*/ return function bar() { console.log(this); z(x => console.log(x, this)); }; }", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // https://github.com/eslint/eslint/issues/6824 + { + code: + "var Ctor = function() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "var func = function() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "Ctor = function() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "func = function() { console.log(this); z(x => console.log(x, this)); }", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "function foo(Ctor = function() { console.log(this); z(x => console.log(x, this)); }) {}", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "function foo(func = function() { console.log(this); z(x => console.log(x, this)); }) {}", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, + { + code: + "[obj.method = function() { console.log(this); z(x => console.log(x, this)); }] = a", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, + { + code: + "[func = function() { console.log(this); z(x => console.log(x, this)); }] = a", + parserOptions: { ecmaVersion: 6 }, + errors, + valid: [NORMAL], + invalid: [USE_STRICT, IMPLIED_STRICT, MODULES], + }, - // https://github.com/eslint/eslint/issues/6824 - { - code: "var Ctor = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "var func = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "Ctor = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "func = function() { console.log(this); z(x => console.log(x, this)); }", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "function foo(Ctor = function() { console.log(this); z(x => console.log(x, this)); }) {}", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "function foo(func = function() { console.log(this); z(x => console.log(x, this)); }) {}", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, - { - code: "[obj.method = function() { console.log(this); z(x => console.log(x, this)); }] = a", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - { - code: "[func = function() { console.log(this); z(x => console.log(x, this)); }] = a", - parserOptions: { ecmaVersion: 6 }, - errors, - valid: [NORMAL], - invalid: [USE_STRICT, IMPLIED_STRICT, MODULES] - }, + // babel/no-invalid-this - // babel/no-invalid-this + // Class Instance Properties. + { + code: "class A {a = this.b;};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // Class Instance Properties. - { - code: "class A {a = this.b;};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + { + code: "class A {a = () => {return this.b;};};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - { - code: "class A {a = () => {return this.b;};};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + // Class Private Instance Properties. + { + code: "class A {#a = this.b;};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, - // Class Private Instance Properties. - { - code: "class A {#a = this.b;};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, - - { - code: "class A {#a = () => {return this.b;};};", - parserOptions: { ecmaVersion: 6 }, - valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], - invalid: [] - }, + { + code: "class A {#a = () => {return this.b;};};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [], + }, ]; const ruleTester = new RuleTester(); ruleTester.run("no-invalid-this", rule, { - valid: extractPatterns(patterns, "valid"), - invalid: extractPatterns(patterns, "invalid") + valid: extractPatterns(patterns, "valid"), + invalid: extractPatterns(patterns, "invalid"), }); diff --git a/eslint/babel-eslint-plugin/test/rules/no-unused-expressions.js b/eslint/babel-eslint-plugin/test/rules/no-unused-expressions.js index b7d4ca6e7b..fc07ad73d5 100644 --- a/eslint/babel-eslint-plugin/test/rules/no-unused-expressions.js +++ b/eslint/babel-eslint-plugin/test/rules/no-unused-expressions.js @@ -9,8 +9,8 @@ // Requirements //------------------------------------------------------------------------------ -const rule = require("../../rules/no-unused-expressions"), - RuleTester = require("../helpers/RuleTester"); +const rule = require("../../src/rules/no-unused-expressions"), + RuleTester = require("../helpers/RuleTester"); //------------------------------------------------------------------------------ // Tests @@ -19,126 +19,372 @@ const rule = require("../../rules/no-unused-expressions"), const ruleTester = new RuleTester(); ruleTester.run("no-unused-expressions", rule, { - valid: [ - // Original test cases. - "function f(){}", - "a = b", - "new a", - "{}", - "f(); g()", - "i++", - "a()", - { code: "a && a()", options: [{ allowShortCircuit: true }] }, - { code: "a() || (b = c)", options: [{ allowShortCircuit: true }] }, - { code: "a ? b() : c()", options: [{ allowTernary: true }] }, - { code: "a ? b() || (c = d) : e()", options: [{ allowShortCircuit: true, allowTernary: true }] }, - "delete foo.bar", - "void new C", - "\"use strict\";", - "\"directive one\"; \"directive two\"; f();", - "function foo() {\"use strict\"; return true; }", - { code: "var foo = () => {\"use strict\"; return true; }", parserOptions: { ecmaVersion: 6 } }, - "function foo() {\"directive one\"; \"directive two\"; f(); }", - "function foo() { var foo = \"use strict\"; return true; }", - { - code: "function* foo(){ yield 0; }", - parserOptions: { ecmaVersion: 6 } - }, - { - code: "async function foo() { await 5; }", - parserOptions: { ecmaVersion: 8 } - }, - { - code: "async function foo() { await foo.bar; }", - parserOptions: { ecmaVersion: 8 } - }, - { - code: "async function foo() { bar && await baz; }", - options: [{ allowShortCircuit: true }], - parserOptions: { ecmaVersion: 8 } - }, - { - code: "async function foo() { foo ? await bar : await baz; }", - options: [{ allowTernary: true }], - parserOptions: { ecmaVersion: 8 } - }, - { - code: "tag`tagged template literal`", - options: [{ allowTaggedTemplates: true }], - parserOptions: { ecmaVersion: 6 } - }, - { - code: "shouldNotBeAffectedByAllowTemplateTagsOption()", - options: [{ allowTaggedTemplates: true }], - parserOptions: { ecmaVersion: 6 } - }, + valid: [ + // Original test cases. + "function f(){}", + "a = b", + "new a", + "{}", + "f(); g()", + "i++", + "a()", + { code: "a && a()", options: [{ allowShortCircuit: true }] }, + { code: "a() || (b = c)", options: [{ allowShortCircuit: true }] }, + { code: "a ? b() : c()", options: [{ allowTernary: true }] }, + { + code: "a ? b() || (c = d) : e()", + options: [{ allowShortCircuit: true, allowTernary: true }], + }, + "delete foo.bar", + "void new C", + '"use strict";', + '"directive one"; "directive two"; f();', + 'function foo() {"use strict"; return true; }', + { + code: 'var foo = () => {"use strict"; return true; }', + parserOptions: { ecmaVersion: 6 }, + }, + 'function foo() {"directive one"; "directive two"; f(); }', + 'function foo() { var foo = "use strict"; return true; }', + { + code: "function* foo(){ yield 0; }", + parserOptions: { ecmaVersion: 6 }, + }, + { + code: "async function foo() { await 5; }", + parserOptions: { ecmaVersion: 8 }, + }, + { + code: "async function foo() { await foo.bar; }", + parserOptions: { ecmaVersion: 8 }, + }, + { + code: "async function foo() { bar && await baz; }", + options: [{ allowShortCircuit: true }], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: "async function foo() { foo ? await bar : await baz; }", + options: [{ allowTernary: true }], + parserOptions: { ecmaVersion: 8 }, + }, + { + code: "tag`tagged template literal`", + options: [{ allowTaggedTemplates: true }], + parserOptions: { ecmaVersion: 6 }, + }, + { + code: "shouldNotBeAffectedByAllowTemplateTagsOption()", + options: [{ allowTaggedTemplates: true }], + parserOptions: { ecmaVersion: 6 }, + }, - // Babel-specific test cases. - "let a = do { if (foo) { foo.bar; } }", - "let a = do { foo; }", - "let a = do { let b = 2; foo; }", - "let a = do { (foo + 1); }", - "let a = do { if (foo) { if (foo.bar) { foo.bar; } } }", - "let a = do { if (foo) { if (foo.bar) { foo.bar; } else if (foo.baz) { foo.baz; } } }", - "foo.bar?.();", + // Babel-specific test cases. + "let a = do { if (foo) { foo.bar; } }", + "let a = do { foo; }", + "let a = do { let b = 2; foo; }", + "let a = do { (foo + 1); }", + "let a = do { if (foo) { if (foo.bar) { foo.bar; } } }", + "let a = do { if (foo) { if (foo.bar) { foo.bar; } else if (foo.baz) { foo.baz; } } }", + "foo.bar?.();", + ], + invalid: [ + { + code: "0", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "f(), 0", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "{0}", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "[]", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a && b();", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a() || false", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a || (b = c)", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a ? b() || (c = d) : e", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "`untagged template literal`", + parserOptions: { ecmaVersion: 6 }, + errors: [ + "Expected an assignment or function call and instead saw an expression.", + ], + }, + { + code: "tag`tagged template literal`", + parserOptions: { ecmaVersion: 6 }, + errors: [ + "Expected an assignment or function call and instead saw an expression.", + ], + }, + { + code: "a && b()", + options: [{ allowTernary: true }], + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a ? b() : c()", + options: [{ allowShortCircuit: true }], + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a || b", + options: [{ allowShortCircuit: true }], + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a() && b", + options: [{ allowShortCircuit: true }], + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a ? b : 0", + options: [{ allowTernary: true }], + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "a ? b : c()", + options: [{ allowTernary: true }], + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "foo.bar;", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "!a", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "+a", + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: '"directive one"; f(); "directive two";', + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: 'function foo() {"directive one"; f(); "directive two"; }', + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: 'if (0) { "not a directive"; f(); }', + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: 'function foo() { var foo = true; "use strict"; }', + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: 'var foo = () => { var foo = true; "use strict"; }', + parserOptions: { ecmaVersion: 6 }, + errors: [ + { + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", + }, + ], + }, + { + code: "`untagged template literal`", + options: [{ allowTaggedTemplates: true }], + parserOptions: { ecmaVersion: 6 }, + errors: [ + "Expected an assignment or function call and instead saw an expression.", + ], + }, + { + code: "`untagged template literal`", + options: [{ allowTaggedTemplates: false }], + parserOptions: { ecmaVersion: 6 }, + errors: [ + "Expected an assignment or function call and instead saw an expression.", + ], + }, + { + code: "tag`tagged template literal`", + options: [{ allowTaggedTemplates: false }], + parserOptions: { ecmaVersion: 6 }, + errors: [ + "Expected an assignment or function call and instead saw an expression.", + ], + }, - ], - invalid: [ - { code: "0", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "f(), 0", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "{0}", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "[]", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a && b();", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a() || false", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a || (b = c)", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b() || (c = d) : e", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, + // Babel-specific test cases. + { + code: "let a = do { foo; let b = 2; }", + errors: [ { - code: "`untagged template literal`", - parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", }, + ], + }, + { + code: "let a = do { if (foo) { foo.bar } else { a; bar.foo } }", + errors: [ { - code: "tag`tagged template literal`", - parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] + message: + "Expected an assignment or function call and instead saw an expression.", + type: "ExpressionStatement", }, - { code: "a && b()", options: [{ allowTernary: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b() : c()", options: [{ allowShortCircuit: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a || b", options: [{ allowShortCircuit: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a() && b", options: [{ allowShortCircuit: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b : 0", options: [{ allowTernary: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b : c()", options: [{ allowTernary: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "foo.bar;", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "!a", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "+a", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "\"directive one\"; f(); \"directive two\";", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "function foo() {\"directive one\"; f(); \"directive two\"; }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "if (0) { \"not a directive\"; f(); }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "function foo() { var foo = true; \"use strict\"; }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "var foo = () => { var foo = true; \"use strict\"; }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { - code: "`untagged template literal`", - options: [{ allowTaggedTemplates: true }], - parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] - }, - { - code: "`untagged template literal`", - options: [{ allowTaggedTemplates: false }], - parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] - }, - { - code: "tag`tagged template literal`", - options: [{ allowTaggedTemplates: false }], - parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] - }, - - // Babel-specific test cases. - { code: "let a = do { foo; let b = 2; }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "let a = do { if (foo) { foo.bar } else { a; bar.foo } }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - - ] + ], + }, + ], }); diff --git a/eslint/babel-eslint-plugin/test/rules/object-curly-spacing.js b/eslint/babel-eslint-plugin/test/rules/object-curly-spacing.js index cf5315102d..ff51d248ba 100644 --- a/eslint/babel-eslint-plugin/test/rules/object-curly-spacing.js +++ b/eslint/babel-eslint-plugin/test/rules/object-curly-spacing.js @@ -6,836 +6,1133 @@ * @copyright 2015 Mathieu M-Gosselin. All rights reserved. */ -var rule = require('../../rules/object-curly-spacing'), - RuleTester = require("../helpers/RuleTester"); +var rule = require("../../src/rules/object-curly-spacing"), + RuleTester = require("../helpers/RuleTester"); var ruleTester = new RuleTester(); -ruleTester.run('babel/object-curly-spacing', rule, { +ruleTester.run("babel/object-curly-spacing", rule, { + valid: [ + // always - object literals + { code: "var obj = { foo: bar, baz: qux };", options: ["always"] }, + { + code: "var obj = { foo: { bar: quxx }, baz: qux };", + options: ["always"], + }, + { code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["always"] }, - valid: [ + // always - destructuring + { + code: "var { x } = y", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var { x, y } = y", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var { x,y } = y", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {\nx,y } = y", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {\nx,y\n} = z", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var { x = 10, y } = y", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var { x: { z }, y } = y", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {\ny,\n} = x", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var { y, } = x", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var { y: x } = x", + options: ["always"], + ecmaFeatures: { destructuring: true }, + }, - // always - object literals - { code: "var obj = { foo: bar, baz: qux };", options: ["always"] }, - { code: "var obj = { foo: { bar: quxx }, baz: qux };", options: ["always"] }, - { code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["always"] }, + // always - import / export + { + code: "import door from 'room'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import * as door from 'room'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import { door } from 'room'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\ndoor } from 'room'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "export { door } from 'room'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import { house, mouse } from 'caravan'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\nhouse,\nmouse\n} from 'caravan'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\nhouse,\nmouse,\n} from 'caravan'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import house, { mouse } from 'caravan'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import door, { house, mouse } from 'caravan'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "export { door }", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {\ndoor,\nhouse\n}", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {\ndoor,\nhouse,\n}", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import 'room'", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import { bar as x } from 'foo';", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import { x, } from 'foo';", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\nx,\n} from 'foo';", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "export { x, } from 'foo';", + options: ["always"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {\nx,\n} from 'foo';", + options: ["always"], + ecmaFeatures: { modules: true }, + }, - // always - destructuring - { code: "var { x } = y", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var { x, y } = y", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var { x,y } = y", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var {\nx,y } = y", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var {\nx,y\n} = z", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var { x = 10, y } = y", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var { x: { z }, y } = y", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var {\ny,\n} = x", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var { y, } = x", options: ["always"], ecmaFeatures: { destructuring: true } }, - { code: "var { y: x } = x", options: ["always"], ecmaFeatures: { destructuring: true } }, + // always - empty object + { code: "var foo = {};", options: ["always"] }, - // always - import / export - { code: "import door from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import * as door from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import { door } from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import {\ndoor } from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "export { door } from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import { house, mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import {\nhouse,\nmouse\n} from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import {\nhouse,\nmouse,\n} from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import house, { mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import door, { house, mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "export { door }", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "export {\ndoor,\nhouse\n}", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "export {\ndoor,\nhouse,\n}", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import 'room'", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import { bar as x } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import { x, } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "import {\nx,\n} from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "export { x, } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, - { code: "export {\nx,\n} from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, + // always - objectsInObjects + { + code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", + options: ["always", { objectsInObjects: false }], + }, - // always - empty object - { code: "var foo = {};", options: ["always"] }, + // always - arraysInObjects + { + code: "var obj = { 'foo': [ 1, 2 ]};", + options: ["always", { arraysInObjects: false }], + }, - // always - objectsInObjects - { code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", options: ["always", {"objectsInObjects": false}] }, + // always - arraysInObjects, objectsInObjects + { + code: "var obj = { 'qux': [ 1, 2 ], 'foo': { 'bar': 1, 'baz': 2 }};", + options: ["always", { arraysInObjects: false, objectsInObjects: false }], + }, - // always - arraysInObjects - { code: "var obj = { 'foo': [ 1, 2 ]};", options: ["always", {"arraysInObjects": false}] }, + // always - arraysInObjects, objectsInObjects (reverse) + { + code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }, 'qux': [ 1, 2 ]};", + options: ["always", { arraysInObjects: false, objectsInObjects: false }], + }, - // always - arraysInObjects, objectsInObjects - { code: "var obj = { 'qux': [ 1, 2 ], 'foo': { 'bar': 1, 'baz': 2 }};", options: ["always", {"arraysInObjects": false, "objectsInObjects": false}] }, + // never + { code: "var obj = {foo: bar,\nbaz: qux\n};", options: ["never"] }, + { code: "var obj = {\nfoo: bar,\nbaz: qux};", options: ["never"] }, - // always - arraysInObjects, objectsInObjects (reverse) - { code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }, 'qux': [ 1, 2 ]};", options: ["always", {"arraysInObjects": false, "objectsInObjects": false}] }, + // never - object literals + { code: "var obj = {foo: bar, baz: qux};", options: ["never"] }, + { code: "var obj = {foo: {bar: quxx}, baz: qux};", options: ["never"] }, + { code: "var obj = {foo: {\nbar: quxx}, baz: qux\n};", options: ["never"] }, + { code: "var obj = {foo: {\nbar: quxx\n}, baz: qux};", options: ["never"] }, + { code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["never"] }, - // never - { code: "var obj = {foo: bar,\nbaz: qux\n};", options: ["never"] }, - { code: "var obj = {\nfoo: bar,\nbaz: qux};", options: ["never"] }, + // never - destructuring + { + code: "var {x} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {x, y} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {x,y} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {\nx,y\n} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {x = 10} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {x = 10, y} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {x: {z}, y} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {\nx: {z\n}, y} = y", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {\ny,\n} = x", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {y,} = x", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {y:x} = x", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, - // never - object literals - { code: "var obj = {foo: bar, baz: qux};", options: ["never"] }, - { code: "var obj = {foo: {bar: quxx}, baz: qux};", options: ["never"] }, - { code: "var obj = {foo: {\nbar: quxx}, baz: qux\n};", options: ["never"] }, - { code: "var obj = {foo: {\nbar: quxx\n}, baz: qux};", options: ["never"] }, - { code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["never"] }, + // never - import / export + { + code: "import door from 'room'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import * as door from 'room'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {door} from 'room'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {door} from 'room'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\ndoor} from 'room'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {\ndoor\n} from 'room'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {house,mouse} from 'caravan'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {house, mouse} from 'caravan'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\nhouse,\nmouse} from 'caravan'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\nhouse,\nmouse,\n} from 'caravan'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {door}", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {\ndoor,\nmouse\n}", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {\ndoor,\nmouse,\n}", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import 'room'", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import x, {bar} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import x, {bar, baz} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {bar as y} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {x,} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "import {\nx,\n} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {x,} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {\nx,\n} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, - // never - destructuring - { code: "var {x} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {x, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {x,y} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {\nx,y\n} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {x = 10} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {x = 10, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {x: {z}, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {\nx: {z\n}, y} = y", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {\ny,\n} = x", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {y,} = x", options: ["never"], ecmaFeatures: { destructuring: true } }, - { code: "var {y:x} = x", options: ["never"], ecmaFeatures: { destructuring: true } }, + // never - empty object + { code: "var foo = {};", options: ["never"] }, - // never - import / export - { code: "import door from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import * as door from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {door} from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "export {door} from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {\ndoor} from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "export {\ndoor\n} from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {house,mouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {house, mouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {\nhouse,\nmouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {\nhouse,\nmouse,\n} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "export {door}", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "export {\ndoor,\nmouse\n}", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "export {\ndoor,\nmouse,\n}", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import 'room'", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import x, {bar} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import x, {bar, baz} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {bar as y} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {x,} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "import {\nx,\n} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "export {x,} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, - { code: "export {\nx,\n} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, + // never - objectsInObjects + { + code: "var obj = {'foo': {'bar': 1, 'baz': 2} };", + options: ["never", { objectsInObjects: true }], + }, + // https://github.com/eslint/eslint/issues/3658 + // Empty cases. + { code: "var {} = foo;", ecmaFeatures: { destructuring: true } }, + { code: "var [] = foo;", ecmaFeatures: { destructuring: true } }, + { code: "var {a: {}} = foo;", ecmaFeatures: { destructuring: true } }, + { code: "var {a: []} = foo;", ecmaFeatures: { destructuring: true } }, + { code: "import {} from 'foo';", ecmaFeatures: { modules: true } }, + { code: "export {} from 'foo';", ecmaFeatures: { modules: true } }, + { code: "export {};", ecmaFeatures: { modules: true } }, + { + code: "var {} = foo;", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var [] = foo;", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {a: {}} = foo;", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "var {a: []} = foo;", + options: ["never"], + ecmaFeatures: { destructuring: true }, + }, + { + code: "import {} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { + code: "export {} from 'foo';", + options: ["never"], + ecmaFeatures: { modules: true }, + }, + { code: "export {};", options: ["never"], ecmaFeatures: { modules: true } }, - // never - empty object - { code: "var foo = {};", options: ["never"] }, + // Babel test cases. + { + code: 'export * as x from "mod";', + parser: "babel-eslint", + ecmaFeatures: { modules: true }, + }, + { + code: 'export x from "mod";', + parser: "babel-eslint", + ecmaFeatures: { modules: true }, + }, - // never - objectsInObjects - { code: "var obj = {'foo': {'bar': 1, 'baz': 2} };", options: ["never", {"objectsInObjects": true}]}, + // always - destructuring typed object param + { + code: "function fn({ a,b }:Object){}", + options: ["always"], + parser: "babel-eslint", + ecmaFeatures: { destructuring: true }, + }, - // https://github.com/eslint/eslint/issues/3658 - // Empty cases. - { code: "var {} = foo;", ecmaFeatures: { destructuring: true }}, - { code: "var [] = foo;", ecmaFeatures: { destructuring: true }}, - { code: "var {a: {}} = foo;", ecmaFeatures: { destructuring: true }}, - { code: "var {a: []} = foo;", ecmaFeatures: { destructuring: true }}, - { code: "import {} from 'foo';", ecmaFeatures: { modules: true }}, - { code: "export {} from 'foo';", ecmaFeatures: { modules: true }}, - { code: "export {};", ecmaFeatures: { modules: true }}, - { code: "var {} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, - { code: "var [] = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, - { code: "var {a: {}} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, - { code: "var {a: []} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, - { code: "import {} from 'foo';", options: ["never"], ecmaFeatures: { modules: true }}, - { code: "export {} from 'foo';", options: ["never"], ecmaFeatures: { modules: true }}, - { code: "export {};", options: ["never"], ecmaFeatures: { modules: true }}, + // never - destructuring typed object param + { + code: "function fn({a,b}: Object){}", + options: ["never"], + parser: "babel-eslint", + ecmaFeatures: { destructuring: true }, + }, + ], - // Babel test cases. - { code: "export * as x from \"mod\";", parser: "babel-eslint", ecmaFeatures: { modules: true } }, - { code: "export x from \"mod\";", parser: "babel-eslint", ecmaFeatures: { modules: true } }, + invalid: [ + { + code: "import {bar} from 'foo.js';", + output: "import { bar } from 'foo.js';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required after '{'.", + type: "ImportDeclaration", + line: 1, + column: 8, + }, + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 12, + }, + ], + }, + { + code: "import { bar as y} from 'foo.js';", + output: "import { bar as y } from 'foo.js';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 18, + }, + ], + }, + { + code: "import {bar as y} from 'foo.js';", + output: "import { bar as y } from 'foo.js';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required after '{'.", + type: "ImportDeclaration", + line: 1, + column: 8, + }, + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 17, + }, + ], + }, + { + code: "import { bar} from 'foo.js';", + output: "import { bar } from 'foo.js';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 13, + }, + ], + }, + { + code: "import x, { bar} from 'foo';", + output: "import x, { bar } from 'foo';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 16, + }, + ], + }, + { + code: "import x, { bar, baz} from 'foo';", + output: "import x, { bar, baz } from 'foo';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 21, + }, + ], + }, + { + code: "import x, {bar} from 'foo';", + output: "import x, { bar } from 'foo';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required after '{'.", + type: "ImportDeclaration", + line: 1, + column: 11, + }, + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 15, + }, + ], + }, + { + code: "import x, {bar, baz} from 'foo';", + output: "import x, { bar, baz } from 'foo';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required after '{'.", + type: "ImportDeclaration", + line: 1, + column: 11, + }, + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 20, + }, + ], + }, + { + code: "import {bar,} from 'foo';", + output: "import { bar, } from 'foo';", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required after '{'.", + type: "ImportDeclaration", + line: 1, + column: 8, + }, + { + message: "A space is required before '}'.", + type: "ImportDeclaration", + line: 1, + column: 13, + }, + ], + }, + { + code: "import { bar, } from 'foo';", + output: "import {bar,} from 'foo';", + options: ["never"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "There should be no space after '{'.", + type: "ImportDeclaration", + line: 1, + column: 8, + }, + { + message: "There should be no space before '}'.", + type: "ImportDeclaration", + line: 1, + column: 15, + }, + ], + }, + { + code: "export {bar};", + output: "export { bar };", + options: ["always"], + ecmaFeatures: { + modules: true, + }, + errors: [ + { + message: "A space is required after '{'.", + type: "ExportNamedDeclaration", + line: 1, + column: 8, + }, + { + message: "A space is required before '}'.", + type: "ExportNamedDeclaration", + line: 1, + column: 12, + }, + ], + }, - // always - destructuring typed object param - { code: "function fn({ a,b }:Object){}", options: ["always"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } }, + // always - arraysInObjects + { + code: "var obj = { 'foo': [ 1, 2 ] };", + output: "var obj = { 'foo': [ 1, 2 ]};", + options: ["always", { arraysInObjects: false }], + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + }, + ], + }, + { + code: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ] };", + output: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ]};", + options: ["always", { arraysInObjects: false }], + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + }, + ], + }, - // never - destructuring typed object param - { code: "function fn({a,b}: Object){}", options: ["never"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } }, - ], + // always-objectsInObjects + { + code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 } };", + output: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", + options: ["always", { objectsInObjects: false }], + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + line: 1, + column: 43, + }, + ], + }, + { + code: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 } };", + output: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 }};", + options: ["always", { objectsInObjects: false }], + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + line: 1, + column: 61, + }, + ], + }, - invalid: [ + // always-destructuring trailing comma + { + code: "var { a,} = x;", + output: "var { a, } = x;", + options: ["always"], + ecmaFeatures: { destructuring: true }, + errors: [ { - code: "import {bar} from 'foo.js';", - output: "import { bar } from 'foo.js';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required after '{'.", - type: "ImportDeclaration", - line: 1, - column: 8 - }, - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 12 - } - ] + message: "A space is required before '}'.", + type: "ObjectPattern", + line: 1, + column: 9, + }, + ], + }, + { + code: "var {a, } = x;", + output: "var {a,} = x;", + options: ["never"], + ecmaFeatures: { destructuring: true }, + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectPattern", + line: 1, + column: 9, + }, + ], + }, + { + code: "var {a:b } = x;", + output: "var {a:b} = x;", + options: ["never"], + ecmaFeatures: { destructuring: true }, + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectPattern", + line: 1, + column: 10, + }, + ], + }, + { + code: "var { a:b } = x;", + output: "var {a:b} = x;", + options: ["never"], + ecmaFeatures: { destructuring: true }, + errors: [ + { + message: "There should be no space after '{'.", + type: "ObjectPattern", + line: 1, + column: 5, }, { - code: "import { bar as y} from 'foo.js';", - output: "import { bar as y } from 'foo.js';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 18 - } - ] + message: "There should be no space before '}'.", + type: "ObjectPattern", + line: 1, + column: 11, }, - { - code: "import {bar as y} from 'foo.js';", - output: "import { bar as y } from 'foo.js';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required after '{'.", - type: "ImportDeclaration", - line: 1, - column: 8 - }, - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 17 - } - ] - }, - { - code: "import { bar} from 'foo.js';", - output: "import { bar } from 'foo.js';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 13 - } - ] - }, - { - code: "import x, { bar} from 'foo';", - output: "import x, { bar } from 'foo';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 16 - } + ], + }, - ] - }, + // never-objectsInObjects + { + code: "var obj = {'foo': {'bar': 1, 'baz': 2}};", + output: "var obj = {'foo': {'bar': 1, 'baz': 2} };", + options: ["never", { objectsInObjects: true }], + errors: [ { - code: "import x, { bar, baz} from 'foo';", - output: "import x, { bar, baz } from 'foo';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 21 - } + message: "A space is required before '}'.", + type: "ObjectExpression", + line: 1, + column: 39, + }, + ], + }, + { + code: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2}};", + output: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2} };", + options: ["never", { objectsInObjects: true }], + errors: [ + { + message: "A space is required before '}'.", + type: "ObjectExpression", + line: 1, + column: 55, + }, + ], + }, - ] + // always & never + { + code: "var obj = {foo: bar, baz: qux};", + output: "var obj = { foo: bar, baz: qux };", + options: ["always"], + errors: [ + { + message: "A space is required after '{'.", + type: "ObjectExpression", + line: 1, + column: 11, }, { - code: "import x, {bar} from 'foo';", - output: "import x, { bar } from 'foo';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required after '{'.", - type: "ImportDeclaration", - line: 1, - column: 11 - }, - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 15 - } + message: "A space is required before '}'.", + type: "ObjectExpression", + line: 1, + column: 30, + }, + ], + }, + { + code: "var obj = {foo: bar, baz: qux };", + output: "var obj = { foo: bar, baz: qux };", + options: ["always"], + errors: [ + { + message: "A space is required after '{'.", + type: "ObjectExpression", + line: 1, + column: 11, + }, + ], + }, + { + code: "var obj = { foo: bar, baz: qux};", + output: "var obj = { foo: bar, baz: qux };", + options: ["always"], + errors: [ + { + message: "A space is required before '}'.", + type: "ObjectExpression", + line: 1, + column: 31, + }, + ], + }, + { + code: "var obj = { foo: bar, baz: qux };", + output: "var obj = {foo: bar, baz: qux};", + options: ["never"], + errors: [ + { + message: "There should be no space after '{'.", + type: "ObjectExpression", + line: 1, + column: 11, + }, + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + line: 1, + column: 32, + }, + ], + }, + { + code: "var obj = {foo: bar, baz: qux };", + output: "var obj = {foo: bar, baz: qux};", + options: ["never"], + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + line: 1, + column: 31, + }, + ], + }, + { + code: "var obj = { foo: bar, baz: qux};", + output: "var obj = {foo: bar, baz: qux};", + options: ["never"], + errors: [ + { + message: "There should be no space after '{'.", + type: "ObjectExpression", + line: 1, + column: 11, + }, + ], + }, + { + code: "var obj = { foo: { bar: quxx}, baz: qux};", + output: "var obj = {foo: {bar: quxx}, baz: qux};", + options: ["never"], + errors: [ + { + message: "There should be no space after '{'.", + type: "ObjectExpression", + line: 1, + column: 11, + }, + { + message: "There should be no space after '{'.", + type: "ObjectExpression", + line: 1, + column: 18, + }, + ], + }, + { + code: "var obj = {foo: {bar: quxx }, baz: qux };", + output: "var obj = {foo: {bar: quxx}, baz: qux};", + options: ["never"], + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + line: 1, + column: 28, + }, + { + message: "There should be no space before '}'.", + type: "ObjectExpression", + line: 1, + column: 40, + }, + ], + }, + { + code: "export const thing = {value: 1 };", + output: "export const thing = { value: 1 };", + ecmaFeatures: { + modules: true, + blockBindings: true, + }, + options: ["always"], + errors: [ + { + message: "A space is required after '{'.", + type: "ObjectExpression", + line: 1, + column: 22, + }, + ], + }, - ] + // destructuring + { + code: "var {x, y} = y", + output: "var { x, y } = y", + ecmaFeatures: { destructuring: true }, + options: ["always"], + errors: [ + { + message: "A space is required after '{'.", + type: "ObjectPattern", + line: 1, + column: 5, }, { - code: "import x, {bar, baz} from 'foo';", - output: "import x, { bar, baz } from 'foo';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required after '{'.", - type: "ImportDeclaration", - line: 1, - column: 11 - }, - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 20 - } - ] + message: "A space is required before '}'.", + type: "ObjectPattern", + line: 1, + column: 10, + }, + ], + }, + { + code: "var { x, y} = y", + output: "var { x, y } = y", + ecmaFeatures: { destructuring: true }, + options: ["always"], + errors: [ + { + message: "A space is required before '}'.", + type: "ObjectPattern", + line: 1, + column: 11, + }, + ], + }, + { + code: "var { x, y } = y", + output: "var {x, y} = y", + ecmaFeatures: { destructuring: true }, + options: ["never"], + errors: [ + { + message: "There should be no space after '{'.", + type: "ObjectPattern", + line: 1, + column: 5, }, { - code: "import {bar,} from 'foo';", - output: "import { bar, } from 'foo';", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required after '{'.", - type: "ImportDeclaration", - line: 1, - column: 8 - }, - { - message: "A space is required before '}'.", - type: "ImportDeclaration", - line: 1, - column: 13 - } + message: "There should be no space before '}'.", + type: "ObjectPattern", + line: 1, + column: 12, + }, + ], + }, + { + code: "var {x, y } = y", + output: "var {x, y} = y", + ecmaFeatures: { destructuring: true }, + options: ["never"], + errors: [ + { + message: "There should be no space before '}'.", + type: "ObjectPattern", + line: 1, + column: 11, + }, + ], + }, + { + code: "var { x=10} = y", + output: "var { x=10 } = y", + ecmaFeatures: { destructuring: true }, + options: ["always"], + errors: [ + { + message: "A space is required before '}'.", + type: "ObjectPattern", + line: 1, + column: 11, + }, + ], + }, + { + code: "var {x=10 } = y", + output: "var { x=10 } = y", + ecmaFeatures: { destructuring: true }, + options: ["always"], + errors: [ + { + message: "A space is required after '{'.", + type: "ObjectPattern", + line: 1, + column: 5, + }, + ], + }, - ] - }, + // never - arraysInObjects + { + code: "var obj = {'foo': [1, 2]};", + output: "var obj = {'foo': [1, 2] };", + options: ["never", { arraysInObjects: true }], + errors: [ { - code: "import { bar, } from 'foo';", - output: "import {bar,} from 'foo';", - options: ["never"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "There should be no space after '{'.", - type: "ImportDeclaration", - line: 1, - column: 8 - }, - { - message: "There should be no space before '}'.", - type: "ImportDeclaration", - line: 1, - column: 15 - } - ] + message: "A space is required before '}'.", + type: "ObjectExpression", }, + ], + }, + { + code: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux']};", + output: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux'] };", + options: ["never", { arraysInObjects: true }], + errors: [ { - code: "export {bar};", - output: "export { bar };", - options: ["always"], - ecmaFeatures: { - modules: true - }, - errors: [ - { - message: "A space is required after '{'.", - type: "ExportNamedDeclaration", - line: 1, - column: 8 - }, - { - message: "A space is required before '}'.", - type: "ExportNamedDeclaration", - line: 1, - column: 12 - } - ] + message: "A space is required before '}'.", + type: "ObjectExpression", }, + ], + }, - // always - arraysInObjects - { - code: "var obj = { 'foo': [ 1, 2 ] };", - output: "var obj = { 'foo': [ 1, 2 ]};", - options: ["always", {"arraysInObjects": false}], - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectExpression" - } - ] - }, - { - code: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ] };", - output: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ]};", - options: ["always", {"arraysInObjects": false}], - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectExpression" - } - ] - }, + // Babel test cases. - // always-objectsInObjects + // always - destructuring typed object param + { + code: "function fn({a,b}: Object){}", + output: "function fn({ a,b }: Object){}", + options: ["always"], + parser: "babel-eslint", + ecmaFeatures: { + destructuring: true, + }, + errors: [ { - code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 } };", - output: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", - options: ["always", {"objectsInObjects": false}], - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectExpression", - line: 1, - column: 43 - } - ] + message: "A space is required after '{'.", + type: "ObjectPattern", + line: 1, + column: 13, }, { - code: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 } };", - output: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 }};", - options: ["always", {"objectsInObjects": false}], - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectExpression", - line: 1, - column: 61 - } - ] + message: "A space is required before '}'.", + type: "ObjectPattern", + line: 1, + column: 17, }, + ], + }, - // always-destructuring trailing comma + // never - destructuring typed object param + { + code: "function fn({ a,b }: Object){}", + output: "function fn({a,b}: Object){}", + options: ["never"], + parser: "babel-eslint", + ecmaFeatures: { + destructuring: true, + }, + errors: [ { - code: "var { a,} = x;", - output: "var { a, } = x;", - options: ["always"], - ecmaFeatures: { destructuring: true }, - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectPattern", - line: 1, - column: 9 - } - ] + message: "There should be no space after '{'.", + type: "ObjectPattern", + line: 1, + column: 13, }, { - code: "var {a, } = x;", - output: "var {a,} = x;", - options: ["never"], - ecmaFeatures: { destructuring: true }, - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectPattern", - line: 1, - column: 9 - } - ] + message: "There should be no space before '}'.", + type: "ObjectPattern", + line: 1, + column: 19, }, - { - code: "var {a:b } = x;", - output: "var {a:b} = x;", - options: ["never"], - ecmaFeatures: { destructuring: true }, - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectPattern", - line: 1, - column: 10 - } - ] - }, - { - code: "var { a:b } = x;", - output: "var {a:b} = x;", - options: ["never"], - ecmaFeatures: { destructuring: true }, - errors: [ - { - message: "There should be no space after '{'.", - type: "ObjectPattern", - line: 1, - column: 5 - }, - { - message: "There should be no space before '}'.", - type: "ObjectPattern", - line: 1, - column: 11 - } - ] - }, - - // never-objectsInObjects - { - code: "var obj = {'foo': {'bar': 1, 'baz': 2}};", - output: "var obj = {'foo': {'bar': 1, 'baz': 2} };", - options: ["never", {"objectsInObjects": true}], - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectExpression", - line: 1, - column: 39 - } - ] - }, - { - code: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2}};", - output: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2} };", - options: ["never", {"objectsInObjects": true}], - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectExpression", - line: 1, - column: 55 - } - ] - }, - - // always & never - { - code: "var obj = {foo: bar, baz: qux};", - output: "var obj = { foo: bar, baz: qux };", - options: ["always"], - errors: [ - { - message: "A space is required after '{'.", - type: "ObjectExpression", - line: 1, - column: 11 - }, - { - message: "A space is required before '}'.", - type: "ObjectExpression", - line: 1, - column: 30 - } - ] - }, - { - code: "var obj = {foo: bar, baz: qux };", - output: "var obj = { foo: bar, baz: qux };", - options: ["always"], - errors: [ - { - message: "A space is required after '{'.", - type: "ObjectExpression", - line: 1, - column: 11 - } - ] - }, - { - code: "var obj = { foo: bar, baz: qux};", - output: "var obj = { foo: bar, baz: qux };", - options: ["always"], - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectExpression", - line: 1, - column: 31 - } - ] - }, - { - code: "var obj = { foo: bar, baz: qux };", - output: "var obj = {foo: bar, baz: qux};", - options: ["never"], - errors: [ - { - message: "There should be no space after '{'.", - type: "ObjectExpression", - line: 1, - column: 11 - }, - { - message: "There should be no space before '}'.", - type: "ObjectExpression", - line: 1, - column: 32 - } - ] - }, - { - code: "var obj = {foo: bar, baz: qux };", - output: "var obj = {foo: bar, baz: qux};", - options: ["never"], - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectExpression", - line: 1, - column: 31 - } - ] - }, - { - code: "var obj = { foo: bar, baz: qux};", - output: "var obj = {foo: bar, baz: qux};", - options: ["never"], - errors: [ - { - message: "There should be no space after '{'.", - type: "ObjectExpression", - line: 1, - column: 11 - } - ] - }, - { - code: "var obj = { foo: { bar: quxx}, baz: qux};", - output: "var obj = {foo: {bar: quxx}, baz: qux};", - options: ["never"], - errors: [ - { - message: "There should be no space after '{'.", - type: "ObjectExpression", - line: 1, - column: 11 - }, - { - message: "There should be no space after '{'.", - type: "ObjectExpression", - line: 1, - column: 18 - } - ] - }, - { - code: "var obj = {foo: {bar: quxx }, baz: qux };", - output: "var obj = {foo: {bar: quxx}, baz: qux};", - options: ["never"], - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectExpression", - line: 1, - column: 28 - }, - { - message: "There should be no space before '}'.", - type: "ObjectExpression", - line: 1, - column: 40 - } - ] - }, - { - code: "export const thing = {value: 1 };", - output: "export const thing = { value: 1 };", - ecmaFeatures: { - modules: true, - blockBindings: true - }, - options: ["always"], - errors: [ - { - message: "A space is required after '{'.", - type: "ObjectExpression", - line: 1, - column: 22 - } - ] - }, - - // destructuring - { - code: "var {x, y} = y", - output: "var { x, y } = y", - ecmaFeatures: {destructuring: true}, - options: ["always"], - errors: [ - { - message: "A space is required after '{'.", - type: "ObjectPattern", - line: 1, - column: 5 - }, - { - message: "A space is required before '}'.", - type: "ObjectPattern", - line: 1, - column: 10 - } - ] - }, - { - code: "var { x, y} = y", - output: "var { x, y } = y", - ecmaFeatures: {destructuring: true}, - options: ["always"], - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectPattern", - line: 1, - column: 11 - } - ] - }, - { - code: "var { x, y } = y", - output: "var {x, y} = y", - ecmaFeatures: {destructuring: true}, - options: ["never"], - errors: [ - { - message: "There should be no space after '{'.", - type: "ObjectPattern", - line: 1, - column: 5 - }, - { - message: "There should be no space before '}'.", - type: "ObjectPattern", - line: 1, - column: 12 - } - ] - }, - { - code: "var {x, y } = y", - output: "var {x, y} = y", - ecmaFeatures: {destructuring: true}, - options: ["never"], - errors: [ - { - message: "There should be no space before '}'.", - type: "ObjectPattern", - line: 1, - column: 11 - } - ] - }, - { - code: "var { x=10} = y", - output: "var { x=10 } = y", - ecmaFeatures: {destructuring: true}, - options: ["always"], - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectPattern", - line: 1, - column: 11 - } - ] - }, - { - code: "var {x=10 } = y", - output: "var { x=10 } = y", - ecmaFeatures: {destructuring: true}, - options: ["always"], - errors: [ - { - message: "A space is required after '{'.", - type: "ObjectPattern", - line: 1, - column: 5 - } - ] - }, - - // never - arraysInObjects - { - code: "var obj = {'foo': [1, 2]};", - output: "var obj = {'foo': [1, 2] };", - options: ["never", {"arraysInObjects": true}], - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectExpression" - } - ] - }, - { - code: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux']};", - output: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux'] };", - options: ["never", {"arraysInObjects": true}], - errors: [ - { - message: "A space is required before '}'.", - type: "ObjectExpression" - } - ] - }, - - // Babel test cases. - - // always - destructuring typed object param - { - code: "function fn({a,b}: Object){}", - output: "function fn({ a,b }: Object){}", - options: ["always"], - parser: "babel-eslint", - ecmaFeatures: { - destructuring: true - }, - errors: [ - { - message: "A space is required after '{'.", - type: "ObjectPattern", - line: 1, - column: 13 - }, - { - message: "A space is required before '}'.", - type: "ObjectPattern", - line: 1, - column: 17 - } - ] - }, - - // never - destructuring typed object param - { - code: "function fn({ a,b }: Object){}", - output: "function fn({a,b}: Object){}", - options: ["never"], - parser: "babel-eslint", - ecmaFeatures: { - destructuring: true - }, - errors: [ - { - message: "There should be no space after '{'.", - type: "ObjectPattern", - line: 1, - column: 13 - }, - { - message: "There should be no space before '}'.", - type: "ObjectPattern", - line: 1, - column: 19 - } - ] - } - ] + ], + }, + ], }); diff --git a/eslint/babel-eslint-plugin/test/rules/quotes.js b/eslint/babel-eslint-plugin/test/rules/quotes.js index 17fde24b6c..938da649d2 100644 --- a/eslint/babel-eslint-plugin/test/rules/quotes.js +++ b/eslint/babel-eslint-plugin/test/rules/quotes.js @@ -1,320 +1,481 @@ -var rule = require('../../rules/quotes'), - RuleTester = require("../helpers/RuleTester"); +var rule = require("../../src/rules/quotes"), + RuleTester = require("../helpers/RuleTester"); var ruleTester = new RuleTester(); -ruleTester.run('babel/quotes', rule, { - valid: [ - "var foo = \"bar\";", - { code: "var foo = 'bar';", options: ["single"] }, - { code: "var foo = \"bar\";", options: ["double"] }, - { code: "var foo = 1;", options: ["single"] }, - { code: "var foo = 1;", options: ["double"] }, - { code: "var foo = \"'\";", options: ["single", { avoidEscape: true }] }, - { code: "var foo = '\"';", options: ["double", { avoidEscape: true }] }, - { code: "var foo =