@sarj/eslint-plugin 16.38.55 → 16.39.0
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/{_docs-IZjowAEc.d.cts → _docs-_eXGTNOq.d.cts} +1 -1
- package/dist/{_docs-IZjowAEc.d.ts → _docs-_eXGTNOq.d.ts} +1 -1
- package/dist/index.cjs +562 -468
- package/dist/index.d.cts +34 -215
- package/dist/index.d.ts +34 -215
- package/dist/index.js +547 -453
- package/dist/rule-examples.cjs +6 -3
- package/dist/rule-examples.d.cts +5 -1
- package/dist/rule-examples.d.ts +5 -1
- package/dist/rule-examples.js +6 -3
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1814,32 +1814,215 @@ var no_generic_json_parser_default = createRule({
|
|
|
1814
1814
|
});
|
|
1815
1815
|
|
|
1816
1816
|
// src/rules/no-redundant-local-alias.ts
|
|
1817
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
1818
|
+
|
|
1819
|
+
// src/rules/_unused-private-binding.ts
|
|
1820
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
1821
|
+
|
|
1822
|
+
// src/rules/_type-binding.ts
|
|
1817
1823
|
var import_utils18 = require("@typescript-eslint/utils");
|
|
1824
|
+
function typeBinding(source, identifier) {
|
|
1825
|
+
let scope = source.getScope(identifier);
|
|
1826
|
+
while (scope !== null) {
|
|
1827
|
+
const variable = scope.set.get(identifier.name);
|
|
1828
|
+
if (variable !== void 0 && (variable.isTypeVariable || variable.defs.some((definition) => definition.isTypeDefinition))) {
|
|
1829
|
+
return variable;
|
|
1830
|
+
}
|
|
1831
|
+
scope = scope.upper;
|
|
1832
|
+
}
|
|
1833
|
+
return null;
|
|
1834
|
+
}
|
|
1835
|
+
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
1836
|
+
function retainsNamedTypeUses(source, removed) {
|
|
1837
|
+
const manager = source.scopeManager;
|
|
1838
|
+
if (manager === null) return false;
|
|
1839
|
+
const index = referenceIndex(source, manager);
|
|
1840
|
+
for (const reference of referencesWithin(index.references, removed)) {
|
|
1841
|
+
if (!reference.isRead()) continue;
|
|
1842
|
+
const binding3 = reference.resolved;
|
|
1843
|
+
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
1844
|
+
if (binding3.defs.length === 0) continue;
|
|
1845
|
+
const reads = publicReadExtents(index, binding3);
|
|
1846
|
+
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
1847
|
+
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
1848
|
+
}
|
|
1849
|
+
return true;
|
|
1850
|
+
}
|
|
1851
|
+
function referenceIndex(source, manager) {
|
|
1852
|
+
const cached = REFERENCE_INDEXES.get(source);
|
|
1853
|
+
if (cached?.manager === manager) return cached;
|
|
1854
|
+
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
1855
|
+
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
1856
|
+
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
1857
|
+
REFERENCE_INDEXES.set(source, index);
|
|
1858
|
+
return index;
|
|
1859
|
+
}
|
|
1860
|
+
function* referencesWithin(references, removed) {
|
|
1861
|
+
let low = 0;
|
|
1862
|
+
let high = references.length;
|
|
1863
|
+
while (low < high) {
|
|
1864
|
+
const middle = low + Math.floor((high - low) / 2);
|
|
1865
|
+
const reference = references[middle];
|
|
1866
|
+
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
1867
|
+
else low = middle + 1;
|
|
1868
|
+
}
|
|
1869
|
+
for (let index = low; index < references.length; index++) {
|
|
1870
|
+
const reference = references[index];
|
|
1871
|
+
if (reference === void 0) continue;
|
|
1872
|
+
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
1873
|
+
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
function publicReadExtents(index, binding3) {
|
|
1877
|
+
const cached = index.publicReads.get(binding3);
|
|
1878
|
+
if (cached !== void 0) return cached;
|
|
1879
|
+
let type = null;
|
|
1880
|
+
let value = null;
|
|
1881
|
+
let both = null;
|
|
1882
|
+
for (const retained of binding3.references) {
|
|
1883
|
+
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
1884
|
+
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
1885
|
+
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
1886
|
+
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
1887
|
+
}
|
|
1888
|
+
const result = { type, value, both };
|
|
1889
|
+
index.publicReads.set(binding3, result);
|
|
1890
|
+
return result;
|
|
1891
|
+
}
|
|
1892
|
+
function extendExtent(extent, identifier) {
|
|
1893
|
+
return {
|
|
1894
|
+
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
1895
|
+
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
function publicTypeUse(identifier) {
|
|
1899
|
+
let node = identifier;
|
|
1900
|
+
while (node.parent) {
|
|
1901
|
+
if (node.type === import_utils18.AST_NODE_TYPES.TSTypeAnnotation || node.type === import_utils18.AST_NODE_TYPES.TSTypePredicate || node.type === import_utils18.AST_NODE_TYPES.TSAsExpression || node.type === import_utils18.AST_NODE_TYPES.TSTypeAssertion) return false;
|
|
1902
|
+
if (node.type === import_utils18.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
1903
|
+
return node.parent.type === import_utils18.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.declaration === node && node.parent.parent.type === import_utils18.AST_NODE_TYPES.Program;
|
|
1904
|
+
}
|
|
1905
|
+
if (node.type === import_utils18.AST_NODE_TYPES.ExportSpecifier) {
|
|
1906
|
+
return node.parent.type === import_utils18.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.source === null && node.parent.parent.type === import_utils18.AST_NODE_TYPES.Program;
|
|
1907
|
+
}
|
|
1908
|
+
node = node.parent;
|
|
1909
|
+
}
|
|
1910
|
+
return false;
|
|
1911
|
+
}
|
|
1912
|
+
function insideTypeRange(node, range) {
|
|
1913
|
+
return node.range[0] >= range.range[0] && node.range[1] <= range.range[1];
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
// src/rules/_unused-private-binding.ts
|
|
1917
|
+
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
1918
|
+
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
1919
|
+
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
1920
|
+
if (bindings.length === 0 || bindings.some((binding3) => binding3.defs.length !== allowedDeclarations.length || binding3.defs.some((definition) => !allowedDeclarations.includes(definition.node)) || binding3.eslintUsed || binding3.references.some((reference) => reference.isRead() || reference.init !== true))) return false;
|
|
1921
|
+
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
1922
|
+
const statement = declaration.type === import_utils19.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
1923
|
+
if (statement.parent.type === import_utils19.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils19.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
1924
|
+
if (statement.parent.type !== import_utils19.AST_NODE_TYPES.Program) return statement.parent.type === import_utils19.AST_NODE_TYPES.BlockStatement;
|
|
1925
|
+
return sourceCode.ast.body.some((node) => node.type === import_utils19.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils19.AST_NODE_TYPES.ExportNamedDeclaration || node.type === import_utils19.AST_NODE_TYPES.ExportDefaultDeclaration || node.type === import_utils19.AST_NODE_TYPES.ExportAllDeclaration);
|
|
1926
|
+
}
|
|
1927
|
+
function hasOnlyDirectFactoryUses(variable) {
|
|
1928
|
+
return variable.references.every((reference) => {
|
|
1929
|
+
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
1930
|
+
const identifier = reference.identifier;
|
|
1931
|
+
const parent = identifier.parent;
|
|
1932
|
+
if (parent.type === import_utils19.AST_NODE_TYPES.CallExpression && parent.callee === identifier) return true;
|
|
1933
|
+
return parent.type === import_utils19.AST_NODE_TYPES.MemberExpression && parent.object === identifier && !parent.computed && parent.parent.type === import_utils19.AST_NODE_TYPES.CallExpression && parent.parent.callee === parent;
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
1937
|
+
function hasIdentifierNamed(node, name) {
|
|
1938
|
+
let names = IDENTIFIER_NAMES.get(node);
|
|
1939
|
+
if (names === void 0) {
|
|
1940
|
+
const collected = /* @__PURE__ */ new Set();
|
|
1941
|
+
const pending = [node];
|
|
1942
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1943
|
+
while (pending.length > 0) {
|
|
1944
|
+
const current = pending.pop();
|
|
1945
|
+
if (current === void 0 || seen.has(current)) continue;
|
|
1946
|
+
seen.add(current);
|
|
1947
|
+
if (current.type === import_utils19.AST_NODE_TYPES.Identifier || current.type === import_utils19.AST_NODE_TYPES.JSXIdentifier) collected.add(current.name);
|
|
1948
|
+
forEachOwnAstChild(current, (child) => {
|
|
1949
|
+
pending.push(child);
|
|
1950
|
+
}, (key) => key !== "tokens" && key !== "comments");
|
|
1951
|
+
}
|
|
1952
|
+
names = collected;
|
|
1953
|
+
IDENTIFIER_NAMES.set(node, names);
|
|
1954
|
+
}
|
|
1955
|
+
return names.has(name);
|
|
1956
|
+
}
|
|
1957
|
+
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
1958
|
+
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !== import_utils19.AST_NODE_TYPES.FunctionDeclaration || node.id === null || !isUnusedPrivateBinding(sourceCode, node, node.id, filename) || sourceCode.getCommentsInside(annotation).length > 0) return null;
|
|
1959
|
+
const text = `boolean${sourceCode.getText(annotation).replace(/[^\r\n\u2028\u2029]/gu, "")}`;
|
|
1960
|
+
const neighbor = Math.max(0, annotation.range[0] - 1);
|
|
1961
|
+
const before = sourceCode.text.slice(neighbor, annotation.range[1] + 1).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
1962
|
+
const after = (sourceCode.text.slice(neighbor, annotation.range[0]) + text + sourceCode.text.slice(annotation.range[1], annotation.range[1] + 1)).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
1963
|
+
if (before.length !== after.length || before.some((ending, index) => ending !== after[index])) return null;
|
|
1964
|
+
return (fixer) => fixer.replaceText(annotation, text);
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
// src/rules/no-redundant-local-alias.ts
|
|
1818
1968
|
var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
1819
1969
|
defaultLevel: "warning",
|
|
1820
1970
|
summary: "Pass the original local into an object field instead of creating a single-use rename.",
|
|
1821
1971
|
rationale: "An unannotated alias used only by its matching object field adds a second name without adding a contract.",
|
|
1822
1972
|
remediation: "Write the object property with the original binding, then remove the redundant alias. Keep annotations, captured snapshots and independently useful names.",
|
|
1823
1973
|
category: "maintainability",
|
|
1974
|
+
autofix: "safe",
|
|
1824
1975
|
limitations: [
|
|
1825
1976
|
"Checks an unannotated local const alias of a stable parameter or earlier const. Its single read must be a shorthand property in the same function scope. Module exports, imported bindings, captures, reassignment, positional uses and typed aliases are preserved.",
|
|
1826
|
-
"
|
|
1977
|
+
"Safe fixes are limited to a plain module-scope function with one explicitly intrinsic-primitive parameter and exactly a const alias followed by a returned object containing that sole shorthand field. The source binding must remain the same at the returned field. Generics, return annotations, optional/default parameters, destructuring, overloads, comments, eval, async/generator functions and the special __proto__ key remain manual. Other diagnostics require review."
|
|
1827
1978
|
],
|
|
1828
1979
|
examples: [
|
|
1829
1980
|
{ id: "redundant-alias", title: "The property already supplies the name", outcome: "match", files: [{ path: "src/request.ts", source: "function request(value: string) { const accountId = value; return { accountId }; }" }], focusPath: "src/request.ts", expectedCount: 1, public: true },
|
|
1830
|
-
{ id: "direct-property", title: "Use the original binding", outcome: "no-match", files: [{ path: "src/request.ts", source: "function request(value: string) { return { accountId: value }; }" }], focusPath: "src/request.ts", expectedCount: 0, public: true }
|
|
1981
|
+
{ id: "direct-property", title: "Use the original binding", outcome: "no-match", files: [{ path: "src/request.ts", source: "function request(value: string) { return { accountId: value }; }" }], focusPath: "src/request.ts", expectedCount: 0, public: true },
|
|
1982
|
+
{ id: "closed-primitive-parameter-alias", scenarioId: "closed-primitive-parameter-alias", title: "The closed primitive return preserves the data-field contract", outcome: "match", files: [{ path: "src/request.ts", source: "export {};\nfunction request(value: string) {\n const accountId = value;\n return { accountId };\n}\n" }], fixedFiles: [{ path: "src/request.ts", source: "export {};\nfunction request(value: string) {\n\n return { accountId: value };\n}\n" }], focusPath: "src/request.ts", expectedCount: 1, public: true },
|
|
1983
|
+
{ id: "closed-primitive-parameter-alias-fixed", scenarioId: "closed-primitive-parameter-alias", title: "The direct data field needs no local alias", outcome: "no-match", files: [{ path: "src/request.ts", source: "export {};\nfunction request(value: string) {\n\n return { accountId: value };\n}\n" }], focusPath: "src/request.ts", expectedCount: 0, public: true }
|
|
1831
1984
|
]
|
|
1832
1985
|
};
|
|
1833
1986
|
function stableSource(variable, alias) {
|
|
1834
1987
|
const definition = variable.defs[0];
|
|
1835
1988
|
if (variable.defs.length !== 1 || definition === void 0 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
1836
|
-
return definition.type === "Parameter" || definition.node.type ===
|
|
1989
|
+
return definition.type === "Parameter" || definition.node.type === import_utils20.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < alias.range[0];
|
|
1990
|
+
}
|
|
1991
|
+
var PRIMITIVE_PARAMETERS = /* @__PURE__ */ new Set([
|
|
1992
|
+
import_utils20.AST_NODE_TYPES.TSStringKeyword,
|
|
1993
|
+
import_utils20.AST_NODE_TYPES.TSNumberKeyword,
|
|
1994
|
+
import_utils20.AST_NODE_TYPES.TSBooleanKeyword,
|
|
1995
|
+
import_utils20.AST_NODE_TYPES.TSBigIntKeyword,
|
|
1996
|
+
import_utils20.AST_NODE_TYPES.TSSymbolKeyword
|
|
1997
|
+
]);
|
|
1998
|
+
function closedPrimitiveReturnFix(sourceCode, node, property, source, target) {
|
|
1999
|
+
const statement = node.parent;
|
|
2000
|
+
const body3 = statement.parent;
|
|
2001
|
+
if (body3.type !== import_utils20.AST_NODE_TYPES.BlockStatement) return null;
|
|
2002
|
+
const owner = body3.parent;
|
|
2003
|
+
if (owner.type !== import_utils20.AST_NODE_TYPES.FunctionDeclaration || owner.parent.type !== import_utils20.AST_NODE_TYPES.Program || owner.id === null || owner.async || owner.generator || owner.typeParameters !== void 0 || owner.returnType !== void 0 || owner.params.length !== 1 || body3.body.length !== 2 || body3.body[0] !== statement || node.id.type !== import_utils20.AST_NODE_TYPES.Identifier || node.id.name === "__proto__" || node.init?.type !== import_utils20.AST_NODE_TYPES.Identifier || sourceCode.getCommentsInside(owner).length !== 0 || hasIdentifierNamed(sourceCode.ast, "eval")) return null;
|
|
2004
|
+
const parameter = owner.params[0];
|
|
2005
|
+
const returned2 = body3.body[1];
|
|
2006
|
+
if (parameter?.type !== import_utils20.AST_NODE_TYPES.Identifier || parameter.optional === true || parameter.typeAnnotation === void 0 || !PRIMITIVE_PARAMETERS.has(parameter.typeAnnotation.typeAnnotation.type) || returned2?.type !== import_utils20.AST_NODE_TYPES.ReturnStatement || returned2.argument !== property.parent || property.parent.type !== import_utils20.AST_NODE_TYPES.ObjectExpression || property.parent.properties.length !== 1 || import_utils20.ASTUtils.findVariable(sourceCode.getScope(parameter), parameter.name) !== source || import_utils20.ASTUtils.findVariable(sourceCode.getScope(property), node.init.name) !== source || source.references.some((reference) => reference.isTypeReference) || target.references.some((reference) => reference.isTypeReference)) return null;
|
|
2007
|
+
const name = owner.id.name;
|
|
2008
|
+
const bindings = sourceCode.getDeclaredVariables(owner).filter((binding3) => binding3.name === name);
|
|
2009
|
+
if (bindings.length !== 1 || bindings[0]?.defs.length !== 1 || bindings[0].defs[0]?.node !== owner || bindings[0].references.some((reference) => reference.isTypeReference)) return null;
|
|
2010
|
+
const span = [body3.range[0] + 1, statement.range[1]];
|
|
2011
|
+
const boundaries = sourceCode.text.slice(...span).replace(/[^\r\n\u2028\u2029]/gu, "");
|
|
2012
|
+
const neighbor = Math.max(0, span[0] - 1);
|
|
2013
|
+
const before = sourceCode.text.slice(neighbor, span[1] + 1).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
2014
|
+
const after = (sourceCode.text.slice(neighbor, span[0]) + boundaries + sourceCode.text.slice(span[1], span[1] + 1)).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
2015
|
+
if (before.length !== after.length || before.some((ending, index) => ending !== after[index])) return null;
|
|
2016
|
+
const key = sourceCode.getText(property.key);
|
|
2017
|
+
const value = sourceCode.getText(node.init);
|
|
2018
|
+
return (fixer) => [fixer.replaceTextRange(span, boundaries), fixer.replaceText(property, `${key}: ${value}`)];
|
|
1837
2019
|
}
|
|
1838
2020
|
var no_redundant_local_alias_default = createRule({
|
|
1839
2021
|
name: "no-redundant-local-alias",
|
|
1840
2022
|
documentation: NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION,
|
|
1841
2023
|
meta: {
|
|
1842
2024
|
type: "suggestion",
|
|
2025
|
+
fixable: "code",
|
|
1843
2026
|
docs: { description: NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION.summary },
|
|
1844
2027
|
schema: [],
|
|
1845
2028
|
messages: { redundantAlias: "This alias is read only by its matching object field; pass `{{source}}` directly as `{{target}}: {{source}}`." }
|
|
@@ -1847,31 +2030,32 @@ var no_redundant_local_alias_default = createRule({
|
|
|
1847
2030
|
defaultOptions: [],
|
|
1848
2031
|
create(context) {
|
|
1849
2032
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2033
|
+
const hasModuleSyntax = context.sourceCode.ast.body.some((candidate2) => candidate2.type === import_utils20.AST_NODE_TYPES.ImportDeclaration || candidate2.type === import_utils20.AST_NODE_TYPES.ExportNamedDeclaration || candidate2.type === import_utils20.AST_NODE_TYPES.ExportDefaultDeclaration || candidate2.type === import_utils20.AST_NODE_TYPES.ExportAllDeclaration);
|
|
1850
2034
|
return {
|
|
1851
2035
|
VariableDeclarator(node) {
|
|
1852
|
-
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !==
|
|
2036
|
+
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !== import_utils20.AST_NODE_TYPES.Identifier || node.id.typeAnnotation !== void 0 || node.init?.type !== import_utils20.AST_NODE_TYPES.Identifier) return;
|
|
1853
2037
|
const scope = context.sourceCode.getScope(node);
|
|
1854
2038
|
if (scope.variableScope.type !== "function") return;
|
|
1855
|
-
const target =
|
|
1856
|
-
const source =
|
|
2039
|
+
const target = import_utils20.ASTUtils.findVariable(scope, node.id.name);
|
|
2040
|
+
const source = import_utils20.ASTUtils.findVariable(scope, node.init.name);
|
|
1857
2041
|
if (target === null || source === null || !stableSource(source, node)) return;
|
|
1858
2042
|
const reads = target.references.filter((reference) => reference.isRead());
|
|
1859
2043
|
if (reads.length !== 1 || target.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
1860
2044
|
const read = reads[0];
|
|
1861
2045
|
if (read === void 0 || read.from.variableScope !== scope.variableScope) return;
|
|
1862
2046
|
const property = read.identifier.parent;
|
|
1863
|
-
if (property.type !==
|
|
1864
|
-
context.report({ node, messageId: "redundantAlias", data: { source: node.init.name, target: node.id.name } });
|
|
2047
|
+
if (property.type !== import_utils20.AST_NODE_TYPES.Property || !property.shorthand || property.value !== read.identifier || property.parent.type !== import_utils20.AST_NODE_TYPES.ObjectExpression || property.computed || property.method || property.kind !== "init") return;
|
|
2048
|
+
context.report({ node, messageId: "redundantAlias", fix: hasModuleSyntax ? closedPrimitiveReturnFix(context.sourceCode, node, property, source, target) : null, data: { source: node.init.name, target: node.id.name } });
|
|
1865
2049
|
}
|
|
1866
2050
|
};
|
|
1867
2051
|
}
|
|
1868
2052
|
});
|
|
1869
2053
|
|
|
1870
2054
|
// src/rules/no-test-comments.ts
|
|
1871
|
-
var
|
|
2055
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
1872
2056
|
|
|
1873
2057
|
// src/rules/_comments.ts
|
|
1874
|
-
var
|
|
2058
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
1875
2059
|
var REF_RE = /https?:\/\/|\bRFC[- ]?\d+|\bPEP[- ]?\d+|\bCVE-\d{4}|\b(?!UTF-|SHA-|ISO-|AES-|CRC-|MD-|PCM-|EOF-|API-|BASE-)[A-Z][A-Z0-9]{1,9}-\d[A-Z0-9]{0,5}\b|(?<![&\w])#\d{2,6}\b|@[a-z][\w.-]*\.(?:us|com|ai|io|net|org|dev)\b/;
|
|
1876
2060
|
var VERSION_RE = /(?:>=|<=|==|<|>)\s*v?\d+\.\d+|\bv\d+\.\d+|\b(?:since|until|as of)\s+(?:v?\d+\.\d+|Python\s*\d)/i;
|
|
1877
2061
|
var UNITS_RE = /[~<>]?\d+(?:\.\d+)?\s?(?:ms|s\b|sec\b|seconds?\b|min\b|minutes?\b|hours?\b|days?\b|KB|MB|MiB|GiB|kHz|Hz|bytes?\b|bit\b|-bit\b|%|px\b|rps\b|qps\b)|\b[1-5]xx\b|\b(?:301|302|304|307|308|400|401|403|404|405|409|410|412|422|425|429|500|501|502|503|504)\b/;
|
|
@@ -1957,10 +2141,10 @@ var NARRATION_MAX_WORDS = 6;
|
|
|
1957
2141
|
var NARRATION_MIN_CONTENT = 1;
|
|
1958
2142
|
var TOKEN_PLURAL_MIN = 4;
|
|
1959
2143
|
var RESTATABLE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
2144
|
+
import_utils21.AST_NODE_TYPES.ExpressionStatement,
|
|
2145
|
+
import_utils21.AST_NODE_TYPES.ReturnStatement,
|
|
2146
|
+
import_utils21.AST_NODE_TYPES.ThrowStatement,
|
|
2147
|
+
import_utils21.AST_NODE_TYPES.VariableDeclaration
|
|
1964
2148
|
]);
|
|
1965
2149
|
var NARRATION_VERB_RE = /^(?:add|append|assign|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|decrement|define|delete|extract|fetch|filter|find|format|generate|get|handle|increment|init|initialise|initialize|insert|iterate|join|load|log|loop|make|map|merge|open|parse|print|process|push|read|remove|render|reset|return|save|send|set|setup|sort|split|start|stop|store|update|validate|wrap|write)(?:s|es|d|ed|ing)?$/i;
|
|
1966
2150
|
var NARRATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
@@ -2019,12 +2203,12 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
2019
2203
|
function restatableStatementNodeBelow(comment, sourceCode) {
|
|
2020
2204
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
2021
2205
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
2022
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
2206
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils21.AST_NODE_TYPES.Program; node = node.parent) {
|
|
2023
2207
|
if (!RESTATABLE_STATEMENTS.has(node.type)) continue;
|
|
2024
2208
|
if (node.loc.start.line !== token.loc.start.line || node.loc.end.line !== node.loc.start.line) {
|
|
2025
2209
|
return null;
|
|
2026
2210
|
}
|
|
2027
|
-
if (node.type ===
|
|
2211
|
+
if (node.type === import_utils21.AST_NODE_TYPES.VariableDeclaration && isTrivialInitializer(node)) {
|
|
2028
2212
|
return null;
|
|
2029
2213
|
}
|
|
2030
2214
|
return node;
|
|
@@ -2034,8 +2218,8 @@ function restatableStatementNodeBelow(comment, sourceCode) {
|
|
|
2034
2218
|
function isTrivialInitializer(node) {
|
|
2035
2219
|
return node.declarations.every((declarator) => {
|
|
2036
2220
|
const init = declarator.init;
|
|
2037
|
-
if (init == null || init.type ===
|
|
2038
|
-
return init.type ===
|
|
2221
|
+
if (init == null || init.type === import_utils21.AST_NODE_TYPES.Literal) return true;
|
|
2222
|
+
return init.type === import_utils21.AST_NODE_TYPES.ArrayExpression && init.elements.length === 0 || init.type === import_utils21.AST_NODE_TYPES.ObjectExpression && init.properties.length === 0;
|
|
2039
2223
|
});
|
|
2040
2224
|
}
|
|
2041
2225
|
function restatesStatementHead(body3, statement) {
|
|
@@ -2062,7 +2246,7 @@ function headTokens(source) {
|
|
|
2062
2246
|
}
|
|
2063
2247
|
|
|
2064
2248
|
// src/rules/_comment-edits.ts
|
|
2065
|
-
var
|
|
2249
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
2066
2250
|
function physicalLineEnd(text, offset) {
|
|
2067
2251
|
const newline = text.indexOf("\n", offset);
|
|
2068
2252
|
return newline < 0 ? text.length : newline;
|
|
@@ -2096,7 +2280,11 @@ function trailingCommentRemovalRange(text, comment) {
|
|
|
2096
2280
|
return { range: [start, contentEnd] };
|
|
2097
2281
|
}
|
|
2098
2282
|
function commentLineEndings(text, removal) {
|
|
2099
|
-
|
|
2283
|
+
const replacement = text.slice(...removal.range).replace(/[^\r\n\u2028\u2029]/gu, "");
|
|
2284
|
+
const neighbor = Math.max(0, removal.range[0] - 1);
|
|
2285
|
+
const original = text.slice(neighbor, removal.range[1] + 1).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
2286
|
+
const rendered = (text.slice(neighbor, removal.range[0]) + replacement + text.slice(removal.range[1], removal.range[1] + 1)).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
2287
|
+
return original.length === rendered.length && original.every((ending, index) => ending === rendered[index]) ? replacement : null;
|
|
2100
2288
|
}
|
|
2101
2289
|
function exactMemberCommentRemovalRange(text, comment, key) {
|
|
2102
2290
|
if (key.type !== "Identifier") return null;
|
|
@@ -2126,6 +2314,7 @@ var NO_TEST_COMMENTS_DOCUMENTATION = {
|
|
|
2126
2314
|
]
|
|
2127
2315
|
};
|
|
2128
2316
|
var DIRECTIVE = /^(?:eslint(?:-\S+)?\b|(?:biome|oxlint|jshint|jslint|c8|v8|istanbul|vitest|prettier|dprint)\b|@(?:ts-(?:check|nocheck|expect-error|ignore)|vitest-environment|jest-environment|jsx\w*|license|preserve)\b|[#!]\s*__(?:PURE|NO_SIDE_EFFECTS)__|\/\s*<(?:reference|amd-module|amd-dependency)\b)/u;
|
|
2317
|
+
var BEHAVIORAL_DIRECTIVE = /(?:[@#]__(?:PURE|NO_SIDE_EFFECTS)__|@vite-ignore\b|\bwebpack(?:ChunkName|Mode|Exports|FetchPriority|Include|Exclude|Prefetch|Preload|Ignore)\s*:)/u;
|
|
2129
2318
|
var LEGAL = /(?:^|\n)\s*\*?\s*(?:Copyright\b|SPDX-License-Identifier:|Licensed under\b|@license\b|@preserve\b)/iu;
|
|
2130
2319
|
var TYPE_CONTRACT = /@(?:type|typedef|template|param|returns?|satisfies|callback|overload|implements|extends|augments|enum|this|import)\b/u;
|
|
2131
2320
|
var DETECT_SECRETS_COMMENT_MARKERS = [
|
|
@@ -2145,12 +2334,13 @@ var PYTHON_EXTRA_WHITESPACE = /* @__PURE__ */ new Set(["", "", "", ""]);
|
|
|
2145
2334
|
function hasDetectSecretsPragma(comment, text) {
|
|
2146
2335
|
if (!comment.value.includes("pragma:")) return false;
|
|
2147
2336
|
let lineStart = Math.max(text.lastIndexOf("\r", comment.range[0] - 1), text.lastIndexOf("\n", comment.range[0] - 1)) + 1;
|
|
2337
|
+
const readerLineEndings = /\r\n?|\n/gu;
|
|
2338
|
+
readerLineEndings.lastIndex = lineStart;
|
|
2148
2339
|
while (lineStart < comment.range[1]) {
|
|
2149
|
-
const
|
|
2150
|
-
const
|
|
2151
|
-
const lineEnd = Math.min(nextCr < 0 ? text.length : nextCr, nextLf < 0 ? text.length : nextLf);
|
|
2340
|
+
const ending = readerLineEndings.exec(text);
|
|
2341
|
+
const lineEnd = ending?.index ?? text.length;
|
|
2152
2342
|
if (hasPragmaInReaderLine(comment, text.slice(lineStart, lineEnd), lineStart)) return true;
|
|
2153
|
-
lineStart = lineEnd + (
|
|
2343
|
+
lineStart = lineEnd + (ending?.[0].length ?? 1);
|
|
2154
2344
|
}
|
|
2155
2345
|
return false;
|
|
2156
2346
|
}
|
|
@@ -2189,7 +2379,7 @@ var no_test_comments_default = createRule({
|
|
|
2189
2379
|
if (!isTestFile(context) || isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2190
2380
|
const filename = scopedFilename(context);
|
|
2191
2381
|
const unambiguous = /(?:^|\/)(?:tests?|__tests__|fixtures|__fixtures__|__mocks__)\//u.test(filename) || /\.(?:test|spec|e2e|integration)\.[cm]?[jt]sx?$/u.test(filename);
|
|
2192
|
-
const framework = context.sourceCode.ast.body.some((statement) => statement.type ===
|
|
2382
|
+
const framework = context.sourceCode.ast.body.some((statement) => statement.type === import_utils23.AST_NODE_TYPES.ImportDeclaration && statement.importKind !== "type" && (statement.specifiers.length === 0 || statement.specifiers.some((specifier) => specifier.type !== import_utils23.AST_NODE_TYPES.ImportSpecifier || specifier.importKind !== "type")) && ["vitest", "@jest/globals", "@playwright/test", "bun:test", "node:test"].includes(statement.source.value));
|
|
2193
2383
|
if (!unambiguous && !framework) return {};
|
|
2194
2384
|
return {
|
|
2195
2385
|
Program() {
|
|
@@ -2210,26 +2400,35 @@ var no_test_comments_default = createRule({
|
|
|
2210
2400
|
}
|
|
2211
2401
|
for (const [index, comment] of comments.entries()) {
|
|
2212
2402
|
const body3 = comment.value.trim().replace(/^\*\s*/u, "");
|
|
2213
|
-
if (DIRECTIVE.test(body3) || LEGAL.test(comment.value) || legalLines.has(index) || TYPE_CONTRACT.test(comment.value) || hasDetectSecretsPragma(comment, context.sourceCode.text)) continue;
|
|
2403
|
+
if (DIRECTIVE.test(body3) || BEHAVIORAL_DIRECTIVE.test(comment.value) || LEGAL.test(comment.value) || legalLines.has(index) || TYPE_CONTRACT.test(comment.value) || hasDetectSecretsPragma(comment, context.sourceCode.text)) continue;
|
|
2214
2404
|
context.report({
|
|
2215
2405
|
node: comment,
|
|
2216
2406
|
messageId: "testComment",
|
|
2217
2407
|
fix: (fixer) => {
|
|
2218
2408
|
const text = context.sourceCode.text;
|
|
2409
|
+
const preserveLineTerminators = (edit) => {
|
|
2410
|
+
const neighbor = Math.max(0, edit.range[0] - 1);
|
|
2411
|
+
const original = text.slice(neighbor, edit.range[1] + 1).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
2412
|
+
const rendered = (text.slice(neighbor, edit.range[0]) + edit.text + text.slice(edit.range[1], edit.range[1] + 1)).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
2413
|
+
return original.length === rendered.length && original.every((ending, position) => ending === rendered[position]) ? edit : null;
|
|
2414
|
+
};
|
|
2219
2415
|
const own = ownLineCommentRemovalRange(text, comment);
|
|
2220
|
-
if (own !== null)
|
|
2416
|
+
if (own !== null) {
|
|
2417
|
+
const ownEndings = commentLineEndings(text, own);
|
|
2418
|
+
return ownEndings === null ? null : preserveLineTerminators(fixer.replaceTextRange(own.range, ownEndings));
|
|
2419
|
+
}
|
|
2221
2420
|
const trailing = trailingCommentRemovalRange(text, comment);
|
|
2222
|
-
if (trailing !== null) return fixer.replaceTextRange(trailing.range, "");
|
|
2421
|
+
if (trailing !== null) return preserveLineTerminators(fixer.replaceTextRange(trailing.range, ""));
|
|
2223
2422
|
const endings = context.sourceCode.getText(comment).replace(/[^\r\n\u2028\u2029]/gu, "");
|
|
2224
2423
|
if (endings.length > 0) {
|
|
2225
2424
|
let start = comment.range[0];
|
|
2226
2425
|
while (start > 0 && /[\t ]/u.test(text[start - 1] ?? "")) start--;
|
|
2227
|
-
return fixer.replaceTextRange([start, comment.range[1]], endings);
|
|
2426
|
+
return preserveLineTerminators(fixer.replaceTextRange([start, comment.range[1]], endings));
|
|
2228
2427
|
}
|
|
2229
2428
|
const before = text[comment.range[0] - 1] ?? "";
|
|
2230
2429
|
const after = text[comment.range[1]] ?? "";
|
|
2231
2430
|
const separator = before.length > 0 && after.length > 0 && !/\s/u.test(before + after) ? " " : "";
|
|
2232
|
-
return fixer.replaceText(comment, separator);
|
|
2431
|
+
return preserveLineTerminators(fixer.replaceText(comment, separator));
|
|
2233
2432
|
}
|
|
2234
2433
|
});
|
|
2235
2434
|
}
|
|
@@ -2239,14 +2438,14 @@ var no_test_comments_default = createRule({
|
|
|
2239
2438
|
});
|
|
2240
2439
|
|
|
2241
2440
|
// src/rules/no-mutating-container-transform.ts
|
|
2242
|
-
var
|
|
2441
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
2243
2442
|
var MUTATORS = /* @__PURE__ */ new Set(["copyWithin", "fill", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"]);
|
|
2244
2443
|
var PRIMITIVES = /* @__PURE__ */ new Set([
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2444
|
+
import_utils24.AST_NODE_TYPES.TSStringKeyword,
|
|
2445
|
+
import_utils24.AST_NODE_TYPES.TSNumberKeyword,
|
|
2446
|
+
import_utils24.AST_NODE_TYPES.TSBooleanKeyword,
|
|
2447
|
+
import_utils24.AST_NODE_TYPES.TSBigIntKeyword,
|
|
2448
|
+
import_utils24.AST_NODE_TYPES.TSSymbolKeyword
|
|
2250
2449
|
]);
|
|
2251
2450
|
var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
2252
2451
|
defaultLevel: "warning",
|
|
@@ -2265,27 +2464,27 @@ var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
|
2265
2464
|
]
|
|
2266
2465
|
};
|
|
2267
2466
|
function arrayElement(node, sourceCode) {
|
|
2268
|
-
if (node.type ===
|
|
2269
|
-
if (node.type ===
|
|
2467
|
+
if (node.type === import_utils24.AST_NODE_TYPES.TSArrayType) return node.elementType;
|
|
2468
|
+
if (node.type === import_utils24.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils24.AST_NODE_TYPES.Identifier && (node.typeName.name === "Array" || node.typeName.name === "ReadonlyArray") && (import_utils24.ASTUtils.findVariable(sourceCode.getScope(node.typeName), node.typeName.name)?.defs.length ?? 0) === 0 && node.typeArguments?.params.length === 1) return node.typeArguments.params[0] ?? null;
|
|
2270
2469
|
return null;
|
|
2271
2470
|
}
|
|
2272
2471
|
function returnsArray(node, sourceCode) {
|
|
2273
2472
|
let annotation = node.returnType?.typeAnnotation;
|
|
2274
|
-
if (annotation?.type ===
|
|
2473
|
+
if (annotation?.type === import_utils24.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils24.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Promise" && (import_utils24.ASTUtils.findVariable(sourceCode.getScope(annotation.typeName), "Promise")?.defs.length ?? 0) === 0 && annotation.typeArguments?.params.length === 1) annotation = annotation.typeArguments.params[0];
|
|
2275
2474
|
return annotation !== void 0 && arrayElement(annotation, sourceCode) !== null;
|
|
2276
2475
|
}
|
|
2277
2476
|
function supported(statements) {
|
|
2278
2477
|
return statements.every((statement) => {
|
|
2279
2478
|
switch (statement.type) {
|
|
2280
|
-
case
|
|
2281
|
-
case
|
|
2282
|
-
case
|
|
2283
|
-
case
|
|
2284
|
-
case
|
|
2479
|
+
case import_utils24.AST_NODE_TYPES.ExpressionStatement:
|
|
2480
|
+
case import_utils24.AST_NODE_TYPES.VariableDeclaration:
|
|
2481
|
+
case import_utils24.AST_NODE_TYPES.ReturnStatement:
|
|
2482
|
+
case import_utils24.AST_NODE_TYPES.ThrowStatement:
|
|
2483
|
+
case import_utils24.AST_NODE_TYPES.EmptyStatement:
|
|
2285
2484
|
return true;
|
|
2286
|
-
case
|
|
2485
|
+
case import_utils24.AST_NODE_TYPES.BlockStatement:
|
|
2287
2486
|
return supported(statement.body);
|
|
2288
|
-
case
|
|
2487
|
+
case import_utils24.AST_NODE_TYPES.IfStatement:
|
|
2289
2488
|
return supported([statement.consequent]) && (statement.alternate === null || supported([statement.alternate]));
|
|
2290
2489
|
default:
|
|
2291
2490
|
return false;
|
|
@@ -2306,13 +2505,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2306
2505
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2307
2506
|
const sourceCode = context.sourceCode;
|
|
2308
2507
|
function binding3(node) {
|
|
2309
|
-
return node.type ===
|
|
2508
|
+
return node.type === import_utils24.AST_NODE_TYPES.Identifier ? import_utils24.ASTUtils.findVariable(sourceCode.getScope(node), node.name) : null;
|
|
2310
2509
|
}
|
|
2311
2510
|
function inspect(node) {
|
|
2312
|
-
if (node.body?.type !==
|
|
2511
|
+
if (node.body?.type !== import_utils24.AST_NODE_TYPES.BlockStatement || !returnsArray(node, sourceCode) || !supported(node.body.body)) return;
|
|
2313
2512
|
const initial = /* @__PURE__ */ new Map();
|
|
2314
2513
|
for (const parameter of node.params) {
|
|
2315
|
-
if (parameter.type !==
|
|
2514
|
+
if (parameter.type !== import_utils24.AST_NODE_TYPES.Identifier || parameter.typeAnnotation === void 0) continue;
|
|
2316
2515
|
const element = arrayElement(parameter.typeAnnotation.typeAnnotation, sourceCode);
|
|
2317
2516
|
const variable = binding3(parameter);
|
|
2318
2517
|
if (element !== null && PRIMITIVES.has(element.type) && variable !== null) initial.set(variable, parameter.name);
|
|
@@ -2325,26 +2524,26 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2325
2524
|
}
|
|
2326
2525
|
function expression(current, state) {
|
|
2327
2526
|
switch (current.type) {
|
|
2328
|
-
case
|
|
2329
|
-
case
|
|
2330
|
-
case
|
|
2527
|
+
case import_utils24.AST_NODE_TYPES.FunctionExpression:
|
|
2528
|
+
case import_utils24.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
2529
|
+
case import_utils24.AST_NODE_TYPES.ClassExpression:
|
|
2331
2530
|
return;
|
|
2332
|
-
case
|
|
2531
|
+
case import_utils24.AST_NODE_TYPES.AssignmentExpression:
|
|
2333
2532
|
assignment(current, state);
|
|
2334
2533
|
return;
|
|
2335
|
-
case
|
|
2534
|
+
case import_utils24.AST_NODE_TYPES.LogicalExpression:
|
|
2336
2535
|
logical(current, state);
|
|
2337
2536
|
return;
|
|
2338
|
-
case
|
|
2537
|
+
case import_utils24.AST_NODE_TYPES.ConditionalExpression:
|
|
2339
2538
|
conditional(current, state);
|
|
2340
2539
|
return;
|
|
2341
|
-
case
|
|
2540
|
+
case import_utils24.AST_NODE_TYPES.UpdateExpression:
|
|
2342
2541
|
write(current.argument, state);
|
|
2343
2542
|
break;
|
|
2344
|
-
case
|
|
2543
|
+
case import_utils24.AST_NODE_TYPES.UnaryExpression:
|
|
2345
2544
|
if (current.operator === "delete") write(current.argument, state);
|
|
2346
2545
|
break;
|
|
2347
|
-
case
|
|
2546
|
+
case import_utils24.AST_NODE_TYPES.CallExpression:
|
|
2348
2547
|
mutationCall(current, state);
|
|
2349
2548
|
break;
|
|
2350
2549
|
default:
|
|
@@ -2364,13 +2563,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2364
2563
|
function logical(current, state) {
|
|
2365
2564
|
expression(current.left, state);
|
|
2366
2565
|
const left = unwrapExpression(current.left);
|
|
2367
|
-
if (left.type ===
|
|
2566
|
+
if (left.type === import_utils24.AST_NODE_TYPES.Literal && (current.operator === "&&" && !left.value || current.operator === "||" && !!left.value || current.operator === "??" && left.value !== null)) return;
|
|
2368
2567
|
expression(current.right, state);
|
|
2369
2568
|
}
|
|
2370
2569
|
function conditional(current, state) {
|
|
2371
2570
|
expression(current.test, state);
|
|
2372
2571
|
const test = unwrapExpression(current.test);
|
|
2373
|
-
if (test.type ===
|
|
2572
|
+
if (test.type === import_utils24.AST_NODE_TYPES.Literal) {
|
|
2374
2573
|
expression(test.value ? current.consequent : current.alternate, state);
|
|
2375
2574
|
return;
|
|
2376
2575
|
}
|
|
@@ -2378,13 +2577,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2378
2577
|
expression(current.alternate, state);
|
|
2379
2578
|
}
|
|
2380
2579
|
function mutationCall(current, state) {
|
|
2381
|
-
if (current.callee.type !==
|
|
2580
|
+
if (current.callee.type !== import_utils24.AST_NODE_TYPES.MemberExpression || !MUTATORS.has(import_utils24.ASTUtils.getPropertyName(current.callee) ?? "")) return;
|
|
2382
2581
|
const parameter = origin(current.callee.object, state);
|
|
2383
2582
|
if (parameter !== void 0 && first === null) first = { node: current, parameter };
|
|
2384
2583
|
}
|
|
2385
2584
|
function write(target, state) {
|
|
2386
2585
|
target = unwrapExpression(target);
|
|
2387
|
-
if (target.type !==
|
|
2586
|
+
if (target.type !== import_utils24.AST_NODE_TYPES.MemberExpression || !target.computed && import_utils24.ASTUtils.getPropertyName(target) !== "length") return;
|
|
2388
2587
|
const parameter = origin(target.object, state);
|
|
2389
2588
|
if (parameter !== void 0 && first === null) first = { node: target, parameter };
|
|
2390
2589
|
}
|
|
@@ -2394,18 +2593,18 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2394
2593
|
}
|
|
2395
2594
|
function statement(current, state) {
|
|
2396
2595
|
switch (current.type) {
|
|
2397
|
-
case
|
|
2596
|
+
case import_utils24.AST_NODE_TYPES.BlockStatement:
|
|
2398
2597
|
return statements(current.body, state);
|
|
2399
|
-
case
|
|
2598
|
+
case import_utils24.AST_NODE_TYPES.IfStatement:
|
|
2400
2599
|
return branch(current, state);
|
|
2401
|
-
case
|
|
2600
|
+
case import_utils24.AST_NODE_TYPES.VariableDeclaration:
|
|
2402
2601
|
declarations(current, state);
|
|
2403
2602
|
return false;
|
|
2404
|
-
case
|
|
2405
|
-
case
|
|
2603
|
+
case import_utils24.AST_NODE_TYPES.ReturnStatement:
|
|
2604
|
+
case import_utils24.AST_NODE_TYPES.ThrowStatement:
|
|
2406
2605
|
if (current.argument !== null) expression(current.argument, state);
|
|
2407
2606
|
return true;
|
|
2408
|
-
case
|
|
2607
|
+
case import_utils24.AST_NODE_TYPES.ExpressionStatement:
|
|
2409
2608
|
expression(current.expression, state);
|
|
2410
2609
|
return false;
|
|
2411
2610
|
default:
|
|
@@ -2414,7 +2613,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2414
2613
|
}
|
|
2415
2614
|
function branch(current, state) {
|
|
2416
2615
|
expression(current.test, state);
|
|
2417
|
-
if (current.test.type ===
|
|
2616
|
+
if (current.test.type === import_utils24.AST_NODE_TYPES.Literal) return current.test.value ? statements([current.consequent], state) : current.alternate !== null && statements([current.alternate], state);
|
|
2418
2617
|
const left = new Map(state);
|
|
2419
2618
|
const right = new Map(state);
|
|
2420
2619
|
const leftEnds = statements([current.consequent], left);
|
|
@@ -2446,7 +2645,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
2446
2645
|
});
|
|
2447
2646
|
|
|
2448
2647
|
// src/rules/no-redundant-consumer-union.ts
|
|
2449
|
-
var
|
|
2648
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
2450
2649
|
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
2451
2650
|
|
|
2452
2651
|
// src/rules/_checked-native-source.ts
|
|
@@ -2557,109 +2756,13 @@ function finiteMember(member3, checker) {
|
|
|
2557
2756
|
}
|
|
2558
2757
|
|
|
2559
2758
|
// src/rules/_private-consumer-fix.ts
|
|
2560
|
-
var
|
|
2759
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
2561
2760
|
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
2562
|
-
|
|
2563
|
-
// src/rules/_type-binding.ts
|
|
2564
|
-
var import_utils23 = require("@typescript-eslint/utils");
|
|
2565
|
-
function typeBinding(source, identifier) {
|
|
2566
|
-
let scope = source.getScope(identifier);
|
|
2567
|
-
while (scope !== null) {
|
|
2568
|
-
const variable = scope.set.get(identifier.name);
|
|
2569
|
-
if (variable !== void 0 && (variable.isTypeVariable || variable.defs.some((definition) => definition.isTypeDefinition))) {
|
|
2570
|
-
return variable;
|
|
2571
|
-
}
|
|
2572
|
-
scope = scope.upper;
|
|
2573
|
-
}
|
|
2574
|
-
return null;
|
|
2575
|
-
}
|
|
2576
|
-
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
2577
|
-
function retainsNamedTypeUses(source, removed) {
|
|
2578
|
-
const manager = source.scopeManager;
|
|
2579
|
-
if (manager === null) return false;
|
|
2580
|
-
const index = referenceIndex(source, manager);
|
|
2581
|
-
for (const reference of referencesWithin(index.references, removed)) {
|
|
2582
|
-
if (!reference.isRead()) continue;
|
|
2583
|
-
const binding3 = reference.resolved;
|
|
2584
|
-
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
2585
|
-
if (binding3.defs.length === 0) continue;
|
|
2586
|
-
const reads = publicReadExtents(index, binding3);
|
|
2587
|
-
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
2588
|
-
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
2589
|
-
}
|
|
2590
|
-
return true;
|
|
2591
|
-
}
|
|
2592
|
-
function referenceIndex(source, manager) {
|
|
2593
|
-
const cached = REFERENCE_INDEXES.get(source);
|
|
2594
|
-
if (cached?.manager === manager) return cached;
|
|
2595
|
-
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
2596
|
-
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
2597
|
-
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
2598
|
-
REFERENCE_INDEXES.set(source, index);
|
|
2599
|
-
return index;
|
|
2600
|
-
}
|
|
2601
|
-
function* referencesWithin(references, removed) {
|
|
2602
|
-
let low = 0;
|
|
2603
|
-
let high = references.length;
|
|
2604
|
-
while (low < high) {
|
|
2605
|
-
const middle = low + Math.floor((high - low) / 2);
|
|
2606
|
-
const reference = references[middle];
|
|
2607
|
-
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
2608
|
-
else low = middle + 1;
|
|
2609
|
-
}
|
|
2610
|
-
for (let index = low; index < references.length; index++) {
|
|
2611
|
-
const reference = references[index];
|
|
2612
|
-
if (reference === void 0) continue;
|
|
2613
|
-
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
2614
|
-
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
function publicReadExtents(index, binding3) {
|
|
2618
|
-
const cached = index.publicReads.get(binding3);
|
|
2619
|
-
if (cached !== void 0) return cached;
|
|
2620
|
-
let type = null;
|
|
2621
|
-
let value = null;
|
|
2622
|
-
let both = null;
|
|
2623
|
-
for (const retained of binding3.references) {
|
|
2624
|
-
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
2625
|
-
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
2626
|
-
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
2627
|
-
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
2628
|
-
}
|
|
2629
|
-
const result = { type, value, both };
|
|
2630
|
-
index.publicReads.set(binding3, result);
|
|
2631
|
-
return result;
|
|
2632
|
-
}
|
|
2633
|
-
function extendExtent(extent, identifier) {
|
|
2634
|
-
return {
|
|
2635
|
-
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
2636
|
-
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
2637
|
-
};
|
|
2638
|
-
}
|
|
2639
|
-
function publicTypeUse(identifier) {
|
|
2640
|
-
let node = identifier;
|
|
2641
|
-
while (node.parent) {
|
|
2642
|
-
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeAnnotation || node.type === import_utils23.AST_NODE_TYPES.TSTypePredicate || node.type === import_utils23.AST_NODE_TYPES.TSAsExpression || node.type === import_utils23.AST_NODE_TYPES.TSTypeAssertion) return false;
|
|
2643
|
-
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
2644
|
-
return node.parent.type === import_utils23.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.declaration === node && node.parent.parent.type === import_utils23.AST_NODE_TYPES.Program;
|
|
2645
|
-
}
|
|
2646
|
-
if (node.type === import_utils23.AST_NODE_TYPES.ExportSpecifier) {
|
|
2647
|
-
return node.parent.type === import_utils23.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.source === null && node.parent.parent.type === import_utils23.AST_NODE_TYPES.Program;
|
|
2648
|
-
}
|
|
2649
|
-
node = node.parent;
|
|
2650
|
-
}
|
|
2651
|
-
return false;
|
|
2652
|
-
}
|
|
2653
|
-
function insideTypeRange(node, range) {
|
|
2654
|
-
return node.range[0] >= range.range[0] && node.range[1] <= range.range[1];
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
// src/rules/_private-consumer-fix.ts
|
|
2658
2761
|
var UNSAFE = import_typescript3.default.TypeFlags.Any | import_typescript3.default.TypeFlags.Unknown | import_typescript3.default.TypeFlags.Never | import_typescript3.default.TypeFlags.TypeParameter | import_typescript3.default.TypeFlags.Conditional | import_typescript3.default.TypeFlags.IndexedAccess | import_typescript3.default.TypeFlags.Substitution;
|
|
2659
2762
|
function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
2660
2763
|
if (sourceCode.getAllComments().some((comment) => /@ts-(?:expect-error|ignore|nocheck)\b/u.test(comment.value))) return false;
|
|
2661
|
-
const owner = node.type ===
|
|
2662
|
-
if (owner.type !==
|
|
2764
|
+
const owner = node.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration ? node : node.parent;
|
|
2765
|
+
if (owner.type !== import_utils25.AST_NODE_TYPES.FunctionDeclaration && owner.type !== import_utils25.AST_NODE_TYPES.VariableDeclarator) return false;
|
|
2663
2766
|
const binding3 = sourceCode.getDeclaredVariables(owner).find((variable) => variable.defs.some((definition) => definition.node === owner && (definition.type === "FunctionName" || definition.type === "Variable")));
|
|
2664
2767
|
if (!binding3) return false;
|
|
2665
2768
|
const declaration = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -2695,7 +2798,7 @@ function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
|
2695
2798
|
continue;
|
|
2696
2799
|
}
|
|
2697
2800
|
const call = reference.identifier.parent;
|
|
2698
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
2801
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils25.AST_NODE_TYPES.CallExpression || call.callee !== reference.identifier || call.optional || call.typeArguments || call.arguments.length !== declaration.parameters.length || !call.arguments.every((argument) => argument.type === import_utils25.AST_NODE_TYPES.Identifier) || !validArguments(call)) return false;
|
|
2699
2802
|
calls += 1;
|
|
2700
2803
|
}
|
|
2701
2804
|
return calls > 0;
|
|
@@ -2747,7 +2850,7 @@ function minimalConsumerFix(sourceCode, annotation, removed) {
|
|
|
2747
2850
|
}
|
|
2748
2851
|
|
|
2749
2852
|
// src/rules/_private-scalar-consumer.ts
|
|
2750
|
-
var
|
|
2853
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
2751
2854
|
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
2752
2855
|
|
|
2753
2856
|
// src/rules/_scalar-parameter-view.ts
|
|
@@ -2897,8 +3000,8 @@ function intrinsicAttribute(attribute, view) {
|
|
|
2897
3000
|
// src/rules/_private-scalar-consumer.ts
|
|
2898
3001
|
function directEval(node) {
|
|
2899
3002
|
let callee = unwrapExpression(node.callee);
|
|
2900
|
-
while (callee.type ===
|
|
2901
|
-
return callee.type ===
|
|
3003
|
+
while (callee.type === import_utils26.AST_NODE_TYPES.TSInstantiationExpression) callee = unwrapExpression(callee.expression);
|
|
3004
|
+
return callee.type === import_utils26.AST_NODE_TYPES.Identifier && callee.name === "eval";
|
|
2902
3005
|
}
|
|
2903
3006
|
function primitiveKeyword(node) {
|
|
2904
3007
|
return node !== void 0 && (node.kind === import_typescript6.default.SyntaxKind.StringKeyword || node.kind === import_typescript6.default.SyntaxKind.NumberKeyword || node.kind === import_typescript6.default.SyntaxKind.BooleanKeyword || node.kind === import_typescript6.default.SyntaxKind.BigIntKeyword);
|
|
@@ -2911,16 +3014,16 @@ function consumerAnnotation(node, auxiliaryScalars = false) {
|
|
|
2911
3014
|
if (!auxiliaryScalars) return void 0;
|
|
2912
3015
|
let annotation;
|
|
2913
3016
|
for (const parameter2 of node.params) {
|
|
2914
|
-
if (parameter2.type !==
|
|
3017
|
+
if (parameter2.type !== import_utils26.AST_NODE_TYPES.Identifier && parameter2.type !== import_utils26.AST_NODE_TYPES.ObjectPattern) continue;
|
|
2915
3018
|
const current = parameter2.typeAnnotation?.typeAnnotation;
|
|
2916
|
-
if (current?.type !==
|
|
3019
|
+
if (current?.type !== import_utils26.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
2917
3020
|
if (annotation) return void 0;
|
|
2918
3021
|
annotation = current;
|
|
2919
3022
|
}
|
|
2920
3023
|
return annotation;
|
|
2921
3024
|
}
|
|
2922
3025
|
const parameter = node.params[0];
|
|
2923
|
-
return parameter?.type ===
|
|
3026
|
+
return parameter?.type === import_utils26.AST_NODE_TYPES.Identifier || parameter?.type === import_utils26.AST_NODE_TYPES.ObjectPattern ? parameter.typeAnnotation?.typeAnnotation : void 0;
|
|
2924
3027
|
}
|
|
2925
3028
|
function exportedSymbols(source, checker) {
|
|
2926
3029
|
const symbol = checker.getSymbolAtLocation(source);
|
|
@@ -2970,12 +3073,12 @@ function auxiliaryBindings(native, selected, checker) {
|
|
|
2970
3073
|
return bindings;
|
|
2971
3074
|
}
|
|
2972
3075
|
function callableBinding(node, sourceCode) {
|
|
2973
|
-
if (node.type ===
|
|
2974
|
-
if (node.parent.type !==
|
|
3076
|
+
if (node.type === import_utils26.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3077
|
+
if (node.parent.type !== import_utils26.AST_NODE_TYPES.Program) return void 0;
|
|
2975
3078
|
return sourceCode.getDeclaredVariables(node).find((variable) => variable.defs.some((definition) => definition.type === "FunctionName" && definition.node === node));
|
|
2976
3079
|
}
|
|
2977
3080
|
const declaration = node.parent;
|
|
2978
|
-
if (declaration.type !==
|
|
3081
|
+
if (declaration.type !== import_utils26.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils26.AST_NODE_TYPES.Identifier || declaration.id.typeAnnotation || declaration.parent.kind !== "const" || declaration.parent.parent.type !== import_utils26.AST_NODE_TYPES.Program) return void 0;
|
|
2979
3082
|
return sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
2980
3083
|
}
|
|
2981
3084
|
function directCalls(binding3, arity) {
|
|
@@ -2983,7 +3086,7 @@ function directCalls(binding3, arity) {
|
|
|
2983
3086
|
const stable2 = stableValueBinding(binding3, (reference) => {
|
|
2984
3087
|
const identifier = reference.identifier;
|
|
2985
3088
|
const call = identifier.parent;
|
|
2986
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
3089
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils26.AST_NODE_TYPES.CallExpression || call.callee !== identifier || call.optional || call.typeArguments || call.arguments.length !== arity || !call.arguments.every((argument) => argument.type === import_utils26.AST_NODE_TYPES.Identifier)) return false;
|
|
2987
3090
|
calls += 1;
|
|
2988
3091
|
return true;
|
|
2989
3092
|
});
|
|
@@ -3043,13 +3146,13 @@ function localContractBindings(roots, source, services) {
|
|
|
3043
3146
|
}
|
|
3044
3147
|
function localContractReferences(node, source, services) {
|
|
3045
3148
|
switch (node.type) {
|
|
3046
|
-
case
|
|
3149
|
+
case import_utils27.AST_NODE_TYPES.TSTypeLiteral:
|
|
3047
3150
|
return [];
|
|
3048
|
-
case
|
|
3151
|
+
case import_utils27.AST_NODE_TYPES.TSIntersectionType:
|
|
3049
3152
|
return node.types;
|
|
3050
|
-
case
|
|
3051
|
-
return !node.typeArguments && node.typeName.type ===
|
|
3052
|
-
case
|
|
3153
|
+
case import_utils27.AST_NODE_TYPES.TSTypeReference:
|
|
3154
|
+
return !node.typeArguments && node.typeName.type === import_utils27.AST_NODE_TYPES.Identifier ? [node.typeName] : null;
|
|
3155
|
+
case import_utils27.AST_NODE_TYPES.Identifier:
|
|
3053
3156
|
return localBindingReferences(node, source, services);
|
|
3054
3157
|
default:
|
|
3055
3158
|
return null;
|
|
@@ -3059,8 +3162,8 @@ function localBindingReferences(identifier, source, services) {
|
|
|
3059
3162
|
const definitions2 = typeBinding(source, identifier)?.defs.filter((definition) => definition.isTypeDefinition).map((definition) => definition.node);
|
|
3060
3163
|
if (!definitions2?.length || !definitions2.every(moduleTypeDeclaration)) return null;
|
|
3061
3164
|
const first = definitions2[0];
|
|
3062
|
-
if (definitions2.length === 1 && first?.type ===
|
|
3063
|
-
const interfaces = definitions2.filter((definition) => definition.type ===
|
|
3165
|
+
if (definitions2.length === 1 && first?.type === import_utils27.AST_NODE_TYPES.TSTypeAliasDeclaration && !first.typeParameters) return [first.typeAnnotation];
|
|
3166
|
+
const interfaces = definitions2.filter((definition) => definition.type === import_utils27.AST_NODE_TYPES.TSInterfaceDeclaration);
|
|
3064
3167
|
if (interfaces.length !== definitions2.length || interfaces.some((declaration) => declaration.typeParameters)) return null;
|
|
3065
3168
|
if (interfaces.length > 1) {
|
|
3066
3169
|
const checker = services.program.getTypeChecker();
|
|
@@ -3068,13 +3171,13 @@ function localBindingReferences(identifier, source, services) {
|
|
|
3068
3171
|
if (!symbol || interfaces.some((declaration) => checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(declaration.id)) !== symbol)) return null;
|
|
3069
3172
|
}
|
|
3070
3173
|
const bases = interfaces.flatMap((declaration) => declaration.extends.map((base) => base.expression));
|
|
3071
|
-
return bases.every((base) => base.type ===
|
|
3174
|
+
return bases.every((base) => base.type === import_utils27.AST_NODE_TYPES.Identifier) ? bases : null;
|
|
3072
3175
|
}
|
|
3073
3176
|
function moduleTypeDeclaration(node) {
|
|
3074
3177
|
const parent = node.parent;
|
|
3075
|
-
if (parent?.type ===
|
|
3076
|
-
if (parent?.type !==
|
|
3077
|
-
return parent.parent.type ===
|
|
3178
|
+
if (parent?.type === import_utils27.AST_NODE_TYPES.Program) return true;
|
|
3179
|
+
if (parent?.type !== import_utils27.AST_NODE_TYPES.ExportNamedDeclaration && parent?.type !== import_utils27.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
3180
|
+
return parent.parent.type === import_utils27.AST_NODE_TYPES.Program;
|
|
3078
3181
|
}
|
|
3079
3182
|
function coveringAlternative(leftNode, rightNode, checker, fieldsOf, reads) {
|
|
3080
3183
|
const left = checker.getTypeFromTypeNode(leftNode);
|
|
@@ -3109,7 +3212,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
3109
3212
|
let dynamic = false;
|
|
3110
3213
|
const remember = (node) => {
|
|
3111
3214
|
const annotation = consumerAnnotation(node);
|
|
3112
|
-
if (annotation?.type ===
|
|
3215
|
+
if (annotation?.type === import_utils27.AST_NODE_TYPES.TSUnionType && annotation.types.length === 2) candidates.push(node);
|
|
3113
3216
|
};
|
|
3114
3217
|
return {
|
|
3115
3218
|
FunctionDeclaration: remember,
|
|
@@ -3119,7 +3222,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
3119
3222
|
},
|
|
3120
3223
|
"Program:exit"() {
|
|
3121
3224
|
if (dynamic || !candidates.length) return;
|
|
3122
|
-
const services =
|
|
3225
|
+
const services = import_utils27.ESLintUtils.getParserServices(context);
|
|
3123
3226
|
const source = currentNativeSource(context.sourceCode, services);
|
|
3124
3227
|
if (!source) return;
|
|
3125
3228
|
const checker = services.program.getTypeChecker();
|
|
@@ -3143,7 +3246,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
3143
3246
|
const coverage = coveringAlternative(leftNode, rightNode, checker, fieldsOf, consumer.reads);
|
|
3144
3247
|
if (!coverage) continue;
|
|
3145
3248
|
const reportNode = services.tsNodeToESTreeNodeMap.get(annotation);
|
|
3146
|
-
if (coverage.mutual && (reportNode.type !==
|
|
3249
|
+
if (coverage.mutual && (reportNode.type !== import_utils27.AST_NODE_TYPES.TSUnionType || !localContractBindings(reportNode.types, context.sourceCode, services))) continue;
|
|
3147
3250
|
const { covered: coveredNode, covering: coveringNode } = coverage;
|
|
3148
3251
|
const fix = privateUnionFix(context.sourceCode, services, {
|
|
3149
3252
|
candidate: candidate2,
|
|
@@ -3161,7 +3264,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
3161
3264
|
});
|
|
3162
3265
|
|
|
3163
3266
|
// src/rules/prefer-minimal-parameter-contract.ts
|
|
3164
|
-
var
|
|
3267
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
3165
3268
|
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
3166
3269
|
var CONFIG2 = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
3167
3270
|
var EXAMPLE2 = 'export {}; const account = {name: "Ada", email: "a"}; function label(user: {readonly email: string; readonly name: string}): string {return user.name;} label(account);';
|
|
@@ -3218,7 +3321,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
3218
3321
|
const candidates = [];
|
|
3219
3322
|
let dynamic = false;
|
|
3220
3323
|
const remember = (node) => {
|
|
3221
|
-
if (consumerAnnotation(node, true)?.type ===
|
|
3324
|
+
if (consumerAnnotation(node, true)?.type === import_utils28.AST_NODE_TYPES.TSTypeLiteral) candidates.push(node);
|
|
3222
3325
|
};
|
|
3223
3326
|
return {
|
|
3224
3327
|
FunctionDeclaration: remember,
|
|
@@ -3228,7 +3331,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
3228
3331
|
},
|
|
3229
3332
|
"Program:exit"() {
|
|
3230
3333
|
if (dynamic || !candidates.length) return;
|
|
3231
|
-
const services =
|
|
3334
|
+
const services = import_utils28.ESLintUtils.getParserServices(context);
|
|
3232
3335
|
const source = currentNativeSource(context.sourceCode, services);
|
|
3233
3336
|
if (!source) return;
|
|
3234
3337
|
const checker = services.program.getTypeChecker();
|
|
@@ -3252,7 +3355,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
3252
3355
|
});
|
|
3253
3356
|
|
|
3254
3357
|
// src/rules/no-excess-jsx-props.ts
|
|
3255
|
-
var
|
|
3358
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
3256
3359
|
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
3257
3360
|
|
|
3258
3361
|
// src/rules/_ordinary-object-effects.ts
|
|
@@ -3594,11 +3697,11 @@ var PRIMITIVE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
3594
3697
|
function plainLiteralFields(node) {
|
|
3595
3698
|
const fields2 = /* @__PURE__ */ new Map();
|
|
3596
3699
|
for (const property of node.properties) {
|
|
3597
|
-
if (property.type !==
|
|
3700
|
+
if (property.type !== import_utils29.AST_NODE_TYPES.Property || property.kind !== "init") return null;
|
|
3598
3701
|
const key = property.key;
|
|
3599
3702
|
let name;
|
|
3600
|
-
if (!property.computed && key.type ===
|
|
3601
|
-
else if (key.type ===
|
|
3703
|
+
if (!property.computed && key.type === import_utils29.AST_NODE_TYPES.Identifier) name = key.name;
|
|
3704
|
+
else if (key.type === import_utils29.AST_NODE_TYPES.Literal && (typeof key.value === "string" || typeof key.value === "number")) name = String(key.value);
|
|
3602
3705
|
else return null;
|
|
3603
3706
|
if (name === "__proto__") return null;
|
|
3604
3707
|
fields2.set(name, property);
|
|
@@ -3710,35 +3813,35 @@ function localObjectFields(symbol, source, proof) {
|
|
|
3710
3813
|
if (!native || native.getSourceFile() !== source || !initializer || !import_typescript10.default.isObjectLiteralExpression(initializer)) return null;
|
|
3711
3814
|
const declaration = proof.services.tsNodeToESTreeNodeMap.get(native);
|
|
3712
3815
|
const literal2 = proof.services.tsNodeToESTreeNodeMap.get(initializer);
|
|
3713
|
-
if (declaration.type !==
|
|
3816
|
+
if (declaration.type !== import_utils29.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.id.type !== import_utils29.AST_NODE_TYPES.Identifier || literal2.type !== import_utils29.AST_NODE_TYPES.ObjectExpression || declaration.parent.parent.type === import_utils29.AST_NODE_TYPES.ExportNamedDeclaration) return null;
|
|
3714
3817
|
const fields2 = plainLiteralFields(literal2);
|
|
3715
3818
|
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
3716
3819
|
if (!fields2 || !binding3 || binding3.defs.length !== 1 || !stableValueBinding(binding3, (reference) => {
|
|
3717
3820
|
if (!reference.isReadOnly() || reference.isTypeReference) return false;
|
|
3718
3821
|
const member3 = reference.identifier.parent;
|
|
3719
|
-
return member3.type ===
|
|
3822
|
+
return member3.type === import_utils29.AST_NODE_TYPES.MemberExpression && member3.object === reference.identifier && readonlyFieldValue(member3, fields2);
|
|
3720
3823
|
})) return null;
|
|
3721
3824
|
return fields2;
|
|
3722
3825
|
}
|
|
3723
3826
|
function staticMemberKey(member3) {
|
|
3724
3827
|
const property = member3.property;
|
|
3725
|
-
return !member3.computed && property.type ===
|
|
3828
|
+
return !member3.computed && property.type === import_utils29.AST_NODE_TYPES.Identifier ? property.name : property.type === import_utils29.AST_NODE_TYPES.Literal && (typeof property.value === "string" || typeof property.value === "number") ? String(property.value) : void 0;
|
|
3726
3829
|
}
|
|
3727
3830
|
function readonlyFieldValue(member3, fields2) {
|
|
3728
3831
|
const key = staticMemberKey(member3);
|
|
3729
3832
|
if (key === void 0 || !fields2.has(key)) return false;
|
|
3730
3833
|
const parent = member3.parent;
|
|
3731
|
-
if (parent.type ===
|
|
3834
|
+
if (parent.type === import_utils29.AST_NODE_TYPES.Property && parent.value === member3 && parent.parent.type === import_utils29.AST_NODE_TYPES.ObjectExpression) {
|
|
3732
3835
|
const object = parent.parent;
|
|
3733
3836
|
const owner = object.parent;
|
|
3734
|
-
return owner.type ===
|
|
3837
|
+
return owner.type === import_utils29.AST_NODE_TYPES.JSXSpreadAttribute && owner.argument === object || owner.type === import_utils29.AST_NODE_TYPES.VariableDeclarator && owner.init === object;
|
|
3735
3838
|
}
|
|
3736
|
-
return parent.type ===
|
|
3839
|
+
return parent.type === import_utils29.AST_NODE_TYPES.JSXExpressionContainer && parent.expression === member3 || parent.type === import_utils29.AST_NODE_TYPES.VariableDeclarator && parent.init === member3;
|
|
3737
3840
|
}
|
|
3738
3841
|
function privateElementDeclaration(opening) {
|
|
3739
3842
|
const value = outerExpression(opening.parent);
|
|
3740
3843
|
const declaration = value.parent;
|
|
3741
|
-
return declaration.type ===
|
|
3844
|
+
return declaration.type === import_utils29.AST_NODE_TYPES.VariableDeclarator && declaration.init === value && declaration.id.type === import_utils29.AST_NODE_TYPES.Identifier && declaration.parent.kind === "const" && declaration.parent.parent.type !== import_utils29.AST_NODE_TYPES.ExportNamedDeclaration ? declaration : null;
|
|
3742
3845
|
}
|
|
3743
3846
|
function closedElementValue(opening, declaration, fields2, reads, proof) {
|
|
3744
3847
|
if (!closedInvocation(opening, proof) || !constInitializer(proof.services.esTreeNodeToTSNodeMap.get(declaration))) return false;
|
|
@@ -3764,10 +3867,10 @@ function closedInvocation(node, proof) {
|
|
|
3764
3867
|
}
|
|
3765
3868
|
function independentInvocation(scope, proof) {
|
|
3766
3869
|
const block = scope.block;
|
|
3767
|
-
if (block.type !==
|
|
3870
|
+
if (block.type !== import_utils29.AST_NODE_TYPES.ArrowFunctionExpression && block.type !== import_utils29.AST_NODE_TYPES.FunctionDeclaration && block.type !== import_utils29.AST_NODE_TYPES.FunctionExpression) return false;
|
|
3768
3871
|
if (block.async || block.generator || scope.set.get("arguments")?.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3769
3872
|
for (const parameter of block.params) {
|
|
3770
|
-
if (parameter.type !==
|
|
3873
|
+
if (parameter.type !== import_utils29.AST_NODE_TYPES.Identifier || parameter.name === "this") return false;
|
|
3771
3874
|
const binding3 = scope.set.get(parameter.name);
|
|
3772
3875
|
if (!binding3 || binding3.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
3773
3876
|
}
|
|
@@ -3775,16 +3878,16 @@ function independentInvocation(scope, proof) {
|
|
|
3775
3878
|
if (typeOnlyReference(reference)) return true;
|
|
3776
3879
|
const value = outerExpression(reference.identifier);
|
|
3777
3880
|
const parent = value.parent;
|
|
3778
|
-
const read = parent?.type ===
|
|
3881
|
+
const read = parent?.type === import_utils29.AST_NODE_TYPES.MemberExpression && parent.object === value ? parent : value;
|
|
3779
3882
|
return primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(read), proof, /* @__PURE__ */ new Set());
|
|
3780
3883
|
});
|
|
3781
3884
|
}
|
|
3782
3885
|
function consumedElementRead(node, fields2, reads) {
|
|
3783
3886
|
const identifier = outerExpression(node);
|
|
3784
3887
|
const props = identifier.parent;
|
|
3785
|
-
if (!props || props.type !==
|
|
3888
|
+
if (!props || props.type !== import_utils29.AST_NODE_TYPES.MemberExpression || props.object !== identifier || props.optional || staticMemberKey(props) !== "props") return false;
|
|
3786
3889
|
const member3 = props.parent;
|
|
3787
|
-
if (member3.type !==
|
|
3890
|
+
if (member3.type !== import_utils29.AST_NODE_TYPES.MemberExpression || member3.object !== props || member3.optional) return false;
|
|
3788
3891
|
const key = staticMemberKey(member3);
|
|
3789
3892
|
return key !== void 0 && reads.has(key) && readonlyFieldValue(member3, fields2);
|
|
3790
3893
|
}
|
|
@@ -3812,7 +3915,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3812
3915
|
const evaluate = (node, declaration, fields2) => {
|
|
3813
3916
|
const keys = [...fields2.keys()];
|
|
3814
3917
|
const opening = node.parent;
|
|
3815
|
-
services ??=
|
|
3918
|
+
services ??= import_utils29.ESLintUtils.getParserServices(context);
|
|
3816
3919
|
standardJSX ??= supportedJSX(services.program.getCompilerOptions(), context.sourceCode.getAllComments());
|
|
3817
3920
|
if (!standardJSX) return;
|
|
3818
3921
|
const checker = services.program.getTypeChecker();
|
|
@@ -3844,9 +3947,9 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3844
3947
|
};
|
|
3845
3948
|
return {
|
|
3846
3949
|
JSXSpreadAttribute(node) {
|
|
3847
|
-
if (node.argument.type !==
|
|
3950
|
+
if (node.argument.type !== import_utils29.AST_NODE_TYPES.ObjectExpression) return;
|
|
3848
3951
|
const opening = node.parent;
|
|
3849
|
-
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !==
|
|
3952
|
+
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !== import_utils29.AST_NODE_TYPES.JSXIdentifier || /^[a-z]/u.test(opening.name.name)) return;
|
|
3850
3953
|
const declaration = privateElementDeclaration(opening);
|
|
3851
3954
|
if (!declaration) return;
|
|
3852
3955
|
const fields2 = literalFields(node.argument);
|
|
@@ -3858,7 +3961,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3858
3961
|
},
|
|
3859
3962
|
"Program:exit"() {
|
|
3860
3963
|
if (!candidates.length || dynamic) return;
|
|
3861
|
-
services =
|
|
3964
|
+
services = import_utils29.ESLintUtils.getParserServices(context);
|
|
3862
3965
|
if (!currentNativeSource(context.sourceCode, services)) return;
|
|
3863
3966
|
for (const { node, declaration, fields: fields2 } of candidates) evaluate(node, declaration, fields2);
|
|
3864
3967
|
}
|
|
@@ -3867,7 +3970,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3867
3970
|
});
|
|
3868
3971
|
|
|
3869
3972
|
// src/rules/prefer-native-fetch-in-server-actions.ts
|
|
3870
|
-
var
|
|
3973
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
3871
3974
|
var KY_MODULE = /^ky(?:\/.*)?$/u;
|
|
3872
3975
|
var PREFER_NATIVE_FETCH_IN_SERVER_ACTIONS_DOCUMENTATION = {
|
|
3873
3976
|
defaultLevel: "warning",
|
|
@@ -3931,19 +4034,19 @@ var prefer_native_fetch_in_server_actions_default = createRule({
|
|
|
3931
4034
|
});
|
|
3932
4035
|
function hasUseServerDirective(program) {
|
|
3933
4036
|
for (const statement of program.body) {
|
|
3934
|
-
if (statement.type !==
|
|
4037
|
+
if (statement.type !== import_utils30.AST_NODE_TYPES.ExpressionStatement || statement.directive === void 0) return false;
|
|
3935
4038
|
if (statement.directive === "use server") return true;
|
|
3936
4039
|
}
|
|
3937
4040
|
return false;
|
|
3938
4041
|
}
|
|
3939
4042
|
function isTypeOnly(node) {
|
|
3940
4043
|
return node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every(
|
|
3941
|
-
(specifier) => specifier.type ===
|
|
4044
|
+
(specifier) => specifier.type === import_utils30.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
3942
4045
|
);
|
|
3943
4046
|
}
|
|
3944
4047
|
|
|
3945
4048
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3946
|
-
var
|
|
4049
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
3947
4050
|
|
|
3948
4051
|
// src/rules/_secret-names.ts
|
|
3949
4052
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -4148,7 +4251,7 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
4148
4251
|
return {
|
|
4149
4252
|
CallExpression(node) {
|
|
4150
4253
|
const callee = unwrapExpression(node.callee);
|
|
4151
|
-
if (callee.type !==
|
|
4254
|
+
if (callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils31.AST_NODE_TYPES.Identifier || callee.property.name !== "setItem" || !isStorage(sourceCode, callee.object)) {
|
|
4152
4255
|
return;
|
|
4153
4256
|
}
|
|
4154
4257
|
const [key] = node.arguments;
|
|
@@ -4156,12 +4259,12 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
4156
4259
|
},
|
|
4157
4260
|
AssignmentExpression(node) {
|
|
4158
4261
|
const target = node.left;
|
|
4159
|
-
if (target.type !==
|
|
4262
|
+
if (target.type !== import_utils31.AST_NODE_TYPES.MemberExpression) return;
|
|
4160
4263
|
if (isStorage(sourceCode, target.object)) {
|
|
4161
4264
|
report2(node, storedPropertyKey(sourceCode, target));
|
|
4162
4265
|
return;
|
|
4163
4266
|
}
|
|
4164
|
-
if (!target.computed && target.property.type ===
|
|
4267
|
+
if (!target.computed && target.property.type === import_utils31.AST_NODE_TYPES.Identifier && target.property.name === "cookie" && globalMemberName(sourceCode, target.object) === "document") {
|
|
4165
4268
|
report2(node, cookieName(node.right));
|
|
4166
4269
|
}
|
|
4167
4270
|
}
|
|
@@ -4174,34 +4277,34 @@ function isStorage(sourceCode, node) {
|
|
|
4174
4277
|
}
|
|
4175
4278
|
function globalMemberName(sourceCode, node) {
|
|
4176
4279
|
const value = unwrapExpression(node);
|
|
4177
|
-
if (value.type ===
|
|
4178
|
-
if (value.type ===
|
|
4280
|
+
if (value.type === import_utils31.AST_NODE_TYPES.Identifier) return isUnshadowed(sourceCode, value) ? value.name : null;
|
|
4281
|
+
if (value.type === import_utils31.AST_NODE_TYPES.MemberExpression && !value.computed && value.object.type === import_utils31.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(value.object.name) && value.property.type === import_utils31.AST_NODE_TYPES.Identifier && isUnshadowed(sourceCode, value.object)) {
|
|
4179
4282
|
return value.property.name;
|
|
4180
4283
|
}
|
|
4181
4284
|
return null;
|
|
4182
4285
|
}
|
|
4183
4286
|
function isUnshadowed(sourceCode, node) {
|
|
4184
|
-
const variable =
|
|
4287
|
+
const variable = import_utils31.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
4185
4288
|
return variable === null || variable.defs.length === 0;
|
|
4186
4289
|
}
|
|
4187
4290
|
function storedPropertyKey(sourceCode, target) {
|
|
4188
|
-
if (!target.computed) return target.property.type ===
|
|
4291
|
+
if (!target.computed) return target.property.type === import_utils31.AST_NODE_TYPES.Identifier ? target.property.name : null;
|
|
4189
4292
|
return scopedStaticString(target.property, sourceCode);
|
|
4190
4293
|
}
|
|
4191
4294
|
function cookieName(value) {
|
|
4192
4295
|
let expression = unwrapExpression(value);
|
|
4193
|
-
while (expression.type ===
|
|
4296
|
+
while (expression.type === import_utils31.AST_NODE_TYPES.BinaryExpression && expression.operator === "+") {
|
|
4194
4297
|
expression = unwrapExpression(expression.left);
|
|
4195
4298
|
}
|
|
4196
4299
|
let text = null;
|
|
4197
|
-
if (expression.type ===
|
|
4198
|
-
if (expression.type ===
|
|
4300
|
+
if (expression.type === import_utils31.AST_NODE_TYPES.Literal && typeof expression.value === "string") text = expression.value;
|
|
4301
|
+
if (expression.type === import_utils31.AST_NODE_TYPES.TemplateLiteral) text = expression.quasis[0]?.value.cooked ?? null;
|
|
4199
4302
|
if (text === null || !text.includes("=")) return null;
|
|
4200
4303
|
return text.slice(0, text.indexOf("=")).trim();
|
|
4201
4304
|
}
|
|
4202
4305
|
|
|
4203
4306
|
// src/rules/no-numeric-search-param-coercion.ts
|
|
4204
|
-
var
|
|
4307
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4205
4308
|
var GLOBAL_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat", "Number"]);
|
|
4206
4309
|
var NUMBER_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat"]);
|
|
4207
4310
|
var SEARCH_PARAM_TYPES = /* @__PURE__ */ new Set(["URLSearchParams", "ReadonlyURLSearchParams"]);
|
|
@@ -4258,7 +4361,7 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4258
4361
|
if (isGeneratedFile(context, context.sourceCode.text) || isTestFile(context)) return {};
|
|
4259
4362
|
let services;
|
|
4260
4363
|
try {
|
|
4261
|
-
services =
|
|
4364
|
+
services = import_utils32.ESLintUtils.getParserServices(context);
|
|
4262
4365
|
} catch {
|
|
4263
4366
|
services = null;
|
|
4264
4367
|
}
|
|
@@ -4280,27 +4383,27 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4280
4383
|
}
|
|
4281
4384
|
});
|
|
4282
4385
|
function isNumericParser(sourceCode, callee) {
|
|
4283
|
-
if (callee.type ===
|
|
4386
|
+
if (callee.type === import_utils32.AST_NODE_TYPES.Identifier) {
|
|
4284
4387
|
return GLOBAL_PARSERS.has(callee.name) && isUnshadowedGlobal(sourceCode, callee);
|
|
4285
4388
|
}
|
|
4286
|
-
return callee.type ===
|
|
4389
|
+
return callee.type === import_utils32.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils32.AST_NODE_TYPES.Identifier && callee.object.name === "Number" && callee.property.type === import_utils32.AST_NODE_TYPES.Identifier && NUMBER_PARSERS.has(callee.property.name) && isUnshadowedGlobal(sourceCode, callee.object);
|
|
4287
4390
|
}
|
|
4288
4391
|
function isUnshadowedGlobal(sourceCode, node) {
|
|
4289
|
-
const variable =
|
|
4392
|
+
const variable = import_utils32.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
4290
4393
|
return variable === null || variable.defs.length === 0;
|
|
4291
4394
|
}
|
|
4292
4395
|
function searchParamGetCall(argument) {
|
|
4293
4396
|
let value = unwrapExpression(argument);
|
|
4294
|
-
if (value.type ===
|
|
4295
|
-
if (value.type ===
|
|
4296
|
-
if (value.type ===
|
|
4297
|
-
if (value.type !==
|
|
4397
|
+
if (value.type === import_utils32.AST_NODE_TYPES.AwaitExpression) value = unwrapExpression(value.argument);
|
|
4398
|
+
if (value.type === import_utils32.AST_NODE_TYPES.LogicalExpression && value.operator === "??") value = unwrapExpression(value.left);
|
|
4399
|
+
if (value.type === import_utils32.AST_NODE_TYPES.ChainExpression) value = value.expression;
|
|
4400
|
+
if (value.type !== import_utils32.AST_NODE_TYPES.CallExpression || value.callee.type !== import_utils32.AST_NODE_TYPES.MemberExpression || value.callee.computed || value.callee.property.type !== import_utils32.AST_NODE_TYPES.Identifier || value.callee.property.name !== "get") {
|
|
4298
4401
|
return null;
|
|
4299
4402
|
}
|
|
4300
4403
|
return value;
|
|
4301
4404
|
}
|
|
4302
4405
|
function isSearchParamReceiver(call, services) {
|
|
4303
|
-
if (call.callee.type !==
|
|
4406
|
+
if (call.callee.type !== import_utils32.AST_NODE_TYPES.MemberExpression) return false;
|
|
4304
4407
|
const checker = services.program.getTypeChecker();
|
|
4305
4408
|
const type = checker.getNonNullableType(
|
|
4306
4409
|
checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(call.callee.object))
|
|
@@ -4312,7 +4415,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4312
4415
|
// package.json
|
|
4313
4416
|
var package_default = {
|
|
4314
4417
|
name: "@sarj/eslint-plugin",
|
|
4315
|
-
version: "16.
|
|
4418
|
+
version: "16.39.0",
|
|
4316
4419
|
packageManager: "npm@12.2.1",
|
|
4317
4420
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4318
4421
|
type: "module",
|
|
@@ -4400,6 +4503,7 @@ var package_default = {
|
|
|
4400
4503
|
"eslint-plugin-zod": "^5.2.2",
|
|
4401
4504
|
globals: "17.13.0",
|
|
4402
4505
|
jiti: "2.7.0",
|
|
4506
|
+
prettier: "3.9.10",
|
|
4403
4507
|
tsup: "9.0.0",
|
|
4404
4508
|
typescript: "npm:@typescript/typescript6@6.0.2",
|
|
4405
4509
|
"typescript-eslint": "^8.72.0",
|
|
@@ -4434,11 +4538,11 @@ var package_default = {
|
|
|
4434
4538
|
};
|
|
4435
4539
|
|
|
4436
4540
|
// src/rules/require-explicit-contract-implementation.ts
|
|
4437
|
-
var
|
|
4541
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
4438
4542
|
var ts12 = __toESM(require("typescript"), 1);
|
|
4439
4543
|
|
|
4440
4544
|
// src/rules/_closed-nominal-inheritance-fix.ts
|
|
4441
|
-
var
|
|
4545
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
4442
4546
|
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
4443
4547
|
function closedNominalInheritanceFix(sourceCode, call, consumer, implementation, contract) {
|
|
4444
4548
|
const source = call.getSourceFile();
|
|
@@ -4512,7 +4616,7 @@ function exactRejection(sourceCode, statement) {
|
|
|
4512
4616
|
const identifier = sourceCode.getNodeByRangeIndex(
|
|
4513
4617
|
rejected.expression.expression.getStart()
|
|
4514
4618
|
);
|
|
4515
|
-
return identifier?.type ===
|
|
4619
|
+
return identifier?.type === import_utils33.AST_NODE_TYPES.Identifier && identifier.name === "TypeError" && (import_utils33.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
4516
4620
|
}
|
|
4517
4621
|
function exactConstruction(node, consumer, implementation) {
|
|
4518
4622
|
if (!import_typescript11.default.isIdentifier(node.expression) || node.expression.text !== consumer || node.typeArguments !== void 0 || node.arguments?.length !== 1)
|
|
@@ -4878,7 +4982,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4878
4982
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
4879
4983
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
4880
4984
|
return {};
|
|
4881
|
-
const services =
|
|
4985
|
+
const services = import_utils34.ESLintUtils.getParserServices(context);
|
|
4882
4986
|
const checker = services.program.getTypeChecker();
|
|
4883
4987
|
function inspect(node) {
|
|
4884
4988
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -4893,7 +4997,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4893
4997
|
return;
|
|
4894
4998
|
const parameters = signature.getParameters();
|
|
4895
4999
|
for (const [index, argument] of node.arguments.entries()) {
|
|
4896
|
-
if (argument.type !==
|
|
5000
|
+
if (argument.type !== import_utils34.AST_NODE_TYPES.NewExpression) continue;
|
|
4897
5001
|
const parameter = parameters[index];
|
|
4898
5002
|
if (parameter === void 0) continue;
|
|
4899
5003
|
const tsArgument = services.esTreeNodeToTSNodeMap.get(argument);
|
|
@@ -4940,18 +5044,18 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4940
5044
|
});
|
|
4941
5045
|
|
|
4942
5046
|
// src/rules/require-explicit-service-contract.ts
|
|
4943
|
-
var
|
|
5047
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
4944
5048
|
|
|
4945
5049
|
// src/rules/_existing-factory-contract-fix.ts
|
|
4946
|
-
var
|
|
5050
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
4947
5051
|
function existingFactoryContractFix(sourceCode, candidate2) {
|
|
4948
5052
|
if (sourceCode.ast.body.length !== 4 || sourceCode.getAllComments().length !== 0)
|
|
4949
5053
|
return null;
|
|
4950
5054
|
const [contractStatement, worker, classStatement, factoryStatement] = sourceCode.ast.body;
|
|
4951
|
-
const contract = contractStatement?.type ===
|
|
4952
|
-
const implementation = classStatement?.type ===
|
|
4953
|
-
const factory = factoryStatement?.type ===
|
|
4954
|
-
if (contract?.type !==
|
|
5055
|
+
const contract = contractStatement?.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? contractStatement.declaration : null;
|
|
5056
|
+
const implementation = classStatement?.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? classStatement.declaration : classStatement;
|
|
5057
|
+
const factory = factoryStatement?.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration ? factoryStatement.declaration : null;
|
|
5058
|
+
if (contract?.type !== import_utils35.AST_NODE_TYPES.TSTypeAliasDeclaration || worker?.type !== import_utils35.AST_NODE_TYPES.TSInterfaceDeclaration || implementation?.type !== import_utils35.AST_NODE_TYPES.ClassDeclaration || implementation !== candidate2 || !ordinaryClass(implementation) || !ordinaryFactory(factory))
|
|
4955
5059
|
return null;
|
|
4956
5060
|
const operation2 = contractOperation(contract);
|
|
4957
5061
|
if (operation2 === null || interfaceOperation(worker) !== operation2)
|
|
@@ -4970,17 +5074,17 @@ function ordinaryClass(node) {
|
|
|
4970
5074
|
return node.id !== null && !node.declare && !node.abstract && node.decorators.length === 0 && node.superClass === null && node.implements.length === 0 && node.typeParameters === void 0 && node.body.body.length === 2;
|
|
4971
5075
|
}
|
|
4972
5076
|
function ordinaryFactory(node) {
|
|
4973
|
-
return node?.type ===
|
|
5077
|
+
return node?.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && !node.declare && !node.async && !node.generator && node.typeParameters === void 0 && node.params.length === 1 && node.body.body.length === 1;
|
|
4974
5078
|
}
|
|
4975
5079
|
function interfaceOperation(node) {
|
|
4976
5080
|
return !node.declare && node.extends.length === 0 && node.typeParameters === void 0 ? singletonOperation(node.body.body) : null;
|
|
4977
5081
|
}
|
|
4978
5082
|
function contractOperation(node) {
|
|
4979
|
-
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type ===
|
|
5083
|
+
return !node.declare && node.typeParameters === void 0 && node.typeAnnotation.type === import_utils35.AST_NODE_TYPES.TSTypeLiteral ? singletonOperation(node.typeAnnotation.members) : null;
|
|
4980
5084
|
}
|
|
4981
5085
|
function singletonOperation(members) {
|
|
4982
5086
|
const member3 = members[0];
|
|
4983
|
-
return members.length === 1 && member3?.type ===
|
|
5087
|
+
return members.length === 1 && member3?.type === import_utils35.AST_NODE_TYPES.TSMethodSignature && member3.kind === "method" && !member3.computed && !member3.optional && member3.key.type === import_utils35.AST_NODE_TYPES.Identifier && member3.params.length === 0 && member3.typeParameters === void 0 && member3.returnType?.typeAnnotation.type === import_utils35.AST_NODE_TYPES.TSVoidKeyword ? member3.key.name : null;
|
|
4984
5088
|
}
|
|
4985
5089
|
function uniqueDeclarations(sourceCode, declarations) {
|
|
4986
5090
|
const names = declarations.flatMap(
|
|
@@ -4991,7 +5095,7 @@ function uniqueDeclarations(sourceCode, declarations) {
|
|
|
4991
5095
|
);
|
|
4992
5096
|
}
|
|
4993
5097
|
function sameBinding(sourceCode, reference, declaration) {
|
|
4994
|
-
const binding3 =
|
|
5098
|
+
const binding3 = import_utils35.ASTUtils.findVariable(
|
|
4995
5099
|
sourceCode.getScope(reference),
|
|
4996
5100
|
reference.name
|
|
4997
5101
|
);
|
|
@@ -4999,45 +5103,45 @@ function sameBinding(sourceCode, reference, declaration) {
|
|
|
4999
5103
|
}
|
|
5000
5104
|
function retainedWorker(sourceCode, implementation, worker) {
|
|
5001
5105
|
const constructor = implementation.body.body[0];
|
|
5002
|
-
if (constructor?.type !==
|
|
5106
|
+
if (constructor?.type !== import_utils35.AST_NODE_TYPES.MethodDefinition || constructor.value.type !== import_utils35.AST_NODE_TYPES.FunctionExpression || constructor.kind !== "constructor" || constructor.computed || constructor.static || constructor.decorators.length !== 0 || constructor.optional || constructor.accessibility !== void 0 && constructor.accessibility !== "public" || constructor.value.async || constructor.value.generator || constructor.value.typeParameters !== void 0 || constructor.value.returnType !== void 0 || constructor.value.body.body.length !== 0 || constructor.value.params.length !== 1)
|
|
5003
5107
|
return null;
|
|
5004
5108
|
const property = constructor.value.params[0];
|
|
5005
|
-
if (property?.type !==
|
|
5109
|
+
if (property?.type !== import_utils35.AST_NODE_TYPES.TSParameterProperty || property.accessibility !== "private" || !property.readonly || property.override || property.decorators.length !== 0 || property.parameter.type !== import_utils35.AST_NODE_TYPES.Identifier || property.parameter.optional || !typeReference(sourceCode, property.parameter.typeAnnotation, worker))
|
|
5006
5110
|
return null;
|
|
5007
5111
|
return property.parameter.name;
|
|
5008
5112
|
}
|
|
5009
5113
|
function typeReference(sourceCode, annotation, declaration) {
|
|
5010
5114
|
const type = annotation?.typeAnnotation;
|
|
5011
|
-
return type?.type ===
|
|
5115
|
+
return type?.type === import_utils35.AST_NODE_TYPES.TSTypeReference && type.typeArguments === void 0 && type.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && sameBinding(sourceCode, type.typeName, declaration);
|
|
5012
5116
|
}
|
|
5013
5117
|
function forwardsOperation(implementation, field, operation2) {
|
|
5014
5118
|
const method = implementation.body.body[1];
|
|
5015
|
-
if (method?.type !==
|
|
5119
|
+
if (method?.type !== import_utils35.AST_NODE_TYPES.MethodDefinition || method.kind !== "method" || method.value.type !== import_utils35.AST_NODE_TYPES.FunctionExpression || method.computed || method.static || method.optional || method.override || method.decorators.length !== 0 || method.accessibility !== void 0 && method.accessibility !== "public" || method.key.type !== import_utils35.AST_NODE_TYPES.Identifier || method.key.name !== operation2 || method.value.async || method.value.generator || method.value.typeParameters !== void 0 || method.value.params.length !== 0 || method.value.body.body.length !== 1 || method.value.returnType?.typeAnnotation.type !== import_utils35.AST_NODE_TYPES.TSVoidKeyword)
|
|
5016
5120
|
return false;
|
|
5017
5121
|
const statement = method.value.body.body[0];
|
|
5018
|
-
const call = statement?.type ===
|
|
5019
|
-
return call?.type ===
|
|
5122
|
+
const call = statement?.type === import_utils35.AST_NODE_TYPES.ExpressionStatement ? statement.expression : null;
|
|
5123
|
+
return call?.type === import_utils35.AST_NODE_TYPES.CallExpression && !call.optional && call.typeArguments === void 0 && call.arguments.length === 0 && forwardedMember(call.callee, field, operation2);
|
|
5020
5124
|
}
|
|
5021
5125
|
function forwardedMember(node, field, operation2) {
|
|
5022
|
-
if (node.type !==
|
|
5126
|
+
if (node.type !== import_utils35.AST_NODE_TYPES.MemberExpression || node.computed || node.optional || node.property.type !== import_utils35.AST_NODE_TYPES.Identifier || node.property.name !== operation2)
|
|
5023
5127
|
return false;
|
|
5024
5128
|
const receiver = node.object;
|
|
5025
|
-
return receiver.type ===
|
|
5129
|
+
return receiver.type === import_utils35.AST_NODE_TYPES.MemberExpression && !receiver.computed && !receiver.optional && receiver.object.type === import_utils35.AST_NODE_TYPES.ThisExpression && receiver.property.type === import_utils35.AST_NODE_TYPES.Identifier && receiver.property.name === field;
|
|
5026
5130
|
}
|
|
5027
5131
|
function factoryAuthority(sourceCode, factory, contract, worker, implementation) {
|
|
5028
5132
|
const parameter = factory.params[0];
|
|
5029
|
-
if (parameter?.type !==
|
|
5133
|
+
if (parameter?.type !== import_utils35.AST_NODE_TYPES.Identifier || parameter.optional || !typeReference(sourceCode, parameter.typeAnnotation, worker) || !typeReference(sourceCode, factory.returnType, contract))
|
|
5030
5134
|
return false;
|
|
5031
5135
|
const statement = factory.body.body[0];
|
|
5032
|
-
const constructed = statement?.type ===
|
|
5033
|
-
if (constructed?.type !==
|
|
5136
|
+
const constructed = statement?.type === import_utils35.AST_NODE_TYPES.ReturnStatement ? statement.argument : null;
|
|
5137
|
+
if (constructed?.type !== import_utils35.AST_NODE_TYPES.NewExpression || constructed.typeArguments !== void 0 || constructed.callee.type !== import_utils35.AST_NODE_TYPES.Identifier || !sameBinding(sourceCode, constructed.callee, implementation) || constructed.arguments.length !== 1)
|
|
5034
5138
|
return false;
|
|
5035
5139
|
const argument = constructed.arguments[0];
|
|
5036
|
-
return argument?.type ===
|
|
5140
|
+
return argument?.type === import_utils35.AST_NODE_TYPES.Identifier && argument.name === parameter.name && sameBinding(sourceCode, argument, factory);
|
|
5037
5141
|
}
|
|
5038
5142
|
|
|
5039
5143
|
// src/rules/require-port-for-service.ts
|
|
5040
|
-
var
|
|
5144
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5041
5145
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
5042
5146
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
5043
5147
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -5121,50 +5225,50 @@ var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
5121
5225
|
"||="
|
|
5122
5226
|
]);
|
|
5123
5227
|
var staticMemberName = (member3) => {
|
|
5124
|
-
if (member3.property.type ===
|
|
5228
|
+
if (member3.property.type === import_utils36.AST_NODE_TYPES.PrivateIdentifier)
|
|
5125
5229
|
return `#${member3.property.name}`;
|
|
5126
|
-
return
|
|
5230
|
+
return import_utils36.ASTUtils.getPropertyName(member3);
|
|
5127
5231
|
};
|
|
5128
5232
|
var detachedValueExports = (program) => {
|
|
5129
5233
|
const names = /* @__PURE__ */ new Set();
|
|
5130
5234
|
for (const statement of program.body) {
|
|
5131
|
-
if (statement.type ===
|
|
5235
|
+
if (statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
5132
5236
|
for (const specifier of statement.specifiers) {
|
|
5133
5237
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
5134
5238
|
}
|
|
5135
|
-
} else if (statement.type ===
|
|
5239
|
+
} else if (statement.type === import_utils36.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5136
5240
|
names.add(statement.declaration.name);
|
|
5137
|
-
} else if (statement.type ===
|
|
5241
|
+
} else if (statement.type === import_utils36.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5138
5242
|
names.add(statement.expression.name);
|
|
5139
5243
|
}
|
|
5140
5244
|
}
|
|
5141
5245
|
return names;
|
|
5142
5246
|
};
|
|
5143
|
-
var isExportedClass = (node, detached) => node.parent.type ===
|
|
5247
|
+
var isExportedClass = (node, detached) => node.parent.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils36.AST_NODE_TYPES.ExportDefaultDeclaration || node.id !== null && detached.has(node.id.name);
|
|
5144
5248
|
var createExportedServiceClassResolver = (program) => {
|
|
5145
5249
|
const detached = detachedValueExports(program);
|
|
5146
5250
|
return (node) => isExportedClass(node, detached);
|
|
5147
5251
|
};
|
|
5148
5252
|
var readTypeReference = (annotation) => {
|
|
5149
|
-
if (annotation?.type ===
|
|
5253
|
+
if (annotation?.type === import_utils36.AST_NODE_TYPES.TSUnionType) {
|
|
5150
5254
|
const members = annotation.types.filter(
|
|
5151
|
-
(member3) => member3.type !==
|
|
5255
|
+
(member3) => member3.type !== import_utils36.AST_NODE_TYPES.TSUndefinedKeyword && member3.type !== import_utils36.AST_NODE_TYPES.TSNullKeyword
|
|
5152
5256
|
);
|
|
5153
5257
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
5154
5258
|
}
|
|
5155
|
-
if (annotation === void 0 || annotation.type !==
|
|
5259
|
+
if (annotation === void 0 || annotation.type !== import_utils36.AST_NODE_TYPES.TSTypeReference)
|
|
5156
5260
|
return null;
|
|
5157
5261
|
const { typeName } = annotation;
|
|
5158
|
-
const rightmost = typeName.type ===
|
|
5262
|
+
const rightmost = typeName.type === import_utils36.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils36.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
5159
5263
|
if (rightmost === null) return null;
|
|
5160
5264
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
5161
5265
|
};
|
|
5162
|
-
var qualifiedName = (name) => name.type ===
|
|
5266
|
+
var qualifiedName = (name) => name.type === import_utils36.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils36.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
5163
5267
|
var propertySignatureTypes = (members) => {
|
|
5164
5268
|
const types = /* @__PURE__ */ new Map();
|
|
5165
5269
|
for (const member3 of members) {
|
|
5166
|
-
if (member3.type !==
|
|
5167
|
-
if (member3.computed || member3.key.type !==
|
|
5270
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5271
|
+
if (member3.computed || member3.key.type !== import_utils36.AST_NODE_TYPES.Identifier)
|
|
5168
5272
|
continue;
|
|
5169
5273
|
const reference = readTypeReference(member3.typeAnnotation?.typeAnnotation);
|
|
5170
5274
|
if (reference === null) continue;
|
|
@@ -5176,18 +5280,18 @@ var fileTypeIndex = (program) => {
|
|
|
5176
5280
|
const objects = /* @__PURE__ */ new Map();
|
|
5177
5281
|
const functionAliases = localFunctionAliases(program);
|
|
5178
5282
|
function collectDeclaredType(statement) {
|
|
5179
|
-
const declaration = statement.type ===
|
|
5180
|
-
if (declaration?.type ===
|
|
5283
|
+
const declaration = statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5284
|
+
if (declaration?.type === import_utils36.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
5181
5285
|
objects.set(
|
|
5182
5286
|
declaration.id.name,
|
|
5183
5287
|
propertySignatureTypes(declaration.body.body)
|
|
5184
5288
|
);
|
|
5185
5289
|
return;
|
|
5186
5290
|
}
|
|
5187
|
-
if (declaration?.type !==
|
|
5291
|
+
if (declaration?.type !== import_utils36.AST_NODE_TYPES.TSTypeAliasDeclaration) return;
|
|
5188
5292
|
const aliased = declaration.typeAnnotation;
|
|
5189
|
-
const literals = aliased.type ===
|
|
5190
|
-
(part) => part.type ===
|
|
5293
|
+
const literals = aliased.type === import_utils36.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils36.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter(
|
|
5294
|
+
(part) => part.type === import_utils36.AST_NODE_TYPES.TSTypeLiteral
|
|
5191
5295
|
) : [];
|
|
5192
5296
|
if (literals.length === 0) return;
|
|
5193
5297
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -5207,12 +5311,12 @@ function localFunctionAliases(program) {
|
|
|
5207
5311
|
const names = /* @__PURE__ */ new Set();
|
|
5208
5312
|
const parents = /* @__PURE__ */ new Map();
|
|
5209
5313
|
for (const statement of program.body) {
|
|
5210
|
-
const declaration = statement.type ===
|
|
5211
|
-
if (declaration?.type !==
|
|
5314
|
+
const declaration = statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5315
|
+
if (declaration?.type !== import_utils36.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
5212
5316
|
const annotation = declaration.typeAnnotation;
|
|
5213
|
-
if (annotation.type ===
|
|
5317
|
+
if (annotation.type === import_utils36.AST_NODE_TYPES.TSFunctionType || annotation.type === import_utils36.AST_NODE_TYPES.TSConstructorType)
|
|
5214
5318
|
names.add(declaration.id.name);
|
|
5215
|
-
if (annotation.type ===
|
|
5319
|
+
if (annotation.type === import_utils36.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5216
5320
|
parents.set(declaration.id.name, annotation.typeName.name);
|
|
5217
5321
|
}
|
|
5218
5322
|
for (let pass = 0; pass < parents.size; pass += 1) {
|
|
@@ -5248,32 +5352,32 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5248
5352
|
function scanStoredFields(body4) {
|
|
5249
5353
|
const pending = [...body4.body];
|
|
5250
5354
|
function recordStoredField(current) {
|
|
5251
|
-
if (current.type ===
|
|
5355
|
+
if (current.type === import_utils36.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils36.AST_NODE_TYPES.FunctionExpression || current.type === import_utils36.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils36.AST_NODE_TYPES.ClassExpression || current.type === import_utils36.AST_NODE_TYPES.ClassDeclaration)
|
|
5252
5356
|
return;
|
|
5253
|
-
if (current.type ===
|
|
5357
|
+
if (current.type === import_utils36.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5254
5358
|
localBindings2.add(current.id.name);
|
|
5255
|
-
const expression = current.type ===
|
|
5359
|
+
const expression = current.type === import_utils36.AST_NODE_TYPES.AssignmentExpression ? current : null;
|
|
5256
5360
|
const storedField = writtenInstanceField(current);
|
|
5257
5361
|
if (storedField !== null) {
|
|
5258
5362
|
if (writtenFieldNames.has(storedField))
|
|
5259
5363
|
unstableFieldNames.add(storedField);
|
|
5260
5364
|
writtenFieldNames.add(storedField);
|
|
5261
|
-
if (expression?.operator !== "=" || expression.parent.type !==
|
|
5365
|
+
if (expression?.operator !== "=" || expression.parent.type !== import_utils36.AST_NODE_TYPES.ExpressionStatement || expression.parent.parent !== body4)
|
|
5262
5366
|
unstableFieldNames.add(storedField);
|
|
5263
5367
|
}
|
|
5264
|
-
if (expression?.type !==
|
|
5368
|
+
if (expression?.type !== import_utils36.AST_NODE_TYPES.AssignmentExpression || !STORAGE_ASSIGNMENT_OPERATORS.has(expression.operator) || expression.left.type !== import_utils36.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils36.AST_NODE_TYPES.ThisExpression || storedField === null) {
|
|
5265
5369
|
enqueueChildren(current);
|
|
5266
5370
|
return;
|
|
5267
5371
|
}
|
|
5268
5372
|
const source = unwrapExpression(expression.right);
|
|
5269
|
-
if (source.type ===
|
|
5373
|
+
if (source.type === import_utils36.AST_NODE_TYPES.NewExpression) {
|
|
5270
5374
|
constructedFields += 1;
|
|
5271
5375
|
constructedFieldNames.add(storedField);
|
|
5272
|
-
} else if (source.type ===
|
|
5376
|
+
} else if (source.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5273
5377
|
const fields2 = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
5274
5378
|
fields2.add(storedField);
|
|
5275
5379
|
storedFieldsFrom.set(source.name, fields2);
|
|
5276
|
-
} else if (source.type ===
|
|
5380
|
+
} else if (source.type === import_utils36.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5277
5381
|
const fields2 = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
5278
5382
|
fields2.add(storedField);
|
|
5279
5383
|
storedFieldsFrom.set(source.object.name, fields2);
|
|
@@ -5308,7 +5412,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5308
5412
|
)) {
|
|
5309
5413
|
if (localBindings2.has(reference.name)) continue;
|
|
5310
5414
|
let fields2 = reference.fields;
|
|
5311
|
-
if (parameter.type ===
|
|
5415
|
+
if (parameter.type === import_utils36.AST_NODE_TYPES.TSParameterProperty) {
|
|
5312
5416
|
if (writtenFieldNames.has(reference.name)) continue;
|
|
5313
5417
|
fields2 = [reference.name];
|
|
5314
5418
|
} else if (fields2.length === 0)
|
|
@@ -5331,8 +5435,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5331
5435
|
};
|
|
5332
5436
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
5333
5437
|
let target = parameter;
|
|
5334
|
-
if (target.type ===
|
|
5335
|
-
if (target.type ===
|
|
5438
|
+
if (target.type === import_utils36.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5439
|
+
if (target.type === import_utils36.AST_NODE_TYPES.ObjectPattern) {
|
|
5336
5440
|
return objectPatternCollaborators(target, declared);
|
|
5337
5441
|
}
|
|
5338
5442
|
const named3 = namedParameterCollaborator(parameter);
|
|
@@ -5342,10 +5446,10 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
5342
5446
|
};
|
|
5343
5447
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
5344
5448
|
let target = annotated;
|
|
5345
|
-
if (target.type ===
|
|
5449
|
+
if (target.type === import_utils36.AST_NODE_TYPES.TSParameterProperty)
|
|
5346
5450
|
target = target.parameter;
|
|
5347
|
-
if (target.type ===
|
|
5348
|
-
if (target.type !==
|
|
5451
|
+
if (target.type === import_utils36.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5452
|
+
if (target.type !== import_utils36.AST_NODE_TYPES.Identifier) return [];
|
|
5349
5453
|
const members = bagMemberTypes(
|
|
5350
5454
|
target.typeAnnotation?.typeAnnotation,
|
|
5351
5455
|
declared
|
|
@@ -5364,10 +5468,10 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
5364
5468
|
};
|
|
5365
5469
|
var namedParameterCollaborator = (annotated) => {
|
|
5366
5470
|
let target = annotated;
|
|
5367
|
-
if (target.type ===
|
|
5471
|
+
if (target.type === import_utils36.AST_NODE_TYPES.TSParameterProperty)
|
|
5368
5472
|
target = target.parameter;
|
|
5369
|
-
if (target.type ===
|
|
5370
|
-
if (target.type !==
|
|
5473
|
+
if (target.type === import_utils36.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
5474
|
+
if (target.type !== import_utils36.AST_NODE_TYPES.Identifier) return null;
|
|
5371
5475
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
5372
5476
|
if (reference === null) return null;
|
|
5373
5477
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -5379,12 +5483,12 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5379
5483
|
if (members === null) return [];
|
|
5380
5484
|
const collaborators = [];
|
|
5381
5485
|
for (const property of pattern.properties) {
|
|
5382
|
-
if (property.type !==
|
|
5486
|
+
if (property.type !== import_utils36.AST_NODE_TYPES.Property || property.computed)
|
|
5383
5487
|
continue;
|
|
5384
|
-
if (property.key.type !==
|
|
5488
|
+
if (property.key.type !== import_utils36.AST_NODE_TYPES.Identifier) continue;
|
|
5385
5489
|
const key = property.key.name;
|
|
5386
|
-
const bound = property.value.type ===
|
|
5387
|
-
if (bound.type !==
|
|
5490
|
+
const bound = property.value.type === import_utils36.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
5491
|
+
if (bound.type !== import_utils36.AST_NODE_TYPES.Identifier) continue;
|
|
5388
5492
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
5389
5493
|
const reference = members.get(key);
|
|
5390
5494
|
if (reference === void 0) continue;
|
|
@@ -5394,22 +5498,22 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5394
5498
|
};
|
|
5395
5499
|
var bagMemberTypes = (annotation, declared) => {
|
|
5396
5500
|
if (annotation === void 0) return null;
|
|
5397
|
-
if (annotation.type ===
|
|
5501
|
+
if (annotation.type === import_utils36.AST_NODE_TYPES.TSTypeLiteral) {
|
|
5398
5502
|
return propertySignatureTypes(annotation.members);
|
|
5399
5503
|
}
|
|
5400
|
-
if (annotation.type !==
|
|
5504
|
+
if (annotation.type !== import_utils36.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5401
5505
|
return null;
|
|
5402
5506
|
}
|
|
5403
5507
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
5404
5508
|
};
|
|
5405
5509
|
var isFrameworkWiring = (body3) => subtreeHas(body3, (node) => {
|
|
5406
|
-
if (node.type ===
|
|
5510
|
+
if (node.type === import_utils36.AST_NODE_TYPES.CallExpression) {
|
|
5407
5511
|
const { callee } = node;
|
|
5408
|
-
if (callee.type ===
|
|
5512
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5409
5513
|
return callee.name === ROUTER_FACTORY_NAME;
|
|
5410
|
-
return callee.type ===
|
|
5514
|
+
return callee.type === import_utils36.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils36.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
5411
5515
|
}
|
|
5412
|
-
return node.type ===
|
|
5516
|
+
return node.type === import_utils36.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils36.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
5413
5517
|
});
|
|
5414
5518
|
var subtreeHas = (root, found) => {
|
|
5415
5519
|
let hit = false;
|
|
@@ -5429,26 +5533,26 @@ var subtreeHas = (root, found) => {
|
|
|
5429
5533
|
};
|
|
5430
5534
|
var invokedInstanceField = (call) => {
|
|
5431
5535
|
let callee = unwrapExpression(call.callee);
|
|
5432
|
-
while (callee.type ===
|
|
5536
|
+
while (callee.type === import_utils36.AST_NODE_TYPES.ChainExpression)
|
|
5433
5537
|
callee = unwrapExpression(callee.expression);
|
|
5434
5538
|
const direct = instanceField(callee);
|
|
5435
5539
|
if (direct !== null) return direct;
|
|
5436
|
-
return callee.type ===
|
|
5540
|
+
return callee.type === import_utils36.AST_NODE_TYPES.MemberExpression ? instanceField(unwrapExpression(callee.object)) : null;
|
|
5437
5541
|
};
|
|
5438
5542
|
var instanceField = (candidate2) => {
|
|
5439
5543
|
let node = candidate2;
|
|
5440
|
-
while (node.type ===
|
|
5544
|
+
while (node.type === import_utils36.AST_NODE_TYPES.ChainExpression || node.type === import_utils36.AST_NODE_TYPES.TSAsExpression || node.type === import_utils36.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils36.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils36.AST_NODE_TYPES.TSTypeAssertion)
|
|
5441
5545
|
node = node.expression;
|
|
5442
|
-
return node.type ===
|
|
5546
|
+
return node.type === import_utils36.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils36.AST_NODE_TYPES.ThisExpression ? staticMemberName(node) : null;
|
|
5443
5547
|
};
|
|
5444
5548
|
function writtenInstanceField(node) {
|
|
5445
|
-
if (node.type ===
|
|
5549
|
+
if (node.type === import_utils36.AST_NODE_TYPES.AssignmentExpression || node.type === import_utils36.AST_NODE_TYPES.ForOfStatement || node.type === import_utils36.AST_NODE_TYPES.ForInStatement)
|
|
5446
5550
|
return instanceField(node.left);
|
|
5447
|
-
if (node.type ===
|
|
5551
|
+
if (node.type === import_utils36.AST_NODE_TYPES.UpdateExpression)
|
|
5448
5552
|
return instanceField(node.argument);
|
|
5449
|
-
if (node.type ===
|
|
5553
|
+
if (node.type === import_utils36.AST_NODE_TYPES.UnaryExpression && node.operator === "delete")
|
|
5450
5554
|
return instanceField(node.argument);
|
|
5451
|
-
if (node.type ===
|
|
5555
|
+
if (node.type === import_utils36.AST_NODE_TYPES.MemberExpression && isDestructuredWriteTarget(node))
|
|
5452
5556
|
return instanceField(node);
|
|
5453
5557
|
return null;
|
|
5454
5558
|
}
|
|
@@ -5457,39 +5561,39 @@ function isDestructuredWriteTarget(node) {
|
|
|
5457
5561
|
let target = access;
|
|
5458
5562
|
for (; ; ) {
|
|
5459
5563
|
const parent = target.parent;
|
|
5460
|
-
if (parent.type ===
|
|
5564
|
+
if (parent.type === import_utils36.AST_NODE_TYPES.Property && parent.value === target && parent.parent.type === import_utils36.AST_NODE_TYPES.ObjectPattern) {
|
|
5461
5565
|
target = parent.parent;
|
|
5462
5566
|
continue;
|
|
5463
5567
|
}
|
|
5464
|
-
if (parent.type ===
|
|
5568
|
+
if (parent.type === import_utils36.AST_NODE_TYPES.ArrayPattern || parent.type === import_utils36.AST_NODE_TYPES.ObjectPattern || parent.type === import_utils36.AST_NODE_TYPES.RestElement && parent.argument === target || parent.type === import_utils36.AST_NODE_TYPES.AssignmentPattern && parent.left === target) {
|
|
5465
5569
|
target = parent;
|
|
5466
5570
|
continue;
|
|
5467
5571
|
}
|
|
5468
|
-
return target !== access && (parent.type ===
|
|
5572
|
+
return target !== access && (parent.type === import_utils36.AST_NODE_TYPES.AssignmentExpression || parent.type === import_utils36.AST_NODE_TYPES.ForOfStatement || parent.type === import_utils36.AST_NODE_TYPES.ForInStatement) && parent.left === target;
|
|
5469
5573
|
}
|
|
5470
5574
|
}
|
|
5471
5575
|
var behaviorallyInvokedFields = (body3) => {
|
|
5472
5576
|
const invoked = /* @__PURE__ */ new Set();
|
|
5473
5577
|
const visit = (current) => {
|
|
5474
|
-
if (current.type ===
|
|
5578
|
+
if (current.type === import_utils36.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils36.AST_NODE_TYPES.ClassExpression || current.type === import_utils36.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils36.AST_NODE_TYPES.FunctionExpression)
|
|
5475
5579
|
return;
|
|
5476
|
-
if (current.type ===
|
|
5580
|
+
if (current.type === import_utils36.AST_NODE_TYPES.CallExpression) {
|
|
5477
5581
|
const field = invokedInstanceField(current);
|
|
5478
5582
|
if (field !== null) invoked.add(field);
|
|
5479
5583
|
}
|
|
5480
5584
|
forEachOwnAstChild(current, visit);
|
|
5481
5585
|
};
|
|
5482
5586
|
for (const member3 of body3.body) {
|
|
5483
|
-
if (member3.type ===
|
|
5484
|
-
if (member3.type ===
|
|
5587
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.StaticBlock || member3.static) continue;
|
|
5588
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.MethodDefinition) {
|
|
5485
5589
|
if (member3.value.body !== null && member3.value.body !== void 0)
|
|
5486
5590
|
visit(member3.value.body);
|
|
5487
5591
|
continue;
|
|
5488
5592
|
}
|
|
5489
|
-
if (member3.type !==
|
|
5593
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.PropertyDefinition || member3.value === null)
|
|
5490
5594
|
continue;
|
|
5491
5595
|
visit(
|
|
5492
|
-
member3.value.type ===
|
|
5596
|
+
member3.value.type === import_utils36.AST_NODE_TYPES.ArrowFunctionExpression ? member3.value.body : member3.value
|
|
5493
5597
|
);
|
|
5494
5598
|
}
|
|
5495
5599
|
return invoked;
|
|
@@ -5509,8 +5613,8 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
5509
5613
|
var fileInterfaceNames = (program) => {
|
|
5510
5614
|
const names = [];
|
|
5511
5615
|
for (const statement of program.body) {
|
|
5512
|
-
const declaration = statement.type ===
|
|
5513
|
-
if (declaration?.type ===
|
|
5616
|
+
const declaration = statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5617
|
+
if (declaration?.type === import_utils36.AST_NODE_TYPES.TSInterfaceDeclaration)
|
|
5514
5618
|
names.push(declaration.id.name);
|
|
5515
5619
|
}
|
|
5516
5620
|
return names;
|
|
@@ -5518,22 +5622,22 @@ var fileInterfaceNames = (program) => {
|
|
|
5518
5622
|
var publicMethodNames = (body3, functionAliases) => {
|
|
5519
5623
|
const names = [];
|
|
5520
5624
|
function collectPublicCallable(member3) {
|
|
5521
|
-
if (member3.type ===
|
|
5625
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.PropertyDefinition) {
|
|
5522
5626
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5523
5627
|
return;
|
|
5524
|
-
if (member3.key.type ===
|
|
5525
|
-
if (member3.value?.type !==
|
|
5628
|
+
if (member3.key.type === import_utils36.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5629
|
+
if (member3.value?.type !== import_utils36.AST_NODE_TYPES.ArrowFunctionExpression && member3.value?.type !== import_utils36.AST_NODE_TYPES.FunctionExpression && member3.typeAnnotation?.typeAnnotation.type !== import_utils36.AST_NODE_TYPES.TSFunctionType && !(member3.typeAnnotation?.typeAnnotation.type === import_utils36.AST_NODE_TYPES.TSTypeReference && member3.typeAnnotation.typeAnnotation.typeName.type === import_utils36.AST_NODE_TYPES.Identifier && functionAliases.has(
|
|
5526
5630
|
member3.typeAnnotation.typeAnnotation.typeName.name
|
|
5527
5631
|
)))
|
|
5528
5632
|
return;
|
|
5529
5633
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5530
5634
|
return;
|
|
5531
5635
|
}
|
|
5532
|
-
if (member3.type !==
|
|
5636
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.MethodDefinition) return;
|
|
5533
5637
|
if (member3.kind !== "method" || member3.static) return;
|
|
5534
5638
|
if (member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5535
5639
|
return;
|
|
5536
|
-
if (member3.key.type ===
|
|
5640
|
+
if (member3.key.type === import_utils36.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5537
5641
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5538
5642
|
}
|
|
5539
5643
|
for (const member3 of body3.body) {
|
|
@@ -5544,13 +5648,13 @@ var publicMethodNames = (body3, functionAliases) => {
|
|
|
5544
5648
|
var isFluentConstructionObject = (node, getText) => {
|
|
5545
5649
|
if (node.id === null) return false;
|
|
5546
5650
|
const methods = node.body.body.filter(
|
|
5547
|
-
(member3) => member3.type ===
|
|
5651
|
+
(member3) => member3.type === import_utils36.AST_NODE_TYPES.MethodDefinition && member3.kind === "method" && !member3.static && member3.accessibility !== "private" && member3.accessibility !== "protected" && member3.value.body !== null
|
|
5548
5652
|
);
|
|
5549
5653
|
if (methods.length === 0) return false;
|
|
5550
5654
|
return methods.every((member3) => {
|
|
5551
5655
|
const result = member3.value.returnType?.typeAnnotation;
|
|
5552
5656
|
if (result === void 0) return false;
|
|
5553
|
-
const returnsOwnType = result.type ===
|
|
5657
|
+
const returnsOwnType = result.type === import_utils36.AST_NODE_TYPES.TSTypeReference && result.typeName.type === import_utils36.AST_NODE_TYPES.Identifier && result.typeName.name === node.id?.name;
|
|
5554
5658
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
5555
5659
|
});
|
|
5556
5660
|
};
|
|
@@ -5558,10 +5662,10 @@ function localClassAbstractness(program) {
|
|
|
5558
5662
|
const classes = /* @__PURE__ */ new Map();
|
|
5559
5663
|
const parents = /* @__PURE__ */ new Map();
|
|
5560
5664
|
for (const statement of program.body) {
|
|
5561
|
-
const declaration = statement.type ===
|
|
5562
|
-
if (declaration?.type ===
|
|
5665
|
+
const declaration = statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils36.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
5666
|
+
if (declaration?.type === import_utils36.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null) {
|
|
5563
5667
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
5564
|
-
if (declaration.superClass?.type ===
|
|
5668
|
+
if (declaration.superClass?.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5565
5669
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
5566
5670
|
}
|
|
5567
5671
|
}
|
|
@@ -5579,9 +5683,9 @@ function localClassAbstractness(program) {
|
|
|
5579
5683
|
return classes;
|
|
5580
5684
|
}
|
|
5581
5685
|
function declaredMemberName(member3) {
|
|
5582
|
-
if (!member3.computed && member3.key.type ===
|
|
5686
|
+
if (!member3.computed && member3.key.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5583
5687
|
return member3.key.name;
|
|
5584
|
-
if (member3.key.type ===
|
|
5688
|
+
if (member3.key.type === import_utils36.AST_NODE_TYPES.Literal && typeof member3.key.value === "string")
|
|
5585
5689
|
return member3.key.value;
|
|
5586
5690
|
return null;
|
|
5587
5691
|
}
|
|
@@ -5590,35 +5694,35 @@ function localInterfaceSurfaces(program) {
|
|
|
5590
5694
|
const parents = /* @__PURE__ */ new Map();
|
|
5591
5695
|
const functionAliases = localFunctionAliases(program);
|
|
5592
5696
|
function collectInterfaceSurface(statement) {
|
|
5593
|
-
const declaration = statement.type ===
|
|
5594
|
-
if (declaration?.type ===
|
|
5697
|
+
const declaration = statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
5698
|
+
if (declaration?.type === import_utils36.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
5595
5699
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5596
|
-
const parts = declaration.typeAnnotation.type ===
|
|
5700
|
+
const parts = declaration.typeAnnotation.type === import_utils36.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
5597
5701
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
5598
5702
|
for (const part of parts) {
|
|
5599
|
-
if (part.type ===
|
|
5703
|
+
if (part.type === import_utils36.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5600
5704
|
inherited.push(part.typeName.name);
|
|
5601
5705
|
continue;
|
|
5602
5706
|
}
|
|
5603
|
-
if (part.type ===
|
|
5707
|
+
if (part.type === import_utils36.AST_NODE_TYPES.TSTypeReference) {
|
|
5604
5708
|
inherited.push("*");
|
|
5605
5709
|
continue;
|
|
5606
5710
|
}
|
|
5607
|
-
if (part.type !==
|
|
5711
|
+
if (part.type !== import_utils36.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
5608
5712
|
addCallableMembers(part.members, callables2);
|
|
5609
5713
|
}
|
|
5610
5714
|
interfaces.set(declaration.id.name, callables2);
|
|
5611
5715
|
parents.set(declaration.id.name, inherited);
|
|
5612
5716
|
return;
|
|
5613
5717
|
}
|
|
5614
|
-
if (declaration?.type !==
|
|
5718
|
+
if (declaration?.type !== import_utils36.AST_NODE_TYPES.TSInterfaceDeclaration) return;
|
|
5615
5719
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5616
5720
|
addCallableMembers(declaration.body.body, callables);
|
|
5617
5721
|
interfaces.set(declaration.id.name, callables);
|
|
5618
5722
|
parents.set(declaration.id.name, [
|
|
5619
5723
|
...parents.get(declaration.id.name) ?? [],
|
|
5620
5724
|
...declaration.extends.flatMap(
|
|
5621
|
-
(heritage) => heritage.expression.type ===
|
|
5725
|
+
(heritage) => heritage.expression.type === import_utils36.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
5622
5726
|
)
|
|
5623
5727
|
]);
|
|
5624
5728
|
}
|
|
@@ -5627,17 +5731,17 @@ function localInterfaceSurfaces(program) {
|
|
|
5627
5731
|
}
|
|
5628
5732
|
function addCallableMembers(members, callables) {
|
|
5629
5733
|
for (const member3 of members) {
|
|
5630
|
-
if (member3.type !==
|
|
5734
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.TSMethodSignature && member3.type !== import_utils36.AST_NODE_TYPES.TSPropertySignature)
|
|
5631
5735
|
continue;
|
|
5632
5736
|
const name = declaredMemberName(member3);
|
|
5633
5737
|
if (name === null) continue;
|
|
5634
|
-
if (member3.type ===
|
|
5738
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.TSMethodSignature) {
|
|
5635
5739
|
callables.add(name);
|
|
5636
5740
|
continue;
|
|
5637
5741
|
}
|
|
5638
|
-
if (member3.type !==
|
|
5742
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5639
5743
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5640
|
-
if (annotation?.type ===
|
|
5744
|
+
if (annotation?.type === import_utils36.AST_NODE_TYPES.TSFunctionType || annotation?.type === import_utils36.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils36.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name))
|
|
5641
5745
|
callables.add(name);
|
|
5642
5746
|
}
|
|
5643
5747
|
}
|
|
@@ -5667,7 +5771,7 @@ function localInterfaceSurfaces(program) {
|
|
|
5667
5771
|
}
|
|
5668
5772
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
5669
5773
|
if (node.superClass !== null) {
|
|
5670
|
-
if (node.superClass.type !==
|
|
5774
|
+
if (node.superClass.type !== import_utils36.AST_NODE_TYPES.Identifier) return true;
|
|
5671
5775
|
const localAbstract = classes.get(node.superClass.name);
|
|
5672
5776
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
5673
5777
|
}
|
|
@@ -5706,7 +5810,7 @@ var require_port_for_service_default = createRule({
|
|
|
5706
5810
|
if (node.abstract === true) return;
|
|
5707
5811
|
if (node.decorators.length > 0) return;
|
|
5708
5812
|
const ctor = node.body.body.find(
|
|
5709
|
-
(member3) => member3.type ===
|
|
5813
|
+
(member3) => member3.type === import_utils36.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null && member3.value.body !== void 0
|
|
5710
5814
|
);
|
|
5711
5815
|
if (ctor === void 0) return;
|
|
5712
5816
|
const constructorFacts = readConstructor(
|
|
@@ -5756,7 +5860,7 @@ var require_port_for_service_default = createRule({
|
|
|
5756
5860
|
function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
5757
5861
|
const combined = /* @__PURE__ */ new Set();
|
|
5758
5862
|
for (const implementation of node.implements) {
|
|
5759
|
-
if (implementation.expression.type !==
|
|
5863
|
+
if (implementation.expression.type !== import_utils36.AST_NODE_TYPES.Identifier)
|
|
5760
5864
|
return true;
|
|
5761
5865
|
const name = implementation.expression.name;
|
|
5762
5866
|
const localAbstract = classes.get(name);
|
|
@@ -5773,7 +5877,7 @@ function createServiceOperationResolver(program) {
|
|
|
5773
5877
|
let declaredTypes = null;
|
|
5774
5878
|
return (node) => {
|
|
5775
5879
|
const ctor = node.body.body.find(
|
|
5776
|
-
(member3) => member3.type ===
|
|
5880
|
+
(member3) => member3.type === import_utils36.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null
|
|
5777
5881
|
);
|
|
5778
5882
|
if (ctor === void 0) return [];
|
|
5779
5883
|
const declared = () => declaredTypes ??= fileTypeIndex(program);
|
|
@@ -5791,7 +5895,7 @@ function createServiceOperationResolver(program) {
|
|
|
5791
5895
|
for (const [name, body3] of serviceOperationBodies(node)) {
|
|
5792
5896
|
forEachServiceCall(body3, (call) => {
|
|
5793
5897
|
if (retained.has(invokedInstanceField(call) ?? "")) active.add(name);
|
|
5794
|
-
if (call.callee.type ===
|
|
5898
|
+
if (call.callee.type === import_utils36.AST_NODE_TYPES.MemberExpression && call.callee.object.type === import_utils36.AST_NODE_TYPES.ThisExpression) {
|
|
5795
5899
|
const callee = staticMemberName(call.callee);
|
|
5796
5900
|
if (callee !== null) {
|
|
5797
5901
|
const linked = callers.get(callee) ?? /* @__PURE__ */ new Set();
|
|
@@ -5830,11 +5934,11 @@ function serviceOperationBodies(node) {
|
|
|
5830
5934
|
});
|
|
5831
5935
|
}
|
|
5832
5936
|
for (const member3 of node.body.body) {
|
|
5833
|
-
if (member3.type !==
|
|
5937
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.MethodDefinition && member3.type !== import_utils36.AST_NODE_TYPES.PropertyDefinition)
|
|
5834
5938
|
continue;
|
|
5835
|
-
if (member3.static || member3.decorators.length > 0 || member3.type ===
|
|
5939
|
+
if (member3.static || member3.decorators.length > 0 || member3.type === import_utils36.AST_NODE_TYPES.MethodDefinition && member3.kind !== "method")
|
|
5836
5940
|
continue;
|
|
5837
|
-
if (member3.value?.type !==
|
|
5941
|
+
if (member3.value?.type !== import_utils36.AST_NODE_TYPES.FunctionExpression && member3.value?.type !== import_utils36.AST_NODE_TYPES.ArrowFunctionExpression)
|
|
5838
5942
|
continue;
|
|
5839
5943
|
const name = declaredMemberName(member3);
|
|
5840
5944
|
if (name !== null && !written.has(name) && member3.value.body !== null)
|
|
@@ -5843,9 +5947,9 @@ function serviceOperationBodies(node) {
|
|
|
5843
5947
|
return bodies;
|
|
5844
5948
|
}
|
|
5845
5949
|
function forEachServiceCall(node, onCall) {
|
|
5846
|
-
if (node.type ===
|
|
5950
|
+
if (node.type === import_utils36.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils36.AST_NODE_TYPES.FunctionExpression || node.type === import_utils36.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils36.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils36.AST_NODE_TYPES.ClassExpression)
|
|
5847
5951
|
return;
|
|
5848
|
-
if (node.type ===
|
|
5952
|
+
if (node.type === import_utils36.AST_NODE_TYPES.BlockStatement) {
|
|
5849
5953
|
for (const statement of node.body) {
|
|
5850
5954
|
forEachServiceCall(statement, onCall);
|
|
5851
5955
|
if (terminatesOperation(statement)) break;
|
|
@@ -5857,29 +5961,29 @@ function forEachServiceCall(node, onCall) {
|
|
|
5857
5961
|
forEachServiceCall(branch, onCall);
|
|
5858
5962
|
return;
|
|
5859
5963
|
}
|
|
5860
|
-
if (node.type ===
|
|
5964
|
+
if (node.type === import_utils36.AST_NODE_TYPES.CallExpression) onCall(node);
|
|
5861
5965
|
forEachOwnAstChild(node, (child) => {
|
|
5862
5966
|
forEachServiceCall(child, onCall);
|
|
5863
5967
|
});
|
|
5864
5968
|
}
|
|
5865
5969
|
function literalExecutionBranch(node) {
|
|
5866
|
-
if (node.type ===
|
|
5970
|
+
if (node.type === import_utils36.AST_NODE_TYPES.WhileStatement && node.test.type === import_utils36.AST_NODE_TYPES.Literal && node.test.value === false)
|
|
5867
5971
|
return node.test;
|
|
5868
|
-
if ((node.type ===
|
|
5972
|
+
if ((node.type === import_utils36.AST_NODE_TYPES.IfStatement || node.type === import_utils36.AST_NODE_TYPES.ConditionalExpression) && node.test.type === import_utils36.AST_NODE_TYPES.Literal && typeof node.test.value === "boolean") {
|
|
5869
5973
|
return node.test.value ? node.consequent : node.alternate ?? node.test;
|
|
5870
5974
|
}
|
|
5871
|
-
if (node.type !==
|
|
5975
|
+
if (node.type !== import_utils36.AST_NODE_TYPES.LogicalExpression || node.left.type !== import_utils36.AST_NODE_TYPES.Literal || typeof node.left.value !== "boolean")
|
|
5872
5976
|
return null;
|
|
5873
5977
|
if (node.operator === "&&") return node.left.value ? node.right : node.left;
|
|
5874
5978
|
if (node.operator === "||") return node.left.value ? node.left : node.right;
|
|
5875
5979
|
return node.left;
|
|
5876
5980
|
}
|
|
5877
5981
|
function terminatesOperation(node) {
|
|
5878
|
-
if (node.type ===
|
|
5982
|
+
if (node.type === import_utils36.AST_NODE_TYPES.ReturnStatement || node.type === import_utils36.AST_NODE_TYPES.ThrowStatement)
|
|
5879
5983
|
return true;
|
|
5880
|
-
if (node.type ===
|
|
5984
|
+
if (node.type === import_utils36.AST_NODE_TYPES.BlockStatement)
|
|
5881
5985
|
return node.body.some(terminatesOperation);
|
|
5882
|
-
if (node.type !==
|
|
5986
|
+
if (node.type !== import_utils36.AST_NODE_TYPES.IfStatement) return false;
|
|
5883
5987
|
const branch = literalExecutionBranch(node);
|
|
5884
5988
|
if (branch !== null) return terminatesOperation(branch);
|
|
5885
5989
|
return node.alternate !== null && terminatesOperation(node.consequent) && terminatesOperation(node.alternate);
|
|
@@ -5893,7 +5997,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5893
5997
|
const seen = /* @__PURE__ */ new Set();
|
|
5894
5998
|
function addImplementedContracts(current) {
|
|
5895
5999
|
for (const implementation of current.implements) {
|
|
5896
|
-
if (implementation.expression.type !==
|
|
6000
|
+
if (implementation.expression.type !== import_utils36.AST_NODE_TYPES.Identifier)
|
|
5897
6001
|
return false;
|
|
5898
6002
|
const name = implementation.expression.name;
|
|
5899
6003
|
const surface = interfaces.get(name);
|
|
@@ -5916,7 +6020,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5916
6020
|
}
|
|
5917
6021
|
if (!addImplementedContracts(current)) return null;
|
|
5918
6022
|
if (current.superClass === null) continue;
|
|
5919
|
-
if (current.superClass.type !==
|
|
6023
|
+
if (current.superClass.type !== import_utils36.AST_NODE_TYPES.Identifier) return null;
|
|
5920
6024
|
const base = classes.get(current.superClass.name);
|
|
5921
6025
|
if (base === void 0) return null;
|
|
5922
6026
|
pending.push(base);
|
|
@@ -5926,8 +6030,8 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5926
6030
|
function localClassDeclarations(program) {
|
|
5927
6031
|
const classes = /* @__PURE__ */ new Map();
|
|
5928
6032
|
for (const statement of program.body) {
|
|
5929
|
-
const declaration = statement.type ===
|
|
5930
|
-
if (declaration?.type ===
|
|
6033
|
+
const declaration = statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils36.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
6034
|
+
if (declaration?.type === import_utils36.AST_NODE_TYPES.ClassDeclaration && declaration.id !== null)
|
|
5931
6035
|
classes.set(declaration.id.name, declaration);
|
|
5932
6036
|
}
|
|
5933
6037
|
return classes;
|
|
@@ -5935,13 +6039,13 @@ function localClassDeclarations(program) {
|
|
|
5935
6039
|
function abstractContractOperations(node, functionAliases) {
|
|
5936
6040
|
const methods = new Set(publicMethodNames(node.body, functionAliases));
|
|
5937
6041
|
for (const member3 of node.body.body) {
|
|
5938
|
-
if (member3.type !==
|
|
6042
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.TSAbstractMethodDefinition && member3.type !== import_utils36.AST_NODE_TYPES.TSAbstractPropertyDefinition)
|
|
5939
6043
|
continue;
|
|
5940
6044
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5941
6045
|
continue;
|
|
5942
|
-
if (member3.type ===
|
|
6046
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.TSAbstractPropertyDefinition) {
|
|
5943
6047
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5944
|
-
if (annotation?.type !==
|
|
6048
|
+
if (annotation?.type !== import_utils36.AST_NODE_TYPES.TSFunctionType && !(annotation?.type === import_utils36.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils36.AST_NODE_TYPES.Identifier && functionAliases.has(annotation.typeName.name)))
|
|
5945
6049
|
continue;
|
|
5946
6050
|
}
|
|
5947
6051
|
const name = declaredMemberName(member3);
|
|
@@ -6077,7 +6181,7 @@ function isServiceRole(name, filename) {
|
|
|
6077
6181
|
}
|
|
6078
6182
|
|
|
6079
6183
|
// src/rules/no-conditional-empty-object-spread.ts
|
|
6080
|
-
var
|
|
6184
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
6081
6185
|
var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
6082
6186
|
summary: "Build conditional properties explicitly instead of spreading an empty-object branch.",
|
|
6083
6187
|
rationale: "An empty-object conditional spread hides whether a property is omitted, which differs from assigning undefined.",
|
|
@@ -6129,7 +6233,7 @@ var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
|
6129
6233
|
]
|
|
6130
6234
|
};
|
|
6131
6235
|
function isEmptyObject(node) {
|
|
6132
|
-
return node.type ===
|
|
6236
|
+
return node.type === import_utils38.AST_NODE_TYPES.ObjectExpression && node.properties.length === 0;
|
|
6133
6237
|
}
|
|
6134
6238
|
var no_conditional_empty_object_spread_default = createRule({
|
|
6135
6239
|
name: "no-conditional-empty-object-spread",
|
|
@@ -6150,13 +6254,13 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
6150
6254
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6151
6255
|
return {
|
|
6152
6256
|
SpreadElement(node) {
|
|
6153
|
-
if (node.parent.type !==
|
|
6257
|
+
if (node.parent.type !== import_utils38.AST_NODE_TYPES.ObjectExpression || node.argument.type !== import_utils38.AST_NODE_TYPES.ConditionalExpression)
|
|
6154
6258
|
return;
|
|
6155
6259
|
if (isEmptyObject(node.argument.consequent) || isEmptyObject(node.argument.alternate)) {
|
|
6156
6260
|
const conditional = node.argument;
|
|
6157
6261
|
const emptyConsequent = isEmptyObject(conditional.consequent);
|
|
6158
6262
|
const populated = emptyConsequent ? conditional.alternate : conditional.consequent;
|
|
6159
|
-
const canFix = populated.type ===
|
|
6263
|
+
const canFix = populated.type === import_utils38.AST_NODE_TYPES.ObjectExpression && populated.properties.length > 0 && context.sourceCode.getCommentsInside(conditional).length === 0;
|
|
6160
6264
|
context.report({
|
|
6161
6265
|
node,
|
|
6162
6266
|
messageId: "avoid",
|
|
@@ -6172,7 +6276,7 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
6172
6276
|
});
|
|
6173
6277
|
|
|
6174
6278
|
// src/rules/prefer-typed-reflection.ts
|
|
6175
|
-
var
|
|
6279
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
6176
6280
|
var import_typescript12 = __toESM(require("typescript"), 1);
|
|
6177
6281
|
var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
6178
6282
|
summary: "Prefer typed access when Reflect.get or Reflect.apply discards a known contract.",
|
|
@@ -6245,20 +6349,20 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6245
6349
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6246
6350
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6247
6351
|
return {};
|
|
6248
|
-
const services =
|
|
6352
|
+
const services = import_utils39.ESLintUtils.getParserServices(context);
|
|
6249
6353
|
if (!services.program) return {};
|
|
6250
6354
|
const checker = services.program.getTypeChecker();
|
|
6251
|
-
const isReflect = (node) => globalName(node, "Reflect") || node.type ===
|
|
6252
|
-
const globalName = (node, name) => node.type ===
|
|
6355
|
+
const isReflect = (node) => globalName(node, "Reflect") || node.type === import_utils39.AST_NODE_TYPES.MemberExpression && import_utils39.ASTUtils.getPropertyName(node) === "Reflect" && globalName(node.object, "globalThis");
|
|
6356
|
+
const globalName = (node, name) => node.type === import_utils39.AST_NODE_TYPES.Identifier && node.name === name && !import_utils39.ASTUtils.findVariable(context.sourceCode.getScope(node), name)?.defs.length;
|
|
6253
6357
|
const closedObject = (type) => {
|
|
6254
6358
|
if (type.isUnion()) return type.types.every(closedObject);
|
|
6255
6359
|
return knownType(type) && type.getProperties().length > 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
6256
6360
|
};
|
|
6257
6361
|
const inspectGet = (node, type) => {
|
|
6258
6362
|
const key = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
6259
|
-
return node.arguments.length === 2 && (staticString(key) !== null || key?.type ===
|
|
6363
|
+
return node.arguments.length === 2 && (staticString(key) !== null || key?.type === import_utils39.AST_NODE_TYPES.Literal && typeof key.value === "number") && closedObject(type);
|
|
6260
6364
|
};
|
|
6261
|
-
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type ===
|
|
6365
|
+
const inspectApply = (node, type) => node.arguments.length === 3 && node.arguments[2]?.type === import_utils39.AST_NODE_TYPES.ArrayExpression && knownType(type) && type.getCallSignatures().some(
|
|
6262
6366
|
(signature) => signature.typeParameters === void 0 && signature.parameters.every(
|
|
6263
6367
|
(parameter) => knownType(
|
|
6264
6368
|
checker.getTypeOfSymbolAtLocation(
|
|
@@ -6269,25 +6373,25 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6269
6373
|
)
|
|
6270
6374
|
);
|
|
6271
6375
|
const getReplacement = (node, type, target) => {
|
|
6272
|
-
if (node.optional || node.callee.type !==
|
|
6376
|
+
if (node.optional || node.callee.type !== import_utils39.AST_NODE_TYPES.MemberExpression || node.callee.optional || context.sourceCode.getCommentsInside(node).length > 0) return null;
|
|
6273
6377
|
let outer = node;
|
|
6274
|
-
while (outer.parent.type ===
|
|
6275
|
-
if (outer.parent.type ===
|
|
6378
|
+
while (outer.parent.type === import_utils39.AST_NODE_TYPES.TSAsExpression || outer.parent.type === import_utils39.AST_NODE_TYPES.TSTypeAssertion || outer.parent.type === import_utils39.AST_NODE_TYPES.TSSatisfiesExpression || outer.parent.type === import_utils39.AST_NODE_TYPES.TSNonNullExpression || outer.parent.type === import_utils39.AST_NODE_TYPES.ChainExpression) outer = outer.parent;
|
|
6379
|
+
if (outer.parent.type === import_utils39.AST_NODE_TYPES.UnaryExpression && outer.parent.operator === "delete" || outer.parent.type === import_utils39.AST_NODE_TYPES.CallExpression && outer.parent.callee === outer || outer.parent.type === import_utils39.AST_NODE_TYPES.TaggedTemplateExpression && outer.parent.tag === outer) return null;
|
|
6276
6380
|
const writtenKey = node.arguments[1];
|
|
6277
|
-
if (writtenKey === void 0 || writtenKey.type ===
|
|
6381
|
+
if (writtenKey === void 0 || writtenKey.type === import_utils39.AST_NODE_TYPES.SpreadElement) return null;
|
|
6278
6382
|
const key = unwrapExpression(writtenKey);
|
|
6279
|
-
const name = staticString(key) ?? (key.type ===
|
|
6383
|
+
const name = staticString(key) ?? (key.type === import_utils39.AST_NODE_TYPES.Literal && typeof key.value === "number" ? String(key.value) : null);
|
|
6280
6384
|
const members = type.isUnion() ? type.types : [type];
|
|
6281
6385
|
if (name === null || !members.every((member3) => (member3.flags & import_typescript12.default.TypeFlags.Object) !== 0 && checker.getPropertyOfType(member3, name) !== void 0)) return null;
|
|
6282
6386
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
6283
6387
|
};
|
|
6284
6388
|
return {
|
|
6285
6389
|
CallExpression(node) {
|
|
6286
|
-
if (node.callee.type !==
|
|
6390
|
+
if (node.callee.type !== import_utils39.AST_NODE_TYPES.MemberExpression || !isReflect(node.callee.object))
|
|
6287
6391
|
return;
|
|
6288
|
-
const method =
|
|
6392
|
+
const method = import_utils39.ASTUtils.getPropertyName(node.callee);
|
|
6289
6393
|
const target = node.arguments[0];
|
|
6290
|
-
if (!target || target.type ===
|
|
6394
|
+
if (!target || target.type === import_utils39.AST_NODE_TYPES.SpreadElement || method !== "get" && method !== "apply")
|
|
6291
6395
|
return;
|
|
6292
6396
|
const type = checker.getTypeAtLocation(
|
|
6293
6397
|
services.esTreeNodeToTSNodeMap.get(target)
|
|
@@ -6304,55 +6408,6 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6304
6408
|
// src/rules/no-broad-return-type.ts
|
|
6305
6409
|
var import_utils40 = require("@typescript-eslint/utils");
|
|
6306
6410
|
var import_typescript13 = __toESM(require("typescript"), 1);
|
|
6307
|
-
|
|
6308
|
-
// src/rules/_unused-private-binding.ts
|
|
6309
|
-
var import_utils39 = require("@typescript-eslint/utils");
|
|
6310
|
-
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
6311
|
-
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
6312
|
-
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
6313
|
-
if (bindings.length === 0 || bindings.some((binding3) => binding3.defs.length !== allowedDeclarations.length || binding3.defs.some((definition) => !allowedDeclarations.includes(definition.node)) || binding3.eslintUsed || binding3.references.some((reference) => reference.isRead() || reference.init !== true))) return false;
|
|
6314
|
-
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
6315
|
-
const statement = declaration.type === import_utils39.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
6316
|
-
if (statement.parent.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
6317
|
-
if (statement.parent.type !== import_utils39.AST_NODE_TYPES.Program) return statement.parent.type === import_utils39.AST_NODE_TYPES.BlockStatement;
|
|
6318
|
-
return sourceCode.ast.body.some((node) => node.type === import_utils39.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration || node.type === import_utils39.AST_NODE_TYPES.ExportAllDeclaration);
|
|
6319
|
-
}
|
|
6320
|
-
function hasOnlyDirectFactoryUses(variable) {
|
|
6321
|
-
return variable.references.every((reference) => {
|
|
6322
|
-
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6323
|
-
const identifier = reference.identifier;
|
|
6324
|
-
const parent = identifier.parent;
|
|
6325
|
-
if (parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.callee === identifier) return true;
|
|
6326
|
-
return parent.type === import_utils39.AST_NODE_TYPES.MemberExpression && parent.object === identifier && !parent.computed && parent.parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.parent.callee === parent;
|
|
6327
|
-
});
|
|
6328
|
-
}
|
|
6329
|
-
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
6330
|
-
function hasIdentifierNamed(node, name) {
|
|
6331
|
-
let names = IDENTIFIER_NAMES.get(node);
|
|
6332
|
-
if (names === void 0) {
|
|
6333
|
-
const collected = /* @__PURE__ */ new Set();
|
|
6334
|
-
const pending = [node];
|
|
6335
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
6336
|
-
while (pending.length > 0) {
|
|
6337
|
-
const current = pending.pop();
|
|
6338
|
-
if (current === void 0 || seen.has(current)) continue;
|
|
6339
|
-
seen.add(current);
|
|
6340
|
-
if (current.type === import_utils39.AST_NODE_TYPES.Identifier || current.type === import_utils39.AST_NODE_TYPES.JSXIdentifier) collected.add(current.name);
|
|
6341
|
-
forEachOwnAstChild(current, (child) => {
|
|
6342
|
-
pending.push(child);
|
|
6343
|
-
}, (key) => key !== "tokens" && key !== "comments");
|
|
6344
|
-
}
|
|
6345
|
-
names = collected;
|
|
6346
|
-
IDENTIFIER_NAMES.set(node, names);
|
|
6347
|
-
}
|
|
6348
|
-
return names.has(name);
|
|
6349
|
-
}
|
|
6350
|
-
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
6351
|
-
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !== import_utils39.AST_NODE_TYPES.FunctionDeclaration || node.id === null || !isUnusedPrivateBinding(sourceCode, node, node.id, filename) || sourceCode.getCommentsInside(annotation).length > 0) return null;
|
|
6352
|
-
return (fixer) => fixer.replaceText(annotation, `boolean${sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")}`);
|
|
6353
|
-
}
|
|
6354
|
-
|
|
6355
|
-
// src/rules/no-broad-return-type.ts
|
|
6356
6411
|
var NO_BROAD_RETURN_TYPE_DOCUMENTATION = {
|
|
6357
6412
|
summary: "Report explicit broad return annotations that erase a known return value.",
|
|
6358
6413
|
rationale: "An unknown, object, or unknown-valued dictionary return hides fields that the implementation already knows.",
|
|
@@ -7196,7 +7251,7 @@ var NO_CONTRADICTORY_TYPE_PREDICATE_DOCUMENTATION = {
|
|
|
7196
7251
|
"For the intrinsic object target, typeof-object also admits null only when the declared input admits null and strictNullChecks is enabled. This narrow check does not infer structural property validation or classify other object/function relationships. Overloaded implementations, contextually typed callbacks and methods with class heritage or contextual object contracts retain their separate callable domain.",
|
|
7197
7252
|
"Compiler-invalid predicate target/input relations and typeof comparisons impossible for the input remain with existing compiler and unnecessary-condition controls. This rule does not validate arbitrary predicates or runtime refinements. Generated files are excluded; tests remain checked.",
|
|
7198
7253
|
"A sole native Array.isArray call on unknown cannot establish a plain primitive-element array target. Standard-library call signatures and an unshadowed Array binding are required. Element validators, any/unknown elements, tuples, enums, branded or opaque elements and independent callable contracts abstain. Visible Array or host-global aliases, mutation, escapes, extracted methods, any value constructor or unresolved computed-property access and unrelated Array namespace uses disable this proof: structural receiver types cannot establish runtime constructor identity. Native Reflect value uses and Object prototype/descriptor reflection or namespace aliases also withdraw authority. Indirect opaque runtime replacements are not inferred.",
|
|
7199
|
-
"For a same-file nongeneric named record with a required data property, a sole typeof-object check, optionally conjoined with a null exclusion, cannot establish that property from unknown or object input. Optional-only records, dictionaries, classes, imported/generic contracts and implementations with field checks are excluded. A non-null object without the required own property supplies the contradiction;
|
|
7254
|
+
"For a same-file nongeneric named record with a required data property, a sole typeof-object check, optionally conjoined with a null exclusion, cannot establish that property from unknown or object input. Optional-only records, dictionaries, classes, imported/generic contracts and implementations with field checks are excluded. A non-null object without the required own property supplies the contradiction. The same unused-private predicate proof may remove its unobserved narrowing contract; observed callable contracts and sole named-type uses remain manual."
|
|
7200
7255
|
],
|
|
7201
7256
|
references: ["https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#inferred-type-predicates"],
|
|
7202
7257
|
examples: [
|
|
@@ -7260,7 +7315,7 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
7260
7315
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(annotation.typeAnnotation.typeAnnotation));
|
|
7261
7316
|
if (!checker.isTypeAssignableTo(target, input)) return;
|
|
7262
7317
|
if (shallowRecordCheck(expression, parameter, input, target, context.sourceCode, checker, services.esTreeNodeToTSNodeMap.get(node).getSourceFile())) {
|
|
7263
|
-
context.report({ node: annotation, messageId: "uncheckedRecordFields", data: { promised: checker.typeToString(target) } });
|
|
7318
|
+
context.report({ node: annotation, messageId: "uncheckedRecordFields", fix: privatePredicateBooleanFix(context.sourceCode, node, annotation, context.filename), data: { promised: checker.typeToString(target) } });
|
|
7264
7319
|
return;
|
|
7265
7320
|
}
|
|
7266
7321
|
if (check === void 0) {
|
|
@@ -7486,7 +7541,7 @@ var NO_PARTIAL_TYPE_PREDICATE_DOCUMENTATION = {
|
|
|
7486
7541
|
"Automatic fixes replace the unsound predicate with boolean only for an unused private function declaration without overloads, exports, eval, comments in the predicate, or declaration-file ownership. Runtime checks are preserved; observed callable contracts remain manual.",
|
|
7487
7542
|
"Requires type information and a non-generic, non-async function with one directly annotated parameter, an explicit broad string/number/bigint/boolean predicate and a single return. Literal, branded, structural, multi-primitive union, assertion, method and overloaded contracts are excluded; contextually typed callbacks are preserved.",
|
|
7488
7543
|
"Recognizes double-negation truthiness, a boolean parameter return or one same-kind literal comparison, optionally after a matching typeof equality. Without a typeof check, the input must already belong to the target primitive, except for double negation. String length comparisons use only concrete witnesses up to 256 characters. Arithmetic, dynamic bounds and complex boolean conditions are not inferred.",
|
|
7489
|
-
"A broad string predicate returning local Schema.safeParse(parameter).success is also checked for a locally unchanged official z.uuid() or z.string().uuid() schema. The checker must resolve the namespace to installed node_modules/zod declaration files; local path aliases and opaque module resolution abstain. The const schema permits local parse/type/direct-export reads; every safeParse call must have exactly one direct argument, without options or spreads. Local aliases, method writes and opaque consumers abstain. Direct export alone is not mutation, but external consumer monkey-patching is not proved absent. Other value uses of its imported Zod namespace cause abstention. Transforms, brands, custom schemas, imported schemas and dynamic parse calls are excluded. Visible RegExp capabilities, regex literals or dynamic evaluation invalidate this initial native-pattern proof; external runtime monkeypatches are not inferred.
|
|
7544
|
+
"A broad string predicate returning local Schema.safeParse(parameter).success is also checked for a locally unchanged official z.uuid() or z.string().uuid() schema. The checker must resolve the namespace to installed node_modules/zod declaration files; local path aliases and opaque module resolution abstain. The const schema permits local parse/type/direct-export reads; every safeParse call must have exactly one direct argument, without options or spreads. Local aliases, method writes and opaque consumers abstain. Direct export alone is not mutation, but external consumer monkey-patching is not proved absent. Other value uses of its imported Zod namespace cause abstention. Transforms, brands, custom schemas, imported schemas and dynamic parse calls are excluded. Visible RegExp capabilities, regex literals or dynamic evaluation invalidate this initial native-pattern proof; external runtime monkeypatches are not inferred. The same unused-private-declaration fix boundary applies; observed or exported predicates remain manual.",
|
|
7490
7545
|
"A concrete member of the promised broad primitive must demonstrably return false. Numeric witnesses must also be assignable as literals to the declared input: broad number assignability alone does not prove membership in a numeric enum. Compiler-invalid target/input relations, any/never/generic inputs and opaque implementations abstain. This rule does not discourage total boundary guards or infer branded refinements. Generated files are excluded; tests remain checked."
|
|
7491
7546
|
],
|
|
7492
7547
|
references: ["https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#inferred-type-predicates"],
|
|
@@ -7525,7 +7580,7 @@ var no_partial_type_predicate_default = createRule({
|
|
|
7525
7580
|
if (predicate === void 0) return;
|
|
7526
7581
|
const uuidWitness = predicate.kind === "string" ? uuidPredicateWitness(predicate.expression, predicate.parameter, context.sourceCode, services) : void 0;
|
|
7527
7582
|
if (uuidWitness !== void 0) {
|
|
7528
|
-
context.report({ node: predicate.annotation, messageId: "partialPredicate", data: { witness: showWitness(uuidWitness), target: "string" } });
|
|
7583
|
+
context.report({ node: predicate.annotation, messageId: "partialPredicate", fix: privatePredicateBooleanFix(context.sourceCode, node, predicate.annotation, context.filename), data: { witness: showWitness(uuidWitness), target: "string" } });
|
|
7529
7584
|
return;
|
|
7530
7585
|
}
|
|
7531
7586
|
const refinement = refinementExpression(predicate, context.sourceCode);
|
|
@@ -11005,7 +11060,16 @@ var no_comment_cruft_default = createRule({
|
|
|
11005
11060
|
while (end + 1 < comments.length && areAdjacentLineComments(comments[end], comments[end + 1])) end += 1;
|
|
11006
11061
|
const removals = comments.slice(start, end + 1).filter(pure).map((candidate2) => ownLineCommentRemovalRange(sourceCode.text, candidate2));
|
|
11007
11062
|
if (removals.some((removal) => removal === null)) return null;
|
|
11008
|
-
return (fixer) =>
|
|
11063
|
+
return (fixer) => {
|
|
11064
|
+
const fixes = [];
|
|
11065
|
+
for (const removal of removals) {
|
|
11066
|
+
if (removal === null) return null;
|
|
11067
|
+
const endings = commentLineEndings(sourceCode.text, removal);
|
|
11068
|
+
if (endings === null) return null;
|
|
11069
|
+
fixes.push(fixer.replaceTextRange(removal.range, endings));
|
|
11070
|
+
}
|
|
11071
|
+
return fixes;
|
|
11072
|
+
};
|
|
11009
11073
|
}
|
|
11010
11074
|
function isSectionJsDoc(comment) {
|
|
11011
11075
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((line) => line.length > 0 && !isDirective(line));
|
|
@@ -18884,7 +18948,10 @@ var no_restated_comment_default = createRule({
|
|
|
18884
18948
|
context.report({
|
|
18885
18949
|
node: comment,
|
|
18886
18950
|
messageId: "restatesLineBelow",
|
|
18887
|
-
fix: removal === null ? null : (fixer) =>
|
|
18951
|
+
fix: removal === null ? null : (fixer) => {
|
|
18952
|
+
const endings = commentLineEndings(sourceCode.text, removal);
|
|
18953
|
+
return endings === null ? null : fixer.replaceTextRange(removal.range, endings);
|
|
18954
|
+
},
|
|
18888
18955
|
suggest: removal === null ? null : [
|
|
18889
18956
|
{
|
|
18890
18957
|
messageId: "deleteComment",
|
|
@@ -19043,7 +19110,10 @@ var no_restated_jsdoc_default = createRule({
|
|
|
19043
19110
|
context.report({
|
|
19044
19111
|
node: comment,
|
|
19045
19112
|
messageId: "restatesSignature",
|
|
19046
|
-
fix: removal === null ? null : (fixer) =>
|
|
19113
|
+
fix: removal === null ? null : (fixer) => {
|
|
19114
|
+
const endings = commentLineEndings(sourceCode.text, removal);
|
|
19115
|
+
return endings === null ? null : fixer.replaceTextRange(removal.range, endings);
|
|
19116
|
+
},
|
|
19047
19117
|
suggest: removal === null ? [] : [
|
|
19048
19118
|
{
|
|
19049
19119
|
messageId: "deleteBlock",
|
|
@@ -21862,7 +21932,10 @@ function typedTagEdit(comment, signature, sourceCode) {
|
|
|
21862
21932
|
if (!removed) return null;
|
|
21863
21933
|
while (retained[0]?.trim() === "") retained.shift();
|
|
21864
21934
|
while (retained.at(-1)?.trim() === "") retained.pop();
|
|
21865
|
-
if (retained.length === 0)
|
|
21935
|
+
if (retained.length === 0) {
|
|
21936
|
+
const endings = commentLineEndings(sourceCode.text, removal);
|
|
21937
|
+
return endings === null ? null : { range: removal.range, text: endings };
|
|
21938
|
+
}
|
|
21866
21939
|
const eol = sourceCode.text.includes("\r\n") ? "\r\n" : "\n";
|
|
21867
21940
|
const indent = " ".repeat(comment.loc.start.column);
|
|
21868
21941
|
return {
|
|
@@ -22465,7 +22538,15 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
22465
22538
|
},
|
|
22466
22539
|
messageId: "commentWall",
|
|
22467
22540
|
data: { restated: String(restated), commented: String(commented) },
|
|
22468
|
-
fix: removals.length === 0 ? null : (fixer) =>
|
|
22541
|
+
fix: removals.length === 0 ? null : (fixer) => {
|
|
22542
|
+
const fixes = [];
|
|
22543
|
+
for (const removal of removals) {
|
|
22544
|
+
const endings = commentLineEndings(sourceCode.text, removal);
|
|
22545
|
+
if (endings === null) return null;
|
|
22546
|
+
fixes.push(fixer.replaceTextRange(removal.range, endings));
|
|
22547
|
+
}
|
|
22548
|
+
return fixes;
|
|
22549
|
+
}
|
|
22469
22550
|
});
|
|
22470
22551
|
}
|
|
22471
22552
|
function isGroupLabel(comment, member3, headsRun) {
|
|
@@ -22816,7 +22897,15 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
22816
22897
|
},
|
|
22817
22898
|
messageId: "commentWall",
|
|
22818
22899
|
data: { restated: String(restated), commented: String(commented) },
|
|
22819
|
-
fix: removals.length === 0 ? null : (fixer) =>
|
|
22900
|
+
fix: removals.length === 0 ? null : (fixer) => {
|
|
22901
|
+
const fixes = [];
|
|
22902
|
+
for (const removal of removals) {
|
|
22903
|
+
const endings = commentLineEndings(sourceCode.text, removal);
|
|
22904
|
+
if (endings === null) return null;
|
|
22905
|
+
fixes.push(fixer.replaceTextRange(removal.range, endings));
|
|
22906
|
+
}
|
|
22907
|
+
return fixes;
|
|
22908
|
+
}
|
|
22820
22909
|
});
|
|
22821
22910
|
}
|
|
22822
22911
|
function isGroupLabel(comment, member3, headsRun) {
|
|
@@ -23825,7 +23914,10 @@ var test_phase_label_comment_default = createRule({
|
|
|
23825
23914
|
context.report({
|
|
23826
23915
|
node: comment,
|
|
23827
23916
|
messageId: "removeLabel",
|
|
23828
|
-
fix: (fixer) =>
|
|
23917
|
+
fix: (fixer) => {
|
|
23918
|
+
const endings = commentLineEndings(context.sourceCode.text, removal);
|
|
23919
|
+
return endings === null ? null : fixer.replaceTextRange(removal.range, endings);
|
|
23920
|
+
}
|
|
23829
23921
|
});
|
|
23830
23922
|
}
|
|
23831
23923
|
}
|
|
@@ -36492,8 +36584,10 @@ var RULE_POLICY = {
|
|
|
36492
36584
|
"@sarj/require-pascal-case-zod-schema-name": ["error", "both"]
|
|
36493
36585
|
};
|
|
36494
36586
|
var ADVISORY_RULES = Object.keys(RULE_POLICY).filter(isAdvisoryRuleName).toSorted();
|
|
36495
|
-
var
|
|
36496
|
-
var
|
|
36587
|
+
var FLAT_RECOMMENDED_RULES = presetRules("recommended");
|
|
36588
|
+
var FLAT_STRICT_RULES = presetRules("strict");
|
|
36589
|
+
var RECOMMENDED_RULES = FLAT_RECOMMENDED_RULES;
|
|
36590
|
+
var STRICT_RULES = FLAT_STRICT_RULES;
|
|
36497
36591
|
function isAdvisoryRuleName(name) {
|
|
36498
36592
|
return isPolicyName(name) && RULE_POLICY[name][0] === "warn";
|
|
36499
36593
|
}
|
|
@@ -36528,12 +36622,12 @@ var PLUGIN = {
|
|
|
36528
36622
|
recommended: {
|
|
36529
36623
|
name: "@sarj/recommended",
|
|
36530
36624
|
plugins: { "@sarj": PLUGIN },
|
|
36531
|
-
rules:
|
|
36625
|
+
rules: FLAT_RECOMMENDED_RULES
|
|
36532
36626
|
},
|
|
36533
36627
|
strict: {
|
|
36534
36628
|
name: "@sarj/strict",
|
|
36535
36629
|
plugins: { "@sarj": PLUGIN },
|
|
36536
|
-
rules:
|
|
36630
|
+
rules: FLAT_STRICT_RULES
|
|
36537
36631
|
}
|
|
36538
36632
|
};
|
|
36539
36633
|
}
|