build: update npm install command to use --legacy-peer-deps
This change modifies the build scripts to use --legacy-peer-deps flag when installing npm dependencies to resolve potential peer dependency conflicts during the build process. The change is applied to both bash (build.sh) and batch (build.bat) build scripts.
This commit is contained in:
+88
-151
@@ -4,53 +4,22 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks whether any of a method's parameters have a decorator or are a parameter property.
|
||||
* @param {ASTNode} node A method definition node.
|
||||
* @returns {boolean} `true` if any parameter had a decorator or is a parameter property.
|
||||
*/
|
||||
function hasDecoratorsOrParameterProperty(node) {
|
||||
return node.value.params.some(
|
||||
param =>
|
||||
param.decorators?.length || param.type === "TSParameterProperty",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a node's accessibility makes it not useless.
|
||||
* @param {ASTNode} node A method definition node.
|
||||
* @returns {boolean} `true` if the node has a useful accessibility.
|
||||
*/
|
||||
function hasUsefulAccessibility(node) {
|
||||
switch (node.accessibility) {
|
||||
case "protected":
|
||||
case "private":
|
||||
return true;
|
||||
case "public":
|
||||
return !!node.parent.parent.superClass;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given array of statements is a single call of `super`.
|
||||
* @param {ASTNode[]} body An array of statements to check.
|
||||
* @returns {boolean} `true` if the body is a single call of `super`.
|
||||
*/
|
||||
function isSingleSuperCall(body) {
|
||||
return (
|
||||
body.length === 1 &&
|
||||
body[0].type === "ExpressionStatement" &&
|
||||
body[0].expression.type === "CallExpression" &&
|
||||
body[0].expression.callee.type === "Super"
|
||||
);
|
||||
return (
|
||||
body.length === 1 &&
|
||||
body[0].type === "ExpressionStatement" &&
|
||||
body[0].expression.type === "CallExpression" &&
|
||||
body[0].expression.callee.type === "Super"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +29,7 @@ function isSingleSuperCall(body) {
|
||||
* @returns {boolean} `true` if the node doesn't have any side effects.
|
||||
*/
|
||||
function isSimple(node) {
|
||||
return node.type === "Identifier" || node.type === "RestElement";
|
||||
return node.type === "Identifier" || node.type === "RestElement";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,12 +39,12 @@ function isSimple(node) {
|
||||
* @returns {boolean} `true` if the superArgs is `...arguments`.
|
||||
*/
|
||||
function isSpreadArguments(superArgs) {
|
||||
return (
|
||||
superArgs.length === 1 &&
|
||||
superArgs[0].type === "SpreadElement" &&
|
||||
superArgs[0].argument.type === "Identifier" &&
|
||||
superArgs[0].argument.name === "arguments"
|
||||
);
|
||||
return (
|
||||
superArgs.length === 1 &&
|
||||
superArgs[0].type === "SpreadElement" &&
|
||||
superArgs[0].argument.type === "Identifier" &&
|
||||
superArgs[0].argument.name === "arguments"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,11 +55,11 @@ function isSpreadArguments(superArgs) {
|
||||
* name.
|
||||
*/
|
||||
function isValidIdentifierPair(ctorParam, superArg) {
|
||||
return (
|
||||
ctorParam.type === "Identifier" &&
|
||||
superArg.type === "Identifier" &&
|
||||
ctorParam.name === superArg.name
|
||||
);
|
||||
return (
|
||||
ctorParam.type === "Identifier" &&
|
||||
superArg.type === "Identifier" &&
|
||||
ctorParam.name === superArg.name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,11 +70,11 @@ function isValidIdentifierPair(ctorParam, superArg) {
|
||||
* same values.
|
||||
*/
|
||||
function isValidRestSpreadPair(ctorParam, superArg) {
|
||||
return (
|
||||
ctorParam.type === "RestElement" &&
|
||||
superArg.type === "SpreadElement" &&
|
||||
isValidIdentifierPair(ctorParam.argument, superArg.argument)
|
||||
);
|
||||
return (
|
||||
ctorParam.type === "RestElement" &&
|
||||
superArg.type === "SpreadElement" &&
|
||||
isValidIdentifierPair(ctorParam.argument, superArg.argument)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,10 +84,10 @@ function isValidRestSpreadPair(ctorParam, superArg) {
|
||||
* @returns {boolean} `true` if the nodes have the same value or not.
|
||||
*/
|
||||
function isValidPair(ctorParam, superArg) {
|
||||
return (
|
||||
isValidIdentifierPair(ctorParam, superArg) ||
|
||||
isValidRestSpreadPair(ctorParam, superArg)
|
||||
);
|
||||
return (
|
||||
isValidIdentifierPair(ctorParam, superArg) ||
|
||||
isValidRestSpreadPair(ctorParam, superArg)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,17 +98,17 @@ function isValidPair(ctorParam, superArg) {
|
||||
* @returns {boolean} `true` if those have the same values.
|
||||
*/
|
||||
function isPassingThrough(ctorParams, superArgs) {
|
||||
if (ctorParams.length !== superArgs.length) {
|
||||
return false;
|
||||
}
|
||||
if (ctorParams.length !== superArgs.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < ctorParams.length; ++i) {
|
||||
if (!isValidPair(ctorParams[i], superArgs[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < ctorParams.length; ++i) {
|
||||
if (!isValidPair(ctorParams[i], superArgs[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,104 +118,72 @@ function isPassingThrough(ctorParams, superArgs) {
|
||||
* @returns {boolean} true if the constructor body is redundant
|
||||
*/
|
||||
function isRedundantSuperCall(body, ctorParams) {
|
||||
return (
|
||||
isSingleSuperCall(body) &&
|
||||
ctorParams.every(isSimple) &&
|
||||
(isSpreadArguments(body[0].expression.arguments) ||
|
||||
isPassingThrough(ctorParams, body[0].expression.arguments))
|
||||
);
|
||||
return (
|
||||
isSingleSuperCall(body) &&
|
||||
ctorParams.every(isSimple) &&
|
||||
(
|
||||
isSpreadArguments(body[0].expression.arguments) ||
|
||||
isPassingThrough(ctorParams, body[0].expression.arguments)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
dialects: ["javascript", "typescript"],
|
||||
language: "javascript",
|
||||
type: "suggestion",
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description: "Disallow unnecessary constructors",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-useless-constructor",
|
||||
},
|
||||
docs: {
|
||||
description: "Disallow unnecessary constructors",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-useless-constructor"
|
||||
},
|
||||
|
||||
hasSuggestions: true,
|
||||
schema: [],
|
||||
|
||||
schema: [],
|
||||
messages: {
|
||||
noUselessConstructor: "Useless constructor."
|
||||
}
|
||||
},
|
||||
|
||||
messages: {
|
||||
noUselessConstructor: "Useless constructor.",
|
||||
removeConstructor: "Remove the constructor.",
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
|
||||
create(context) {
|
||||
/**
|
||||
* Checks whether a node is a redundant constructor
|
||||
* @param {ASTNode} node node to check
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkForConstructor(node) {
|
||||
if (
|
||||
node.kind !== "constructor" ||
|
||||
node.value.type !== "FunctionExpression" ||
|
||||
hasDecoratorsOrParameterProperty(node) ||
|
||||
hasUsefulAccessibility(node)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Checks whether a node is a redundant constructor
|
||||
* @param {ASTNode} node node to check
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkForConstructor(node) {
|
||||
if (node.kind !== "constructor") {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevent crashing on parsers which do not require class constructor
|
||||
* to have a body, e.g. typescript and flow
|
||||
*/
|
||||
if (!node.value.body) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Prevent crashing on parsers which do not require class constructor
|
||||
* to have a body, e.g. typescript and flow
|
||||
*/
|
||||
if (!node.value.body) {
|
||||
return;
|
||||
}
|
||||
|
||||
const body = node.value.body.body;
|
||||
const ctorParams = node.value.params;
|
||||
const superClass = node.parent.parent.superClass;
|
||||
const body = node.value.body.body;
|
||||
const ctorParams = node.value.params;
|
||||
const superClass = node.parent.parent.superClass;
|
||||
|
||||
if (
|
||||
superClass
|
||||
? isRedundantSuperCall(body, ctorParams)
|
||||
: body.length === 0
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "noUselessConstructor",
|
||||
suggest: [
|
||||
{
|
||||
messageId: "removeConstructor",
|
||||
*fix(fixer) {
|
||||
const nextToken =
|
||||
context.sourceCode.getTokenAfter(node);
|
||||
const addSemiColon =
|
||||
nextToken.type === "Punctuator" &&
|
||||
nextToken.value === "[" &&
|
||||
astUtils.needsPrecedingSemicolon(
|
||||
context.sourceCode,
|
||||
node,
|
||||
);
|
||||
if (superClass ? isRedundantSuperCall(body, ctorParams) : (body.length === 0)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "noUselessConstructor"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
yield fixer.replaceText(
|
||||
node,
|
||||
addSemiColon ? ";" : "",
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
MethodDefinition: checkForConstructor,
|
||||
};
|
||||
},
|
||||
return {
|
||||
MethodDefinition: checkForConstructor
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user