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:
+243
-252
@@ -20,7 +20,7 @@ const astUtils = require("./utils/ast-utils");
|
||||
* @returns {boolean} Whether or not it is a comparison operator.
|
||||
*/
|
||||
function isComparisonOperator(operator) {
|
||||
return /^(?:==|===|!=|!==|<|>|<=|>=)$/u.test(operator);
|
||||
return /^(==|===|!=|!==|<|>|<=|>=)$/u.test(operator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ function isComparisonOperator(operator) {
|
||||
* @returns {boolean} Whether or not it is an equality operator.
|
||||
*/
|
||||
function isEqualityOperator(operator) {
|
||||
return /^(?:==|===)$/u.test(operator);
|
||||
return /^(==|===)$/u.test(operator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ function isEqualityOperator(operator) {
|
||||
* @returns {boolean} Whether the operator is used in range tests.
|
||||
*/
|
||||
function isRangeTestOperator(operator) {
|
||||
return ["<", "<="].includes(operator);
|
||||
return ["<", "<="].includes(operator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,12 +50,12 @@ function isRangeTestOperator(operator) {
|
||||
* real literal and should be treated as such.
|
||||
*/
|
||||
function isNegativeNumericLiteral(node) {
|
||||
return (
|
||||
node.type === "UnaryExpression" &&
|
||||
node.operator === "-" &&
|
||||
node.prefix &&
|
||||
astUtils.isNumericLiteral(node.argument)
|
||||
);
|
||||
return (
|
||||
node.type === "UnaryExpression" &&
|
||||
node.operator === "-" &&
|
||||
node.prefix &&
|
||||
astUtils.isNumericLiteral(node.argument)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,9 +64,7 @@ function isNegativeNumericLiteral(node) {
|
||||
* @returns {boolean} True if the node should be treated as a single Literal node.
|
||||
*/
|
||||
function looksLikeLiteral(node) {
|
||||
return (
|
||||
isNegativeNumericLiteral(node) || astUtils.isStaticTemplateLiteral(node)
|
||||
);
|
||||
return isNegativeNumericLiteral(node) || astUtils.isStaticTemplateLiteral(node);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,282 +79,275 @@ function looksLikeLiteral(node) {
|
||||
* 4. Otherwise `null`.
|
||||
*/
|
||||
function getNormalizedLiteral(node) {
|
||||
if (node.type === "Literal") {
|
||||
return node;
|
||||
}
|
||||
if (node.type === "Literal") {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (isNegativeNumericLiteral(node)) {
|
||||
return {
|
||||
type: "Literal",
|
||||
value: -node.argument.value,
|
||||
raw: `-${node.argument.value}`,
|
||||
};
|
||||
}
|
||||
if (isNegativeNumericLiteral(node)) {
|
||||
return {
|
||||
type: "Literal",
|
||||
value: -node.argument.value,
|
||||
raw: `-${node.argument.value}`
|
||||
};
|
||||
}
|
||||
|
||||
if (astUtils.isStaticTemplateLiteral(node)) {
|
||||
return {
|
||||
type: "Literal",
|
||||
value: node.quasis[0].value.cooked,
|
||||
raw: node.quasis[0].value.raw,
|
||||
};
|
||||
}
|
||||
if (astUtils.isStaticTemplateLiteral(node)) {
|
||||
return {
|
||||
type: "Literal",
|
||||
value: node.quasis[0].value.cooked,
|
||||
raw: node.quasis[0].value.raw
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [
|
||||
"never",
|
||||
{
|
||||
exceptRange: false,
|
||||
onlyEquality: false,
|
||||
},
|
||||
],
|
||||
docs: {
|
||||
description: 'Require or disallow "Yoda" conditions',
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/yoda"
|
||||
},
|
||||
|
||||
docs: {
|
||||
description: 'Require or disallow "Yoda" conditions',
|
||||
recommended: false,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/yoda",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
enum: ["always", "never"]
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
exceptRange: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
},
|
||||
onlyEquality: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
}
|
||||
],
|
||||
|
||||
schema: [
|
||||
{
|
||||
enum: ["always", "never"],
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
exceptRange: {
|
||||
type: "boolean",
|
||||
},
|
||||
onlyEquality: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
fixable: "code",
|
||||
messages: {
|
||||
expected:
|
||||
"Expected literal to be on the {{expectedSide}} side of {{operator}}."
|
||||
}
|
||||
},
|
||||
|
||||
fixable: "code",
|
||||
messages: {
|
||||
expected:
|
||||
"Expected literal to be on the {{expectedSide}} side of {{operator}}.",
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
|
||||
create(context) {
|
||||
const [when, { exceptRange, onlyEquality }] = context.options;
|
||||
const always = when === "always";
|
||||
const sourceCode = context.sourceCode;
|
||||
// Default to "never" (!always) if no option
|
||||
const always = context.options[0] === "always";
|
||||
const exceptRange =
|
||||
context.options[1] && context.options[1].exceptRange;
|
||||
const onlyEquality =
|
||||
context.options[1] && context.options[1].onlyEquality;
|
||||
|
||||
/**
|
||||
* Determines whether node represents a range test.
|
||||
* A range test is a "between" test like `(0 <= x && x < 1)` or an "outside"
|
||||
* test like `(x < 0 || 1 <= x)`. It must be wrapped in parentheses, and
|
||||
* both operators must be `<` or `<=`. Finally, the literal on the left side
|
||||
* must be less than or equal to the literal on the right side so that the
|
||||
* test makes any sense.
|
||||
* @param {ASTNode} node LogicalExpression node to test.
|
||||
* @returns {boolean} Whether node is a range test.
|
||||
*/
|
||||
function isRangeTest(node) {
|
||||
const left = node.left,
|
||||
right = node.right;
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
/**
|
||||
* Determines whether node is of the form `0 <= x && x < 1`.
|
||||
* @returns {boolean} Whether node is a "between" range test.
|
||||
*/
|
||||
function isBetweenTest() {
|
||||
if (
|
||||
node.operator === "&&" &&
|
||||
astUtils.isSameReference(left.right, right.left)
|
||||
) {
|
||||
const leftLiteral = getNormalizedLiteral(left.left);
|
||||
const rightLiteral = getNormalizedLiteral(right.right);
|
||||
/**
|
||||
* Determines whether node represents a range test.
|
||||
* A range test is a "between" test like `(0 <= x && x < 1)` or an "outside"
|
||||
* test like `(x < 0 || 1 <= x)`. It must be wrapped in parentheses, and
|
||||
* both operators must be `<` or `<=`. Finally, the literal on the left side
|
||||
* must be less than or equal to the literal on the right side so that the
|
||||
* test makes any sense.
|
||||
* @param {ASTNode} node LogicalExpression node to test.
|
||||
* @returns {boolean} Whether node is a range test.
|
||||
*/
|
||||
function isRangeTest(node) {
|
||||
const left = node.left,
|
||||
right = node.right;
|
||||
|
||||
if (leftLiteral === null && rightLiteral === null) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Determines whether node is of the form `0 <= x && x < 1`.
|
||||
* @returns {boolean} Whether node is a "between" range test.
|
||||
*/
|
||||
function isBetweenTest() {
|
||||
if (node.operator === "&&" && astUtils.isSameReference(left.right, right.left)) {
|
||||
const leftLiteral = getNormalizedLiteral(left.left);
|
||||
const rightLiteral = getNormalizedLiteral(right.right);
|
||||
|
||||
if (rightLiteral === null || leftLiteral === null) {
|
||||
return true;
|
||||
}
|
||||
if (leftLiteral === null && rightLiteral === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (leftLiteral.value <= rightLiteral.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (rightLiteral === null || leftLiteral === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether node is of the form `x < 0 || 1 <= x`.
|
||||
* @returns {boolean} Whether node is an "outside" range test.
|
||||
*/
|
||||
function isOutsideTest() {
|
||||
if (
|
||||
node.operator === "||" &&
|
||||
astUtils.isSameReference(left.left, right.right)
|
||||
) {
|
||||
const leftLiteral = getNormalizedLiteral(left.right);
|
||||
const rightLiteral = getNormalizedLiteral(right.left);
|
||||
if (leftLiteral.value <= rightLiteral.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (leftLiteral === null && rightLiteral === null) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Determines whether node is of the form `x < 0 || 1 <= x`.
|
||||
* @returns {boolean} Whether node is an "outside" range test.
|
||||
*/
|
||||
function isOutsideTest() {
|
||||
if (node.operator === "||" && astUtils.isSameReference(left.left, right.right)) {
|
||||
const leftLiteral = getNormalizedLiteral(left.right);
|
||||
const rightLiteral = getNormalizedLiteral(right.left);
|
||||
|
||||
if (rightLiteral === null || leftLiteral === null) {
|
||||
return true;
|
||||
}
|
||||
if (leftLiteral === null && rightLiteral === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (leftLiteral.value <= rightLiteral.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (rightLiteral === null || leftLiteral === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (leftLiteral.value <= rightLiteral.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether node is wrapped in parentheses.
|
||||
* @returns {boolean} Whether node is preceded immediately by an open
|
||||
* paren token and followed immediately by a close
|
||||
* paren token.
|
||||
*/
|
||||
function isParenWrapped() {
|
||||
return astUtils.isParenthesised(sourceCode, node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
node.type === "LogicalExpression" &&
|
||||
left.type === "BinaryExpression" &&
|
||||
right.type === "BinaryExpression" &&
|
||||
isRangeTestOperator(left.operator) &&
|
||||
isRangeTestOperator(right.operator) &&
|
||||
(isBetweenTest() || isOutsideTest()) &&
|
||||
isParenWrapped()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Determines whether node is wrapped in parentheses.
|
||||
* @returns {boolean} Whether node is preceded immediately by an open
|
||||
* paren token and followed immediately by a close
|
||||
* paren token.
|
||||
*/
|
||||
function isParenWrapped() {
|
||||
return astUtils.isParenthesised(sourceCode, node);
|
||||
}
|
||||
|
||||
const OPERATOR_FLIP_MAP = {
|
||||
"===": "===",
|
||||
"!==": "!==",
|
||||
"==": "==",
|
||||
"!=": "!=",
|
||||
"<": ">",
|
||||
">": "<",
|
||||
"<=": ">=",
|
||||
">=": "<=",
|
||||
};
|
||||
return (
|
||||
node.type === "LogicalExpression" &&
|
||||
left.type === "BinaryExpression" &&
|
||||
right.type === "BinaryExpression" &&
|
||||
isRangeTestOperator(left.operator) &&
|
||||
isRangeTestOperator(right.operator) &&
|
||||
(isBetweenTest() || isOutsideTest()) &&
|
||||
isParenWrapped()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of a BinaryExpression node with its sides/operator flipped around.
|
||||
* @param {ASTNode} node The BinaryExpression node
|
||||
* @returns {string} A string representation of the node with the sides and operator flipped
|
||||
*/
|
||||
function getFlippedString(node) {
|
||||
const operatorToken = sourceCode.getFirstTokenBetween(
|
||||
node.left,
|
||||
node.right,
|
||||
token => token.value === node.operator,
|
||||
);
|
||||
const lastLeftToken = sourceCode.getTokenBefore(operatorToken);
|
||||
const firstRightToken = sourceCode.getTokenAfter(operatorToken);
|
||||
const OPERATOR_FLIP_MAP = {
|
||||
"===": "===",
|
||||
"!==": "!==",
|
||||
"==": "==",
|
||||
"!=": "!=",
|
||||
"<": ">",
|
||||
">": "<",
|
||||
"<=": ">=",
|
||||
">=": "<="
|
||||
};
|
||||
|
||||
const source = sourceCode.getText();
|
||||
/**
|
||||
* Returns a string representation of a BinaryExpression node with its sides/operator flipped around.
|
||||
* @param {ASTNode} node The BinaryExpression node
|
||||
* @returns {string} A string representation of the node with the sides and operator flipped
|
||||
*/
|
||||
function getFlippedString(node) {
|
||||
const operatorToken = sourceCode.getFirstTokenBetween(
|
||||
node.left,
|
||||
node.right,
|
||||
token => token.value === node.operator
|
||||
);
|
||||
const lastLeftToken = sourceCode.getTokenBefore(operatorToken);
|
||||
const firstRightToken = sourceCode.getTokenAfter(operatorToken);
|
||||
|
||||
const leftText = source.slice(
|
||||
node.range[0],
|
||||
lastLeftToken.range[1],
|
||||
);
|
||||
const textBeforeOperator = source.slice(
|
||||
lastLeftToken.range[1],
|
||||
operatorToken.range[0],
|
||||
);
|
||||
const textAfterOperator = source.slice(
|
||||
operatorToken.range[1],
|
||||
firstRightToken.range[0],
|
||||
);
|
||||
const rightText = source.slice(
|
||||
firstRightToken.range[0],
|
||||
node.range[1],
|
||||
);
|
||||
const source = sourceCode.getText();
|
||||
|
||||
const tokenBefore = sourceCode.getTokenBefore(node);
|
||||
const tokenAfter = sourceCode.getTokenAfter(node);
|
||||
let prefix = "";
|
||||
let suffix = "";
|
||||
const leftText = source.slice(
|
||||
node.range[0],
|
||||
lastLeftToken.range[1]
|
||||
);
|
||||
const textBeforeOperator = source.slice(
|
||||
lastLeftToken.range[1],
|
||||
operatorToken.range[0]
|
||||
);
|
||||
const textAfterOperator = source.slice(
|
||||
operatorToken.range[1],
|
||||
firstRightToken.range[0]
|
||||
);
|
||||
const rightText = source.slice(
|
||||
firstRightToken.range[0],
|
||||
node.range[1]
|
||||
);
|
||||
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.range[1] === node.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(tokenBefore, firstRightToken)
|
||||
) {
|
||||
prefix = " ";
|
||||
}
|
||||
const tokenBefore = sourceCode.getTokenBefore(node);
|
||||
const tokenAfter = sourceCode.getTokenAfter(node);
|
||||
let prefix = "";
|
||||
let suffix = "";
|
||||
|
||||
if (
|
||||
tokenAfter &&
|
||||
node.range[1] === tokenAfter.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(lastLeftToken, tokenAfter)
|
||||
) {
|
||||
suffix = " ";
|
||||
}
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.range[1] === node.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(tokenBefore, firstRightToken)
|
||||
) {
|
||||
prefix = " ";
|
||||
}
|
||||
|
||||
return (
|
||||
prefix +
|
||||
rightText +
|
||||
textBeforeOperator +
|
||||
OPERATOR_FLIP_MAP[operatorToken.value] +
|
||||
textAfterOperator +
|
||||
leftText +
|
||||
suffix
|
||||
);
|
||||
}
|
||||
if (
|
||||
tokenAfter &&
|
||||
node.range[1] === tokenAfter.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(lastLeftToken, tokenAfter)
|
||||
) {
|
||||
suffix = " ";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
return (
|
||||
prefix +
|
||||
rightText +
|
||||
textBeforeOperator +
|
||||
OPERATOR_FLIP_MAP[operatorToken.value] +
|
||||
textAfterOperator +
|
||||
leftText +
|
||||
suffix
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
BinaryExpression(node) {
|
||||
const expectedLiteral = always ? node.left : node.right;
|
||||
const expectedNonLiteral = always ? node.right : node.left;
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// If `expectedLiteral` is not a literal, and `expectedNonLiteral` is a literal, raise an error.
|
||||
if (
|
||||
(expectedNonLiteral.type === "Literal" ||
|
||||
looksLikeLiteral(expectedNonLiteral)) &&
|
||||
!(
|
||||
expectedLiteral.type === "Literal" ||
|
||||
looksLikeLiteral(expectedLiteral)
|
||||
) &&
|
||||
!(!isEqualityOperator(node.operator) && onlyEquality) &&
|
||||
isComparisonOperator(node.operator) &&
|
||||
!(exceptRange && isRangeTest(node.parent))
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "expected",
|
||||
data: {
|
||||
operator: node.operator,
|
||||
expectedSide: always ? "left" : "right",
|
||||
},
|
||||
fix: fixer =>
|
||||
fixer.replaceText(node, getFlippedString(node)),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
return {
|
||||
BinaryExpression(node) {
|
||||
const expectedLiteral = always ? node.left : node.right;
|
||||
const expectedNonLiteral = always ? node.right : node.left;
|
||||
|
||||
// If `expectedLiteral` is not a literal, and `expectedNonLiteral` is a literal, raise an error.
|
||||
if (
|
||||
(expectedNonLiteral.type === "Literal" ||
|
||||
looksLikeLiteral(expectedNonLiteral)) &&
|
||||
!(
|
||||
expectedLiteral.type === "Literal" ||
|
||||
looksLikeLiteral(expectedLiteral)
|
||||
) &&
|
||||
!(!isEqualityOperator(node.operator) && onlyEquality) &&
|
||||
isComparisonOperator(node.operator) &&
|
||||
!(exceptRange && isRangeTest(node.parent))
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "expected",
|
||||
data: {
|
||||
operator: node.operator,
|
||||
expectedSide: always ? "left" : "right"
|
||||
},
|
||||
fix: fixer =>
|
||||
fixer.replaceText(node, getFlippedString(node))
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user