pasika 0.10.61 → 0.10.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint/pasika/index.js +110 -7
- package/package.json +1 -1
|
@@ -4988,6 +4988,54 @@ var noMixedConcernsRule = {
|
|
|
4988
4988
|
import path39 from "path";
|
|
4989
4989
|
var DOC4 = "See docs/next-codebase-guide/rules/redundant-aliases-rule.md";
|
|
4990
4990
|
var VALUE_SENTINELS = /* @__PURE__ */ new Set(["undefined", "NaN", "Infinity"]);
|
|
4991
|
+
var RESERVED_LOCAL_NAMES = /* @__PURE__ */ new Set([
|
|
4992
|
+
"await",
|
|
4993
|
+
"break",
|
|
4994
|
+
"case",
|
|
4995
|
+
"catch",
|
|
4996
|
+
"class",
|
|
4997
|
+
"const",
|
|
4998
|
+
"continue",
|
|
4999
|
+
"debugger",
|
|
5000
|
+
"default",
|
|
5001
|
+
"delete",
|
|
5002
|
+
"do",
|
|
5003
|
+
"else",
|
|
5004
|
+
"enum",
|
|
5005
|
+
"export",
|
|
5006
|
+
"extends",
|
|
5007
|
+
"false",
|
|
5008
|
+
"finally",
|
|
5009
|
+
"for",
|
|
5010
|
+
"function",
|
|
5011
|
+
"if",
|
|
5012
|
+
"implements",
|
|
5013
|
+
"import",
|
|
5014
|
+
"in",
|
|
5015
|
+
"instanceof",
|
|
5016
|
+
"interface",
|
|
5017
|
+
"let",
|
|
5018
|
+
"new",
|
|
5019
|
+
"null",
|
|
5020
|
+
"package",
|
|
5021
|
+
"private",
|
|
5022
|
+
"protected",
|
|
5023
|
+
"public",
|
|
5024
|
+
"return",
|
|
5025
|
+
"static",
|
|
5026
|
+
"super",
|
|
5027
|
+
"switch",
|
|
5028
|
+
"this",
|
|
5029
|
+
"throw",
|
|
5030
|
+
"true",
|
|
5031
|
+
"try",
|
|
5032
|
+
"typeof",
|
|
5033
|
+
"var",
|
|
5034
|
+
"void",
|
|
5035
|
+
"while",
|
|
5036
|
+
"with",
|
|
5037
|
+
"yield"
|
|
5038
|
+
]);
|
|
4991
5039
|
var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
|
|
4992
5040
|
var PRIMITIVE_TYPE_NAMES = {
|
|
4993
5041
|
TSBigIntKeyword: "bigint",
|
|
@@ -5041,9 +5089,23 @@ function isExportedVariable2(context, variable) {
|
|
|
5041
5089
|
(definition) => definition.type === "Variable" && context.sourceCode.getAncestors(definition.parent).at(-1)?.type === "ExportNamedDeclaration"
|
|
5042
5090
|
);
|
|
5043
5091
|
}
|
|
5044
|
-
function
|
|
5092
|
+
function canUsePropertyNameAsLocal(name) {
|
|
5093
|
+
return /^[a-z][A-Za-z0-9]*$/u.test(name) && !RESERVED_LOCAL_NAMES.has(name);
|
|
5094
|
+
}
|
|
5095
|
+
function visibleVariable(context, node, name) {
|
|
5096
|
+
let scope = context.sourceCode.getScope(node);
|
|
5097
|
+
while (scope) {
|
|
5098
|
+
const variable = scope.set.get(name);
|
|
5099
|
+
if (variable) return variable;
|
|
5100
|
+
scope = scope.upper;
|
|
5101
|
+
}
|
|
5102
|
+
return void 0;
|
|
5103
|
+
}
|
|
5104
|
+
function canRenameIdentifierProducer(context, node, targetName) {
|
|
5045
5105
|
const variable = findVariable(context, node);
|
|
5046
5106
|
if (!variable || isExportedVariable2(context, variable)) return false;
|
|
5107
|
+
const targetVariable = visibleVariable(context, node, targetName);
|
|
5108
|
+
if (targetVariable && targetVariable !== variable) return false;
|
|
5047
5109
|
const definition = variable.defs[0];
|
|
5048
5110
|
if (!definition || variable.defs.length !== 1) return false;
|
|
5049
5111
|
if (definition.type === "ImportBinding") return false;
|
|
@@ -5056,17 +5118,53 @@ function memberRootIdentifier(node) {
|
|
|
5056
5118
|
while (current.type === "MemberExpression") current = current.object;
|
|
5057
5119
|
return current.type === "Identifier" ? current : void 0;
|
|
5058
5120
|
}
|
|
5059
|
-
function canBindMemberExpression(context, node) {
|
|
5121
|
+
function canBindMemberExpression(context, node, targetName) {
|
|
5122
|
+
if (visibleVariable(context, node, targetName)) return false;
|
|
5060
5123
|
const root = memberRootIdentifier(node);
|
|
5061
5124
|
if (!root) return true;
|
|
5062
5125
|
if (/^[A-Z]/u.test(root.name)) return false;
|
|
5063
5126
|
const variable = findVariable(context, root);
|
|
5064
5127
|
return !variable?.defs.some((definition) => definition.type === "ImportBinding");
|
|
5065
5128
|
}
|
|
5129
|
+
function listStatement(node) {
|
|
5130
|
+
let current = node;
|
|
5131
|
+
while (current.parent && current.parent.type !== "Program" && current.parent.type !== "BlockStatement") {
|
|
5132
|
+
current = current.parent;
|
|
5133
|
+
}
|
|
5134
|
+
return current.parent ? current : void 0;
|
|
5135
|
+
}
|
|
5136
|
+
function identifierPropertyFixes(context, node, value, propertyName4, fixer) {
|
|
5137
|
+
if (value.name === propertyName4) return [fixer.replaceText(node, propertyName4)];
|
|
5138
|
+
const variable = findVariable(context, value);
|
|
5139
|
+
if (!variable) return [];
|
|
5140
|
+
return [
|
|
5141
|
+
...variable.identifiers.map((identifier) => fixer.replaceText(identifier, propertyName4)),
|
|
5142
|
+
fixer.replaceText(node, propertyName4)
|
|
5143
|
+
];
|
|
5144
|
+
}
|
|
5145
|
+
function memberPropertyFixes(context, node, value, propertyName4, source, fixer) {
|
|
5146
|
+
const statement = listStatement(node);
|
|
5147
|
+
if (!statement) return [];
|
|
5148
|
+
const root = memberRootIdentifier(value);
|
|
5149
|
+
const rootVariable = root ? findVariable(context, root) : void 0;
|
|
5150
|
+
if (rootVariable?.defs.some((definition) => {
|
|
5151
|
+
const [statementStart, statementEnd] = context.sourceCode.getRange(statement);
|
|
5152
|
+
const [definitionStart, definitionEnd] = context.sourceCode.getRange(definition.node);
|
|
5153
|
+
return definitionStart >= statementStart && definitionEnd <= statementEnd;
|
|
5154
|
+
})) {
|
|
5155
|
+
return [];
|
|
5156
|
+
}
|
|
5157
|
+
return [
|
|
5158
|
+
fixer.insertTextBefore(statement, `const ${propertyName4} = ${source};
|
|
5159
|
+
`),
|
|
5160
|
+
fixer.replaceText(node, propertyName4)
|
|
5161
|
+
];
|
|
5162
|
+
}
|
|
5066
5163
|
var noRedundantAliasRule = {
|
|
5067
5164
|
meta: {
|
|
5068
5165
|
schema: [],
|
|
5069
5166
|
type: "problem",
|
|
5167
|
+
fixable: "code",
|
|
5070
5168
|
docs: {
|
|
5071
5169
|
description: "Disallow redundant aliases and inline identifier/member-expression object mappings."
|
|
5072
5170
|
}
|
|
@@ -5089,16 +5187,21 @@ var noRedundantAliasRule = {
|
|
|
5089
5187
|
if (node.parent.type !== "ObjectExpression" || node.computed || node.key.type !== "Identifier") return;
|
|
5090
5188
|
if (node.value.type !== "Identifier" && node.value.type !== "MemberExpression") return;
|
|
5091
5189
|
const propertyName4 = node.key.name;
|
|
5092
|
-
|
|
5093
|
-
|
|
5190
|
+
if (!canUsePropertyNameAsLocal(propertyName4)) return;
|
|
5191
|
+
const propertyValue = node.value;
|
|
5192
|
+
const source = context.sourceCode.getText(propertyValue);
|
|
5193
|
+
if (propertyValue.type === "Identifier") {
|
|
5094
5194
|
if (node.shorthand) return;
|
|
5095
|
-
if (source !== propertyName4 && !canRenameIdentifierProducer(context,
|
|
5096
|
-
} else if (!canBindMemberExpression(context,
|
|
5195
|
+
if (source !== propertyName4 && !canRenameIdentifierProducer(context, propertyValue, propertyName4)) return;
|
|
5196
|
+
} else if (!canBindMemberExpression(context, propertyValue, propertyName4)) {
|
|
5097
5197
|
return;
|
|
5098
5198
|
}
|
|
5099
5199
|
context.report({
|
|
5100
5200
|
node,
|
|
5101
|
-
message: objectPropertyMessage(propertyName4, source,
|
|
5201
|
+
message: objectPropertyMessage(propertyName4, source, propertyValue.type === "Identifier"),
|
|
5202
|
+
fix(fixer) {
|
|
5203
|
+
return propertyValue.type === "Identifier" ? identifierPropertyFixes(context, node, propertyValue, propertyName4, fixer) : memberPropertyFixes(context, node, propertyValue, propertyName4, source, fixer);
|
|
5204
|
+
}
|
|
5102
5205
|
});
|
|
5103
5206
|
},
|
|
5104
5207
|
TSTypeAliasDeclaration(node) {
|