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
This commit is contained in:
parent
17dfdab7d2
commit
b4c42601d1
@ -24,3 +24,7 @@ packages/babel-preset-env-standalone/babel-preset-env.min.js
|
|||||||
packages/babel-standalone/babel.js
|
packages/babel-standalone/babel.js
|
||||||
packages/babel-standalone/babel.min.js
|
packages/babel-standalone/babel.min.js
|
||||||
packages/babel-parser/test/expressions
|
packages/babel-parser/test/expressions
|
||||||
|
|
||||||
|
eslint/*/node_modules
|
||||||
|
eslint/*/test
|
||||||
|
eslint/*/tests
|
||||||
|
|||||||
2
Makefile
2
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
|
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
||||||
export FORCE_COLOR = true
|
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
|
.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap
|
||||||
|
|
||||||
|
|||||||
@ -4,12 +4,12 @@ module.exports = {
|
|||||||
plugins: ["flowtype"],
|
plugins: ["flowtype"],
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
ecmaVersion: 2017,
|
ecmaVersion: 2017,
|
||||||
sourceType: "module"
|
sourceType: "module",
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
"camelcase": "off",
|
camelcase: "off",
|
||||||
"consistent-return": "off",
|
"consistent-return": "off",
|
||||||
"curly": ["error", "multi-line"],
|
curly: ["error", "multi-line"],
|
||||||
"linebreak-style": ["error", "unix"],
|
"linebreak-style": ["error", "unix"],
|
||||||
"max-len": ["error", 110, 2],
|
"max-len": ["error", 110, 2],
|
||||||
"new-cap": "off",
|
"new-cap": "off",
|
||||||
@ -31,18 +31,18 @@ module.exports = {
|
|||||||
"no-use-before-define": "off",
|
"no-use-before-define": "off",
|
||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"prefer-const": "error",
|
"prefer-const": "error",
|
||||||
"strict": "off",
|
strict: "off",
|
||||||
"flowtype/define-flow-type": "warn",
|
"flowtype/define-flow-type": "warn",
|
||||||
"flowtype/use-flow-type": "warn",
|
"flowtype/use-flow-type": "warn",
|
||||||
},
|
},
|
||||||
globals: {
|
globals: {
|
||||||
// Flow
|
// Flow
|
||||||
Iterator: true,
|
Iterator: true,
|
||||||
$Keys: true
|
$Keys: true,
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
node: true,
|
node: true,
|
||||||
es6: true,
|
es6: true,
|
||||||
browser: true
|
browser: true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
*.json
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"trailingComma": "es5"
|
|
||||||
}
|
|
||||||
@ -13,11 +13,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/babel/babel-eslint",
|
"homepage": "https://github.com/babel/babel-eslint",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run lint && npm run test-only",
|
"test": "cd test && mocha specs && cd -",
|
||||||
"test-only": "cd test && mocha specs && cd -",
|
|
||||||
"lint": "eslint .",
|
|
||||||
"lint-fix": "npm run lint -- --fix",
|
|
||||||
"precommit": "lint-staged",
|
|
||||||
"preversion": "npm test",
|
"preversion": "npm test",
|
||||||
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'"
|
"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-env": "^7.1.5",
|
||||||
"@babel/preset-flow": "^7.0.0",
|
"@babel/preset-flow": "^7.0.0",
|
||||||
"@babel/preset-react": "^7.0.0",
|
"@babel/preset-react": "^7.0.0",
|
||||||
"babel-eslint": "^10.0.2",
|
|
||||||
"dedent": "^0.7.0",
|
"dedent": "^0.7.0",
|
||||||
"eslint": "^6.0.1",
|
"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",
|
"espree": "^6.0.0",
|
||||||
"husky": "^1.0.0-rc.13",
|
"mocha": "^6.1.4"
|
||||||
"lint-staged": "^7.2.2",
|
|
||||||
"mocha": "^6.1.4",
|
|
||||||
"prettier": "^1.4.4"
|
|
||||||
},
|
|
||||||
"lint-staged": {
|
|
||||||
"*.js": [
|
|
||||||
"eslint --format=codeframe --fix",
|
|
||||||
"git add"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"arrowParens": "avoid",
|
|
||||||
"trailingComma": "all",
|
|
||||||
"useTabs": false,
|
|
||||||
"semi": true,
|
|
||||||
"singleQuote": false,
|
|
||||||
"bracketSpacing": true,
|
|
||||||
"jsxBracketSameLine": false,
|
|
||||||
"tabWidth": 2,
|
|
||||||
"printWidth": 80
|
|
||||||
}
|
|
||||||
@ -14,14 +14,11 @@
|
|||||||
},
|
},
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha tests --recursive",
|
"test": "mocha tests --recursive"
|
||||||
"lint": "eslint src tests"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^5.9.0",
|
"eslint": "^5.9.0",
|
||||||
"eslint-plugin-prettier": "^3.0.0",
|
"mocha": "^5.2.0"
|
||||||
"mocha": "^5.2.0",
|
|
||||||
"prettier": "^1.15.2"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.0.0"
|
"node": ">=8.0.0"
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
// @flow
|
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const getReferenceOrigin = require("../utils/get-reference-origin");
|
const getReferenceOrigin = require("../utils/get-reference-origin");
|
||||||
|
|||||||
@ -32,7 +32,7 @@ module.exports = {
|
|||||||
) {
|
) {
|
||||||
context.report(
|
context.report(
|
||||||
node,
|
node,
|
||||||
"Use path.scope.buildUndefinedNode() to create an undefined identifier directly.",
|
"Use path.scope.buildUndefinedNode() to create an undefined identifier directly."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -44,7 +44,7 @@ module.exports = {
|
|||||||
if (!returnValue.properties.some(p => p.key.name === "name")) {
|
if (!returnValue.properties.some(p => p.key.name === "name")) {
|
||||||
context.report(
|
context.report(
|
||||||
returnValue,
|
returnValue,
|
||||||
"This Babel plugin doesn't have a 'name' property.",
|
"This Babel plugin doesn't have a 'name' property."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ const isBabelPluginFactory = require("./is-babel-plugin-factory");
|
|||||||
// is a reference to a @babel/types export.
|
// is a reference to a @babel/types export.
|
||||||
module.exports = function isFromBabelTypes(
|
module.exports = function isFromBabelTypes(
|
||||||
origin /*: ReferenceOrigin */,
|
origin /*: ReferenceOrigin */,
|
||||||
scope /*: Scope */,
|
scope /*: Scope */
|
||||||
) {
|
) {
|
||||||
if (origin.kind === "import" && origin.source === "@babel/types") {
|
if (origin.kind === "import" && origin.source === "@babel/types") {
|
||||||
// imported from @babel/types
|
// imported from @babel/types
|
||||||
|
|||||||
@ -1,38 +1,38 @@
|
|||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
rules: {
|
rules: {
|
||||||
'array-bracket-spacing': require('./rules/array-bracket-spacing'),
|
"array-bracket-spacing": require("./rules/array-bracket-spacing"),
|
||||||
'arrow-parens': require('./rules/arrow-parens'),
|
"arrow-parens": require("./rules/arrow-parens"),
|
||||||
'flow-object-type': require('./rules/flow-object-type'),
|
"flow-object-type": require("./rules/flow-object-type"),
|
||||||
'func-params-comma-dangle': require('./rules/func-params-comma-dangle'),
|
"func-params-comma-dangle": require("./rules/func-params-comma-dangle"),
|
||||||
'generator-star-spacing': require('./rules/generator-star-spacing'),
|
"generator-star-spacing": require("./rules/generator-star-spacing"),
|
||||||
'new-cap': require('./rules/new-cap'),
|
"new-cap": require("./rules/new-cap"),
|
||||||
'camelcase': require('./rules/camelcase'),
|
camelcase: require("./rules/camelcase"),
|
||||||
'no-await-in-loop': require('./rules/no-await-in-loop'),
|
"no-await-in-loop": require("./rules/no-await-in-loop"),
|
||||||
'no-invalid-this': require('./rules/no-invalid-this'),
|
"no-invalid-this": require("./rules/no-invalid-this"),
|
||||||
'no-unused-expressions': require('./rules/no-unused-expressions'),
|
"no-unused-expressions": require("./rules/no-unused-expressions"),
|
||||||
'object-curly-spacing': require('./rules/object-curly-spacing'),
|
"object-curly-spacing": require("./rules/object-curly-spacing"),
|
||||||
'object-shorthand': require('./rules/object-shorthand'),
|
"object-shorthand": require("./rules/object-shorthand"),
|
||||||
'quotes': require('./rules/quotes'),
|
quotes: require("./rules/quotes"),
|
||||||
'semi': require('./rules/semi'),
|
semi: require("./rules/semi"),
|
||||||
'valid-typeof': require('./rules/valid-typeof'),
|
"valid-typeof": require("./rules/valid-typeof"),
|
||||||
},
|
},
|
||||||
rulesConfig: {
|
rulesConfig: {
|
||||||
'array-bracket-spacing': 0,
|
"array-bracket-spacing": 0,
|
||||||
'arrow-parens': 0,
|
"arrow-parens": 0,
|
||||||
'camelcase': 0,
|
camelcase: 0,
|
||||||
'flow-object-type': 0,
|
"flow-object-type": 0,
|
||||||
'func-params-comma-dangle': 0,
|
"func-params-comma-dangle": 0,
|
||||||
'generator-star-spacing': 0,
|
"generator-star-spacing": 0,
|
||||||
'new-cap': 0,
|
"new-cap": 0,
|
||||||
'no-await-in-loop': 0,
|
"no-await-in-loop": 0,
|
||||||
'no-invalid-this': 0,
|
"no-invalid-this": 0,
|
||||||
'no-unused-expressions': 0,
|
"no-unused-expressions": 0,
|
||||||
'object-curly-spacing': 0,
|
"object-curly-spacing": 0,
|
||||||
'object-shorthand': 0,
|
"object-shorthand": 0,
|
||||||
'quotes': 0,
|
quotes: 0,
|
||||||
'semi': 0,
|
semi: 0,
|
||||||
'valid-typeof': 0,
|
"valid-typeof": 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,43 +1,46 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var isWarnedForDeprecation = false;
|
let isWarnedForDeprecation = false;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
meta: {
|
meta: {
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
schema: [
|
schema: [
|
||||||
{
|
{
|
||||||
"enum": ["always", "never"]
|
enum: ["always", "never"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "object",
|
type: "object",
|
||||||
"properties": {
|
properties: {
|
||||||
"singleValue": {
|
singleValue: {
|
||||||
"type": "boolean"
|
type: "boolean",
|
||||||
},
|
},
|
||||||
"objectsInArrays": {
|
objectsInArrays: {
|
||||||
"type": "boolean"
|
type: "boolean",
|
||||||
},
|
},
|
||||||
"arraysInArrays": {
|
arraysInArrays: {
|
||||||
"type": "boolean"
|
type: "boolean",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
additionalProperties: false,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
create: function() {
|
create: function() {
|
||||||
return {
|
return {
|
||||||
Program: function() {
|
Program: function() {
|
||||||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
if (
|
||||||
return;
|
isWarnedForDeprecation ||
|
||||||
}
|
/=-(f|-format)=/.test(process.argv.join("="))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
console.log(
|
||||||
console.log('The babel/array-bracket-spacing rule is deprecated. Please ' +
|
"The babel/array-bracket-spacing rule is deprecated. Please " +
|
||||||
'use the built in array-bracket-spacing rule instead.');
|
"use the built in array-bracket-spacing rule instead."
|
||||||
/* eslint-enable no-console */
|
);
|
||||||
isWarnedForDeprecation = true;
|
isWarnedForDeprecation = true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,28 +1,31 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var isWarnedForDeprecation = false;
|
let isWarnedForDeprecation = false;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
meta: {
|
meta: {
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
schema: [
|
schema: [
|
||||||
{
|
{
|
||||||
"enum": ["always", "as-needed"]
|
enum: ["always", "as-needed"],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
create: function() {
|
create: function() {
|
||||||
return {
|
return {
|
||||||
Program: function() {
|
Program: function() {
|
||||||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
if (
|
||||||
return;
|
isWarnedForDeprecation ||
|
||||||
}
|
/=-(f|-format)=/.test(process.argv.join("="))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
console.log(
|
||||||
console.log('The babel/arrow-parens rule is deprecated. Please ' +
|
"The babel/arrow-parens rule is deprecated. Please " +
|
||||||
'use the built in arrow-parens rule instead.');
|
"use the built in arrow-parens rule instead."
|
||||||
/* eslint-enable no-console */
|
);
|
||||||
isWarnedForDeprecation = true;
|
isWarnedForDeprecation = true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -15,7 +15,7 @@ module.exports = {
|
|||||||
description: "enforce camelcase naming convention",
|
description: "enforce camelcase naming convention",
|
||||||
category: "Stylistic Issues",
|
category: "Stylistic Issues",
|
||||||
recommended: false,
|
recommended: false,
|
||||||
url: "https://eslint.org/docs/rules/camelcase"
|
url: "https://eslint.org/docs/rules/camelcase",
|
||||||
},
|
},
|
||||||
|
|
||||||
schema: [
|
schema: [
|
||||||
@ -23,23 +23,22 @@ module.exports = {
|
|||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
ignoreDestructuring: {
|
ignoreDestructuring: {
|
||||||
type: "boolean"
|
type: "boolean",
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
enum: ["always", "never"]
|
enum: ["always", "never"],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
additionalProperties: false
|
additionalProperties: false,
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
messages: {
|
messages: {
|
||||||
notCamelCase: "Identifier '{{name}}' is not in camel case."
|
notCamelCase: "Identifier '{{name}}' is not in camel case.",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
create(context) {
|
create(context) {
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
// Helpers
|
// Helpers
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -66,7 +65,6 @@ module.exports = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function isUnderscored(name) {
|
function isUnderscored(name) {
|
||||||
|
|
||||||
// if there's an underscore, it might be A_CONSTANT, which is okay
|
// if there's an underscore, it might be A_CONSTANT, which is okay
|
||||||
return name.indexOf("_") > -1 && name !== name.toUpperCase();
|
return name.indexOf("_") > -1 && name !== name.toUpperCase();
|
||||||
}
|
}
|
||||||
@ -100,7 +98,11 @@ module.exports = {
|
|||||||
function report(node) {
|
function report(node) {
|
||||||
if (reported.indexOf(node.parent) < 0) {
|
if (reported.indexOf(node.parent) < 0) {
|
||||||
reported.push(node.parent);
|
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 {
|
return {
|
||||||
|
|
||||||
Identifier(node) {
|
Identifier(node) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Leading and trailing underscores are commonly used to flag
|
* Leading and trailing underscores are commonly used to flag
|
||||||
* private/protected identifiers, strip them
|
* private/protected identifiers, strip them
|
||||||
*/
|
*/
|
||||||
const name = node.name.replace(/^_+|_+$/g, ""),
|
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
|
// MemberExpressions get special rules
|
||||||
if (isMemberExpression(node.parent.type)) {
|
if (isMemberExpression(node.parent.type)) {
|
||||||
|
|
||||||
// "never" check properties
|
// "never" check properties
|
||||||
if (properties === "never") {
|
if (properties === "never") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always report underscored object names
|
// 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(node);
|
||||||
|
|
||||||
// Report AssignmentExpressions only if they are the left side of the assignment
|
// 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);
|
report(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,50 +156,76 @@ module.exports = {
|
|||||||
* AssignmentPattern nodes can be treated like Properties:
|
* AssignmentPattern nodes can be treated like Properties:
|
||||||
* e.g.: const { no_camelcased = false } = bar;
|
* e.g.: const { no_camelcased = false } = bar;
|
||||||
*/
|
*/
|
||||||
} else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") {
|
} else if (
|
||||||
|
node.parent.type === "Property" ||
|
||||||
if (node.parent.parent && node.parent.parent.type === "ObjectPattern") {
|
node.parent.type === "AssignmentPattern"
|
||||||
|
) {
|
||||||
const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name;
|
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
|
// prevent checking righthand side of destructured object
|
||||||
if (node.parent.key === node && node.parent.value !== node) {
|
if (node.parent.key === node && node.parent.value !== node) {
|
||||||
return;
|
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
|
// ignore destructuring if the option is set, unless a new identifier is created
|
||||||
if (valueIsUnderscored && !(assignmentKeyEqualsValue && ignoreDestructuring)) {
|
if (
|
||||||
|
valueIsUnderscored &&
|
||||||
|
!(assignmentKeyEqualsValue && ignoreDestructuring)
|
||||||
|
) {
|
||||||
report(node);
|
report(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// "never" check properties or always ignore destructuring
|
// "never" check properties or always ignore destructuring
|
||||||
if (properties === "never" || (ignoreDestructuring && isInsideObjectPattern(node))) {
|
if (
|
||||||
|
properties === "never" ||
|
||||||
|
(ignoreDestructuring && isInsideObjectPattern(node))
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't check right hand side of AssignmentExpression to prevent duplicate warnings
|
// 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);
|
report(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it's an import specifier
|
// 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
|
// 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(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report anything that is underscored that isn't a CallExpression
|
// 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);
|
report(node);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
},
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,29 +1,34 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var isWarnedForDeprecation = false;
|
let isWarnedForDeprecation = false;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
meta: {
|
meta: {
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
schema: [
|
schema: [
|
||||||
{
|
{
|
||||||
"enum": ["semicolon", "comma"],
|
enum: ["semicolon", "comma"],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
create: function() {
|
create: function() {
|
||||||
return {
|
return {
|
||||||
Program: function() {
|
Program: function() {
|
||||||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
if (
|
||||||
return;
|
isWarnedForDeprecation ||
|
||||||
}
|
/=-(f|-format)=/.test(process.argv.join("="))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
console.log(
|
||||||
console.log('The babel/flow-object-type rule is deprecated. Please ' +
|
"The babel/flow-object-type rule is deprecated. Please " +
|
||||||
'use the flowtype/object-type-delimiter rule instead.\n' +
|
"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-disable-next-line
|
||||||
/* eslint-enable no-console */
|
"Check out https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter"
|
||||||
isWarnedForDeprecation = true;
|
);
|
||||||
}
|
|
||||||
};
|
isWarnedForDeprecation = true;
|
||||||
}
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,28 +1,31 @@
|
|||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var isWarnedForDeprecation = false;
|
let isWarnedForDeprecation = false;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
meta: {
|
meta: {
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
schema: [
|
schema: [
|
||||||
{
|
{
|
||||||
"enum": ["always", "always-multiline", "only-multiline", "never"]
|
enum: ["always", "always-multiline", "only-multiline", "never"],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
create: function() {
|
create: function() {
|
||||||
return {
|
return {
|
||||||
Program: function() {
|
Program: function() {
|
||||||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
if (
|
||||||
return;
|
isWarnedForDeprecation ||
|
||||||
}
|
/=-(f|-format)=/.test(process.argv.join("="))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
console.log(
|
||||||
console.log('The babel/func-params-comma-dangle rule is deprecated. Please ' +
|
"The babel/func-params-comma-dangle rule is deprecated. Please " +
|
||||||
'use the built in comma-dangle rule instead.');
|
"use the built in comma-dangle rule instead."
|
||||||
/* eslint-enable no-console */
|
);
|
||||||
isWarnedForDeprecation = true;
|
isWarnedForDeprecation = true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,40 +1,43 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var isWarnedForDeprecation = false;
|
let isWarnedForDeprecation = false;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
meta: {
|
meta: {
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
schema: [
|
schema: [
|
||||||
{
|
{
|
||||||
"oneOf": [
|
oneOf: [
|
||||||
{
|
{
|
||||||
"enum": ["before", "after", "both", "neither"]
|
enum: ["before", "after", "both", "neither"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "object",
|
type: "object",
|
||||||
"properties": {
|
properties: {
|
||||||
"before": {"type": "boolean"},
|
before: { type: "boolean" },
|
||||||
"after": {"type": "boolean"}
|
after: { type: "boolean" },
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
additionalProperties: false,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
create: function() {
|
create: function() {
|
||||||
return {
|
return {
|
||||||
Program: function() {
|
Program: function() {
|
||||||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
if (
|
||||||
return;
|
isWarnedForDeprecation ||
|
||||||
}
|
/=-(f|-format)=/.test(process.argv.join("="))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
console.log(
|
||||||
console.log('The babel/generator-star-spacing rule is deprecated. Please ' +
|
"The babel/generator-star-spacing rule is deprecated. Please " +
|
||||||
'use the built in generator-star-spacing rule instead.');
|
"use the built in generator-star-spacing rule instead."
|
||||||
/* eslint-enable no-console */
|
);
|
||||||
isWarnedForDeprecation = true;
|
isWarnedForDeprecation = true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const ruleComposer = require('eslint-rule-composer');
|
const ruleComposer = require("eslint-rule-composer");
|
||||||
const eslint = require('eslint');
|
const eslint = require("eslint");
|
||||||
const newCapRule = new eslint.Linter().getRules().get('new-cap');
|
const newCapRule = new eslint.Linter().getRules().get("new-cap");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether a node is under a decorator or not.
|
* 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.
|
* @returns {Boolean} Returns true if the node is under a decorator.
|
||||||
*/
|
*/
|
||||||
function isDecorator(node) {
|
function isDecorator(node) {
|
||||||
return node.parent.type === "Decorator";
|
return node.parent.type === "Decorator";
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ruleComposer.filterReports(
|
module.exports = ruleComposer.filterReports(
|
||||||
newCapRule,
|
newCapRule,
|
||||||
(problem, metadata) => !isDecorator(problem.node)
|
problem => !isDecorator(problem.node)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,24 +1,27 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var isWarnedForDeprecation = false;
|
let isWarnedForDeprecation = false;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
meta: {
|
meta: {
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
schema: []
|
schema: [],
|
||||||
},
|
},
|
||||||
create: function() {
|
create: function() {
|
||||||
return {
|
return {
|
||||||
Program: function() {
|
Program: function() {
|
||||||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
if (
|
||||||
return;
|
isWarnedForDeprecation ||
|
||||||
}
|
/=-(f|-format)=/.test(process.argv.join("="))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
console.log(
|
||||||
console.log('The babel/no-await-in-loop rule is deprecated. Please ' +
|
"The babel/no-await-in-loop rule is deprecated. Please " +
|
||||||
'use the built in no-await-in-loop rule instead.');
|
"use the built in no-await-in-loop rule instead."
|
||||||
/* eslint-enable no-console */
|
);
|
||||||
isWarnedForDeprecation = true;
|
isWarnedForDeprecation = true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,25 +1,21 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const ruleComposer = require('eslint-rule-composer');
|
const ruleComposer = require("eslint-rule-composer");
|
||||||
const eslint = require('eslint');
|
const eslint = require("eslint");
|
||||||
const noInvalidThisRule = new eslint.Linter().getRules().get('no-invalid-this');
|
const noInvalidThisRule = new eslint.Linter().getRules().get("no-invalid-this");
|
||||||
|
|
||||||
module.exports = ruleComposer.filterReports(
|
module.exports = ruleComposer.filterReports(noInvalidThisRule, problem => {
|
||||||
noInvalidThisRule,
|
let inClassProperty = false;
|
||||||
(problem, metadata) => {
|
let node = problem.node;
|
||||||
let inClassProperty = false;
|
|
||||||
let node = problem.node;
|
|
||||||
|
|
||||||
while (node) {
|
while (node) {
|
||||||
if (node.type === "ClassProperty" ||
|
if (node.type === "ClassProperty" || node.type === "ClassPrivateProperty") {
|
||||||
node.type === "ClassPrivateProperty") {
|
inClassProperty = true;
|
||||||
inClassProperty = true;
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
node = node.parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !inClassProperty;
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
node = node.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !inClassProperty;
|
||||||
|
});
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const ruleComposer = require('eslint-rule-composer');
|
const ruleComposer = require("eslint-rule-composer");
|
||||||
const eslint = require('eslint');
|
const eslint = require("eslint");
|
||||||
const rule = new eslint.Linter().getRules().get('no-unused-expressions');
|
const rule = new eslint.Linter().getRules().get("no-unused-expressions");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ASTNode} node - any node
|
* @param {ASTNode} node - any node
|
||||||
@ -11,9 +11,11 @@ const rule = new eslint.Linter().getRules().get('no-unused-expressions');
|
|||||||
*/
|
*/
|
||||||
function isFinalStatementInBlockStatement(node) {
|
function isFinalStatementInBlockStatement(node) {
|
||||||
const parent = node.parent;
|
const parent = node.parent;
|
||||||
return /^(?:If|Expression)Statement$/.test(node.type) &&
|
return (
|
||||||
parent.type === 'BlockStatement' &&
|
/^(?:If|Expression)Statement$/.test(node.type) &&
|
||||||
parent.body[parent.body.length - 1] === node;
|
parent.type === "BlockStatement" &&
|
||||||
|
parent.body[parent.body.length - 1] === node
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,13 +26,13 @@ function isFinalStatementInBlockStatement(node) {
|
|||||||
function isInDoStatement(node) {
|
function isInDoStatement(node) {
|
||||||
if (!node) return false;
|
if (!node) return false;
|
||||||
|
|
||||||
if (node.type === 'DoExpression') return true;
|
if (node.type === "DoExpression") return true;
|
||||||
|
|
||||||
// this is an `else if`
|
// this is an `else if`
|
||||||
if (
|
if (
|
||||||
node.type === 'IfStatement' &&
|
node.type === "IfStatement" &&
|
||||||
node.parent &&
|
node.parent &&
|
||||||
node.parent.type === 'IfStatement'
|
node.parent.type === "IfStatement"
|
||||||
) {
|
) {
|
||||||
return isInDoStatement(node.parent);
|
return isInDoStatement(node.parent);
|
||||||
}
|
}
|
||||||
@ -50,14 +52,13 @@ function isInDoStatement(node) {
|
|||||||
function isOptionalCallExpression(node) {
|
function isOptionalCallExpression(node) {
|
||||||
return (
|
return (
|
||||||
!!node &&
|
!!node &&
|
||||||
node.type === 'ExpressionStatement' &&
|
node.type === "ExpressionStatement" &&
|
||||||
node.expression.type === 'OptionalCallExpression'
|
node.expression.type === "OptionalCallExpression"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ruleComposer.filterReports(
|
module.exports = ruleComposer.filterReports(
|
||||||
rule,
|
rule,
|
||||||
(problem, metadata) =>
|
problem =>
|
||||||
!isInDoStatement(problem.node) && !isOptionalCallExpression(problem.node)
|
!isInDoStatement(problem.node) && !isOptionalCallExpression(problem.node)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -1,25 +1,27 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const ruleComposer = require('eslint-rule-composer');
|
const ruleComposer = require("eslint-rule-composer");
|
||||||
const eslint = require('eslint');
|
const eslint = require("eslint");
|
||||||
const objectCurlySpacingRule = new eslint.Linter().getRules().get('object-curly-spacing');
|
const objectCurlySpacingRule = new eslint.Linter()
|
||||||
|
.getRules()
|
||||||
|
.get("object-curly-spacing");
|
||||||
|
|
||||||
module.exports = ruleComposer.filterReports(
|
module.exports = ruleComposer.filterReports(
|
||||||
objectCurlySpacingRule,
|
objectCurlySpacingRule,
|
||||||
(problem, metadata) => {
|
(problem, metadata) => {
|
||||||
const node = problem.node;
|
const node = problem.node;
|
||||||
|
|
||||||
// Allow `exportNamespaceFrom` and `exportDefaultFrom` syntax:
|
// Allow `exportNamespaceFrom` and `exportDefaultFrom` syntax:
|
||||||
// export * as x from '...';
|
// export * as x from '...';
|
||||||
// export x from '...';
|
// export x from '...';
|
||||||
if (
|
if (
|
||||||
node.type === 'ExportNamedDeclaration' &&
|
node.type === "ExportNamedDeclaration" &&
|
||||||
node.specifiers.length > 0 &&
|
node.specifiers.length > 0 &&
|
||||||
metadata.sourceCode.getTokenBefore(node.specifiers[0]).value === "export"
|
metadata.sourceCode.getTokenBefore(node.specifiers[0]).value === "export"
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,28 +1,31 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var isWarnedForDeprecation = false;
|
let isWarnedForDeprecation = false;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
meta: {
|
meta: {
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
schema: [
|
schema: [
|
||||||
{
|
{
|
||||||
"enum": ["always", "methods", "properties", "never"]
|
enum: ["always", "methods", "properties", "never"],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
create: function() {
|
create: function() {
|
||||||
return {
|
return {
|
||||||
Program: function() {
|
Program: function() {
|
||||||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
if (
|
||||||
return;
|
isWarnedForDeprecation ||
|
||||||
}
|
/=-(f|-format)=/.test(process.argv.join("="))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
console.log(
|
||||||
console.log('The babel/object-shorthand rule is deprecated. Please ' +
|
"The babel/object-shorthand rule is deprecated. Please " +
|
||||||
'use the built in object-shorthand rule instead.');
|
"use the built in object-shorthand rule instead."
|
||||||
/* eslint-enable no-console */
|
);
|
||||||
isWarnedForDeprecation = true;
|
isWarnedForDeprecation = true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
const ruleComposer = require('eslint-rule-composer');
|
const ruleComposer = require("eslint-rule-composer");
|
||||||
const eslint = require('eslint');
|
const eslint = require("eslint");
|
||||||
const quotesRule = new eslint.Linter().getRules().get('quotes');
|
const quotesRule = new eslint.Linter().getRules().get("quotes");
|
||||||
|
|
||||||
module.exports = ruleComposer.filterReports(
|
module.exports = ruleComposer.filterReports(quotesRule, problem => {
|
||||||
quotesRule,
|
// Workaround for JSX fragment syntax until
|
||||||
(problem, metadata) => {
|
// https://github.com/eslint/eslint/issues/9662
|
||||||
// Workaround for JSX fragment syntax until
|
if (problem.node.parent.type === "JSXFragment") {
|
||||||
// https://github.com/eslint/eslint/issues/9662
|
return false;
|
||||||
if (problem.node.parent.type === "JSXFragment") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|||||||
@ -1,115 +1,123 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const ruleComposer = require('eslint-rule-composer');
|
const ruleComposer = require("eslint-rule-composer");
|
||||||
const eslint = require('eslint');
|
const eslint = require("eslint");
|
||||||
const semiRule = new eslint.Linter().getRules().get('semi');
|
const semiRule = new eslint.Linter().getRules().get("semi");
|
||||||
|
|
||||||
const OPT_OUT_PATTERN = /^[-[(/+`]/; // One of [(/+-`
|
const OPT_OUT_PATTERN = /^[-[(/+`]/; // One of [(/+-`
|
||||||
|
|
||||||
const isSemicolon = token => token.type === "Punctuator" && token.value === ";";
|
const isSemicolon = token => token.type === "Punctuator" && token.value === ";";
|
||||||
|
|
||||||
const isUnnecessarySemicolon = (context, lastToken) => {
|
const isUnnecessarySemicolon = (context, lastToken) => {
|
||||||
if (!isSemicolon(lastToken)) {
|
if (!isSemicolon(lastToken)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextToken = context.getSourceCode().getTokenAfter(lastToken);
|
const nextToken = context.getSourceCode().getTokenAfter(lastToken);
|
||||||
|
|
||||||
if (!nextToken) {
|
if (!nextToken) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastTokenLine = lastToken.loc.end.line;
|
const lastTokenLine = lastToken.loc.end.line;
|
||||||
const nextTokenLine = nextToken.loc.start.line;
|
const nextTokenLine = nextToken.loc.start.line;
|
||||||
const isOptOutToken = OPT_OUT_PATTERN.test(nextToken.value) && nextToken.value !== "++" && nextToken.value !== "--";
|
const isOptOutToken =
|
||||||
const isDivider = (nextToken.value === "}" || nextToken.value === ";");
|
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 isOneLinerBlock = (context, node) => {
|
||||||
const nextToken = context.getSourceCode().getTokenAfter(node);
|
const nextToken = context.getSourceCode().getTokenAfter(node);
|
||||||
|
|
||||||
if (!nextToken || nextToken.value !== "}") {
|
if (!nextToken || nextToken.value !== "}") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = node.parent;
|
const parent = node.parent;
|
||||||
|
|
||||||
return parent && parent.type === "BlockStatement" &&
|
return (
|
||||||
parent.loc.start.line === parent.loc.end.line;
|
parent &&
|
||||||
|
parent.type === "BlockStatement" &&
|
||||||
|
parent.loc.start.line === parent.loc.end.line
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const report = (context, node, missing) => {
|
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) {
|
if (!missing) {
|
||||||
message = "Missing semicolon.";
|
message = "Missing semicolon.";
|
||||||
loc = loc.end;
|
loc = loc.end;
|
||||||
fix = function(fixer) {
|
fix = function(fixer) {
|
||||||
return fixer.insertTextAfter(lastToken, ";");
|
return fixer.insertTextAfter(lastToken, ";");
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
message = "Extra semicolon.";
|
message = "Extra semicolon.";
|
||||||
loc = loc.start;
|
loc = loc.start;
|
||||||
fix = function(fixer) {
|
fix = function(fixer) {
|
||||||
return fixer.remove(lastToken);
|
return fixer.remove(lastToken);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
context.report({
|
context.report({
|
||||||
node,
|
node,
|
||||||
loc,
|
loc,
|
||||||
message,
|
message,
|
||||||
fix
|
fix,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const semiRuleWithClassProperty = ruleComposer.joinReports([
|
const semiRuleWithClassProperty = ruleComposer.joinReports([
|
||||||
semiRule,
|
semiRule,
|
||||||
context => ({
|
context => ({
|
||||||
ClassProperty(node) {
|
ClassProperty(node) {
|
||||||
const options = context.options[1];
|
const options = context.options[1];
|
||||||
const exceptOneLine = options && options.omitLastInOneLineBlock === true;
|
const exceptOneLine = options && options.omitLastInOneLineBlock === true;
|
||||||
|
|
||||||
const sourceCode = context.getSourceCode();
|
const sourceCode = context.getSourceCode();
|
||||||
const lastToken = sourceCode.getLastToken(node);
|
const lastToken = sourceCode.getLastToken(node);
|
||||||
|
|
||||||
if (context.options[0] === "never") {
|
if (context.options[0] === "never") {
|
||||||
if (isUnnecessarySemicolon(context, lastToken)) {
|
if (isUnnecessarySemicolon(context, lastToken)) {
|
||||||
report(context, node, true);
|
report(context, node, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isSemicolon(lastToken)) {
|
if (!isSemicolon(lastToken)) {
|
||||||
if (!exceptOneLine || !isOneLinerBlock(context, node)) {
|
if (!exceptOneLine || !isOneLinerBlock(context, node)) {
|
||||||
report(context, node);
|
report(context, node);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (exceptOneLine && isOneLinerBlock(context, node)) {
|
if (exceptOneLine && isOneLinerBlock(context, node)) {
|
||||||
report(context, node, true);
|
report(context, node, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
module.exports = ruleComposer.filterReports(
|
module.exports = ruleComposer.filterReports(
|
||||||
semiRuleWithClassProperty,
|
semiRuleWithClassProperty,
|
||||||
(problem, metadata) => {
|
problem => {
|
||||||
const node = problem.node;
|
const node = problem.node;
|
||||||
|
|
||||||
// Handle async iterator:
|
// Handle async iterator:
|
||||||
// for await (let something of {})
|
// for await (let something of {})
|
||||||
if (
|
if (
|
||||||
node.type === "VariableDeclaration" &&
|
node.type === "VariableDeclaration" &&
|
||||||
node.parent.type === "ForAwaitStatement"
|
node.parent.type === "ForAwaitStatement"
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const ruleComposer = require('eslint-rule-composer');
|
const ruleComposer = require("eslint-rule-composer");
|
||||||
const eslint = require('eslint');
|
const eslint = require("eslint");
|
||||||
const validTypeOf = new eslint.Linter().getRules().get('valid-typeof');
|
const validTypeOf = new eslint.Linter().getRules().get("valid-typeof");
|
||||||
|
|
||||||
module.exports = ruleComposer.filterReports(
|
module.exports = ruleComposer.filterReports(validTypeOf, problem => {
|
||||||
validTypeOf,
|
return problem.node.value !== "bigint";
|
||||||
(problem, metadata) => {
|
});
|
||||||
return problem.node.value !== 'bigint';
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview Tests for new-cap rule.
|
* @fileoverview Tests for new-cap rule.
|
||||||
* @author Nicholas C. Zakas
|
* @author Nicholas C. Zakas
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview Disallows or enforces spaces inside of object literals.
|
* @fileoverview Disallows or enforces spaces inside of object literals.
|
||||||
* @author Jamund Ferguson
|
* @author Jamund Ferguson
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user