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:
+72
-106
@@ -22,127 +22,93 @@ const astUtils = require("./utils/ast-utils");
|
||||
* @returns {boolean} `true` if `node.object` is `Object`, `Object.prototype`, or `{}` (empty 'ObjectExpression' node).
|
||||
*/
|
||||
function hasLeftHandObject(node) {
|
||||
/*
|
||||
* ({}).hasOwnProperty.call(obj, prop) - `true`
|
||||
* ({ foo }.hasOwnProperty.call(obj, prop)) - `false`, object literal should be empty
|
||||
*/
|
||||
if (
|
||||
node.object.type === "ObjectExpression" &&
|
||||
node.object.properties.length === 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const objectNodeToCheck =
|
||||
node.object.type === "MemberExpression" &&
|
||||
astUtils.getStaticPropertyName(node.object) === "prototype"
|
||||
? node.object.object
|
||||
: node.object;
|
||||
/*
|
||||
* ({}).hasOwnProperty.call(obj, prop) - `true`
|
||||
* ({ foo }.hasOwnProperty.call(obj, prop)) - `false`, object literal should be empty
|
||||
*/
|
||||
if (node.object.type === "ObjectExpression" && node.object.properties.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
objectNodeToCheck.type === "Identifier" &&
|
||||
objectNodeToCheck.name === "Object"
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
const objectNodeToCheck = node.object.type === "MemberExpression" && astUtils.getStaticPropertyName(node.object) === "prototype" ? node.object.object : node.object;
|
||||
|
||||
return false;
|
||||
if (objectNodeToCheck.type === "Identifier" && objectNodeToCheck.name === "Object") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
docs: {
|
||||
description:
|
||||
"Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/prefer-object-has-own",
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
useHasOwn:
|
||||
"Use 'Object.hasOwn()' instead of 'Object.prototype.hasOwnProperty.call()'.",
|
||||
},
|
||||
fixable: "code",
|
||||
},
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
docs: {
|
||||
description:
|
||||
"Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/prefer-object-has-own"
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
useHasOwn: "Use 'Object.hasOwn()' instead of 'Object.prototype.hasOwnProperty.call()'."
|
||||
},
|
||||
fixable: "code"
|
||||
},
|
||||
create(context) {
|
||||
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (
|
||||
!(
|
||||
node.callee.type === "MemberExpression" &&
|
||||
node.callee.object.type === "MemberExpression"
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
const calleePropertyName = astUtils.getStaticPropertyName(
|
||||
node.callee,
|
||||
);
|
||||
const objectPropertyName = astUtils.getStaticPropertyName(
|
||||
node.callee.object,
|
||||
);
|
||||
const isObject = hasLeftHandObject(node.callee.object);
|
||||
return {
|
||||
CallExpression(node) {
|
||||
if (!(node.callee.type === "MemberExpression" && node.callee.object.type === "MemberExpression")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check `Object` scope
|
||||
const scope = sourceCode.getScope(node);
|
||||
const variable = astUtils.getVariableByName(scope, "Object");
|
||||
const calleePropertyName = astUtils.getStaticPropertyName(node.callee);
|
||||
const objectPropertyName = astUtils.getStaticPropertyName(node.callee.object);
|
||||
const isObject = hasLeftHandObject(node.callee.object);
|
||||
|
||||
if (
|
||||
calleePropertyName === "call" &&
|
||||
objectPropertyName === "hasOwnProperty" &&
|
||||
isObject &&
|
||||
variable &&
|
||||
variable.scope.type === "global"
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "useHasOwn",
|
||||
fix(fixer) {
|
||||
if (
|
||||
sourceCode.getCommentsInside(node.callee)
|
||||
.length > 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
// check `Object` scope
|
||||
const scope = sourceCode.getScope(node);
|
||||
const variable = astUtils.getVariableByName(scope, "Object");
|
||||
|
||||
const tokenJustBeforeNode =
|
||||
sourceCode.getTokenBefore(node.callee, {
|
||||
includeComments: true,
|
||||
});
|
||||
if (
|
||||
calleePropertyName === "call" &&
|
||||
objectPropertyName === "hasOwnProperty" &&
|
||||
isObject &&
|
||||
variable && variable.scope.type === "global"
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "useHasOwn",
|
||||
fix(fixer) {
|
||||
|
||||
// for https://github.com/eslint/eslint/pull/15346#issuecomment-991417335
|
||||
if (
|
||||
tokenJustBeforeNode &&
|
||||
tokenJustBeforeNode.range[1] ===
|
||||
node.callee.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(
|
||||
tokenJustBeforeNode,
|
||||
"Object.hasOwn",
|
||||
)
|
||||
) {
|
||||
return fixer.replaceText(
|
||||
node.callee,
|
||||
" Object.hasOwn",
|
||||
);
|
||||
}
|
||||
if (sourceCode.getCommentsInside(node.callee).length > 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
node.callee,
|
||||
"Object.hasOwn",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
const tokenJustBeforeNode = sourceCode.getTokenBefore(node.callee, { includeComments: true });
|
||||
|
||||
// for https://github.com/eslint/eslint/pull/15346#issuecomment-991417335
|
||||
if (
|
||||
tokenJustBeforeNode &&
|
||||
tokenJustBeforeNode.range[1] === node.callee.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(tokenJustBeforeNode, "Object.hasOwn")
|
||||
) {
|
||||
return fixer.replaceText(node.callee, " Object.hasOwn");
|
||||
}
|
||||
|
||||
return fixer.replaceText(node.callee, "Object.hasOwn");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user