From 4cb214827319738bcf6f54812af1398f1aac44c7 Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Fri, 10 Jan 2020 14:22:39 -0500 Subject: [PATCH] @babel/eslint-plugin: remove deprecated rules (#10975) --- eslint/babel-eslint-plugin/README.md | 28 +- eslint/babel-eslint-plugin/src/index.js | 29 +- .../src/rules/array-bracket-spacing.js | 45 -- .../src/rules/arrow-parens.js | 30 -- .../src/rules/flow-object-type.js | 33 -- .../src/rules/func-params-comma-dangle.js | 30 -- .../src/rules/generator-star-spacing.js | 42 -- .../src/rules/no-await-in-loop.js | 26 - .../src/rules/object-shorthand.js | 30 -- .../babel-eslint-plugin/src/rules/quotes.js | 14 - .../src/rules/valid-typeof.js | 8 - .../babel-eslint-plugin/test/rules/quotes.js | 481 ------------------ .../test/rules/valid-typeof.js | 256 ---------- 13 files changed, 7 insertions(+), 1045 deletions(-) delete mode 100644 eslint/babel-eslint-plugin/src/rules/array-bracket-spacing.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/arrow-parens.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/flow-object-type.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/func-params-comma-dangle.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/generator-star-spacing.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/no-await-in-loop.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/object-shorthand.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/quotes.js delete mode 100644 eslint/babel-eslint-plugin/src/rules/valid-typeof.js delete mode 100644 eslint/babel-eslint-plugin/test/rules/quotes.js delete mode 100644 eslint/babel-eslint-plugin/test/rules/valid-typeof.js diff --git a/eslint/babel-eslint-plugin/README.md b/eslint/babel-eslint-plugin/README.md index 1ea757adac..2d1e11c458 100644 --- a/eslint/babel-eslint-plugin/README.md +++ b/eslint/babel-eslint-plugin/README.md @@ -26,14 +26,12 @@ original ones as well!). ```json { "rules": { - "babel/new-cap": "error", "babel/camelcase": "error", + "babel/new-cap": "error", "babel/no-invalid-this": "error", - "babel/object-curly-spacing": "error", - "babel/quotes": "error", - "babel/semi": "error", "babel/no-unused-expressions": "error", - "babel/valid-typeof": "error" + "babel/object-curly-spacing": "error", + "babel/semi": "error", } } ``` @@ -43,23 +41,9 @@ Each rule corresponds to a core `eslint` rule, and has the same options. 🛠: means it's autofixable with `--fix`. -- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`) - `babel/camelcase: doesn't complain about optional chaining (`var foo = bar?.a_b;`) +- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`) - `babel/no-invalid-this`: doesn't fail when inside class properties (`class A { a = this.b; }`) -- `babel/object-curly-spacing`: doesn't complain about `export x from "mod";` or `export * as x from "mod";` (🛠) -- `babel/quotes`: doesn't complain about JSX fragment shorthand syntax (`<>foo;`) -- `babel/semi`: doesn't fail when using `for await (let something of {})`. Includes class properties (🛠) - `babel/no-unused-expressions`: doesn't fail when using `do` expressions or [optional chaining](https://github.com/tc39/proposal-optional-chaining) (`a?.b()`). -- `babel/valid-typeof`: doesn't complain when used with [BigInt](https://github.com/tc39/proposal-bigint) (`typeof BigInt(9007199254740991) === 'bigint'`). - -#### Deprecated - -| Rule | Notes | -|:---------------------------------|:-----------------------------------| -| `babel/generator-star-spacing` | Use [`generator-star-spacing`](http://eslint.org/docs/rules/generator-star-spacing) since eslint@3.6.0 | -| `babel/object-shorthand` | Use [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand) since eslint@0.20.0 | -| `babel/arrow-parens` | Use [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens) since eslint@3.10.0 | -| `babel/func-params-comma-dangle` | Use [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle) since eslint@3.8.0 | -| `babel/array-bracket-spacing` | Use [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing) since eslint@3.9.0 | -| `babel/flow-object-type` | Use [`flowtype/object-type-delimiter`](https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter) since eslint-plugin-flowtype@2.23.0 | -| `babel/no-await-in-loop` | Use [`no-await-in-loop`](http://eslint.org/docs/rules/no-await-in-loop) since eslint@3.12.0 | +- `babel/object-curly-spacing`: doesn't complain about `export x from "mod";` or `export * as x from "mod";` (🛠) +- `babel/semi`: doesn't fail when using `for await (let something of {})`. Includes class properties (🛠) diff --git a/eslint/babel-eslint-plugin/src/index.js b/eslint/babel-eslint-plugin/src/index.js index 2e8a37bad1..8b8c0fbf37 100644 --- a/eslint/babel-eslint-plugin/src/index.js +++ b/eslint/babel-eslint-plugin/src/index.js @@ -1,52 +1,25 @@ -import arrayBracketSpacing from "./rules/array-bracket-spacing"; -import arrowParens from "./rules/arrow-parens"; -import flowObjectType from "./rules/flow-object-type"; -import funcParamsCommaDangle from "./rules/func-params-comma-dangle"; -import generatorStarSpacing from "./rules/generator-star-spacing"; import newCap from "./rules/new-cap"; import camelcase from "./rules/camelcase"; -import noAwaitInLoop from "./rules/no-await-in-loop"; import noInvalidThis from "./rules/no-invalid-this"; import noUnusedExpressions from "./rules/no-unused-expressions"; import objectCurlySpacing from "./rules/object-curly-spacing"; -import objectShorthand from "./rules/object-shorthand"; -import quotes from "./rules/quotes"; import semi from "./rules/semi"; -import validTypeof from "./rules/valid-typeof"; module.exports = { rules: { - "array-bracket-spacing": arrayBracketSpacing, - "arrow-parens": arrowParens, - "flow-object-type": flowObjectType, - "func-params-comma-dangle": funcParamsCommaDangle, - "generator-star-spacing": generatorStarSpacing, - "new-cap": newCap, camelcase, - "no-await-in-loop": noAwaitInLoop, + "new-cap": newCap, "no-invalid-this": noInvalidThis, "no-unused-expressions": noUnusedExpressions, "object-curly-spacing": objectCurlySpacing, - "object-shorthand": objectShorthand, - quotes, semi, - "valid-typeof": validTypeof, }, rulesConfig: { - "array-bracket-spacing": "off", - "arrow-parens": "off", camelcase: "off", - "flow-object-type": "off", - "func-params-comma-dangle": "off", - "generator-star-spacing": "off", "new-cap": "off", - "no-await-in-loop": "off", "no-invalid-this": "off", "no-unused-expressions": "off", "object-curly-spacing": "off", - "object-shorthand": "off", - quotes: "off", semi: "off", - "valid-typeof": "off", }, }; diff --git a/eslint/babel-eslint-plugin/src/rules/array-bracket-spacing.js b/eslint/babel-eslint-plugin/src/rules/array-bracket-spacing.js deleted file mode 100644 index b071db8ec8..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/array-bracket-spacing.js +++ /dev/null @@ -1,45 +0,0 @@ -let isWarnedForDeprecation = false; - -export default { - meta: { - deprecated: true, - schema: [ - { - enum: ["always", "never"], - }, - { - type: "object", - properties: { - singleValue: { - type: "boolean", - }, - objectsInArrays: { - type: "boolean", - }, - arraysInArrays: { - type: "boolean", - }, - }, - additionalProperties: false, - }, - ], - }, - create() { - return { - Program() { - if ( - isWarnedForDeprecation || - /=-(f|-format)=/.test(process.argv.join("=")) - ) { - return; - } - - console.log( - "The babel/array-bracket-spacing rule is deprecated. Please " + - "use the built in array-bracket-spacing rule instead.", - ); - isWarnedForDeprecation = true; - }, - }; - }, -}; diff --git a/eslint/babel-eslint-plugin/src/rules/arrow-parens.js b/eslint/babel-eslint-plugin/src/rules/arrow-parens.js deleted file mode 100644 index c5ac81a290..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/arrow-parens.js +++ /dev/null @@ -1,30 +0,0 @@ -let isWarnedForDeprecation = false; - -export default { - meta: { - deprecated: true, - schema: [ - { - enum: ["always", "as-needed"], - }, - ], - }, - create() { - return { - Program() { - if ( - isWarnedForDeprecation || - /=-(f|-format)=/.test(process.argv.join("=")) - ) { - return; - } - - console.log( - "The babel/arrow-parens rule is deprecated. Please " + - "use the built in arrow-parens rule instead.", - ); - isWarnedForDeprecation = true; - }, - }; - }, -}; diff --git a/eslint/babel-eslint-plugin/src/rules/flow-object-type.js b/eslint/babel-eslint-plugin/src/rules/flow-object-type.js deleted file mode 100644 index 2834b19f11..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/flow-object-type.js +++ /dev/null @@ -1,33 +0,0 @@ -let isWarnedForDeprecation = false; - -export default { - meta: { - deprecated: true, - schema: [ - { - enum: ["semicolon", "comma"], - }, - ], - }, - create() { - return { - Program() { - if ( - isWarnedForDeprecation || - /=-(f|-format)=/.test(process.argv.join("=")) - ) { - return; - } - - console.log( - "The babel/flow-object-type rule is deprecated. Please " + - "use the flowtype/object-type-delimiter rule instead.\n" + - // eslint-disable-next-line - "Check out https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter", - ); - - isWarnedForDeprecation = true; - }, - }; - }, -}; diff --git a/eslint/babel-eslint-plugin/src/rules/func-params-comma-dangle.js b/eslint/babel-eslint-plugin/src/rules/func-params-comma-dangle.js deleted file mode 100644 index 00d8006f85..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/func-params-comma-dangle.js +++ /dev/null @@ -1,30 +0,0 @@ -let isWarnedForDeprecation = false; - -export default { - meta: { - deprecated: true, - schema: [ - { - enum: ["always", "always-multiline", "only-multiline", "never"], - }, - ], - }, - create() { - return { - Program() { - if ( - isWarnedForDeprecation || - /=-(f|-format)=/.test(process.argv.join("=")) - ) { - return; - } - - console.log( - "The babel/func-params-comma-dangle rule is deprecated. Please " + - "use the built in comma-dangle rule instead.", - ); - isWarnedForDeprecation = true; - }, - }; - }, -}; diff --git a/eslint/babel-eslint-plugin/src/rules/generator-star-spacing.js b/eslint/babel-eslint-plugin/src/rules/generator-star-spacing.js deleted file mode 100644 index 108c299513..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/generator-star-spacing.js +++ /dev/null @@ -1,42 +0,0 @@ -let isWarnedForDeprecation = false; - -export default { - meta: { - deprecated: true, - schema: [ - { - oneOf: [ - { - enum: ["before", "after", "both", "neither"], - }, - { - type: "object", - properties: { - before: { type: "boolean" }, - after: { type: "boolean" }, - }, - additionalProperties: false, - }, - ], - }, - ], - }, - create() { - return { - Program() { - if ( - isWarnedForDeprecation || - /=-(f|-format)=/.test(process.argv.join("=")) - ) { - return; - } - - console.log( - "The babel/generator-star-spacing rule is deprecated. Please " + - "use the built in generator-star-spacing rule instead.", - ); - isWarnedForDeprecation = true; - }, - }; - }, -}; diff --git a/eslint/babel-eslint-plugin/src/rules/no-await-in-loop.js b/eslint/babel-eslint-plugin/src/rules/no-await-in-loop.js deleted file mode 100644 index 05470be35b..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/no-await-in-loop.js +++ /dev/null @@ -1,26 +0,0 @@ -let isWarnedForDeprecation = false; - -export default { - meta: { - deprecated: true, - schema: [], - }, - create() { - return { - Program() { - if ( - isWarnedForDeprecation || - /=-(f|-format)=/.test(process.argv.join("=")) - ) { - return; - } - - console.log( - "The babel/no-await-in-loop rule is deprecated. Please " + - "use the built in no-await-in-loop rule instead.", - ); - isWarnedForDeprecation = true; - }, - }; - }, -}; diff --git a/eslint/babel-eslint-plugin/src/rules/object-shorthand.js b/eslint/babel-eslint-plugin/src/rules/object-shorthand.js deleted file mode 100644 index 47b865f1e3..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/object-shorthand.js +++ /dev/null @@ -1,30 +0,0 @@ -let isWarnedForDeprecation = false; - -export default { - meta: { - deprecated: true, - schema: [ - { - enum: ["always", "methods", "properties", "never"], - }, - ], - }, - create() { - return { - Program() { - if ( - isWarnedForDeprecation || - /=-(f|-format)=/.test(process.argv.join("=")) - ) { - return; - } - - console.log( - "The babel/object-shorthand rule is deprecated. Please " + - "use the built in object-shorthand rule instead.", - ); - isWarnedForDeprecation = true; - }, - }; - }, -}; diff --git a/eslint/babel-eslint-plugin/src/rules/quotes.js b/eslint/babel-eslint-plugin/src/rules/quotes.js deleted file mode 100644 index 5b38352658..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/quotes.js +++ /dev/null @@ -1,14 +0,0 @@ -import ruleComposer from "eslint-rule-composer"; -import eslint from "eslint"; - -const quotesRule = new eslint.Linter().getRules().get("quotes"); - -export default ruleComposer.filterReports(quotesRule, problem => { - // Workaround for JSX fragment syntax until - // https://github.com/eslint/eslint/issues/9662 - if (problem.node.parent.type === "JSXFragment") { - return false; - } - - return true; -}); diff --git a/eslint/babel-eslint-plugin/src/rules/valid-typeof.js b/eslint/babel-eslint-plugin/src/rules/valid-typeof.js deleted file mode 100644 index ebdd7a33f1..0000000000 --- a/eslint/babel-eslint-plugin/src/rules/valid-typeof.js +++ /dev/null @@ -1,8 +0,0 @@ -import ruleComposer from "eslint-rule-composer"; -import eslint from "eslint"; - -const validTypeOf = new eslint.Linter().getRules().get("valid-typeof"); - -export default ruleComposer.filterReports(validTypeOf, problem => { - return problem.node.value !== "bigint"; -}); diff --git a/eslint/babel-eslint-plugin/test/rules/quotes.js b/eslint/babel-eslint-plugin/test/rules/quotes.js deleted file mode 100644 index 7bd4e7ea34..0000000000 --- a/eslint/babel-eslint-plugin/test/rules/quotes.js +++ /dev/null @@ -1,481 +0,0 @@ -import rule from "../../src/rules/quotes"; -import RuleTester from "../helpers/RuleTester"; - -const 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 =
Hello world
;", - options: ["single"], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: 'var foo =
;', - options: ["single"], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: "var foo =
Hello world
;", - options: ["double"], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: "var foo =
Hello world
;", - options: ["double", { avoidEscape: true }], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: "var foo = `bar`;", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `bar 'baz'`;", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: 'var foo = `bar "baz"`;', - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { code: "var foo = 1;", options: ["backtick"] }, - { - code: 'var foo = "a string containing `backtick` quotes";', - options: ["backtick", { avoidEscape: true }], - }, - { - code: 'var foo =
;', - options: ["backtick"], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - { - code: "var foo =
Hello world
;", - options: ["backtick"], - parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, - }, - - // Backticks are only okay if they have substitutions, contain a line break, or are tagged - { - code: "var foo = `back\ntick`;", - options: ["single"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `back\rtick`;", - options: ["single"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `back\u2028tick`;", - options: ["single"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `back\u2029tick`;", - options: ["single"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `back\\\\\ntick`;", // 2 backslashes followed by a newline - options: ["single"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `back\\\\\\\\\ntick`;", - options: ["single"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `\n`;", - options: ["single"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `back${x}tick`;", - options: ["double"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = tag`backtick`;", - options: ["double"], - parserOptions: { ecmaVersion: 6 }, - }, - - // Backticks are also okay if allowTemplateLiterals - { - code: "var foo = `bar 'foo' baz` + 'bar';", - options: ["single", { allowTemplateLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `bar 'foo' baz` + \"bar\";", - options: ["double", { allowTemplateLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "var foo = `bar 'foo' baz` + `bar`;", - options: ["backtick", { allowTemplateLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - }, - - // `backtick` should not warn the directive prologues. - { - code: '"use strict"; var foo = `backtick`;', - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: '"use strict"; \'use strong\'; "use asm"; var foo = `backtick`;', - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: - 'function foo() { "use strict"; "use strong"; "use asm"; var foo = `backtick`; }', - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: - "(function() { 'use strict'; 'use strong'; 'use asm'; var foo = `backtick`; })();", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: - '(() => { "use strict"; "use strong"; "use asm"; var foo = `backtick`; })();', - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - - // `backtick` should not warn import/export sources. - { - code: "import \"a\"; import 'b';", - options: ["backtick"], - parserOptions: { sourceType: "module" }, - }, - { - code: "import a from \"a\"; import b from 'b';", - options: ["backtick"], - parserOptions: { sourceType: "module" }, - }, - { - code: "export * from \"a\"; export * from 'b';", - options: ["backtick"], - parserOptions: { sourceType: "module" }, - }, - - // `backtick` should not warn property/method names (not computed). - { - code: "var obj = {\"key0\": 0, 'key1': 1};", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "class Foo { 'bar'(){} }", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "class Foo { static ''(){} }", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - }, - - // Babel - "<>foo;", - { code: "<>foo;", options: ["single"] }, - { code: "<>foo;", options: ["double"] }, - "<>
;", - { code: "<>
;", options: ["single"] }, - { code: "<>
;", options: ["double"] }, - ], - invalid: [ - { - code: "var foo = 'bar';", - output: 'var foo = "bar";', - errors: [{ message: "Strings must use doublequote.", type: "Literal" }], - }, - { - code: 'var foo = "bar";', - output: "var foo = 'bar';", - options: ["single"], - errors: [{ message: "Strings must use singlequote.", type: "Literal" }], - }, - { - code: "var foo = `bar`;", - output: "var foo = 'bar';", - options: ["single"], - parserOptions: { - ecmaVersion: 6, - }, - errors: [ - { message: "Strings must use singlequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "var foo = 'don\\'t';", - output: 'var foo = "don\'t";', - errors: [{ message: "Strings must use doublequote.", type: "Literal" }], - }, - { - code: 'var msg = "Plugin \'" + name + "\' not found"', - output: "var msg = 'Plugin \\'' + name + '\\' not found'", - options: ["single"], - errors: [ - { - message: "Strings must use singlequote.", - type: "Literal", - column: 11, - }, - { - message: "Strings must use singlequote.", - type: "Literal", - column: 31, - }, - ], - }, - { - code: "var foo = 'bar';", - output: 'var foo = "bar";', - options: ["double"], - errors: [{ message: "Strings must use doublequote.", type: "Literal" }], - }, - { - code: "var foo = `bar`;", - output: 'var foo = "bar";', - options: ["double"], - parserOptions: { - ecmaVersion: 6, - }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: 'var foo = "bar";', - output: "var foo = 'bar';", - options: ["single", { avoidEscape: true }], - errors: [{ message: "Strings must use singlequote.", type: "Literal" }], - }, - { - code: "var foo = 'bar';", - output: 'var foo = "bar";', - options: ["double", { avoidEscape: true }], - errors: [{ message: "Strings must use doublequote.", type: "Literal" }], - }, - { - code: "var foo = '\\\\';", - output: 'var foo = "\\\\";', - options: ["double", { avoidEscape: true }], - errors: [{ message: "Strings must use doublequote.", type: "Literal" }], - }, - { - code: 'var foo = "bar";', - output: "var foo = 'bar';", - options: ["single", { allowTemplateLiterals: true }], - errors: [{ message: "Strings must use singlequote.", type: "Literal" }], - }, - { - code: "var foo = 'bar';", - output: 'var foo = "bar";', - options: ["double", { allowTemplateLiterals: true }], - errors: [{ message: "Strings must use doublequote.", type: "Literal" }], - }, - { - code: "var foo = 'bar';", - output: "var foo = `bar`;", - options: ["backtick"], - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - { - code: "var foo = 'b${x}a$r';", - output: "var foo = `b\\${x}a$r`;", - options: ["backtick"], - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - { - code: 'var foo = "bar";', - output: "var foo = `bar`;", - options: ["backtick"], - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - { - code: 'var foo = "bar";', - output: "var foo = `bar`;", - options: ["backtick", { avoidEscape: true }], - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - { - code: "var foo = 'bar';", - output: "var foo = `bar`;", - options: ["backtick", { avoidEscape: true }], - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - - // "use strict" is *not* a directive prologue in these statements so is subject to the rule - { - code: 'var foo = `backtick`; "use strict";', - output: "var foo = `backtick`; `use strict`;", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - { - code: '{ "use strict"; var foo = `backtick`; }', - output: "{ `use strict`; var foo = `backtick`; }", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - { - code: 'if (1) { "use strict"; var foo = `backtick`; }', - output: "if (1) { `use strict`; var foo = `backtick`; }", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - - // `backtick` should warn computed property names. - { - code: "var obj = {[\"key0\"]: 0, ['key1']: 1};", - output: "var obj = {[`key0`]: 0, [`key1`]: 1};", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use backtick.", type: "Literal" }, - { message: "Strings must use backtick.", type: "Literal" }, - ], - }, - { - code: "class Foo { ['a'](){} static ['b'](){} }", - output: "class Foo { [`a`](){} static [`b`](){} }", - options: ["backtick"], - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use backtick.", type: "Literal" }, - { message: "Strings must use backtick.", type: "Literal" }, - ], - }, - - // https://github.com/eslint/eslint/issues/7084 - { - code: '
', - output: "
", - options: ["single"], - parserOptions: { ecmaFeatures: { jsx: true } }, - errors: [{ message: "Strings must use singlequote.", type: "Literal" }], - }, - { - code: "
", - output: '
', - options: ["double"], - parserOptions: { ecmaFeatures: { jsx: true } }, - errors: [{ message: "Strings must use doublequote.", type: "Literal" }], - }, - { - code: "
", - output: "
", - options: ["backtick"], - parserOptions: { ecmaFeatures: { jsx: true } }, - errors: [{ message: "Strings must use backtick.", type: "Literal" }], - }, - - // https://github.com/eslint/eslint/issues/7610 - { - code: "`use strict`;", - output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "function foo() { `use strict`; foo(); }", - output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "foo = function() { `use strict`; foo(); }", - output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "() => { `use strict`; foo(); }", - output: null, - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "() => { foo(); `use strict`; }", - output: '() => { foo(); "use strict"; }', - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "foo(); `use strict`;", - output: 'foo(); "use strict";', - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - - // https://github.com/eslint/eslint/issues/7646 - { - code: "var foo = `foo\\nbar`;", - output: 'var foo = "foo\\nbar";', - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "var foo = `foo\\\nbar`;", // 1 backslash followed by a newline - output: 'var foo = "foo\\\nbar";', - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "var foo = `foo\\\\\\\nbar`;", // 3 backslashes followed by a newline - output: 'var foo = "foo\\\\\\\nbar";', - parserOptions: { ecmaVersion: 6 }, - errors: [ - { message: "Strings must use doublequote.", type: "TemplateLiteral" }, - ], - }, - { - code: "````", - output: '""``', - parserOptions: { ecmaVersion: 6 }, - errors: [ - { - message: "Strings must use doublequote.", - type: "TemplateLiteral", - line: 1, - column: 1, - }, - ], - }, - ], -}); diff --git a/eslint/babel-eslint-plugin/test/rules/valid-typeof.js b/eslint/babel-eslint-plugin/test/rules/valid-typeof.js deleted file mode 100644 index ee23bd5291..0000000000 --- a/eslint/babel-eslint-plugin/test/rules/valid-typeof.js +++ /dev/null @@ -1,256 +0,0 @@ -/** - * @fileoverview Ensures that the results of typeof are compared against a valid string - * @author Ian Christian Myers - */ - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -import rule from "../../src/rules/valid-typeof"; -import RuleTester from "../helpers/RuleTester"; - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -const ruleTester = new RuleTester(); - -ruleTester.run("valid-typeof", rule, { - valid: [ - // Original test cases. - "typeof foo === 'string'", - "typeof foo === 'object'", - "typeof foo === 'function'", - "typeof foo === 'undefined'", - "typeof foo === 'boolean'", - "typeof foo === 'number'", - "'string' === typeof foo", - "'object' === typeof foo", - "'function' === typeof foo", - "'undefined' === typeof foo", - "'boolean' === typeof foo", - "'number' === typeof foo", - "typeof foo === typeof bar", - "typeof foo === baz", - "typeof foo !== someType", - "typeof bar != someType", - "someType === typeof bar", - "someType == typeof bar", - "typeof foo == 'string'", - "typeof(foo) === 'string'", - "typeof(foo) !== 'string'", - "typeof(foo) == 'string'", - "typeof(foo) != 'string'", - "var oddUse = typeof foo + 'thing'", - { - code: "typeof foo === 'number'", - options: [{ requireStringLiterals: true }], - }, - { - code: 'typeof foo === "number"', - options: [{ requireStringLiterals: true }], - }, - { - code: "var baz = typeof foo + 'thing'", - options: [{ requireStringLiterals: true }], - }, - { - code: "typeof foo === typeof bar", - options: [{ requireStringLiterals: true }], - }, - { - code: "typeof foo === `string`", - options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "`object` === typeof foo", - options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - }, - { - code: "typeof foo === `str${somethingElse}`", - parserOptions: { ecmaVersion: 6 }, - }, - - // Babel-specific test cases. - { - code: "typeof BigInt(Number.MAX_SAFE_INTEGER) === 'bigint'", - }, - { - code: "'bigint' === typeof BigInt(Number.MAX_SAFE_INTEGER)", - }, - { - code: "typeof BigInt(Number.MAX_SAFE_INTEGER) === 'bigint'", - options: [{ requireStringLiterals: true }], - }, - ], - invalid: [ - { - code: "typeof foo === 'strnig'", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "'strnig' === typeof foo", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "if (typeof bar === 'umdefined') {}", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "typeof foo !== 'strnig'", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "'strnig' !== typeof foo", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "if (typeof bar !== 'umdefined') {}", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "typeof foo != 'strnig'", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "'strnig' != typeof foo", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "if (typeof bar != 'umdefined') {}", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "typeof foo == 'strnig'", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "'strnig' == typeof foo", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "if (typeof bar == 'umdefined') {}", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "if (typeof bar === `umdefined`) {}", - parserOptions: { ecmaVersion: 6 }, - errors: [ - { - message: "Invalid typeof comparison value.", - type: "TemplateLiteral", - }, - ], - }, - { - code: "typeof foo == 'invalid string'", - options: [{ requireStringLiterals: true }], - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "typeof foo == Object", - options: [{ requireStringLiterals: true }], - errors: [ - { - message: "Typeof comparisons should be to string literals.", - type: "Identifier", - }, - ], - }, - { - code: "typeof foo === undefined", - options: [{ requireStringLiterals: true }], - errors: [ - { - message: "Typeof comparisons should be to string literals.", - type: "Identifier", - }, - ], - }, - { - code: "undefined === typeof foo", - options: [{ requireStringLiterals: true }], - errors: [ - { - message: "Typeof comparisons should be to string literals.", - type: "Identifier", - }, - ], - }, - { - code: "undefined == typeof foo", - options: [{ requireStringLiterals: true }], - errors: [ - { - message: "Typeof comparisons should be to string literals.", - type: "Identifier", - }, - ], - }, - { - code: "typeof foo === `undefined${foo}`", - options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [ - { - message: "Typeof comparisons should be to string literals.", - type: "TemplateLiteral", - }, - ], - }, - { - code: "typeof foo === `${string}`", - options: [{ requireStringLiterals: true }], - parserOptions: { ecmaVersion: 6 }, - errors: [ - { - message: "Typeof comparisons should be to string literals.", - type: "TemplateLiteral", - }, - ], - }, - - // Babel-specific test cases. - { - code: "typeof foo === 'bgiint'", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - { - code: "'bignit' === typeof foo", - errors: [ - { message: "Invalid typeof comparison value.", type: "Literal" }, - ], - }, - ], -});