tools: update ESLint to 5.15.3
Update ESLint to 5.15.3 PR-URL: https://github.com/nodejs/node/pull/26746 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
parent
cd3a9eebca
commit
2b89ac6818
177
tools/node_modules/eslint/lib/rules/implicit-arrow-linebreak.js
generated
vendored
177
tools/node_modules/eslint/lib/rules/implicit-arrow-linebreak.js
generated
vendored
@ -4,10 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const {
|
const { isCommentToken, isNotOpeningParenToken } = require("../util/ast-utils");
|
||||||
isArrowToken,
|
|
||||||
isParenthesised
|
|
||||||
} = require("../util/ast-utils");
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Rule Definition
|
// Rule Definition
|
||||||
@ -38,142 +35,7 @@ module.exports = {
|
|||||||
|
|
||||||
create(context) {
|
create(context) {
|
||||||
const sourceCode = context.getSourceCode();
|
const sourceCode = context.getSourceCode();
|
||||||
|
const option = context.options[0] || "beside";
|
||||||
//----------------------------------------------------------------------
|
|
||||||
// Helpers
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Gets the applicable preference for a particular keyword
|
|
||||||
* @returns {string} The applicable option for the keyword, e.g. 'beside'
|
|
||||||
*/
|
|
||||||
function getOption() {
|
|
||||||
return context.options[0] || "beside";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats the comments depending on whether it's a line or block comment.
|
|
||||||
* @param {Comment[]} comments The array of comments between the arrow and body
|
|
||||||
* @param {Integer} column The column number of the first token
|
|
||||||
* @returns {string} A string of comment text joined by line breaks
|
|
||||||
*/
|
|
||||||
function formatComments(comments) {
|
|
||||||
|
|
||||||
return `${comments.map(comment => {
|
|
||||||
|
|
||||||
if (comment.type === "Line") {
|
|
||||||
return `//${comment.value}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `/*${comment.value}*/`;
|
|
||||||
}).join("\n")}\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the first token to prepend comments to depending on the parent type
|
|
||||||
* @param {ASTNode} node The validated node
|
|
||||||
* @returns {Token|Node} The node to prepend comments to
|
|
||||||
*/
|
|
||||||
function findFirstToken(node) {
|
|
||||||
switch (node.parent.type) {
|
|
||||||
case "VariableDeclarator":
|
|
||||||
|
|
||||||
// If the parent is first or only declarator, return the declaration, else, declarator
|
|
||||||
return sourceCode.getFirstToken(
|
|
||||||
node.parent.parent.declarations.length === 1 ||
|
|
||||||
node.parent.parent.declarations[0].id.name === node.parent.id.name
|
|
||||||
? node.parent.parent : node.parent
|
|
||||||
);
|
|
||||||
case "CallExpression":
|
|
||||||
case "Property":
|
|
||||||
|
|
||||||
// find the object key
|
|
||||||
return sourceCode.getFirstToken(node.parent);
|
|
||||||
default:
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function for adding parentheses fixes for nodes containing nested arrow functions
|
|
||||||
* @param {Fixer} fixer Fixer
|
|
||||||
* @param {Token} arrow - The arrow token
|
|
||||||
* @param {ASTNode} arrowBody - The arrow function body
|
|
||||||
* @returns {Function[]} autofixer -- wraps function bodies with parentheses
|
|
||||||
*/
|
|
||||||
function addParentheses(fixer, arrow, arrowBody) {
|
|
||||||
const parenthesesFixes = [];
|
|
||||||
let closingParentheses = "";
|
|
||||||
|
|
||||||
let followingBody = arrowBody;
|
|
||||||
let currentArrow = arrow;
|
|
||||||
|
|
||||||
while (currentArrow && followingBody.type !== "BlockStatement") {
|
|
||||||
if (!isParenthesised(sourceCode, followingBody)) {
|
|
||||||
parenthesesFixes.push(
|
|
||||||
fixer.insertTextAfter(currentArrow, " (")
|
|
||||||
);
|
|
||||||
|
|
||||||
closingParentheses = `\n)${closingParentheses}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentArrow = sourceCode.getTokenAfter(currentArrow, isArrowToken);
|
|
||||||
|
|
||||||
if (currentArrow) {
|
|
||||||
followingBody = followingBody.body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [...parenthesesFixes,
|
|
||||||
fixer.insertTextAfter(arrowBody, closingParentheses)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Autofixes the function body to collapse onto the same line as the arrow.
|
|
||||||
* If comments exist, checks if the function body contains arrow functions, and appends the body with parentheses.
|
|
||||||
* Otherwise, prepends the comments before the arrow function.
|
|
||||||
* @param {Token} arrowToken The arrow token.
|
|
||||||
* @param {ASTNode|Token} arrowBody the function body
|
|
||||||
* @param {ASTNode} node The evaluated node
|
|
||||||
* @returns {Function} autofixer -- validates the node to adhere to besides
|
|
||||||
*/
|
|
||||||
function autoFixBesides(arrowToken, arrowBody, node) {
|
|
||||||
return fixer => {
|
|
||||||
const placeBesides = fixer.replaceTextRange([arrowToken.range[1], arrowBody.range[0]], " ");
|
|
||||||
|
|
||||||
const comments = sourceCode.getCommentsInside(node).filter(comment =>
|
|
||||||
comment.loc.start.line < arrowBody.loc.start.line);
|
|
||||||
|
|
||||||
if (comments.length) {
|
|
||||||
|
|
||||||
// If the grandparent is not a variable declarator
|
|
||||||
if (
|
|
||||||
arrowBody.parent &&
|
|
||||||
arrowBody.parent.parent &&
|
|
||||||
arrowBody.parent.parent.type !== "VariableDeclarator"
|
|
||||||
) {
|
|
||||||
|
|
||||||
// If any arrow functions follow, return the necessary parens fixes.
|
|
||||||
if (node.body.type === "ArrowFunctionExpression" &&
|
|
||||||
arrowBody.parent.parent.type !== "VariableDeclarator"
|
|
||||||
) {
|
|
||||||
return addParentheses(fixer, arrowToken, arrowBody);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstToken = findFirstToken(node);
|
|
||||||
|
|
||||||
const commentBeforeExpression = fixer.insertTextBeforeRange(
|
|
||||||
firstToken.range,
|
|
||||||
formatComments(comments)
|
|
||||||
);
|
|
||||||
|
|
||||||
return [placeBesides, commentBeforeExpression];
|
|
||||||
}
|
|
||||||
|
|
||||||
return placeBesides;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the location of an arrow function body
|
* Validates the location of an arrow function body
|
||||||
@ -181,35 +43,30 @@ module.exports = {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function validateExpression(node) {
|
function validateExpression(node) {
|
||||||
const option = getOption();
|
if (node.body.type === "BlockStatement") {
|
||||||
|
|
||||||
let tokenBefore = sourceCode.getTokenBefore(node.body);
|
|
||||||
const hasParens = tokenBefore.value === "(";
|
|
||||||
|
|
||||||
if (node.type === "BlockStatement") {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let fixerTarget = node.body;
|
const arrowToken = sourceCode.getTokenBefore(node.body, isNotOpeningParenToken);
|
||||||
|
const firstTokenOfBody = sourceCode.getTokenAfter(arrowToken);
|
||||||
|
|
||||||
if (hasParens) {
|
if (arrowToken.loc.end.line === firstTokenOfBody.loc.start.line && option === "below") {
|
||||||
|
|
||||||
// Gets the first token before the function body that is not an open paren
|
|
||||||
tokenBefore = sourceCode.getTokenBefore(node.body, token => token.value !== "(");
|
|
||||||
fixerTarget = sourceCode.getTokenAfter(tokenBefore);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokenBefore.loc.end.line === fixerTarget.loc.start.line && option === "below") {
|
|
||||||
context.report({
|
context.report({
|
||||||
node: fixerTarget,
|
node: firstTokenOfBody,
|
||||||
messageId: "expected",
|
messageId: "expected",
|
||||||
fix: fixer => fixer.insertTextBefore(fixerTarget, "\n")
|
fix: fixer => fixer.insertTextBefore(firstTokenOfBody, "\n")
|
||||||
});
|
});
|
||||||
} else if (tokenBefore.loc.end.line !== fixerTarget.loc.start.line && option === "beside") {
|
} else if (arrowToken.loc.end.line !== firstTokenOfBody.loc.start.line && option === "beside") {
|
||||||
context.report({
|
context.report({
|
||||||
node: fixerTarget,
|
node: firstTokenOfBody,
|
||||||
messageId: "unexpected",
|
messageId: "unexpected",
|
||||||
fix: autoFixBesides(tokenBefore, fixerTarget, node)
|
fix(fixer) {
|
||||||
|
if (sourceCode.getFirstTokenBetween(arrowToken, firstTokenOfBody, { includeComments: true, filter: isCommentToken })) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fixer.replaceTextRange([arrowToken.range[1], firstTokenOfBody.range[0]], " ");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
tools/node_modules/eslint/node_modules/inquirer/node_modules/strip-ansi/index.js
generated
vendored
5
tools/node_modules/eslint/node_modules/inquirer/node_modules/strip-ansi/index.js
generated
vendored
@ -1,4 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const ansiRegex = require('ansi-regex');
|
const ansiRegex = require('ansi-regex');
|
||||||
|
|
||||||
module.exports = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
|
const stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
|
||||||
|
|
||||||
|
module.exports = stripAnsi;
|
||||||
|
module.exports.default = stripAnsi;
|
||||||
|
14
tools/node_modules/eslint/node_modules/inquirer/node_modules/strip-ansi/package.json
generated
vendored
14
tools/node_modules/eslint/node_modules/inquirer/node_modules/strip-ansi/package.json
generated
vendored
@ -12,16 +12,18 @@
|
|||||||
"ansi-regex": "^4.1.0"
|
"ansi-regex": "^4.1.0"
|
||||||
},
|
},
|
||||||
"deprecated": false,
|
"deprecated": false,
|
||||||
"description": "Strip ANSI escape codes",
|
"description": "Strip ANSI escape codes from a string",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^0.25.0",
|
"ava": "^1.3.1",
|
||||||
"xo": "^0.23.0"
|
"tsd-check": "^0.5.0",
|
||||||
|
"xo": "^0.24.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"index.js"
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/chalk/strip-ansi#readme",
|
"homepage": "https://github.com/chalk/strip-ansi#readme",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -55,7 +57,7 @@
|
|||||||
"url": "git+https://github.com/chalk/strip-ansi.git"
|
"url": "git+https://github.com/chalk/strip-ansi.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "xo && ava"
|
"test": "xo && ava && tsd-check"
|
||||||
},
|
},
|
||||||
"version": "5.1.0"
|
"version": "5.2.0"
|
||||||
}
|
}
|
4
tools/node_modules/eslint/node_modules/inquirer/node_modules/strip-ansi/readme.md
generated
vendored
4
tools/node_modules/eslint/node_modules/inquirer/node_modules/strip-ansi/readme.md
generated
vendored
@ -1,6 +1,6 @@
|
|||||||
# strip-ansi [](https://travis-ci.org/chalk/strip-ansi)
|
# strip-ansi [](https://travis-ci.org/chalk/strip-ansi)
|
||||||
|
|
||||||
> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
|
> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ const stripAnsi = require('strip-ansi');
|
|||||||
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
||||||
//=> 'Unicorn'
|
//=> 'Unicorn'
|
||||||
|
|
||||||
stripAnsi('\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007');
|
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
||||||
//=> 'Click'
|
//=> 'Click'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
5
tools/node_modules/eslint/node_modules/table/node_modules/strip-ansi/index.js
generated
vendored
5
tools/node_modules/eslint/node_modules/table/node_modules/strip-ansi/index.js
generated
vendored
@ -1,4 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const ansiRegex = require('ansi-regex');
|
const ansiRegex = require('ansi-regex');
|
||||||
|
|
||||||
module.exports = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
|
const stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
|
||||||
|
|
||||||
|
module.exports = stripAnsi;
|
||||||
|
module.exports.default = stripAnsi;
|
||||||
|
14
tools/node_modules/eslint/node_modules/table/node_modules/strip-ansi/package.json
generated
vendored
14
tools/node_modules/eslint/node_modules/table/node_modules/strip-ansi/package.json
generated
vendored
@ -12,16 +12,18 @@
|
|||||||
"ansi-regex": "^4.1.0"
|
"ansi-regex": "^4.1.0"
|
||||||
},
|
},
|
||||||
"deprecated": false,
|
"deprecated": false,
|
||||||
"description": "Strip ANSI escape codes",
|
"description": "Strip ANSI escape codes from a string",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^0.25.0",
|
"ava": "^1.3.1",
|
||||||
"xo": "^0.23.0"
|
"tsd-check": "^0.5.0",
|
||||||
|
"xo": "^0.24.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"index.js"
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/chalk/strip-ansi#readme",
|
"homepage": "https://github.com/chalk/strip-ansi#readme",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -55,7 +57,7 @@
|
|||||||
"url": "git+https://github.com/chalk/strip-ansi.git"
|
"url": "git+https://github.com/chalk/strip-ansi.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "xo && ava"
|
"test": "xo && ava && tsd-check"
|
||||||
},
|
},
|
||||||
"version": "5.1.0"
|
"version": "5.2.0"
|
||||||
}
|
}
|
4
tools/node_modules/eslint/node_modules/table/node_modules/strip-ansi/readme.md
generated
vendored
4
tools/node_modules/eslint/node_modules/table/node_modules/strip-ansi/readme.md
generated
vendored
@ -1,6 +1,6 @@
|
|||||||
# strip-ansi [](https://travis-ci.org/chalk/strip-ansi)
|
# strip-ansi [](https://travis-ci.org/chalk/strip-ansi)
|
||||||
|
|
||||||
> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
|
> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ const stripAnsi = require('strip-ansi');
|
|||||||
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
||||||
//=> 'Unicorn'
|
//=> 'Unicorn'
|
||||||
|
|
||||||
stripAnsi('\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007');
|
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
||||||
//=> 'Click'
|
//=> 'Click'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
2
tools/node_modules/eslint/package.json
generated
vendored
2
tools/node_modules/eslint/package.json
generated
vendored
@ -135,5 +135,5 @@
|
|||||||
"test": "node Makefile.js test",
|
"test": "node Makefile.js test",
|
||||||
"webpack": "node Makefile.js webpack"
|
"webpack": "node Makefile.js webpack"
|
||||||
},
|
},
|
||||||
"version": "5.15.2"
|
"version": "5.15.3"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user