J'ai juste update le cutie.js, CONNARD
Ah oui, j'ai aussi add le info.js, qui est merdique d'ailleurs
This commit is contained in:
Syxpi
2025-10-11 22:06:46 +02:00
parent 14d4df5a40
commit b5cba1c318
283 changed files with 15040 additions and 12924 deletions

View File

@@ -282,6 +282,7 @@ function getFunctionHeadLocation(node, sourceCode) {
/* globals globalThis, global, self, window */
/** @typedef {import("./types.mjs").StaticValue} StaticValue */
/** @typedef {import("eslint").Scope.Scope} Scope */
/** @typedef {import("eslint").Scope.Variable} Variable */
/** @typedef {import("estree").Node} Node */
/** @typedef {import("@typescript-eslint/types").TSESTree.Node} TSESTreeNode */
/** @typedef {import("@typescript-eslint/types").TSESTree.AST_NODE_TYPES} TSESTreeNodeTypes */
@@ -545,9 +546,40 @@ function getElementValues(nodeList, initialScope) {
return valueList
}
/**
* Checks if a variable is a built-in global.
* @param {Variable|null} variable The variable to check.
* @returns {variable is Variable & {defs:[]}}
*/
function isBuiltinGlobal(variable) {
return (
variable != null &&
variable.defs.length === 0 &&
builtinNames.has(variable.name) &&
variable.name in globalObject
)
}
/**
* Checks if a variable can be considered as a constant.
* @param {Variable} variable
* @returns {variable is Variable & {defs: [import("eslint").Scope.Definition & { type: "Variable" }]}} True if the variable can be considered as a constant.
*/
function canBeConsideredConst(variable) {
if (variable.defs.length !== 1) {
return false
}
const def = variable.defs[0];
return Boolean(
def.parent &&
def.type === "Variable" &&
(def.parent.kind === "const" || isEffectivelyConst(variable)),
)
}
/**
* Returns whether the given variable is never written to after initialization.
* @param {import("eslint").Scope.Variable} variable
* @param {Variable} variable
* @returns {boolean}
*/
function isEffectivelyConst(variable) {
@@ -562,6 +594,68 @@ function isEffectivelyConst(variable) {
return false
}
/**
* Checks if a variable has mutation in its property.
* @param {Variable} variable The variable to check.
* @param {Scope|null} initialScope The scope to start finding variable. Optional. If the node is a computed property node and this scope was given, this checks the computed property name by the `getStringIfConstant` function with the scope, and returns the value of it.
* @returns {boolean} True if the variable has mutation in its property.
*/
function hasMutationInProperty(variable, initialScope) {
for (const ref of variable.references) {
let node = /** @type {TSESTreeNode} */ (ref.identifier);
while (node && node.parent && node.parent.type === "MemberExpression") {
node = node.parent;
}
if (!node || !node.parent) {
continue
}
if (
(node.parent.type === "AssignmentExpression" &&
node.parent.left === node) ||
(node.parent.type === "UpdateExpression" &&
node.parent.argument === node)
) {
// This is a mutation.
return true
}
if (
node.parent.type === "CallExpression" &&
node.parent.callee === node &&
node.type === "MemberExpression"
) {
const methodName = getStaticPropertyNameValue(node, initialScope);
if (isNameOfMutationArrayMethod(methodName)) {
// This is a mutation.
return true
}
}
}
return false
/**
* Checks if a method name is one of the mutation array methods.
* @param {StaticValue|null} methodName The method name to check.
* @returns {boolean} True if the method name is a mutation array method.
*/
function isNameOfMutationArrayMethod(methodName) {
if (methodName == null || methodName.value == null) {
return false
}
const name = methodName.value;
return (
name === "copyWithin" ||
name === "fill" ||
name === "pop" ||
name === "push" ||
name === "reverse" ||
name === "shift" ||
name === "sort" ||
name === "splice" ||
name === "unshift"
)
}
}
/**
* @template {TSESTreeNodeTypes} T
* @callback VisitorCallback
@@ -791,28 +885,35 @@ const operations = Object.freeze({
if (initialScope != null) {
const variable = findVariable(initialScope, node);
// Built-in globals.
if (
variable != null &&
variable.defs.length === 0 &&
builtinNames.has(variable.name) &&
variable.name in globalObject
) {
return { value: globalObject[variable.name] }
}
if (variable != null) {
// Built-in globals.
if (isBuiltinGlobal(variable)) {
return { value: globalObject[variable.name] }
}
// Constants.
if (variable != null && variable.defs.length === 1) {
const def = variable.defs[0];
if (
def.parent &&
def.type === "Variable" &&
(def.parent.kind === "const" ||
isEffectivelyConst(variable)) &&
// TODO(mysticatea): don't support destructuring here.
def.node.id.type === "Identifier"
) {
return getStaticValueR(def.node.init, initialScope)
// Constants.
if (canBeConsideredConst(variable)) {
const def = variable.defs[0];
if (
// TODO(mysticatea): don't support destructuring here.
def.node.id.type === "Identifier"
) {
const init = getStaticValueR(
def.node.init,
initialScope,
);
if (
init &&
typeof init.value === "object" &&
init.value !== null
) {
if (hasMutationInProperty(variable, initialScope)) {
// This variable has mutation in its property.
return null
}
}
return init
}
}
}
}
@@ -1537,6 +1638,8 @@ function hasSideEffect(node, sourceCode, options = {}) {
}
/** @typedef {import("estree").Node} Node */
/** @typedef {import("@typescript-eslint/types").TSESTree.NewExpression} TSNewExpression */
/** @typedef {import("@typescript-eslint/types").TSESTree.CallExpression} TSCallExpression */
/** @typedef {import("eslint").SourceCode} SourceCode */
/** @typedef {import("eslint").AST.Token} Token */
/** @typedef {import("eslint").Rule.Node} RuleNode */
@@ -1548,6 +1651,7 @@ function hasSideEffect(node, sourceCode, options = {}) {
* @param {SourceCode} sourceCode The source code object to get tokens.
* @returns {Token|null} The left parenthesis of the parent node syntax
*/
// eslint-disable-next-line complexity
function getParentSyntaxParen(node, sourceCode) {
const parent = /** @type {RuleNode} */ (node).parent;
@@ -1556,7 +1660,16 @@ function getParentSyntaxParen(node, sourceCode) {
case "NewExpression":
if (parent.arguments.length === 1 && parent.arguments[0] === node) {
return sourceCode.getTokenAfter(
parent.callee,
// @ts-expect-error https://github.com/typescript-eslint/typescript-eslint/pull/5384
parent.typeArguments ||
/** @type {RuleNode} */ (
/** @type {unknown} */ (
/** @type {TSNewExpression | TSCallExpression} */ (
parent
).typeParameters
)
) ||
parent.callee,
isOpeningParenToken,
)
}