Bump packages to fix linter

This commit is contained in:
Henry Mercer 2023-01-18 20:50:03 +00:00
parent ed9506bbaf
commit 0a11e3fdd9
6063 changed files with 378752 additions and 306784 deletions

View file

@ -32,10 +32,11 @@ const thisTagPattern = /^[\s*]*@this/mu;
const COMMENTS_IGNORE_PATTERN = /^\s*(?:eslint|jshint\s+|jslint\s+|istanbul\s+|globals?\s+|exported\s+|jscs)/u;
const ESLINT_DIRECTIVE_PATTERN = /^(?:eslint[- ]|(?:globals?|exported) )/u;
const LINEBREAKS = new Set(["\r\n", "\r", "\n", "\u2028", "\u2029"]);
// A set of node types that can contain a list of statements
const STATEMENT_LIST_PARENTS = new Set(["Program", "BlockStatement", "SwitchCase"]);
const STATEMENT_LIST_PARENTS = new Set(["Program", "BlockStatement", "StaticBlock", "SwitchCase"]);
const DECIMAL_INTEGER_PATTERN = /^(?:0|0[0-7]*[89]\d*|[1-9](?:_?\d)*)$/u;
@ -266,6 +267,7 @@ function getStaticPropertyName(node) {
return getStaticPropertyName(node.expression);
case "Property":
case "PropertyDefinition":
case "MethodDefinition":
prop = node.key;
break;
@ -407,6 +409,7 @@ function isSameReference(left, right, disableStaticComputedKey = false) {
return true;
case "Identifier":
case "PrivateIdentifier":
return left.name === right.name;
case "Literal":
return equalLiteralValue(left, right);
@ -516,6 +519,15 @@ function isParenthesised(sourceCode, node) {
nextToken.value === ")" && nextToken.range[0] >= node.range[1];
}
/**
* Checks if the given token is a `=` token or not.
* @param {Token} token The token to check.
* @returns {boolean} `true` if the token is a `=` token.
*/
function isEqToken(token) {
return token.value === "=" && token.type === "Punctuator";
}
/**
* Checks if the given token is an arrow token or not.
* @param {Token} token The token to check.
@ -649,6 +661,16 @@ function isKeywordToken(token) {
* @returns {Token} `(` token.
*/
function getOpeningParenOfParams(node, sourceCode) {
// If the node is an arrow function and doesn't have parens, this returns the identifier of the first param.
if (node.type === "ArrowFunctionExpression" && node.params.length === 1) {
const argToken = sourceCode.getFirstToken(node.params[0]);
const maybeParenToken = sourceCode.getTokenBefore(argToken);
return isOpeningParenToken(maybeParenToken) ? maybeParenToken : argToken;
}
// Otherwise, returns paren.
return node.id
? sourceCode.getTokenAfter(node.id, isOpeningParenToken)
: sourceCode.getFirstToken(node, isOpeningParenToken);
@ -735,6 +757,235 @@ function isLogicalAssignmentOperator(operator) {
return LOGICAL_ASSIGNMENT_OPERATORS.has(operator);
}
/**
* Get the colon token of the given SwitchCase node.
* @param {ASTNode} node The SwitchCase node to get.
* @param {SourceCode} sourceCode The source code object to get tokens.
* @returns {Token} The colon token of the node.
*/
function getSwitchCaseColonToken(node, sourceCode) {
if (node.test) {
return sourceCode.getTokenAfter(node.test, isColonToken);
}
return sourceCode.getFirstToken(node, 1);
}
/**
* Gets ESM module export name represented by the given node.
* @param {ASTNode} node `Identifier` or string `Literal` node in a position
* that represents a module export name:
* - `ImportSpecifier#imported`
* - `ExportSpecifier#local` (if it is a re-export from another module)
* - `ExportSpecifier#exported`
* - `ExportAllDeclaration#exported`
* @returns {string} The module export name.
*/
function getModuleExportName(node) {
if (node.type === "Identifier") {
return node.name;
}
// string literal
return node.value;
}
/**
* Returns literal's value converted to the Boolean type
* @param {ASTNode} node any `Literal` node
* @returns {boolean | null} `true` when node is truthy, `false` when node is falsy,
* `null` when it cannot be determined.
*/
function getBooleanValue(node) {
if (node.value === null) {
/*
* it might be a null literal or bigint/regex literal in unsupported environments .
* https://github.com/estree/estree/blob/14df8a024956ea289bd55b9c2226a1d5b8a473ee/es5.md#regexpliteral
* https://github.com/estree/estree/blob/14df8a024956ea289bd55b9c2226a1d5b8a473ee/es2020.md#bigintliteral
*/
if (node.raw === "null") {
return false;
}
// regex is always truthy
if (typeof node.regex === "object") {
return true;
}
return null;
}
return !!node.value;
}
/**
* Checks if a branch node of LogicalExpression short circuits the whole condition
* @param {ASTNode} node The branch of main condition which needs to be checked
* @param {string} operator The operator of the main LogicalExpression.
* @returns {boolean} true when condition short circuits whole condition
*/
function isLogicalIdentity(node, operator) {
switch (node.type) {
case "Literal":
return (operator === "||" && getBooleanValue(node) === true) ||
(operator === "&&" && getBooleanValue(node) === false);
case "UnaryExpression":
return (operator === "&&" && node.operator === "void");
case "LogicalExpression":
/*
* handles `a && false || b`
* `false` is an identity element of `&&` but not `||`
*/
return operator === node.operator &&
(
isLogicalIdentity(node.left, operator) ||
isLogicalIdentity(node.right, operator)
);
case "AssignmentExpression":
return ["||=", "&&="].includes(node.operator) &&
operator === node.operator.slice(0, -1) &&
isLogicalIdentity(node.right, operator);
// no default
}
return false;
}
/**
* Checks if an identifier is a reference to a global variable.
* @param {Scope} scope The scope in which the identifier is referenced.
* @param {ASTNode} node An identifier node to check.
* @returns {boolean} `true` if the identifier is a reference to a global variable.
*/
function isReferenceToGlobalVariable(scope, node) {
const reference = scope.references.find(ref => ref.identifier === node);
return Boolean(
reference &&
reference.resolved &&
reference.resolved.scope.type === "global" &&
reference.resolved.defs.length === 0
);
}
/**
* Checks if a node has a constant truthiness value.
* @param {Scope} scope Scope in which the node appears.
* @param {ASTNode} node The AST node to check.
* @param {boolean} inBooleanPosition `true` if checking the test of a
* condition. `false` in all other cases. When `false`, checks if -- for
* both string and number -- if coerced to that type, the value will
* be constant.
* @returns {boolean} true when node's truthiness is constant
* @private
*/
function isConstant(scope, node, inBooleanPosition) {
// node.elements can return null values in the case of sparse arrays ex. [,]
if (!node) {
return true;
}
switch (node.type) {
case "Literal":
case "ArrowFunctionExpression":
case "FunctionExpression":
return true;
case "ClassExpression":
case "ObjectExpression":
/**
* In theory objects like:
*
* `{toString: () => a}`
* `{valueOf: () => a}`
*
* Or a classes like:
*
* `class { static toString() { return a } }`
* `class { static valueOf() { return a } }`
*
* Are not constant verifiably when `inBooleanPosition` is
* false, but it's an edge case we've opted not to handle.
*/
return true;
case "TemplateLiteral":
return (inBooleanPosition && node.quasis.some(quasi => quasi.value.cooked.length)) ||
node.expressions.every(exp => isConstant(scope, exp, false));
case "ArrayExpression": {
if (!inBooleanPosition) {
return node.elements.every(element => isConstant(scope, element, false));
}
return true;
}
case "UnaryExpression":
if (
node.operator === "void" ||
node.operator === "typeof" && inBooleanPosition
) {
return true;
}
if (node.operator === "!") {
return isConstant(scope, node.argument, true);
}
return isConstant(scope, node.argument, false);
case "BinaryExpression":
return isConstant(scope, node.left, false) &&
isConstant(scope, node.right, false) &&
node.operator !== "in";
case "LogicalExpression": {
const isLeftConstant = isConstant(scope, node.left, inBooleanPosition);
const isRightConstant = isConstant(scope, node.right, inBooleanPosition);
const isLeftShortCircuit = (isLeftConstant && isLogicalIdentity(node.left, node.operator));
const isRightShortCircuit = (inBooleanPosition && isRightConstant && isLogicalIdentity(node.right, node.operator));
return (isLeftConstant && isRightConstant) ||
isLeftShortCircuit ||
isRightShortCircuit;
}
case "NewExpression":
return inBooleanPosition;
case "AssignmentExpression":
if (node.operator === "=") {
return isConstant(scope, node.right, inBooleanPosition);
}
if (["||=", "&&="].includes(node.operator) && inBooleanPosition) {
return isLogicalIdentity(node.right, node.operator.slice(0, -1));
}
return false;
case "SequenceExpression":
return isConstant(scope, node.expressions[node.expressions.length - 1], inBooleanPosition);
case "SpreadElement":
return isConstant(scope, node.argument, inBooleanPosition);
case "CallExpression":
if (node.callee.type === "Identifier" && node.callee.name === "Boolean") {
if (node.arguments.length === 0 || isConstant(scope, node.arguments[0], true)) {
return isReferenceToGlobalVariable(scope, node.callee);
}
}
return false;
case "Identifier":
return node.name === "undefined" && isReferenceToGlobalVariable(scope, node);
// no default
}
return false;
}
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
@ -794,6 +1045,7 @@ module.exports = {
isOpeningBracketToken,
isOpeningParenToken,
isSemicolonToken,
isEqToken,
/**
* Checks whether or not a given node is a string literal.
@ -836,8 +1088,8 @@ module.exports = {
/**
* Validate that a string passed in is surrounded by the specified character
* @param {string} val The text to check.
* @param {string} character The character to see if it's surrounded by.
* @param {string} val The text to check.
* @param {string} character The character to see if it's surrounded by.
* @returns {boolean} True if the text is surrounded by the character, false if not.
* @private
*/
@ -854,12 +1106,8 @@ module.exports = {
const comment = node.value.trim();
return (
node.type === "Line" && comment.indexOf("eslint-") === 0 ||
node.type === "Block" && (
comment.indexOf("global ") === 0 ||
comment.indexOf("eslint ") === 0 ||
comment.indexOf("eslint-") === 0
)
node.type === "Line" && comment.startsWith("eslint-") ||
node.type === "Block" && ESLINT_DIRECTIVE_PATTERN.test(comment)
);
},
@ -902,6 +1150,8 @@ module.exports = {
*
* First, this checks the node:
*
* - The given node is not in `PropertyDefinition#value` position.
* - The given node is not `StaticBlock`.
* - The function name does not start with uppercase. It's a convention to capitalize the names
* of constructor functions. This check is not performed if `capIsConstructor` is set to `false`.
* - The function does not have a JSDoc comment that has a @this tag.
@ -916,13 +1166,29 @@ module.exports = {
* - The location is not on an ES2015 class.
* - Its `bind`/`call`/`apply` method is not called directly.
* - The function is not a callback of array methods (such as `.forEach()`) if `thisArg` is given.
* @param {ASTNode} node A function node to check.
* @param {ASTNode} node A function node to check. It also can be an implicit function, like `StaticBlock`
* or any expression that is `PropertyDefinition#value` node.
* @param {SourceCode} sourceCode A SourceCode instance to get comments.
* @param {boolean} [capIsConstructor = true] `false` disables the assumption that functions which name starts
* with an uppercase or are assigned to a variable which name starts with an uppercase are constructors.
* @returns {boolean} The function node is the default `this` binding.
*/
isDefaultThisBinding(node, sourceCode, { capIsConstructor = true } = {}) {
/*
* Class field initializers are implicit functions, but ESTree doesn't have the AST node of field initializers.
* Therefore, A expression node at `PropertyDefinition#value` is a function.
* In this case, `this` is always not default binding.
*/
if (node.parent.type === "PropertyDefinition" && node.parent.value === node) {
return false;
}
// Class static blocks are implicit functions. In this case, `this` is always not default binding.
if (node.type === "StaticBlock") {
return false;
}
if (
(capIsConstructor && isES5Constructor(node)) ||
hasJSDocThisTag(node, sourceCode)
@ -983,8 +1249,10 @@ module.exports = {
* class A { get foo() { ... } }
* class A { set foo() { ... } }
* class A { static foo() { ... } }
* class A { foo = function() { ... } }
*/
case "Property":
case "PropertyDefinition":
case "MethodDefinition":
return parent.value !== currentNode;
@ -1082,7 +1350,7 @@ module.exports = {
}
}
/* istanbul ignore next */
/* c8 ignore next */
return true;
},
@ -1261,7 +1529,8 @@ module.exports = {
* 5e1_000 // false
* 5n // false
* 1_000n // false
* '5' // false
* "5" // false
*
*/
isDecimalInteger(node) {
return node.type === "Literal" && typeof node.value === "number" &&
@ -1323,6 +1592,16 @@ module.exports = {
* - `class A { static async foo() {} }` .... `static async method 'foo'`
* - `class A { static get foo() {} }` ...... `static getter 'foo'`
* - `class A { static set foo(a) {} }` ..... `static setter 'foo'`
* - `class A { foo = () => {}; }` .......... `method 'foo'`
* - `class A { foo = function() {}; }` ..... `method 'foo'`
* - `class A { foo = function bar() {}; }` . `method 'foo'`
* - `class A { static foo = () => {}; }` ... `static method 'foo'`
* - `class A { '#foo' = () => {}; }` ....... `method '#foo'`
* - `class A { #foo = () => {}; }` ......... `private method #foo`
* - `class A { static #foo = () => {}; }` .. `static private method #foo`
* - `class A { '#foo'() {} }` .............. `method '#foo'`
* - `class A { #foo() {} }` ................ `private method #foo`
* - `class A { static #foo() {} }` ......... `static private method #foo`
* @param {ASTNode} node The function node to get.
* @returns {string} The name and kind of the function node.
*/
@ -1330,8 +1609,15 @@ module.exports = {
const parent = node.parent;
const tokens = [];
if (parent.type === "MethodDefinition" && parent.static) {
tokens.push("static");
if (parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") {
// The proposal uses `static` word consistently before visibility words: https://github.com/tc39/proposal-static-class-features
if (parent.static) {
tokens.push("static");
}
if (!parent.computed && parent.key.type === "PrivateIdentifier") {
tokens.push("private");
}
}
if (node.async) {
tokens.push("async");
@ -1340,9 +1626,7 @@ module.exports = {
tokens.push("generator");
}
if (node.type === "ArrowFunctionExpression") {
tokens.push("arrow", "function");
} else if (parent.type === "Property" || parent.type === "MethodDefinition") {
if (parent.type === "Property" || parent.type === "MethodDefinition") {
if (parent.kind === "constructor") {
return "constructor";
}
@ -1353,18 +1637,29 @@ module.exports = {
} else {
tokens.push("method");
}
} else if (parent.type === "PropertyDefinition") {
tokens.push("method");
} else {
if (node.type === "ArrowFunctionExpression") {
tokens.push("arrow");
}
tokens.push("function");
}
if (node.id) {
tokens.push(`'${node.id.name}'`);
} else {
const name = getStaticPropertyName(parent);
if (parent.type === "Property" || parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") {
if (!parent.computed && parent.key.type === "PrivateIdentifier") {
tokens.push(`#${parent.key.name}`);
} else {
const name = getStaticPropertyName(parent);
if (name !== null) {
tokens.push(`'${name}'`);
if (name !== null) {
tokens.push(`'${name}'`);
} else if (node.id) {
tokens.push(`'${node.id.name}'`);
}
}
} else if (node.id) {
tokens.push(`'${node.id.name}'`);
}
return tokens.join(" ");
@ -1457,6 +1752,12 @@ module.exports = {
* ^^^^^^^^^^^^^^
* - `class A { static set foo(a) {} }`
* ^^^^^^^^^^^^^^
* - `class A { foo = function() {} }`
* ^^^^^^^^^^^^^^
* - `class A { static foo = function() {} }`
* ^^^^^^^^^^^^^^^^^^^^^
* - `class A { foo = (a, b) => {} }`
* ^^^^^^
* @param {ASTNode} node The function node to get.
* @param {SourceCode} sourceCode The source code object to get tokens.
* @returns {string} The location of the function node for reporting.
@ -1466,14 +1767,14 @@ module.exports = {
let start = null;
let end = null;
if (node.type === "ArrowFunctionExpression") {
if (parent.type === "Property" || parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") {
start = parent.loc.start;
end = getOpeningParenOfParams(node, sourceCode).loc.start;
} else if (node.type === "ArrowFunctionExpression") {
const arrowToken = sourceCode.getTokenBefore(node.body, isArrowToken);
start = arrowToken.loc.start;
end = arrowToken.loc.end;
} else if (parent.type === "Property" || parent.type === "MethodDefinition") {
start = parent.loc.start;
end = getOpeningParenOfParams(node, sourceCode).loc.start;
} else {
start = node.loc.start;
end = getOpeningParenOfParams(node, sourceCode).loc.start;
@ -1573,9 +1874,9 @@ module.exports = {
return sourceCode.getText().slice(leftToken.range[0], rightToken.range[1]);
},
/*
/**
* Determine if a node has a possibility to be an Error object
* @param {ASTNode} node ASTNode to check
* @param {ASTNode} node ASTNode to check
* @returns {boolean} True if there is a chance it contains an Error obj
*/
couldBeError(node) {
@ -1677,7 +1978,7 @@ module.exports = {
if (comments.length) {
const lastComment = comments[comments.length - 1];
if (lastComment.range[0] > leftToken.range[0]) {
if (!leftToken || lastComment.range[0] > leftToken.range[0]) {
leftToken = lastComment;
}
}
@ -1685,7 +1986,13 @@ module.exports = {
leftToken = leftValue;
}
if (leftToken.type === "Shebang") {
/*
* If a hashbang comment was passed as a token object from SourceCode,
* its type will be "Shebang" because of the way ESLint itself handles hashbangs.
* If a hashbang comment was passed in a string and then tokenized in this function,
* its type will be "Hashbang" because of the way Espree tokenizes hashbangs.
*/
if (leftToken.type === "Shebang" || leftToken.type === "Hashbang") {
return false;
}
@ -1706,7 +2013,7 @@ module.exports = {
if (comments.length) {
const firstComment = comments[0];
if (firstComment.range[0] < rightToken.range[0]) {
if (!rightToken || firstComment.range[0] < rightToken.range[0]) {
rightToken = firstComment;
}
}
@ -1745,6 +2052,10 @@ module.exports = {
return true;
}
if (rightToken.type === "PrivateIdentifier") {
return true;
}
return false;
},
@ -1794,6 +2105,7 @@ module.exports = {
return OCTAL_OR_NON_OCTAL_DECIMAL_ESCAPE_PATTERN.test(rawString);
},
isReferenceToGlobalVariable,
isLogicalExpression,
isCoalesceExpression,
isMixedLogicalAndCoalesceExpressions,
@ -1805,5 +2117,8 @@ module.exports = {
isSpecificMemberAccess,
equalLiteralValue,
isSameReference,
isLogicalAssignmentOperator
isLogicalAssignmentOperator,
getSwitchCaseColonToken,
getModuleExportName,
isConstant
};