From b4c42601d1943256ecfc20ab6a6306ee786e2e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 14 Nov 2019 22:05:26 +0100 Subject: [PATCH] Fix linting in ESLint packages (#10712) * Lint eslint/* * Run "make fix-js" * Fix remaining problems * Remove linting from subpackages * Remove husky * Add back eslint dep --- .eslintignore | 4 + Makefile | 2 +- eslint/babel-eslint-config-internal/index.js | 14 +- eslint/babel-eslint-parser/.prettierignore | 1 - eslint/babel-eslint-parser/.prettierrc | 3 - eslint/babel-eslint-parser/package.json | 22 +-- .../.eslintrc.json | 20 --- .../.prettierrc | 11 -- .../package.json | 7 +- .../src/rules/no-deprecated-clone.js | 2 - .../src/rules/no-undefined-identifier.js | 2 +- .../src/rules/plugin-name.js | 2 +- .../src/utils/is-from-babel-types.js | 2 +- eslint/babel-eslint-plugin/index.js | 62 +++---- .../rules/array-bracket-spacing.js | 79 ++++---- .../babel-eslint-plugin/rules/arrow-parens.js | 49 ++--- eslint/babel-eslint-plugin/rules/camelcase.js | 105 +++++++---- .../rules/flow-object-type.js | 53 +++--- .../rules/func-params-comma-dangle.js | 51 +++--- .../rules/generator-star-spacing.js | 73 ++++---- eslint/babel-eslint-plugin/rules/new-cap.js | 12 +- .../rules/no-await-in-loop.js | 41 +++-- .../rules/no-invalid-this.js | 36 ++-- .../rules/no-unused-expressions.js | 27 +-- .../rules/object-curly-spacing.js | 38 ++-- .../rules/object-shorthand.js | 49 ++--- eslint/babel-eslint-plugin/rules/quotes.js | 27 ++- eslint/babel-eslint-plugin/rules/semi.js | 170 +++++++++--------- .../babel-eslint-plugin/rules/valid-typeof.js | 15 +- .../tests/rules/new-cap.js | 2 - .../tests/rules/object-curly-spacing.js | 2 - 31 files changed, 493 insertions(+), 490 deletions(-) delete mode 100644 eslint/babel-eslint-parser/.prettierignore delete mode 100644 eslint/babel-eslint-parser/.prettierrc delete mode 100644 eslint/babel-eslint-plugin-development/.eslintrc.json delete mode 100644 eslint/babel-eslint-plugin-development/.prettierrc diff --git a/.eslintignore b/.eslintignore index 092fbbb802..ab69469269 100644 --- a/.eslintignore +++ b/.eslintignore @@ -24,3 +24,7 @@ packages/babel-preset-env-standalone/babel-preset-env.min.js packages/babel-standalone/babel.js packages/babel-standalone/babel.min.js packages/babel-parser/test/expressions + +eslint/*/node_modules +eslint/*/test +eslint/*/tests diff --git a/Makefile b/Makefile index b552967d9f..b2b2d3c4e7 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ FORCE_PUBLISH = "@babel/runtime,@babel/runtime-corejs2,@babel/runtime-corejs3,@b # Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967 export FORCE_COLOR = true -SOURCES = packages codemods +SOURCES = packages codemods eslint .PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap diff --git a/eslint/babel-eslint-config-internal/index.js b/eslint/babel-eslint-config-internal/index.js index 82d4013ef6..4d8e8da89b 100644 --- a/eslint/babel-eslint-config-internal/index.js +++ b/eslint/babel-eslint-config-internal/index.js @@ -4,12 +4,12 @@ module.exports = { plugins: ["flowtype"], parserOptions: { ecmaVersion: 2017, - sourceType: "module" + sourceType: "module", }, rules: { - "camelcase": "off", + camelcase: "off", "consistent-return": "off", - "curly": ["error", "multi-line"], + curly: ["error", "multi-line"], "linebreak-style": ["error", "unix"], "max-len": ["error", 110, 2], "new-cap": "off", @@ -31,18 +31,18 @@ module.exports = { "no-use-before-define": "off", "no-var": "error", "prefer-const": "error", - "strict": "off", + strict: "off", "flowtype/define-flow-type": "warn", "flowtype/use-flow-type": "warn", }, globals: { // Flow Iterator: true, - $Keys: true + $Keys: true, }, env: { node: true, es6: true, - browser: true - } + browser: true, + }, }; diff --git a/eslint/babel-eslint-parser/.prettierignore b/eslint/babel-eslint-parser/.prettierignore deleted file mode 100644 index a6c57f5fb2..0000000000 --- a/eslint/babel-eslint-parser/.prettierignore +++ /dev/null @@ -1 +0,0 @@ -*.json diff --git a/eslint/babel-eslint-parser/.prettierrc b/eslint/babel-eslint-parser/.prettierrc deleted file mode 100644 index 88a0e9a299..0000000000 --- a/eslint/babel-eslint-parser/.prettierrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "trailingComma": "es5" - } \ No newline at end of file diff --git a/eslint/babel-eslint-parser/package.json b/eslint/babel-eslint-parser/package.json index 3a5d1d282b..a92949e7e0 100644 --- a/eslint/babel-eslint-parser/package.json +++ b/eslint/babel-eslint-parser/package.json @@ -13,11 +13,7 @@ }, "homepage": "https://github.com/babel/babel-eslint", "scripts": { - "test": "npm run lint && npm run test-only", - "test-only": "cd test && mocha specs && cd -", - "lint": "eslint .", - "lint-fix": "npm run lint -- --fix", - "precommit": "lint-staged", + "test": "cd test && mocha specs && cd -", "preversion": "npm test", "changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'" }, @@ -52,23 +48,9 @@ "@babel/preset-env": "^7.1.5", "@babel/preset-flow": "^7.0.0", "@babel/preset-react": "^7.0.0", - "babel-eslint": "^10.0.2", "dedent": "^0.7.0", "eslint": "^6.0.1", - "eslint-config-babel": "^9.0.0", - "eslint-plugin-flowtype": "^3.11.1", - "eslint-plugin-import": "^2.14.0", - "eslint-plugin-prettier": "^3.1.0", "espree": "^6.0.0", - "husky": "^1.0.0-rc.13", - "lint-staged": "^7.2.2", - "mocha": "^6.1.4", - "prettier": "^1.4.4" - }, - "lint-staged": { - "*.js": [ - "eslint --format=codeframe --fix", - "git add" - ] + "mocha": "^6.1.4" } } diff --git a/eslint/babel-eslint-plugin-development/.eslintrc.json b/eslint/babel-eslint-plugin-development/.eslintrc.json deleted file mode 100644 index 0b09e73c3d..0000000000 --- a/eslint/babel-eslint-plugin-development/.eslintrc.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "root": true, - "extends": "eslint:recommended", - "plugins": ["prettier"], - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "script" - }, - "env": { - "node": true - }, - "rules": { - "prettier/prettier": "error", - - "curly": ["error", "multi-line"], - "linebreak-style": ["error", "unix"], - "no-var": "error", - "prefer-const": "error" - } -} diff --git a/eslint/babel-eslint-plugin-development/.prettierrc b/eslint/babel-eslint-plugin-development/.prettierrc deleted file mode 100644 index bf2972ae07..0000000000 --- a/eslint/babel-eslint-plugin-development/.prettierrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "arrowParens": "avoid", - "trailingComma": "all", - "useTabs": false, - "semi": true, - "singleQuote": false, - "bracketSpacing": true, - "jsxBracketSameLine": false, - "tabWidth": 2, - "printWidth": 80 -} diff --git a/eslint/babel-eslint-plugin-development/package.json b/eslint/babel-eslint-plugin-development/package.json index 9a8810acea..9a65d7b6cf 100644 --- a/eslint/babel-eslint-plugin-development/package.json +++ b/eslint/babel-eslint-plugin-development/package.json @@ -14,14 +14,11 @@ }, "main": "src/index.js", "scripts": { - "test": "mocha tests --recursive", - "lint": "eslint src tests" + "test": "mocha tests --recursive" }, "devDependencies": { "eslint": "^5.9.0", - "eslint-plugin-prettier": "^3.0.0", - "mocha": "^5.2.0", - "prettier": "^1.15.2" + "mocha": "^5.2.0" }, "engines": { "node": ">=8.0.0" diff --git a/eslint/babel-eslint-plugin-development/src/rules/no-deprecated-clone.js b/eslint/babel-eslint-plugin-development/src/rules/no-deprecated-clone.js index 08bfef8c9b..e6e72f1b9b 100644 --- a/eslint/babel-eslint-plugin-development/src/rules/no-deprecated-clone.js +++ b/eslint/babel-eslint-plugin-development/src/rules/no-deprecated-clone.js @@ -1,5 +1,3 @@ -// @flow - "use strict"; const getReferenceOrigin = require("../utils/get-reference-origin"); diff --git a/eslint/babel-eslint-plugin-development/src/rules/no-undefined-identifier.js b/eslint/babel-eslint-plugin-development/src/rules/no-undefined-identifier.js index c1b4b8a993..7a433b160c 100644 --- a/eslint/babel-eslint-plugin-development/src/rules/no-undefined-identifier.js +++ b/eslint/babel-eslint-plugin-development/src/rules/no-undefined-identifier.js @@ -32,7 +32,7 @@ module.exports = { ) { context.report( node, - "Use path.scope.buildUndefinedNode() to create an undefined identifier directly.", + "Use path.scope.buildUndefinedNode() to create an undefined identifier directly." ); } }, diff --git a/eslint/babel-eslint-plugin-development/src/rules/plugin-name.js b/eslint/babel-eslint-plugin-development/src/rules/plugin-name.js index 58a4bc9f63..11dd02808a 100644 --- a/eslint/babel-eslint-plugin-development/src/rules/plugin-name.js +++ b/eslint/babel-eslint-plugin-development/src/rules/plugin-name.js @@ -44,7 +44,7 @@ module.exports = { if (!returnValue.properties.some(p => p.key.name === "name")) { context.report( returnValue, - "This Babel plugin doesn't have a 'name' property.", + "This Babel plugin doesn't have a 'name' property." ); } } diff --git a/eslint/babel-eslint-plugin-development/src/utils/is-from-babel-types.js b/eslint/babel-eslint-plugin-development/src/utils/is-from-babel-types.js index 36ab618817..3045616217 100644 --- a/eslint/babel-eslint-plugin-development/src/utils/is-from-babel-types.js +++ b/eslint/babel-eslint-plugin-development/src/utils/is-from-babel-types.js @@ -6,7 +6,7 @@ const isBabelPluginFactory = require("./is-babel-plugin-factory"); // is a reference to a @babel/types export. module.exports = function isFromBabelTypes( origin /*: ReferenceOrigin */, - scope /*: Scope */, + scope /*: Scope */ ) { if (origin.kind === "import" && origin.source === "@babel/types") { // imported from @babel/types diff --git a/eslint/babel-eslint-plugin/index.js b/eslint/babel-eslint-plugin/index.js index 6cd30daefb..eda05b28c8 100644 --- a/eslint/babel-eslint-plugin/index.js +++ b/eslint/babel-eslint-plugin/index.js @@ -1,38 +1,38 @@ -'use strict'; +"use strict"; module.exports = { rules: { - 'array-bracket-spacing': require('./rules/array-bracket-spacing'), - 'arrow-parens': require('./rules/arrow-parens'), - 'flow-object-type': require('./rules/flow-object-type'), - 'func-params-comma-dangle': require('./rules/func-params-comma-dangle'), - 'generator-star-spacing': require('./rules/generator-star-spacing'), - 'new-cap': require('./rules/new-cap'), - 'camelcase': require('./rules/camelcase'), - 'no-await-in-loop': require('./rules/no-await-in-loop'), - 'no-invalid-this': require('./rules/no-invalid-this'), - 'no-unused-expressions': require('./rules/no-unused-expressions'), - 'object-curly-spacing': require('./rules/object-curly-spacing'), - 'object-shorthand': require('./rules/object-shorthand'), - 'quotes': require('./rules/quotes'), - 'semi': require('./rules/semi'), - 'valid-typeof': require('./rules/valid-typeof'), + "array-bracket-spacing": require("./rules/array-bracket-spacing"), + "arrow-parens": require("./rules/arrow-parens"), + "flow-object-type": require("./rules/flow-object-type"), + "func-params-comma-dangle": require("./rules/func-params-comma-dangle"), + "generator-star-spacing": require("./rules/generator-star-spacing"), + "new-cap": require("./rules/new-cap"), + camelcase: require("./rules/camelcase"), + "no-await-in-loop": require("./rules/no-await-in-loop"), + "no-invalid-this": require("./rules/no-invalid-this"), + "no-unused-expressions": require("./rules/no-unused-expressions"), + "object-curly-spacing": require("./rules/object-curly-spacing"), + "object-shorthand": require("./rules/object-shorthand"), + quotes: require("./rules/quotes"), + semi: require("./rules/semi"), + "valid-typeof": require("./rules/valid-typeof"), }, rulesConfig: { - 'array-bracket-spacing': 0, - 'arrow-parens': 0, - 'camelcase': 0, - 'flow-object-type': 0, - 'func-params-comma-dangle': 0, - 'generator-star-spacing': 0, - 'new-cap': 0, - 'no-await-in-loop': 0, - 'no-invalid-this': 0, - 'no-unused-expressions': 0, - 'object-curly-spacing': 0, - 'object-shorthand': 0, - 'quotes': 0, - 'semi': 0, - 'valid-typeof': 0, + "array-bracket-spacing": 0, + "arrow-parens": 0, + camelcase: 0, + "flow-object-type": 0, + "func-params-comma-dangle": 0, + "generator-star-spacing": 0, + "new-cap": 0, + "no-await-in-loop": 0, + "no-invalid-this": 0, + "no-unused-expressions": 0, + "object-curly-spacing": 0, + "object-shorthand": 0, + quotes: 0, + semi: 0, + "valid-typeof": 0, }, }; diff --git a/eslint/babel-eslint-plugin/rules/array-bracket-spacing.js b/eslint/babel-eslint-plugin/rules/array-bracket-spacing.js index 0a9ba37521..e7eafff0d2 100644 --- a/eslint/babel-eslint-plugin/rules/array-bracket-spacing.js +++ b/eslint/babel-eslint-plugin/rules/array-bracket-spacing.js @@ -1,43 +1,46 @@ "use strict"; -var isWarnedForDeprecation = false; +let isWarnedForDeprecation = false; module.exports = { - meta: { - deprecated: true, - schema: [ - { - "enum": ["always", "never"] - }, - { - "type": "object", - "properties": { - "singleValue": { - "type": "boolean" - }, - "objectsInArrays": { - "type": "boolean" - }, - "arraysInArrays": { - "type": "boolean" - } - }, - "additionalProperties": false - } - ] - }, - create: function() { - return { - Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { - return; - } + meta: { + deprecated: true, + schema: [ + { + enum: ["always", "never"], + }, + { + type: "object", + properties: { + singleValue: { + type: "boolean", + }, + objectsInArrays: { + type: "boolean", + }, + arraysInArrays: { + type: "boolean", + }, + }, + additionalProperties: false, + }, + ], + }, + create: function() { + return { + Program: function() { + if ( + isWarnedForDeprecation || + /=-(f|-format)=/.test(process.argv.join("=")) + ) { + return; + } - /* eslint-disable no-console */ - console.log('The babel/array-bracket-spacing rule is deprecated. Please ' + - 'use the built in array-bracket-spacing rule instead.'); - /* eslint-enable no-console */ - isWarnedForDeprecation = true; - } - }; - } + 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/rules/arrow-parens.js b/eslint/babel-eslint-plugin/rules/arrow-parens.js index 13d9c8ffe0..848045ff7b 100644 --- a/eslint/babel-eslint-plugin/rules/arrow-parens.js +++ b/eslint/babel-eslint-plugin/rules/arrow-parens.js @@ -1,28 +1,31 @@ "use strict"; -var isWarnedForDeprecation = false; +let isWarnedForDeprecation = false; module.exports = { - meta: { - deprecated: true, - schema: [ - { - "enum": ["always", "as-needed"] - } - ] - }, - create: function() { - return { - Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { - return; - } + meta: { + deprecated: true, + schema: [ + { + enum: ["always", "as-needed"], + }, + ], + }, + create: function() { + return { + Program: function() { + if ( + isWarnedForDeprecation || + /=-(f|-format)=/.test(process.argv.join("=")) + ) { + return; + } - /* eslint-disable no-console */ - console.log('The babel/arrow-parens rule is deprecated. Please ' + - 'use the built in arrow-parens rule instead.'); - /* eslint-enable no-console */ - isWarnedForDeprecation = true; - } - }; - } + 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/rules/camelcase.js b/eslint/babel-eslint-plugin/rules/camelcase.js index 65e8164cd7..6528b4a7f4 100644 --- a/eslint/babel-eslint-plugin/rules/camelcase.js +++ b/eslint/babel-eslint-plugin/rules/camelcase.js @@ -15,7 +15,7 @@ module.exports = { description: "enforce camelcase naming convention", category: "Stylistic Issues", recommended: false, - url: "https://eslint.org/docs/rules/camelcase" + url: "https://eslint.org/docs/rules/camelcase", }, schema: [ @@ -23,23 +23,22 @@ module.exports = { type: "object", properties: { ignoreDestructuring: { - type: "boolean" + type: "boolean", }, properties: { - enum: ["always", "never"] - } + enum: ["always", "never"], + }, }, - additionalProperties: false - } + additionalProperties: false, + }, ], messages: { - notCamelCase: "Identifier '{{name}}' is not in camel case." - } + notCamelCase: "Identifier '{{name}}' is not in camel case.", + }, }, create(context) { - //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- @@ -66,7 +65,6 @@ module.exports = { * @private */ function isUnderscored(name) { - // if there's an underscore, it might be A_CONSTANT, which is okay return name.indexOf("_") > -1 && name !== name.toUpperCase(); } @@ -100,7 +98,11 @@ module.exports = { function report(node) { if (reported.indexOf(node.parent) < 0) { reported.push(node.parent); - context.report({ node, messageId: "notCamelCase", data: { name: node.name } }); + context.report({ + node, + messageId: "notCamelCase", + data: { name: node.name }, + }); } } @@ -113,30 +115,39 @@ module.exports = { } return { - Identifier(node) { - /* * Leading and trailing underscores are commonly used to flag * private/protected identifiers, strip them */ const name = node.name.replace(/^_+|_+$/g, ""), - effectiveParent = isMemberExpression(node.parent.type) ? node.parent.parent : node.parent; + effectiveParent = isMemberExpression(node.parent.type) + ? node.parent.parent + : node.parent; // MemberExpressions get special rules if (isMemberExpression(node.parent.type)) { - // "never" check properties if (properties === "never") { return; } // Always report underscored object names - if (node.parent.object.type === "Identifier" && node.parent.object.name === node.name && isUnderscored(name)) { + if ( + node.parent.object.type === "Identifier" && + node.parent.object.name === node.name && + isUnderscored(name) + ) { report(node); // Report AssignmentExpressions only if they are the left side of the assignment - } else if (effectiveParent.type === "AssignmentExpression" && isUnderscored(name) && (!isMemberExpression(effectiveParent.right.type) || isMemberExpression(effectiveParent.left.type) && effectiveParent.left.property.name === node.name)) { + } else if ( + effectiveParent.type === "AssignmentExpression" && + isUnderscored(name) && + (!isMemberExpression(effectiveParent.right.type) || + (isMemberExpression(effectiveParent.left.type) && + effectiveParent.left.property.name === node.name)) + ) { report(node); } @@ -145,50 +156,76 @@ module.exports = { * AssignmentPattern nodes can be treated like Properties: * e.g.: const { no_camelcased = false } = bar; */ - } else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") { - - if (node.parent.parent && node.parent.parent.type === "ObjectPattern") { - - const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name; + } else if ( + node.parent.type === "Property" || + node.parent.type === "AssignmentPattern" + ) { + if ( + node.parent.parent && + node.parent.parent.type === "ObjectPattern" + ) { + const assignmentKeyEqualsValue = + node.parent.key.name === node.parent.value.name; // prevent checking righthand side of destructured object if (node.parent.key === node && node.parent.value !== node) { return; } - const valueIsUnderscored = node.parent.value.name && isUnderscored(name); + const valueIsUnderscored = + node.parent.value.name && isUnderscored(name); // ignore destructuring if the option is set, unless a new identifier is created - if (valueIsUnderscored && !(assignmentKeyEqualsValue && ignoreDestructuring)) { + if ( + valueIsUnderscored && + !(assignmentKeyEqualsValue && ignoreDestructuring) + ) { report(node); } } // "never" check properties or always ignore destructuring - if (properties === "never" || (ignoreDestructuring && isInsideObjectPattern(node))) { + if ( + properties === "never" || + (ignoreDestructuring && isInsideObjectPattern(node)) + ) { return; } // don't check right hand side of AssignmentExpression to prevent duplicate warnings - if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type) && !(node.parent.right === node)) { + if ( + isUnderscored(name) && + !ALLOWED_PARENT_TYPES.has(effectiveParent.type) && + !(node.parent.right === node) + ) { report(node); } // Check if it's an import specifier - } else if (["ImportSpecifier", "ImportNamespaceSpecifier", "ImportDefaultSpecifier"].indexOf(node.parent.type) >= 0) { - + } else if ( + [ + "ImportSpecifier", + "ImportNamespaceSpecifier", + "ImportDefaultSpecifier", + ].indexOf(node.parent.type) >= 0 + ) { // Report only if the local imported identifier is underscored - if (node.parent.local && node.parent.local.name === node.name && isUnderscored(name)) { + if ( + node.parent.local && + node.parent.local.name === node.name && + isUnderscored(name) + ) { report(node); } // Report anything that is underscored that isn't a CallExpression - } else if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type)) { + } else if ( + isUnderscored(name) && + !ALLOWED_PARENT_TYPES.has(effectiveParent.type) + ) { report(node); } - } - + }, }; - - } + }, }; diff --git a/eslint/babel-eslint-plugin/rules/flow-object-type.js b/eslint/babel-eslint-plugin/rules/flow-object-type.js index 73cd3ed17a..4e45f8328b 100644 --- a/eslint/babel-eslint-plugin/rules/flow-object-type.js +++ b/eslint/babel-eslint-plugin/rules/flow-object-type.js @@ -1,29 +1,34 @@ "use strict"; -var isWarnedForDeprecation = false; +let isWarnedForDeprecation = false; module.exports = { - meta: { - deprecated: true, - schema: [ - { - "enum": ["semicolon", "comma"], - } - ] - }, - create: function() { - return { - Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { - return; - } + meta: { + deprecated: true, + schema: [ + { + enum: ["semicolon", "comma"], + }, + ], + }, + create: function() { + return { + Program: function() { + if ( + isWarnedForDeprecation || + /=-(f|-format)=/.test(process.argv.join("=")) + ) { + return; + } - /* eslint-disable no-console */ - console.log('The babel/flow-object-type rule is deprecated. Please ' + - 'use the flowtype/object-type-delimiter rule instead.\n' + - 'Check out https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter'); - /* eslint-enable no-console */ - isWarnedForDeprecation = true; - } - }; - } + 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/rules/func-params-comma-dangle.js b/eslint/babel-eslint-plugin/rules/func-params-comma-dangle.js index 0290d81323..40bd08b3bb 100644 --- a/eslint/babel-eslint-plugin/rules/func-params-comma-dangle.js +++ b/eslint/babel-eslint-plugin/rules/func-params-comma-dangle.js @@ -1,28 +1,31 @@ -'use strict'; +"use strict"; -var isWarnedForDeprecation = false; +let isWarnedForDeprecation = false; module.exports = { - meta: { - deprecated: true, - schema: [ - { - "enum": ["always", "always-multiline", "only-multiline", "never"] - } - ] - }, - create: function() { - return { - Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { - return; - } + meta: { + deprecated: true, + schema: [ + { + enum: ["always", "always-multiline", "only-multiline", "never"], + }, + ], + }, + create: function() { + return { + Program: function() { + if ( + isWarnedForDeprecation || + /=-(f|-format)=/.test(process.argv.join("=")) + ) { + return; + } - /* eslint-disable no-console */ - console.log('The babel/func-params-comma-dangle rule is deprecated. Please ' + - 'use the built in comma-dangle rule instead.'); - /* eslint-enable no-console */ - isWarnedForDeprecation = true; - } - }; - } + 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/rules/generator-star-spacing.js b/eslint/babel-eslint-plugin/rules/generator-star-spacing.js index 64186ffe68..6befc25d04 100644 --- a/eslint/babel-eslint-plugin/rules/generator-star-spacing.js +++ b/eslint/babel-eslint-plugin/rules/generator-star-spacing.js @@ -1,40 +1,43 @@ "use strict"; -var isWarnedForDeprecation = false; +let isWarnedForDeprecation = false; module.exports = { - meta: { - deprecated: true, - schema: [ - { - "oneOf": [ - { - "enum": ["before", "after", "both", "neither"] - }, - { - "type": "object", - "properties": { - "before": {"type": "boolean"}, - "after": {"type": "boolean"} - }, - "additionalProperties": false - } - ] - } - ] - }, - create: function() { - return { - Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { - return; - } + meta: { + deprecated: true, + schema: [ + { + oneOf: [ + { + enum: ["before", "after", "both", "neither"], + }, + { + type: "object", + properties: { + before: { type: "boolean" }, + after: { type: "boolean" }, + }, + additionalProperties: false, + }, + ], + }, + ], + }, + create: function() { + return { + Program: function() { + if ( + isWarnedForDeprecation || + /=-(f|-format)=/.test(process.argv.join("=")) + ) { + return; + } - /* eslint-disable no-console */ - console.log('The babel/generator-star-spacing rule is deprecated. Please ' + - 'use the built in generator-star-spacing rule instead.'); - /* eslint-enable no-console */ - isWarnedForDeprecation = true; - } - }; - } + 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/rules/new-cap.js b/eslint/babel-eslint-plugin/rules/new-cap.js index 37ee633bf2..3e09bb25df 100644 --- a/eslint/babel-eslint-plugin/rules/new-cap.js +++ b/eslint/babel-eslint-plugin/rules/new-cap.js @@ -1,8 +1,8 @@ "use strict"; -const ruleComposer = require('eslint-rule-composer'); -const eslint = require('eslint'); -const newCapRule = new eslint.Linter().getRules().get('new-cap'); +const ruleComposer = require("eslint-rule-composer"); +const eslint = require("eslint"); +const newCapRule = new eslint.Linter().getRules().get("new-cap"); /** * Returns whether a node is under a decorator or not. @@ -10,10 +10,10 @@ const newCapRule = new eslint.Linter().getRules().get('new-cap'); * @returns {Boolean} Returns true if the node is under a decorator. */ function isDecorator(node) { - return node.parent.type === "Decorator"; + return node.parent.type === "Decorator"; } module.exports = ruleComposer.filterReports( - newCapRule, - (problem, metadata) => !isDecorator(problem.node) + newCapRule, + problem => !isDecorator(problem.node) ); diff --git a/eslint/babel-eslint-plugin/rules/no-await-in-loop.js b/eslint/babel-eslint-plugin/rules/no-await-in-loop.js index 8ef295f36f..a46a19da88 100644 --- a/eslint/babel-eslint-plugin/rules/no-await-in-loop.js +++ b/eslint/babel-eslint-plugin/rules/no-await-in-loop.js @@ -1,24 +1,27 @@ "use strict"; -var isWarnedForDeprecation = false; +let isWarnedForDeprecation = false; module.exports = { - meta: { - deprecated: true, - schema: [] - }, - create: function() { - return { - Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { - return; - } + meta: { + deprecated: true, + schema: [], + }, + create: function() { + return { + Program: function() { + if ( + isWarnedForDeprecation || + /=-(f|-format)=/.test(process.argv.join("=")) + ) { + return; + } - /* eslint-disable no-console */ - console.log('The babel/no-await-in-loop rule is deprecated. Please ' + - 'use the built in no-await-in-loop rule instead.'); - /* eslint-enable no-console */ - isWarnedForDeprecation = true; - } - }; - } + 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/rules/no-invalid-this.js b/eslint/babel-eslint-plugin/rules/no-invalid-this.js index 994499eaad..101ec655a6 100644 --- a/eslint/babel-eslint-plugin/rules/no-invalid-this.js +++ b/eslint/babel-eslint-plugin/rules/no-invalid-this.js @@ -1,25 +1,21 @@ "use strict"; -const ruleComposer = require('eslint-rule-composer'); -const eslint = require('eslint'); -const noInvalidThisRule = new eslint.Linter().getRules().get('no-invalid-this'); +const ruleComposer = require("eslint-rule-composer"); +const eslint = require("eslint"); +const noInvalidThisRule = new eslint.Linter().getRules().get("no-invalid-this"); -module.exports = ruleComposer.filterReports( - noInvalidThisRule, - (problem, metadata) => { - let inClassProperty = false; - let node = problem.node; +module.exports = ruleComposer.filterReports(noInvalidThisRule, problem => { + let inClassProperty = false; + let node = problem.node; - while (node) { - if (node.type === "ClassProperty" || - node.type === "ClassPrivateProperty") { - inClassProperty = true; - return; - } - - node = node.parent; - } - - return !inClassProperty; + while (node) { + if (node.type === "ClassProperty" || node.type === "ClassPrivateProperty") { + inClassProperty = true; + return; } -); + + node = node.parent; + } + + return !inClassProperty; +}); diff --git a/eslint/babel-eslint-plugin/rules/no-unused-expressions.js b/eslint/babel-eslint-plugin/rules/no-unused-expressions.js index eb1955ab0b..81c779d3c7 100644 --- a/eslint/babel-eslint-plugin/rules/no-unused-expressions.js +++ b/eslint/babel-eslint-plugin/rules/no-unused-expressions.js @@ -1,8 +1,8 @@ "use strict"; -const ruleComposer = require('eslint-rule-composer'); -const eslint = require('eslint'); -const rule = new eslint.Linter().getRules().get('no-unused-expressions'); +const ruleComposer = require("eslint-rule-composer"); +const eslint = require("eslint"); +const rule = new eslint.Linter().getRules().get("no-unused-expressions"); /** * @param {ASTNode} node - any node @@ -11,9 +11,11 @@ const rule = new eslint.Linter().getRules().get('no-unused-expressions'); */ function isFinalStatementInBlockStatement(node) { const parent = node.parent; - return /^(?:If|Expression)Statement$/.test(node.type) && - parent.type === 'BlockStatement' && - parent.body[parent.body.length - 1] === node; + return ( + /^(?:If|Expression)Statement$/.test(node.type) && + parent.type === "BlockStatement" && + parent.body[parent.body.length - 1] === node + ); } /** @@ -24,13 +26,13 @@ function isFinalStatementInBlockStatement(node) { function isInDoStatement(node) { if (!node) return false; - if (node.type === 'DoExpression') return true; + if (node.type === "DoExpression") return true; // this is an `else if` if ( - node.type === 'IfStatement' && + node.type === "IfStatement" && node.parent && - node.parent.type === 'IfStatement' + node.parent.type === "IfStatement" ) { return isInDoStatement(node.parent); } @@ -50,14 +52,13 @@ function isInDoStatement(node) { function isOptionalCallExpression(node) { return ( !!node && - node.type === 'ExpressionStatement' && - node.expression.type === 'OptionalCallExpression' + node.type === "ExpressionStatement" && + node.expression.type === "OptionalCallExpression" ); } module.exports = ruleComposer.filterReports( rule, - (problem, metadata) => + problem => !isInDoStatement(problem.node) && !isOptionalCallExpression(problem.node) ); - diff --git a/eslint/babel-eslint-plugin/rules/object-curly-spacing.js b/eslint/babel-eslint-plugin/rules/object-curly-spacing.js index 19953bf04f..d3ec196201 100644 --- a/eslint/babel-eslint-plugin/rules/object-curly-spacing.js +++ b/eslint/babel-eslint-plugin/rules/object-curly-spacing.js @@ -1,25 +1,27 @@ "use strict"; -const ruleComposer = require('eslint-rule-composer'); -const eslint = require('eslint'); -const objectCurlySpacingRule = new eslint.Linter().getRules().get('object-curly-spacing'); +const ruleComposer = require("eslint-rule-composer"); +const eslint = require("eslint"); +const objectCurlySpacingRule = new eslint.Linter() + .getRules() + .get("object-curly-spacing"); module.exports = ruleComposer.filterReports( - objectCurlySpacingRule, - (problem, metadata) => { - const node = problem.node; + objectCurlySpacingRule, + (problem, metadata) => { + const node = problem.node; - // Allow `exportNamespaceFrom` and `exportDefaultFrom` syntax: - // export * as x from '...'; - // export x from '...'; - if ( - node.type === 'ExportNamedDeclaration' && - node.specifiers.length > 0 && - metadata.sourceCode.getTokenBefore(node.specifiers[0]).value === "export" - ) { - return false; - } - - return true; + // Allow `exportNamespaceFrom` and `exportDefaultFrom` syntax: + // export * as x from '...'; + // export x from '...'; + if ( + node.type === "ExportNamedDeclaration" && + node.specifiers.length > 0 && + metadata.sourceCode.getTokenBefore(node.specifiers[0]).value === "export" + ) { + return false; } + + return true; + } ); diff --git a/eslint/babel-eslint-plugin/rules/object-shorthand.js b/eslint/babel-eslint-plugin/rules/object-shorthand.js index 73ce1365ba..21f41e639e 100644 --- a/eslint/babel-eslint-plugin/rules/object-shorthand.js +++ b/eslint/babel-eslint-plugin/rules/object-shorthand.js @@ -1,28 +1,31 @@ "use strict"; -var isWarnedForDeprecation = false; +let isWarnedForDeprecation = false; module.exports = { - meta: { - deprecated: true, - schema: [ - { - "enum": ["always", "methods", "properties", "never"] - } - ] - }, - create: function() { - return { - Program: function() { - if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { - return; - } + meta: { + deprecated: true, + schema: [ + { + enum: ["always", "methods", "properties", "never"], + }, + ], + }, + create: function() { + return { + Program: function() { + if ( + isWarnedForDeprecation || + /=-(f|-format)=/.test(process.argv.join("=")) + ) { + return; + } - /* eslint-disable no-console */ - console.log('The babel/object-shorthand rule is deprecated. Please ' + - 'use the built in object-shorthand rule instead.'); - /* eslint-enable no-console */ - isWarnedForDeprecation = true; - } - }; - } + 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/rules/quotes.js b/eslint/babel-eslint-plugin/rules/quotes.js index 41cd7da5a3..a4bb46df45 100644 --- a/eslint/babel-eslint-plugin/rules/quotes.js +++ b/eslint/babel-eslint-plugin/rules/quotes.js @@ -1,18 +1,15 @@ -'use strict'; +"use strict"; -const ruleComposer = require('eslint-rule-composer'); -const eslint = require('eslint'); -const quotesRule = new eslint.Linter().getRules().get('quotes'); +const ruleComposer = require("eslint-rule-composer"); +const eslint = require("eslint"); +const quotesRule = new eslint.Linter().getRules().get("quotes"); -module.exports = ruleComposer.filterReports( - quotesRule, - (problem, metadata) => { - // Workaround for JSX fragment syntax until - // https://github.com/eslint/eslint/issues/9662 - if (problem.node.parent.type === "JSXFragment") { - return false; - } - - return true; +module.exports = 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/rules/semi.js b/eslint/babel-eslint-plugin/rules/semi.js index 2d2fcc4ed2..8888bf4cac 100644 --- a/eslint/babel-eslint-plugin/rules/semi.js +++ b/eslint/babel-eslint-plugin/rules/semi.js @@ -1,115 +1,123 @@ "use strict"; -const ruleComposer = require('eslint-rule-composer'); -const eslint = require('eslint'); -const semiRule = new eslint.Linter().getRules().get('semi'); +const ruleComposer = require("eslint-rule-composer"); +const eslint = require("eslint"); +const semiRule = new eslint.Linter().getRules().get("semi"); const OPT_OUT_PATTERN = /^[-[(/+`]/; // One of [(/+-` const isSemicolon = token => token.type === "Punctuator" && token.value === ";"; const isUnnecessarySemicolon = (context, lastToken) => { - if (!isSemicolon(lastToken)) { - return false; - } + if (!isSemicolon(lastToken)) { + return false; + } - const nextToken = context.getSourceCode().getTokenAfter(lastToken); + const nextToken = context.getSourceCode().getTokenAfter(lastToken); - if (!nextToken) { - return true; - } + if (!nextToken) { + return true; + } - const lastTokenLine = lastToken.loc.end.line; - const nextTokenLine = nextToken.loc.start.line; - const isOptOutToken = OPT_OUT_PATTERN.test(nextToken.value) && nextToken.value !== "++" && nextToken.value !== "--"; - const isDivider = (nextToken.value === "}" || nextToken.value === ";"); + const lastTokenLine = lastToken.loc.end.line; + const nextTokenLine = nextToken.loc.start.line; + const isOptOutToken = + OPT_OUT_PATTERN.test(nextToken.value) && + nextToken.value !== "++" && + nextToken.value !== "--"; + const isDivider = nextToken.value === "}" || nextToken.value === ";"; - return (lastTokenLine !== nextTokenLine && !isOptOutToken) || isDivider; -} + return (lastTokenLine !== nextTokenLine && !isOptOutToken) || isDivider; +}; const isOneLinerBlock = (context, node) => { - const nextToken = context.getSourceCode().getTokenAfter(node); + const nextToken = context.getSourceCode().getTokenAfter(node); - if (!nextToken || nextToken.value !== "}") { - return false; - } + if (!nextToken || nextToken.value !== "}") { + return false; + } - const parent = node.parent; + const parent = node.parent; - return parent && parent.type === "BlockStatement" && - parent.loc.start.line === parent.loc.end.line; + return ( + parent && + parent.type === "BlockStatement" && + parent.loc.start.line === parent.loc.end.line + ); }; const report = (context, node, missing) => { - const lastToken = context.getSourceCode().getLastToken(node); + const lastToken = context.getSourceCode().getLastToken(node); - let message, fix, loc = lastToken.loc; + let message, + fix, + loc = lastToken.loc; - if (!missing) { - message = "Missing semicolon."; - loc = loc.end; - fix = function(fixer) { - return fixer.insertTextAfter(lastToken, ";"); - }; - } else { - message = "Extra semicolon."; - loc = loc.start; - fix = function(fixer) { - return fixer.remove(lastToken); - }; - } + if (!missing) { + message = "Missing semicolon."; + loc = loc.end; + fix = function(fixer) { + return fixer.insertTextAfter(lastToken, ";"); + }; + } else { + message = "Extra semicolon."; + loc = loc.start; + fix = function(fixer) { + return fixer.remove(lastToken); + }; + } - context.report({ - node, - loc, - message, - fix - }); + context.report({ + node, + loc, + message, + fix, + }); }; const semiRuleWithClassProperty = ruleComposer.joinReports([ - semiRule, - context => ({ - ClassProperty(node) { - const options = context.options[1]; - const exceptOneLine = options && options.omitLastInOneLineBlock === true; + semiRule, + context => ({ + ClassProperty(node) { + const options = context.options[1]; + const exceptOneLine = options && options.omitLastInOneLineBlock === true; - const sourceCode = context.getSourceCode(); - const lastToken = sourceCode.getLastToken(node); + const sourceCode = context.getSourceCode(); + const lastToken = sourceCode.getLastToken(node); - if (context.options[0] === "never") { - if (isUnnecessarySemicolon(context, lastToken)) { - report(context, node, true); - } - } else { - if (!isSemicolon(lastToken)) { - if (!exceptOneLine || !isOneLinerBlock(context, node)) { - report(context, node); - } - } else { - if (exceptOneLine && isOneLinerBlock(context, node)) { - report(context, node, true); - } - } - } - }, - }), + if (context.options[0] === "never") { + if (isUnnecessarySemicolon(context, lastToken)) { + report(context, node, true); + } + } else { + if (!isSemicolon(lastToken)) { + if (!exceptOneLine || !isOneLinerBlock(context, node)) { + report(context, node); + } + } else { + if (exceptOneLine && isOneLinerBlock(context, node)) { + report(context, node, true); + } + } + } + }, + }), ]); module.exports = ruleComposer.filterReports( - semiRuleWithClassProperty, - (problem, metadata) => { - const node = problem.node; + semiRuleWithClassProperty, + problem => { + const node = problem.node; - // Handle async iterator: - // for await (let something of {}) - if ( - node.type === "VariableDeclaration" && - node.parent.type === "ForAwaitStatement" - ) { - return false; - } - - return true; + // Handle async iterator: + // for await (let something of {}) + if ( + node.type === "VariableDeclaration" && + node.parent.type === "ForAwaitStatement" + ) { + return false; } + + return true; + } ); diff --git a/eslint/babel-eslint-plugin/rules/valid-typeof.js b/eslint/babel-eslint-plugin/rules/valid-typeof.js index df5110be05..aa8321ec98 100644 --- a/eslint/babel-eslint-plugin/rules/valid-typeof.js +++ b/eslint/babel-eslint-plugin/rules/valid-typeof.js @@ -1,12 +1,9 @@ "use strict"; -const ruleComposer = require('eslint-rule-composer'); -const eslint = require('eslint'); -const validTypeOf = new eslint.Linter().getRules().get('valid-typeof'); +const ruleComposer = require("eslint-rule-composer"); +const eslint = require("eslint"); +const validTypeOf = new eslint.Linter().getRules().get("valid-typeof"); -module.exports = ruleComposer.filterReports( - validTypeOf, - (problem, metadata) => { - return problem.node.value !== 'bigint'; - } -) +module.exports = ruleComposer.filterReports(validTypeOf, problem => { + return problem.node.value !== "bigint"; +}); diff --git a/eslint/babel-eslint-plugin/tests/rules/new-cap.js b/eslint/babel-eslint-plugin/tests/rules/new-cap.js index d03adde071..c37f2e9f06 100644 --- a/eslint/babel-eslint-plugin/tests/rules/new-cap.js +++ b/eslint/babel-eslint-plugin/tests/rules/new-cap.js @@ -1,5 +1,3 @@ -/* eslint-disable */ - /** * @fileoverview Tests for new-cap rule. * @author Nicholas C. Zakas diff --git a/eslint/babel-eslint-plugin/tests/rules/object-curly-spacing.js b/eslint/babel-eslint-plugin/tests/rules/object-curly-spacing.js index 8771785ff5..a982ba5d39 100644 --- a/eslint/babel-eslint-plugin/tests/rules/object-curly-spacing.js +++ b/eslint/babel-eslint-plugin/tests/rules/object-curly-spacing.js @@ -1,5 +1,3 @@ -/* eslint-disable */ - /** * @fileoverview Disallows or enforces spaces inside of object literals. * @author Jamund Ferguson