@babel/eslint-plugin: remove deprecated rules (#10975)
This commit is contained in:
parent
3dcb8ca99e
commit
4cb2148273
@ -26,14 +26,12 @@ original ones as well!).
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"rules": {
|
"rules": {
|
||||||
"babel/new-cap": "error",
|
|
||||||
"babel/camelcase": "error",
|
"babel/camelcase": "error",
|
||||||
|
"babel/new-cap": "error",
|
||||||
"babel/no-invalid-this": "error",
|
"babel/no-invalid-this": "error",
|
||||||
"babel/object-curly-spacing": "error",
|
|
||||||
"babel/quotes": "error",
|
|
||||||
"babel/semi": "error",
|
|
||||||
"babel/no-unused-expressions": "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`.
|
🛠: 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/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/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/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'`).
|
- `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 (🛠)
|
||||||
#### 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 |
|
|
||||||
|
|||||||
@ -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 newCap from "./rules/new-cap";
|
||||||
import camelcase from "./rules/camelcase";
|
import camelcase from "./rules/camelcase";
|
||||||
import noAwaitInLoop from "./rules/no-await-in-loop";
|
|
||||||
import noInvalidThis from "./rules/no-invalid-this";
|
import noInvalidThis from "./rules/no-invalid-this";
|
||||||
import noUnusedExpressions from "./rules/no-unused-expressions";
|
import noUnusedExpressions from "./rules/no-unused-expressions";
|
||||||
import objectCurlySpacing from "./rules/object-curly-spacing";
|
import objectCurlySpacing from "./rules/object-curly-spacing";
|
||||||
import objectShorthand from "./rules/object-shorthand";
|
|
||||||
import quotes from "./rules/quotes";
|
|
||||||
import semi from "./rules/semi";
|
import semi from "./rules/semi";
|
||||||
import validTypeof from "./rules/valid-typeof";
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
rules: {
|
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,
|
camelcase,
|
||||||
"no-await-in-loop": noAwaitInLoop,
|
"new-cap": newCap,
|
||||||
"no-invalid-this": noInvalidThis,
|
"no-invalid-this": noInvalidThis,
|
||||||
"no-unused-expressions": noUnusedExpressions,
|
"no-unused-expressions": noUnusedExpressions,
|
||||||
"object-curly-spacing": objectCurlySpacing,
|
"object-curly-spacing": objectCurlySpacing,
|
||||||
"object-shorthand": objectShorthand,
|
|
||||||
quotes,
|
|
||||||
semi,
|
semi,
|
||||||
"valid-typeof": validTypeof,
|
|
||||||
},
|
},
|
||||||
rulesConfig: {
|
rulesConfig: {
|
||||||
"array-bracket-spacing": "off",
|
|
||||||
"arrow-parens": "off",
|
|
||||||
camelcase: "off",
|
camelcase: "off",
|
||||||
"flow-object-type": "off",
|
|
||||||
"func-params-comma-dangle": "off",
|
|
||||||
"generator-star-spacing": "off",
|
|
||||||
"new-cap": "off",
|
"new-cap": "off",
|
||||||
"no-await-in-loop": "off",
|
|
||||||
"no-invalid-this": "off",
|
"no-invalid-this": "off",
|
||||||
"no-unused-expressions": "off",
|
"no-unused-expressions": "off",
|
||||||
"object-curly-spacing": "off",
|
"object-curly-spacing": "off",
|
||||||
"object-shorthand": "off",
|
|
||||||
quotes: "off",
|
|
||||||
semi: "off",
|
semi: "off",
|
||||||
"valid-typeof": "off",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
});
|
|
||||||
@ -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";
|
|
||||||
});
|
|
||||||
@ -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 = <div>Hello world</div>;",
|
|
||||||
options: ["single"],
|
|
||||||
parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'var foo = <div id="foo"></div>;',
|
|
||||||
options: ["single"],
|
|
||||||
parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = <div>Hello world</div>;",
|
|
||||||
options: ["double"],
|
|
||||||
parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = <div>Hello world</div>;",
|
|
||||||
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 = <div id="foo"></div>;',
|
|
||||||
options: ["backtick"],
|
|
||||||
parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = <div>Hello world</div>;",
|
|
||||||
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"] },
|
|
||||||
"<><div /><div /></>;",
|
|
||||||
{ code: "<><div /><div /></>;", options: ["single"] },
|
|
||||||
{ code: "<><div /><div /></>;", 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: '<div blah={"blah"} />',
|
|
||||||
output: "<div blah={'blah'} />",
|
|
||||||
options: ["single"],
|
|
||||||
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
||||||
errors: [{ message: "Strings must use singlequote.", type: "Literal" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "<div blah={'blah'} />",
|
|
||||||
output: '<div blah={"blah"} />',
|
|
||||||
options: ["double"],
|
|
||||||
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
||||||
errors: [{ message: "Strings must use doublequote.", type: "Literal" }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "<div blah={'blah'} />",
|
|
||||||
output: "<div blah={`blah`} />",
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
@ -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" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user