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:
1 parent
20129a1ac7
commit
ac4f232e5e
787 files changed
+82341
-121690
No files matched your search
+213
-220
@@ -20,7 +20,7 @@
|
||||
* @returns {boolean} `true` if the node has the initializer.
|
||||
*/
|
||||
function isInitialized(node) {
|
||||
return Boolean(node.init);
|
||||
return Boolean(node.init);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,272 +29,265 @@ function isInitialized(node) {
|
||||
* @returns {boolean} True if all segments are unreachable; false otherwise.
|
||||
*/
|
||||
function areAllSegmentsUnreachable(segments) {
|
||||
for (const segment of segments) {
|
||||
if (segment.reachable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
for (const segment of segments) {
|
||||
if (segment.reachable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The class to distinguish consecutive unreachable statements.
|
||||
*/
|
||||
class ConsecutiveRange {
|
||||
constructor(sourceCode) {
|
||||
this.sourceCode = sourceCode;
|
||||
this.startNode = null;
|
||||
this.endNode = null;
|
||||
}
|
||||
constructor(sourceCode) {
|
||||
this.sourceCode = sourceCode;
|
||||
this.startNode = null;
|
||||
this.endNode = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The location object of this range.
|
||||
* @type {Object}
|
||||
*/
|
||||
get location() {
|
||||
return {
|
||||
start: this.startNode.loc.start,
|
||||
end: this.endNode.loc.end,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* The location object of this range.
|
||||
* @type {Object}
|
||||
*/
|
||||
get location() {
|
||||
return {
|
||||
start: this.startNode.loc.start,
|
||||
end: this.endNode.loc.end
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* `true` if this range is empty.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isEmpty() {
|
||||
return !(this.startNode && this.endNode);
|
||||
}
|
||||
/**
|
||||
* `true` if this range is empty.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isEmpty() {
|
||||
return !(this.startNode && this.endNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given node is inside of this range.
|
||||
* @param {ASTNode|Token} node The node to check.
|
||||
* @returns {boolean} `true` if the node is inside of this range.
|
||||
*/
|
||||
contains(node) {
|
||||
return (
|
||||
node.range[0] >= this.startNode.range[0] &&
|
||||
node.range[1] <= this.endNode.range[1]
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Checks whether the given node is inside of this range.
|
||||
* @param {ASTNode|Token} node The node to check.
|
||||
* @returns {boolean} `true` if the node is inside of this range.
|
||||
*/
|
||||
contains(node) {
|
||||
return (
|
||||
node.range[0] >= this.startNode.range[0] &&
|
||||
node.range[1] <= this.endNode.range[1]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given node is consecutive to this range.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {boolean} `true` if the node is consecutive to this range.
|
||||
*/
|
||||
isConsecutive(node) {
|
||||
return this.contains(this.sourceCode.getTokenBefore(node));
|
||||
}
|
||||
/**
|
||||
* Checks whether the given node is consecutive to this range.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {boolean} `true` if the node is consecutive to this range.
|
||||
*/
|
||||
isConsecutive(node) {
|
||||
return this.contains(this.sourceCode.getTokenBefore(node));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the given node to this range.
|
||||
* @param {ASTNode} node The node to merge.
|
||||
* @returns {void}
|
||||
*/
|
||||
merge(node) {
|
||||
this.endNode = node;
|
||||
}
|
||||
/**
|
||||
* Merges the given node to this range.
|
||||
* @param {ASTNode} node The node to merge.
|
||||
* @returns {void}
|
||||
*/
|
||||
merge(node) {
|
||||
this.endNode = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this range by the given node or null.
|
||||
* @param {ASTNode|null} node The node to reset, or null.
|
||||
* @returns {void}
|
||||
*/
|
||||
reset(node) {
|
||||
this.startNode = this.endNode = node;
|
||||
}
|
||||
/**
|
||||
* Resets this range by the given node or null.
|
||||
* @param {ASTNode|null} node The node to reset, or null.
|
||||
* @returns {void}
|
||||
*/
|
||||
reset(node) {
|
||||
this.startNode = this.endNode = node;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
meta: {
|
||||
type: "problem",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-unreachable",
|
||||
},
|
||||
docs: {
|
||||
description: "Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-unreachable"
|
||||
},
|
||||
|
||||
schema: [],
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
unreachableCode: "Unreachable code.",
|
||||
},
|
||||
},
|
||||
messages: {
|
||||
unreachableCode: "Unreachable code."
|
||||
}
|
||||
},
|
||||
|
||||
create(context) {
|
||||
/** @type {ConstructorInfo | null} */
|
||||
let constructorInfo = null;
|
||||
create(context) {
|
||||
|
||||
/** @type {ConsecutiveRange} */
|
||||
const range = new ConsecutiveRange(context.sourceCode);
|
||||
/** @type {ConstructorInfo | null} */
|
||||
let constructorInfo = null;
|
||||
|
||||
/** @type {Array<Set<CodePathSegment>>} */
|
||||
const codePathSegments = [];
|
||||
/** @type {ConsecutiveRange} */
|
||||
const range = new ConsecutiveRange(context.sourceCode);
|
||||
|
||||
/** @type {Set<CodePathSegment>} */
|
||||
let currentCodePathSegments = new Set();
|
||||
/** @type {Array<Set<CodePathSegment>>} */
|
||||
const codePathSegments = [];
|
||||
|
||||
/**
|
||||
* Reports a given node if it's unreachable.
|
||||
* @param {ASTNode} node A statement node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function reportIfUnreachable(node) {
|
||||
let nextNode = null;
|
||||
/** @type {Set<CodePathSegment>} */
|
||||
let currentCodePathSegments = new Set();
|
||||
|
||||
if (
|
||||
node &&
|
||||
(node.type === "PropertyDefinition" ||
|
||||
areAllSegmentsUnreachable(currentCodePathSegments))
|
||||
) {
|
||||
// Store this statement to distinguish consecutive statements.
|
||||
if (range.isEmpty) {
|
||||
range.reset(node);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Reports a given node if it's unreachable.
|
||||
* @param {ASTNode} node A statement node to report.
|
||||
* @returns {void}
|
||||
*/
|
||||
function reportIfUnreachable(node) {
|
||||
let nextNode = null;
|
||||
|
||||
// Skip if this statement is inside of the current range.
|
||||
if (range.contains(node)) {
|
||||
return;
|
||||
}
|
||||
if (node && (node.type === "PropertyDefinition" || areAllSegmentsUnreachable(currentCodePathSegments))) {
|
||||
|
||||
// Merge if this statement is consecutive to the current range.
|
||||
if (range.isConsecutive(node)) {
|
||||
range.merge(node);
|
||||
return;
|
||||
}
|
||||
// Store this statement to distinguish consecutive statements.
|
||||
if (range.isEmpty) {
|
||||
range.reset(node);
|
||||
return;
|
||||
}
|
||||
|
||||
nextNode = node;
|
||||
}
|
||||
// Skip if this statement is inside of the current range.
|
||||
if (range.contains(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report the current range since this statement is reachable or is
|
||||
* not consecutive to the current range.
|
||||
*/
|
||||
if (!range.isEmpty) {
|
||||
context.report({
|
||||
messageId: "unreachableCode",
|
||||
loc: range.location,
|
||||
node: range.startNode,
|
||||
});
|
||||
}
|
||||
// Merge if this statement is consecutive to the current range.
|
||||
if (range.isConsecutive(node)) {
|
||||
range.merge(node);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the current range.
|
||||
range.reset(nextNode);
|
||||
}
|
||||
nextNode = node;
|
||||
}
|
||||
|
||||
return {
|
||||
// Manages the current code path.
|
||||
onCodePathStart() {
|
||||
codePathSegments.push(currentCodePathSegments);
|
||||
currentCodePathSegments = new Set();
|
||||
},
|
||||
/*
|
||||
* Report the current range since this statement is reachable or is
|
||||
* not consecutive to the current range.
|
||||
*/
|
||||
if (!range.isEmpty) {
|
||||
context.report({
|
||||
messageId: "unreachableCode",
|
||||
loc: range.location,
|
||||
node: range.startNode
|
||||
});
|
||||
}
|
||||
|
||||
onCodePathEnd() {
|
||||
currentCodePathSegments = codePathSegments.pop();
|
||||
},
|
||||
// Update the current range.
|
||||
range.reset(nextNode);
|
||||
}
|
||||
|
||||
onUnreachableCodePathSegmentStart(segment) {
|
||||
currentCodePathSegments.add(segment);
|
||||
},
|
||||
return {
|
||||
|
||||
onUnreachableCodePathSegmentEnd(segment) {
|
||||
currentCodePathSegments.delete(segment);
|
||||
},
|
||||
// Manages the current code path.
|
||||
onCodePathStart() {
|
||||
codePathSegments.push(currentCodePathSegments);
|
||||
currentCodePathSegments = new Set();
|
||||
},
|
||||
|
||||
onCodePathSegmentEnd(segment) {
|
||||
currentCodePathSegments.delete(segment);
|
||||
},
|
||||
onCodePathEnd() {
|
||||
currentCodePathSegments = codePathSegments.pop();
|
||||
},
|
||||
|
||||
onCodePathSegmentStart(segment) {
|
||||
currentCodePathSegments.add(segment);
|
||||
},
|
||||
onUnreachableCodePathSegmentStart(segment) {
|
||||
currentCodePathSegments.add(segment);
|
||||
},
|
||||
|
||||
// Registers for all statement nodes (excludes FunctionDeclaration).
|
||||
BlockStatement: reportIfUnreachable,
|
||||
BreakStatement: reportIfUnreachable,
|
||||
ClassDeclaration: reportIfUnreachable,
|
||||
ContinueStatement: reportIfUnreachable,
|
||||
DebuggerStatement: reportIfUnreachable,
|
||||
DoWhileStatement: reportIfUnreachable,
|
||||
ExpressionStatement: reportIfUnreachable,
|
||||
ForInStatement: reportIfUnreachable,
|
||||
ForOfStatement: reportIfUnreachable,
|
||||
ForStatement: reportIfUnreachable,
|
||||
IfStatement: reportIfUnreachable,
|
||||
ImportDeclaration: reportIfUnreachable,
|
||||
LabeledStatement: reportIfUnreachable,
|
||||
ReturnStatement: reportIfUnreachable,
|
||||
SwitchStatement: reportIfUnreachable,
|
||||
ThrowStatement: reportIfUnreachable,
|
||||
TryStatement: reportIfUnreachable,
|
||||
onUnreachableCodePathSegmentEnd(segment) {
|
||||
currentCodePathSegments.delete(segment);
|
||||
},
|
||||
|
||||
VariableDeclaration(node) {
|
||||
if (
|
||||
node.kind !== "var" ||
|
||||
node.declarations.some(isInitialized)
|
||||
) {
|
||||
reportIfUnreachable(node);
|
||||
}
|
||||
},
|
||||
onCodePathSegmentEnd(segment) {
|
||||
currentCodePathSegments.delete(segment);
|
||||
},
|
||||
|
||||
WhileStatement: reportIfUnreachable,
|
||||
WithStatement: reportIfUnreachable,
|
||||
ExportNamedDeclaration: reportIfUnreachable,
|
||||
ExportDefaultDeclaration: reportIfUnreachable,
|
||||
ExportAllDeclaration: reportIfUnreachable,
|
||||
onCodePathSegmentStart(segment) {
|
||||
currentCodePathSegments.add(segment);
|
||||
},
|
||||
|
||||
"Program:exit"() {
|
||||
reportIfUnreachable();
|
||||
},
|
||||
// Registers for all statement nodes (excludes FunctionDeclaration).
|
||||
BlockStatement: reportIfUnreachable,
|
||||
BreakStatement: reportIfUnreachable,
|
||||
ClassDeclaration: reportIfUnreachable,
|
||||
ContinueStatement: reportIfUnreachable,
|
||||
DebuggerStatement: reportIfUnreachable,
|
||||
DoWhileStatement: reportIfUnreachable,
|
||||
ExpressionStatement: reportIfUnreachable,
|
||||
ForInStatement: reportIfUnreachable,
|
||||
ForOfStatement: reportIfUnreachable,
|
||||
ForStatement: reportIfUnreachable,
|
||||
IfStatement: reportIfUnreachable,
|
||||
ImportDeclaration: reportIfUnreachable,
|
||||
LabeledStatement: reportIfUnreachable,
|
||||
ReturnStatement: reportIfUnreachable,
|
||||
SwitchStatement: reportIfUnreachable,
|
||||
ThrowStatement: reportIfUnreachable,
|
||||
TryStatement: reportIfUnreachable,
|
||||
|
||||
/*
|
||||
* Instance fields defined in a subclass are never created if the constructor of the subclass
|
||||
* doesn't call `super()`, so their definitions are unreachable code.
|
||||
*/
|
||||
"MethodDefinition[kind='constructor']"() {
|
||||
constructorInfo = {
|
||||
upper: constructorInfo,
|
||||
hasSuperCall: false,
|
||||
};
|
||||
},
|
||||
"MethodDefinition[kind='constructor']:exit"(node) {
|
||||
const { hasSuperCall } = constructorInfo;
|
||||
VariableDeclaration(node) {
|
||||
if (node.kind !== "var" || node.declarations.some(isInitialized)) {
|
||||
reportIfUnreachable(node);
|
||||
}
|
||||
},
|
||||
|
||||
constructorInfo = constructorInfo.upper;
|
||||
WhileStatement: reportIfUnreachable,
|
||||
WithStatement: reportIfUnreachable,
|
||||
ExportNamedDeclaration: reportIfUnreachable,
|
||||
ExportDefaultDeclaration: reportIfUnreachable,
|
||||
ExportAllDeclaration: reportIfUnreachable,
|
||||
|
||||
// skip typescript constructors without the body
|
||||
if (!node.value.body) {
|
||||
return;
|
||||
}
|
||||
"Program:exit"() {
|
||||
reportIfUnreachable();
|
||||
},
|
||||
|
||||
const classDefinition = node.parent.parent;
|
||||
/*
|
||||
* Instance fields defined in a subclass are never created if the constructor of the subclass
|
||||
* doesn't call `super()`, so their definitions are unreachable code.
|
||||
*/
|
||||
"MethodDefinition[kind='constructor']"() {
|
||||
constructorInfo = {
|
||||
upper: constructorInfo,
|
||||
hasSuperCall: false
|
||||
};
|
||||
},
|
||||
"MethodDefinition[kind='constructor']:exit"(node) {
|
||||
const { hasSuperCall } = constructorInfo;
|
||||
|
||||
if (classDefinition.superClass && !hasSuperCall) {
|
||||
for (const element of classDefinition.body.body) {
|
||||
if (
|
||||
element.type === "PropertyDefinition" &&
|
||||
!element.static
|
||||
) {
|
||||
reportIfUnreachable(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"CallExpression > Super.callee"() {
|
||||
if (constructorInfo) {
|
||||
constructorInfo.hasSuperCall = true;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
constructorInfo = constructorInfo.upper;
|
||||
|
||||
// skip typescript constructors without the body
|
||||
if (!node.value.body) {
|
||||
return;
|
||||
}
|
||||
|
||||
const classDefinition = node.parent.parent;
|
||||
|
||||
if (classDefinition.superClass && !hasSuperCall) {
|
||||
for (const element of classDefinition.body.body) {
|
||||
if (element.type === "PropertyDefinition" && !element.static) {
|
||||
reportIfUnreachable(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"CallExpression > Super.callee"() {
|
||||
if (constructorInfo) {
|
||||
constructorInfo.hasSuperCall = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user