@sarj/eslint-plugin 16.38.54 → 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 +565 -472
- package/dist/index.d.cts +34 -215
- package/dist/index.d.ts +34 -215
- package/dist/index.js +550 -457
- 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);
|
|
@@ -3695,7 +3798,7 @@ function primitiveResult(value, proof, active) {
|
|
|
3695
3798
|
return initializer !== void 0 && initializer.getSourceFile() === value.getSourceFile() && primitiveValue(initializer, proof, active);
|
|
3696
3799
|
}
|
|
3697
3800
|
function primitiveMember(node, proof, active) {
|
|
3698
|
-
if (!
|
|
3801
|
+
if (!import_typescript10.default.isIdentifier(node.expression)) return false;
|
|
3699
3802
|
const key = import_typescript10.default.isPropertyAccessExpression(node) ? node.name.text : node.argumentExpression && (import_typescript10.default.isStringLiteralLike(node.argumentExpression) || import_typescript10.default.isNumericLiteral(node.argumentExpression)) ? node.argumentExpression.text : void 0;
|
|
3700
3803
|
const symbol = proof.checker.getSymbolAtLocation(node.expression);
|
|
3701
3804
|
if (!symbol || key === void 0 || (symbol.flags & import_typescript10.default.SymbolFlags.Alias) !== 0) return false;
|
|
@@ -3710,38 +3813,38 @@ 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
|
-
if (!
|
|
3847
|
+
if (!closedInvocation(opening, proof) || !constInitializer(proof.services.esTreeNodeToTSNodeMap.get(declaration))) return false;
|
|
3745
3848
|
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
3746
3849
|
const symbol = proof.checker.getSymbolAtLocation(proof.services.esTreeNodeToTSNodeMap.get(declaration.id));
|
|
3747
3850
|
if (!symbol || proof.exports.has(symbol)) 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();
|
|
@@ -3832,7 +3935,6 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3832
3935
|
checker,
|
|
3833
3936
|
services,
|
|
3834
3937
|
sourceCode: context.sourceCode,
|
|
3835
|
-
staticScope: !dynamic,
|
|
3836
3938
|
exports: exportedSymbols(services.esTreeNodeToTSNodeMap.get(context.sourceCode.ast), checker),
|
|
3837
3939
|
values: /* @__PURE__ */ new WeakSet(),
|
|
3838
3940
|
objects: /* @__PURE__ */ new WeakMap(),
|
|
@@ -3845,9 +3947,9 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3845
3947
|
};
|
|
3846
3948
|
return {
|
|
3847
3949
|
JSXSpreadAttribute(node) {
|
|
3848
|
-
if (node.argument.type !==
|
|
3950
|
+
if (node.argument.type !== import_utils29.AST_NODE_TYPES.ObjectExpression) return;
|
|
3849
3951
|
const opening = node.parent;
|
|
3850
|
-
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;
|
|
3851
3953
|
const declaration = privateElementDeclaration(opening);
|
|
3852
3954
|
if (!declaration) return;
|
|
3853
3955
|
const fields2 = literalFields(node.argument);
|
|
@@ -3858,8 +3960,8 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3858
3960
|
if (directEval(node)) dynamic = true;
|
|
3859
3961
|
},
|
|
3860
3962
|
"Program:exit"() {
|
|
3861
|
-
if (!candidates.length) return;
|
|
3862
|
-
services =
|
|
3963
|
+
if (!candidates.length || dynamic) return;
|
|
3964
|
+
services = import_utils29.ESLintUtils.getParserServices(context);
|
|
3863
3965
|
if (!currentNativeSource(context.sourceCode, services)) return;
|
|
3864
3966
|
for (const { node, declaration, fields: fields2 } of candidates) evaluate(node, declaration, fields2);
|
|
3865
3967
|
}
|
|
@@ -3868,7 +3970,7 @@ var no_excess_jsx_props_default = createRule({
|
|
|
3868
3970
|
});
|
|
3869
3971
|
|
|
3870
3972
|
// src/rules/prefer-native-fetch-in-server-actions.ts
|
|
3871
|
-
var
|
|
3973
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
3872
3974
|
var KY_MODULE = /^ky(?:\/.*)?$/u;
|
|
3873
3975
|
var PREFER_NATIVE_FETCH_IN_SERVER_ACTIONS_DOCUMENTATION = {
|
|
3874
3976
|
defaultLevel: "warning",
|
|
@@ -3932,19 +4034,19 @@ var prefer_native_fetch_in_server_actions_default = createRule({
|
|
|
3932
4034
|
});
|
|
3933
4035
|
function hasUseServerDirective(program) {
|
|
3934
4036
|
for (const statement of program.body) {
|
|
3935
|
-
if (statement.type !==
|
|
4037
|
+
if (statement.type !== import_utils30.AST_NODE_TYPES.ExpressionStatement || statement.directive === void 0) return false;
|
|
3936
4038
|
if (statement.directive === "use server") return true;
|
|
3937
4039
|
}
|
|
3938
4040
|
return false;
|
|
3939
4041
|
}
|
|
3940
4042
|
function isTypeOnly(node) {
|
|
3941
4043
|
return node.importKind === "type" || node.specifiers.length > 0 && node.specifiers.every(
|
|
3942
|
-
(specifier) => specifier.type ===
|
|
4044
|
+
(specifier) => specifier.type === import_utils30.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
3943
4045
|
);
|
|
3944
4046
|
}
|
|
3945
4047
|
|
|
3946
4048
|
// src/rules/no-credential-in-browser-storage.ts
|
|
3947
|
-
var
|
|
4049
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
3948
4050
|
|
|
3949
4051
|
// src/rules/_secret-names.ts
|
|
3950
4052
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -4149,7 +4251,7 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
4149
4251
|
return {
|
|
4150
4252
|
CallExpression(node) {
|
|
4151
4253
|
const callee = unwrapExpression(node.callee);
|
|
4152
|
-
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)) {
|
|
4153
4255
|
return;
|
|
4154
4256
|
}
|
|
4155
4257
|
const [key] = node.arguments;
|
|
@@ -4157,12 +4259,12 @@ var no_credential_in_browser_storage_default = createRule({
|
|
|
4157
4259
|
},
|
|
4158
4260
|
AssignmentExpression(node) {
|
|
4159
4261
|
const target = node.left;
|
|
4160
|
-
if (target.type !==
|
|
4262
|
+
if (target.type !== import_utils31.AST_NODE_TYPES.MemberExpression) return;
|
|
4161
4263
|
if (isStorage(sourceCode, target.object)) {
|
|
4162
4264
|
report2(node, storedPropertyKey(sourceCode, target));
|
|
4163
4265
|
return;
|
|
4164
4266
|
}
|
|
4165
|
-
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") {
|
|
4166
4268
|
report2(node, cookieName(node.right));
|
|
4167
4269
|
}
|
|
4168
4270
|
}
|
|
@@ -4175,34 +4277,34 @@ function isStorage(sourceCode, node) {
|
|
|
4175
4277
|
}
|
|
4176
4278
|
function globalMemberName(sourceCode, node) {
|
|
4177
4279
|
const value = unwrapExpression(node);
|
|
4178
|
-
if (value.type ===
|
|
4179
|
-
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)) {
|
|
4180
4282
|
return value.property.name;
|
|
4181
4283
|
}
|
|
4182
4284
|
return null;
|
|
4183
4285
|
}
|
|
4184
4286
|
function isUnshadowed(sourceCode, node) {
|
|
4185
|
-
const variable =
|
|
4287
|
+
const variable = import_utils31.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
4186
4288
|
return variable === null || variable.defs.length === 0;
|
|
4187
4289
|
}
|
|
4188
4290
|
function storedPropertyKey(sourceCode, target) {
|
|
4189
|
-
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;
|
|
4190
4292
|
return scopedStaticString(target.property, sourceCode);
|
|
4191
4293
|
}
|
|
4192
4294
|
function cookieName(value) {
|
|
4193
4295
|
let expression = unwrapExpression(value);
|
|
4194
|
-
while (expression.type ===
|
|
4296
|
+
while (expression.type === import_utils31.AST_NODE_TYPES.BinaryExpression && expression.operator === "+") {
|
|
4195
4297
|
expression = unwrapExpression(expression.left);
|
|
4196
4298
|
}
|
|
4197
4299
|
let text = null;
|
|
4198
|
-
if (expression.type ===
|
|
4199
|
-
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;
|
|
4200
4302
|
if (text === null || !text.includes("=")) return null;
|
|
4201
4303
|
return text.slice(0, text.indexOf("=")).trim();
|
|
4202
4304
|
}
|
|
4203
4305
|
|
|
4204
4306
|
// src/rules/no-numeric-search-param-coercion.ts
|
|
4205
|
-
var
|
|
4307
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4206
4308
|
var GLOBAL_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat", "Number"]);
|
|
4207
4309
|
var NUMBER_PARSERS = /* @__PURE__ */ new Set(["parseInt", "parseFloat"]);
|
|
4208
4310
|
var SEARCH_PARAM_TYPES = /* @__PURE__ */ new Set(["URLSearchParams", "ReadonlyURLSearchParams"]);
|
|
@@ -4259,7 +4361,7 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4259
4361
|
if (isGeneratedFile(context, context.sourceCode.text) || isTestFile(context)) return {};
|
|
4260
4362
|
let services;
|
|
4261
4363
|
try {
|
|
4262
|
-
services =
|
|
4364
|
+
services = import_utils32.ESLintUtils.getParserServices(context);
|
|
4263
4365
|
} catch {
|
|
4264
4366
|
services = null;
|
|
4265
4367
|
}
|
|
@@ -4281,27 +4383,27 @@ var no_numeric_search_param_coercion_default = createRule({
|
|
|
4281
4383
|
}
|
|
4282
4384
|
});
|
|
4283
4385
|
function isNumericParser(sourceCode, callee) {
|
|
4284
|
-
if (callee.type ===
|
|
4386
|
+
if (callee.type === import_utils32.AST_NODE_TYPES.Identifier) {
|
|
4285
4387
|
return GLOBAL_PARSERS.has(callee.name) && isUnshadowedGlobal(sourceCode, callee);
|
|
4286
4388
|
}
|
|
4287
|
-
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);
|
|
4288
4390
|
}
|
|
4289
4391
|
function isUnshadowedGlobal(sourceCode, node) {
|
|
4290
|
-
const variable =
|
|
4392
|
+
const variable = import_utils32.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
4291
4393
|
return variable === null || variable.defs.length === 0;
|
|
4292
4394
|
}
|
|
4293
4395
|
function searchParamGetCall(argument) {
|
|
4294
4396
|
let value = unwrapExpression(argument);
|
|
4295
|
-
if (value.type ===
|
|
4296
|
-
if (value.type ===
|
|
4297
|
-
if (value.type ===
|
|
4298
|
-
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") {
|
|
4299
4401
|
return null;
|
|
4300
4402
|
}
|
|
4301
4403
|
return value;
|
|
4302
4404
|
}
|
|
4303
4405
|
function isSearchParamReceiver(call, services) {
|
|
4304
|
-
if (call.callee.type !==
|
|
4406
|
+
if (call.callee.type !== import_utils32.AST_NODE_TYPES.MemberExpression) return false;
|
|
4305
4407
|
const checker = services.program.getTypeChecker();
|
|
4306
4408
|
const type = checker.getNonNullableType(
|
|
4307
4409
|
checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(call.callee.object))
|
|
@@ -4313,7 +4415,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
4313
4415
|
// package.json
|
|
4314
4416
|
var package_default = {
|
|
4315
4417
|
name: "@sarj/eslint-plugin",
|
|
4316
|
-
version: "16.
|
|
4418
|
+
version: "16.39.0",
|
|
4317
4419
|
packageManager: "npm@12.2.1",
|
|
4318
4420
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
4319
4421
|
type: "module",
|
|
@@ -4401,6 +4503,7 @@ var package_default = {
|
|
|
4401
4503
|
"eslint-plugin-zod": "^5.2.2",
|
|
4402
4504
|
globals: "17.13.0",
|
|
4403
4505
|
jiti: "2.7.0",
|
|
4506
|
+
prettier: "3.9.10",
|
|
4404
4507
|
tsup: "9.0.0",
|
|
4405
4508
|
typescript: "npm:@typescript/typescript6@6.0.2",
|
|
4406
4509
|
"typescript-eslint": "^8.72.0",
|
|
@@ -4435,11 +4538,11 @@ var package_default = {
|
|
|
4435
4538
|
};
|
|
4436
4539
|
|
|
4437
4540
|
// src/rules/require-explicit-contract-implementation.ts
|
|
4438
|
-
var
|
|
4541
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
4439
4542
|
var ts12 = __toESM(require("typescript"), 1);
|
|
4440
4543
|
|
|
4441
4544
|
// src/rules/_closed-nominal-inheritance-fix.ts
|
|
4442
|
-
var
|
|
4545
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
4443
4546
|
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
4444
4547
|
function closedNominalInheritanceFix(sourceCode, call, consumer, implementation, contract) {
|
|
4445
4548
|
const source = call.getSourceFile();
|
|
@@ -4513,7 +4616,7 @@ function exactRejection(sourceCode, statement) {
|
|
|
4513
4616
|
const identifier = sourceCode.getNodeByRangeIndex(
|
|
4514
4617
|
rejected.expression.expression.getStart()
|
|
4515
4618
|
);
|
|
4516
|
-
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;
|
|
4517
4620
|
}
|
|
4518
4621
|
function exactConstruction(node, consumer, implementation) {
|
|
4519
4622
|
if (!import_typescript11.default.isIdentifier(node.expression) || node.expression.text !== consumer || node.typeArguments !== void 0 || node.arguments?.length !== 1)
|
|
@@ -4879,7 +4982,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4879
4982
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
4880
4983
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
4881
4984
|
return {};
|
|
4882
|
-
const services =
|
|
4985
|
+
const services = import_utils34.ESLintUtils.getParserServices(context);
|
|
4883
4986
|
const checker = services.program.getTypeChecker();
|
|
4884
4987
|
function inspect(node) {
|
|
4885
4988
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -4894,7 +4997,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4894
4997
|
return;
|
|
4895
4998
|
const parameters = signature.getParameters();
|
|
4896
4999
|
for (const [index, argument] of node.arguments.entries()) {
|
|
4897
|
-
if (argument.type !==
|
|
5000
|
+
if (argument.type !== import_utils34.AST_NODE_TYPES.NewExpression) continue;
|
|
4898
5001
|
const parameter = parameters[index];
|
|
4899
5002
|
if (parameter === void 0) continue;
|
|
4900
5003
|
const tsArgument = services.esTreeNodeToTSNodeMap.get(argument);
|
|
@@ -4941,18 +5044,18 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
4941
5044
|
});
|
|
4942
5045
|
|
|
4943
5046
|
// src/rules/require-explicit-service-contract.ts
|
|
4944
|
-
var
|
|
5047
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
4945
5048
|
|
|
4946
5049
|
// src/rules/_existing-factory-contract-fix.ts
|
|
4947
|
-
var
|
|
5050
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
4948
5051
|
function existingFactoryContractFix(sourceCode, candidate2) {
|
|
4949
5052
|
if (sourceCode.ast.body.length !== 4 || sourceCode.getAllComments().length !== 0)
|
|
4950
5053
|
return null;
|
|
4951
5054
|
const [contractStatement, worker, classStatement, factoryStatement] = sourceCode.ast.body;
|
|
4952
|
-
const contract = contractStatement?.type ===
|
|
4953
|
-
const implementation = classStatement?.type ===
|
|
4954
|
-
const factory = factoryStatement?.type ===
|
|
4955
|
-
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))
|
|
4956
5059
|
return null;
|
|
4957
5060
|
const operation2 = contractOperation(contract);
|
|
4958
5061
|
if (operation2 === null || interfaceOperation(worker) !== operation2)
|
|
@@ -4971,17 +5074,17 @@ function ordinaryClass(node) {
|
|
|
4971
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;
|
|
4972
5075
|
}
|
|
4973
5076
|
function ordinaryFactory(node) {
|
|
4974
|
-
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;
|
|
4975
5078
|
}
|
|
4976
5079
|
function interfaceOperation(node) {
|
|
4977
5080
|
return !node.declare && node.extends.length === 0 && node.typeParameters === void 0 ? singletonOperation(node.body.body) : null;
|
|
4978
5081
|
}
|
|
4979
5082
|
function contractOperation(node) {
|
|
4980
|
-
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;
|
|
4981
5084
|
}
|
|
4982
5085
|
function singletonOperation(members) {
|
|
4983
5086
|
const member3 = members[0];
|
|
4984
|
-
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;
|
|
4985
5088
|
}
|
|
4986
5089
|
function uniqueDeclarations(sourceCode, declarations) {
|
|
4987
5090
|
const names = declarations.flatMap(
|
|
@@ -4992,7 +5095,7 @@ function uniqueDeclarations(sourceCode, declarations) {
|
|
|
4992
5095
|
);
|
|
4993
5096
|
}
|
|
4994
5097
|
function sameBinding(sourceCode, reference, declaration) {
|
|
4995
|
-
const binding3 =
|
|
5098
|
+
const binding3 = import_utils35.ASTUtils.findVariable(
|
|
4996
5099
|
sourceCode.getScope(reference),
|
|
4997
5100
|
reference.name
|
|
4998
5101
|
);
|
|
@@ -5000,45 +5103,45 @@ function sameBinding(sourceCode, reference, declaration) {
|
|
|
5000
5103
|
}
|
|
5001
5104
|
function retainedWorker(sourceCode, implementation, worker) {
|
|
5002
5105
|
const constructor = implementation.body.body[0];
|
|
5003
|
-
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)
|
|
5004
5107
|
return null;
|
|
5005
5108
|
const property = constructor.value.params[0];
|
|
5006
|
-
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))
|
|
5007
5110
|
return null;
|
|
5008
5111
|
return property.parameter.name;
|
|
5009
5112
|
}
|
|
5010
5113
|
function typeReference(sourceCode, annotation, declaration) {
|
|
5011
5114
|
const type = annotation?.typeAnnotation;
|
|
5012
|
-
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);
|
|
5013
5116
|
}
|
|
5014
5117
|
function forwardsOperation(implementation, field, operation2) {
|
|
5015
5118
|
const method = implementation.body.body[1];
|
|
5016
|
-
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)
|
|
5017
5120
|
return false;
|
|
5018
5121
|
const statement = method.value.body.body[0];
|
|
5019
|
-
const call = statement?.type ===
|
|
5020
|
-
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);
|
|
5021
5124
|
}
|
|
5022
5125
|
function forwardedMember(node, field, operation2) {
|
|
5023
|
-
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)
|
|
5024
5127
|
return false;
|
|
5025
5128
|
const receiver = node.object;
|
|
5026
|
-
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;
|
|
5027
5130
|
}
|
|
5028
5131
|
function factoryAuthority(sourceCode, factory, contract, worker, implementation) {
|
|
5029
5132
|
const parameter = factory.params[0];
|
|
5030
|
-
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))
|
|
5031
5134
|
return false;
|
|
5032
5135
|
const statement = factory.body.body[0];
|
|
5033
|
-
const constructed = statement?.type ===
|
|
5034
|
-
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)
|
|
5035
5138
|
return false;
|
|
5036
5139
|
const argument = constructed.arguments[0];
|
|
5037
|
-
return argument?.type ===
|
|
5140
|
+
return argument?.type === import_utils35.AST_NODE_TYPES.Identifier && argument.name === parameter.name && sameBinding(sourceCode, argument, factory);
|
|
5038
5141
|
}
|
|
5039
5142
|
|
|
5040
5143
|
// src/rules/require-port-for-service.ts
|
|
5041
|
-
var
|
|
5144
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5042
5145
|
var REQUIRE_PORT_FOR_SERVICE_DOCUMENTATION = {
|
|
5043
5146
|
summary: "Advise when an exported service with injected collaborators has public methods not covered by its declared ports.",
|
|
5044
5147
|
rationale: "A declared port keeps consumers coupled to the service capability instead of its concrete implementation.",
|
|
@@ -5122,50 +5225,50 @@ var STORAGE_ASSIGNMENT_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
5122
5225
|
"||="
|
|
5123
5226
|
]);
|
|
5124
5227
|
var staticMemberName = (member3) => {
|
|
5125
|
-
if (member3.property.type ===
|
|
5228
|
+
if (member3.property.type === import_utils36.AST_NODE_TYPES.PrivateIdentifier)
|
|
5126
5229
|
return `#${member3.property.name}`;
|
|
5127
|
-
return
|
|
5230
|
+
return import_utils36.ASTUtils.getPropertyName(member3);
|
|
5128
5231
|
};
|
|
5129
5232
|
var detachedValueExports = (program) => {
|
|
5130
5233
|
const names = /* @__PURE__ */ new Set();
|
|
5131
5234
|
for (const statement of program.body) {
|
|
5132
|
-
if (statement.type ===
|
|
5235
|
+
if (statement.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration === null && statement.source === null && statement.exportKind !== "type") {
|
|
5133
5236
|
for (const specifier of statement.specifiers) {
|
|
5134
5237
|
if (specifier.exportKind !== "type") names.add(specifier.local.name);
|
|
5135
5238
|
}
|
|
5136
|
-
} else if (statement.type ===
|
|
5239
|
+
} else if (statement.type === import_utils36.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5137
5240
|
names.add(statement.declaration.name);
|
|
5138
|
-
} else if (statement.type ===
|
|
5241
|
+
} else if (statement.type === import_utils36.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5139
5242
|
names.add(statement.expression.name);
|
|
5140
5243
|
}
|
|
5141
5244
|
}
|
|
5142
5245
|
return names;
|
|
5143
5246
|
};
|
|
5144
|
-
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);
|
|
5145
5248
|
var createExportedServiceClassResolver = (program) => {
|
|
5146
5249
|
const detached = detachedValueExports(program);
|
|
5147
5250
|
return (node) => isExportedClass(node, detached);
|
|
5148
5251
|
};
|
|
5149
5252
|
var readTypeReference = (annotation) => {
|
|
5150
|
-
if (annotation?.type ===
|
|
5253
|
+
if (annotation?.type === import_utils36.AST_NODE_TYPES.TSUnionType) {
|
|
5151
5254
|
const members = annotation.types.filter(
|
|
5152
|
-
(member3) => member3.type !==
|
|
5255
|
+
(member3) => member3.type !== import_utils36.AST_NODE_TYPES.TSUndefinedKeyword && member3.type !== import_utils36.AST_NODE_TYPES.TSNullKeyword
|
|
5153
5256
|
);
|
|
5154
5257
|
annotation = members.length === 1 ? members[0] : void 0;
|
|
5155
5258
|
}
|
|
5156
|
-
if (annotation === void 0 || annotation.type !==
|
|
5259
|
+
if (annotation === void 0 || annotation.type !== import_utils36.AST_NODE_TYPES.TSTypeReference)
|
|
5157
5260
|
return null;
|
|
5158
5261
|
const { typeName } = annotation;
|
|
5159
|
-
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;
|
|
5160
5263
|
if (rightmost === null) return null;
|
|
5161
5264
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
5162
5265
|
};
|
|
5163
|
-
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}` : "";
|
|
5164
5267
|
var propertySignatureTypes = (members) => {
|
|
5165
5268
|
const types = /* @__PURE__ */ new Map();
|
|
5166
5269
|
for (const member3 of members) {
|
|
5167
|
-
if (member3.type !==
|
|
5168
|
-
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)
|
|
5169
5272
|
continue;
|
|
5170
5273
|
const reference = readTypeReference(member3.typeAnnotation?.typeAnnotation);
|
|
5171
5274
|
if (reference === null) continue;
|
|
@@ -5177,18 +5280,18 @@ var fileTypeIndex = (program) => {
|
|
|
5177
5280
|
const objects = /* @__PURE__ */ new Map();
|
|
5178
5281
|
const functionAliases = localFunctionAliases(program);
|
|
5179
5282
|
function collectDeclaredType(statement) {
|
|
5180
|
-
const declaration = statement.type ===
|
|
5181
|
-
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) {
|
|
5182
5285
|
objects.set(
|
|
5183
5286
|
declaration.id.name,
|
|
5184
5287
|
propertySignatureTypes(declaration.body.body)
|
|
5185
5288
|
);
|
|
5186
5289
|
return;
|
|
5187
5290
|
}
|
|
5188
|
-
if (declaration?.type !==
|
|
5291
|
+
if (declaration?.type !== import_utils36.AST_NODE_TYPES.TSTypeAliasDeclaration) return;
|
|
5189
5292
|
const aliased = declaration.typeAnnotation;
|
|
5190
|
-
const literals = aliased.type ===
|
|
5191
|
-
(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
|
|
5192
5295
|
) : [];
|
|
5193
5296
|
if (literals.length === 0) return;
|
|
5194
5297
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -5208,12 +5311,12 @@ function localFunctionAliases(program) {
|
|
|
5208
5311
|
const names = /* @__PURE__ */ new Set();
|
|
5209
5312
|
const parents = /* @__PURE__ */ new Map();
|
|
5210
5313
|
for (const statement of program.body) {
|
|
5211
|
-
const declaration = statement.type ===
|
|
5212
|
-
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;
|
|
5213
5316
|
const annotation = declaration.typeAnnotation;
|
|
5214
|
-
if (annotation.type ===
|
|
5317
|
+
if (annotation.type === import_utils36.AST_NODE_TYPES.TSFunctionType || annotation.type === import_utils36.AST_NODE_TYPES.TSConstructorType)
|
|
5215
5318
|
names.add(declaration.id.name);
|
|
5216
|
-
if (annotation.type ===
|
|
5319
|
+
if (annotation.type === import_utils36.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5217
5320
|
parents.set(declaration.id.name, annotation.typeName.name);
|
|
5218
5321
|
}
|
|
5219
5322
|
for (let pass = 0; pass < parents.size; pass += 1) {
|
|
@@ -5249,32 +5352,32 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5249
5352
|
function scanStoredFields(body4) {
|
|
5250
5353
|
const pending = [...body4.body];
|
|
5251
5354
|
function recordStoredField(current) {
|
|
5252
|
-
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)
|
|
5253
5356
|
return;
|
|
5254
|
-
if (current.type ===
|
|
5357
|
+
if (current.type === import_utils36.AST_NODE_TYPES.VariableDeclarator && current.id.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5255
5358
|
localBindings2.add(current.id.name);
|
|
5256
|
-
const expression = current.type ===
|
|
5359
|
+
const expression = current.type === import_utils36.AST_NODE_TYPES.AssignmentExpression ? current : null;
|
|
5257
5360
|
const storedField = writtenInstanceField(current);
|
|
5258
5361
|
if (storedField !== null) {
|
|
5259
5362
|
if (writtenFieldNames.has(storedField))
|
|
5260
5363
|
unstableFieldNames.add(storedField);
|
|
5261
5364
|
writtenFieldNames.add(storedField);
|
|
5262
|
-
if (expression?.operator !== "=" || expression.parent.type !==
|
|
5365
|
+
if (expression?.operator !== "=" || expression.parent.type !== import_utils36.AST_NODE_TYPES.ExpressionStatement || expression.parent.parent !== body4)
|
|
5263
5366
|
unstableFieldNames.add(storedField);
|
|
5264
5367
|
}
|
|
5265
|
-
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) {
|
|
5266
5369
|
enqueueChildren(current);
|
|
5267
5370
|
return;
|
|
5268
5371
|
}
|
|
5269
5372
|
const source = unwrapExpression(expression.right);
|
|
5270
|
-
if (source.type ===
|
|
5373
|
+
if (source.type === import_utils36.AST_NODE_TYPES.NewExpression) {
|
|
5271
5374
|
constructedFields += 1;
|
|
5272
5375
|
constructedFieldNames.add(storedField);
|
|
5273
|
-
} else if (source.type ===
|
|
5376
|
+
} else if (source.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5274
5377
|
const fields2 = storedFieldsFrom.get(source.name) ?? /* @__PURE__ */ new Set();
|
|
5275
5378
|
fields2.add(storedField);
|
|
5276
5379
|
storedFieldsFrom.set(source.name, fields2);
|
|
5277
|
-
} else if (source.type ===
|
|
5380
|
+
} else if (source.type === import_utils36.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5278
5381
|
const fields2 = storedFieldsFrom.get(source.object.name) ?? /* @__PURE__ */ new Set();
|
|
5279
5382
|
fields2.add(storedField);
|
|
5280
5383
|
storedFieldsFrom.set(source.object.name, fields2);
|
|
@@ -5309,7 +5412,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5309
5412
|
)) {
|
|
5310
5413
|
if (localBindings2.has(reference.name)) continue;
|
|
5311
5414
|
let fields2 = reference.fields;
|
|
5312
|
-
if (parameter.type ===
|
|
5415
|
+
if (parameter.type === import_utils36.AST_NODE_TYPES.TSParameterProperty) {
|
|
5313
5416
|
if (writtenFieldNames.has(reference.name)) continue;
|
|
5314
5417
|
fields2 = [reference.name];
|
|
5315
5418
|
} else if (fields2.length === 0)
|
|
@@ -5332,8 +5435,8 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
5332
5435
|
};
|
|
5333
5436
|
var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
5334
5437
|
let target = parameter;
|
|
5335
|
-
if (target.type ===
|
|
5336
|
-
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) {
|
|
5337
5440
|
return objectPatternCollaborators(target, declared);
|
|
5338
5441
|
}
|
|
5339
5442
|
const named3 = namedParameterCollaborator(parameter);
|
|
@@ -5343,10 +5446,10 @@ var parameterCollaborators = (parameter, declared, storedMemberFieldsFrom) => {
|
|
|
5343
5446
|
};
|
|
5344
5447
|
var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
5345
5448
|
let target = annotated;
|
|
5346
|
-
if (target.type ===
|
|
5449
|
+
if (target.type === import_utils36.AST_NODE_TYPES.TSParameterProperty)
|
|
5347
5450
|
target = target.parameter;
|
|
5348
|
-
if (target.type ===
|
|
5349
|
-
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 [];
|
|
5350
5453
|
const members = bagMemberTypes(
|
|
5351
5454
|
target.typeAnnotation?.typeAnnotation,
|
|
5352
5455
|
declared
|
|
@@ -5365,10 +5468,10 @@ var namedBagCollaborators = (annotated, declared, storedMemberFieldsFrom) => {
|
|
|
5365
5468
|
};
|
|
5366
5469
|
var namedParameterCollaborator = (annotated) => {
|
|
5367
5470
|
let target = annotated;
|
|
5368
|
-
if (target.type ===
|
|
5471
|
+
if (target.type === import_utils36.AST_NODE_TYPES.TSParameterProperty)
|
|
5369
5472
|
target = target.parameter;
|
|
5370
|
-
if (target.type ===
|
|
5371
|
-
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;
|
|
5372
5475
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
5373
5476
|
if (reference === null) return null;
|
|
5374
5477
|
return { name: target.name, ...reference, fields: [] };
|
|
@@ -5380,12 +5483,12 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5380
5483
|
if (members === null) return [];
|
|
5381
5484
|
const collaborators = [];
|
|
5382
5485
|
for (const property of pattern.properties) {
|
|
5383
|
-
if (property.type !==
|
|
5486
|
+
if (property.type !== import_utils36.AST_NODE_TYPES.Property || property.computed)
|
|
5384
5487
|
continue;
|
|
5385
|
-
if (property.key.type !==
|
|
5488
|
+
if (property.key.type !== import_utils36.AST_NODE_TYPES.Identifier) continue;
|
|
5386
5489
|
const key = property.key.name;
|
|
5387
|
-
const bound = property.value.type ===
|
|
5388
|
-
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;
|
|
5389
5492
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
5390
5493
|
const reference = members.get(key);
|
|
5391
5494
|
if (reference === void 0) continue;
|
|
@@ -5395,22 +5498,22 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
5395
5498
|
};
|
|
5396
5499
|
var bagMemberTypes = (annotation, declared) => {
|
|
5397
5500
|
if (annotation === void 0) return null;
|
|
5398
|
-
if (annotation.type ===
|
|
5501
|
+
if (annotation.type === import_utils36.AST_NODE_TYPES.TSTypeLiteral) {
|
|
5399
5502
|
return propertySignatureTypes(annotation.members);
|
|
5400
5503
|
}
|
|
5401
|
-
if (annotation.type !==
|
|
5504
|
+
if (annotation.type !== import_utils36.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5402
5505
|
return null;
|
|
5403
5506
|
}
|
|
5404
5507
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
5405
5508
|
};
|
|
5406
5509
|
var isFrameworkWiring = (body3) => subtreeHas(body3, (node) => {
|
|
5407
|
-
if (node.type ===
|
|
5510
|
+
if (node.type === import_utils36.AST_NODE_TYPES.CallExpression) {
|
|
5408
5511
|
const { callee } = node;
|
|
5409
|
-
if (callee.type ===
|
|
5512
|
+
if (callee.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5410
5513
|
return callee.name === ROUTER_FACTORY_NAME;
|
|
5411
|
-
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;
|
|
5412
5515
|
}
|
|
5413
|
-
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);
|
|
5414
5517
|
});
|
|
5415
5518
|
var subtreeHas = (root, found) => {
|
|
5416
5519
|
let hit = false;
|
|
@@ -5430,26 +5533,26 @@ var subtreeHas = (root, found) => {
|
|
|
5430
5533
|
};
|
|
5431
5534
|
var invokedInstanceField = (call) => {
|
|
5432
5535
|
let callee = unwrapExpression(call.callee);
|
|
5433
|
-
while (callee.type ===
|
|
5536
|
+
while (callee.type === import_utils36.AST_NODE_TYPES.ChainExpression)
|
|
5434
5537
|
callee = unwrapExpression(callee.expression);
|
|
5435
5538
|
const direct = instanceField(callee);
|
|
5436
5539
|
if (direct !== null) return direct;
|
|
5437
|
-
return callee.type ===
|
|
5540
|
+
return callee.type === import_utils36.AST_NODE_TYPES.MemberExpression ? instanceField(unwrapExpression(callee.object)) : null;
|
|
5438
5541
|
};
|
|
5439
5542
|
var instanceField = (candidate2) => {
|
|
5440
5543
|
let node = candidate2;
|
|
5441
|
-
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)
|
|
5442
5545
|
node = node.expression;
|
|
5443
|
-
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;
|
|
5444
5547
|
};
|
|
5445
5548
|
function writtenInstanceField(node) {
|
|
5446
|
-
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)
|
|
5447
5550
|
return instanceField(node.left);
|
|
5448
|
-
if (node.type ===
|
|
5551
|
+
if (node.type === import_utils36.AST_NODE_TYPES.UpdateExpression)
|
|
5449
5552
|
return instanceField(node.argument);
|
|
5450
|
-
if (node.type ===
|
|
5553
|
+
if (node.type === import_utils36.AST_NODE_TYPES.UnaryExpression && node.operator === "delete")
|
|
5451
5554
|
return instanceField(node.argument);
|
|
5452
|
-
if (node.type ===
|
|
5555
|
+
if (node.type === import_utils36.AST_NODE_TYPES.MemberExpression && isDestructuredWriteTarget(node))
|
|
5453
5556
|
return instanceField(node);
|
|
5454
5557
|
return null;
|
|
5455
5558
|
}
|
|
@@ -5458,39 +5561,39 @@ function isDestructuredWriteTarget(node) {
|
|
|
5458
5561
|
let target = access;
|
|
5459
5562
|
for (; ; ) {
|
|
5460
5563
|
const parent = target.parent;
|
|
5461
|
-
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) {
|
|
5462
5565
|
target = parent.parent;
|
|
5463
5566
|
continue;
|
|
5464
5567
|
}
|
|
5465
|
-
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) {
|
|
5466
5569
|
target = parent;
|
|
5467
5570
|
continue;
|
|
5468
5571
|
}
|
|
5469
|
-
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;
|
|
5470
5573
|
}
|
|
5471
5574
|
}
|
|
5472
5575
|
var behaviorallyInvokedFields = (body3) => {
|
|
5473
5576
|
const invoked = /* @__PURE__ */ new Set();
|
|
5474
5577
|
const visit = (current) => {
|
|
5475
|
-
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)
|
|
5476
5579
|
return;
|
|
5477
|
-
if (current.type ===
|
|
5580
|
+
if (current.type === import_utils36.AST_NODE_TYPES.CallExpression) {
|
|
5478
5581
|
const field = invokedInstanceField(current);
|
|
5479
5582
|
if (field !== null) invoked.add(field);
|
|
5480
5583
|
}
|
|
5481
5584
|
forEachOwnAstChild(current, visit);
|
|
5482
5585
|
};
|
|
5483
5586
|
for (const member3 of body3.body) {
|
|
5484
|
-
if (member3.type ===
|
|
5485
|
-
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) {
|
|
5486
5589
|
if (member3.value.body !== null && member3.value.body !== void 0)
|
|
5487
5590
|
visit(member3.value.body);
|
|
5488
5591
|
continue;
|
|
5489
5592
|
}
|
|
5490
|
-
if (member3.type !==
|
|
5593
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.PropertyDefinition || member3.value === null)
|
|
5491
5594
|
continue;
|
|
5492
5595
|
visit(
|
|
5493
|
-
member3.value.type ===
|
|
5596
|
+
member3.value.type === import_utils36.AST_NODE_TYPES.ArrowFunctionExpression ? member3.value.body : member3.value
|
|
5494
5597
|
);
|
|
5495
5598
|
}
|
|
5496
5599
|
return invoked;
|
|
@@ -5510,8 +5613,8 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
5510
5613
|
var fileInterfaceNames = (program) => {
|
|
5511
5614
|
const names = [];
|
|
5512
5615
|
for (const statement of program.body) {
|
|
5513
|
-
const declaration = statement.type ===
|
|
5514
|
-
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)
|
|
5515
5618
|
names.push(declaration.id.name);
|
|
5516
5619
|
}
|
|
5517
5620
|
return names;
|
|
@@ -5519,22 +5622,22 @@ var fileInterfaceNames = (program) => {
|
|
|
5519
5622
|
var publicMethodNames = (body3, functionAliases) => {
|
|
5520
5623
|
const names = [];
|
|
5521
5624
|
function collectPublicCallable(member3) {
|
|
5522
|
-
if (member3.type ===
|
|
5625
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.PropertyDefinition) {
|
|
5523
5626
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5524
5627
|
return;
|
|
5525
|
-
if (member3.key.type ===
|
|
5526
|
-
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(
|
|
5527
5630
|
member3.typeAnnotation.typeAnnotation.typeName.name
|
|
5528
5631
|
)))
|
|
5529
5632
|
return;
|
|
5530
5633
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5531
5634
|
return;
|
|
5532
5635
|
}
|
|
5533
|
-
if (member3.type !==
|
|
5636
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.MethodDefinition) return;
|
|
5534
5637
|
if (member3.kind !== "method" || member3.static) return;
|
|
5535
5638
|
if (member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5536
5639
|
return;
|
|
5537
|
-
if (member3.key.type ===
|
|
5640
|
+
if (member3.key.type === import_utils36.AST_NODE_TYPES.PrivateIdentifier) return;
|
|
5538
5641
|
names.push(declaredMemberName(member3) ?? "\u2026");
|
|
5539
5642
|
}
|
|
5540
5643
|
for (const member3 of body3.body) {
|
|
@@ -5545,13 +5648,13 @@ var publicMethodNames = (body3, functionAliases) => {
|
|
|
5545
5648
|
var isFluentConstructionObject = (node, getText) => {
|
|
5546
5649
|
if (node.id === null) return false;
|
|
5547
5650
|
const methods = node.body.body.filter(
|
|
5548
|
-
(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
|
|
5549
5652
|
);
|
|
5550
5653
|
if (methods.length === 0) return false;
|
|
5551
5654
|
return methods.every((member3) => {
|
|
5552
5655
|
const result = member3.value.returnType?.typeAnnotation;
|
|
5553
5656
|
if (result === void 0) return false;
|
|
5554
|
-
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;
|
|
5555
5658
|
return returnsOwnType || FLUENT_BUILDER_NAME_RE.test(node.id?.name ?? "") && FLUENT_RESULT_TYPE_RE.test(getText(result));
|
|
5556
5659
|
});
|
|
5557
5660
|
};
|
|
@@ -5559,10 +5662,10 @@ function localClassAbstractness(program) {
|
|
|
5559
5662
|
const classes = /* @__PURE__ */ new Map();
|
|
5560
5663
|
const parents = /* @__PURE__ */ new Map();
|
|
5561
5664
|
for (const statement of program.body) {
|
|
5562
|
-
const declaration = statement.type ===
|
|
5563
|
-
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) {
|
|
5564
5667
|
classes.set(declaration.id.name, declaration.abstract === true);
|
|
5565
|
-
if (declaration.superClass?.type ===
|
|
5668
|
+
if (declaration.superClass?.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5566
5669
|
parents.set(declaration.id.name, declaration.superClass.name);
|
|
5567
5670
|
}
|
|
5568
5671
|
}
|
|
@@ -5580,9 +5683,9 @@ function localClassAbstractness(program) {
|
|
|
5580
5683
|
return classes;
|
|
5581
5684
|
}
|
|
5582
5685
|
function declaredMemberName(member3) {
|
|
5583
|
-
if (!member3.computed && member3.key.type ===
|
|
5686
|
+
if (!member3.computed && member3.key.type === import_utils36.AST_NODE_TYPES.Identifier)
|
|
5584
5687
|
return member3.key.name;
|
|
5585
|
-
if (member3.key.type ===
|
|
5688
|
+
if (member3.key.type === import_utils36.AST_NODE_TYPES.Literal && typeof member3.key.value === "string")
|
|
5586
5689
|
return member3.key.value;
|
|
5587
5690
|
return null;
|
|
5588
5691
|
}
|
|
@@ -5591,35 +5694,35 @@ function localInterfaceSurfaces(program) {
|
|
|
5591
5694
|
const parents = /* @__PURE__ */ new Map();
|
|
5592
5695
|
const functionAliases = localFunctionAliases(program);
|
|
5593
5696
|
function collectInterfaceSurface(statement) {
|
|
5594
|
-
const declaration = statement.type ===
|
|
5595
|
-
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) {
|
|
5596
5699
|
const callables2 = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5597
|
-
const parts = declaration.typeAnnotation.type ===
|
|
5700
|
+
const parts = declaration.typeAnnotation.type === import_utils36.AST_NODE_TYPES.TSIntersectionType ? declaration.typeAnnotation.types : [declaration.typeAnnotation];
|
|
5598
5701
|
const inherited = parents.get(declaration.id.name) ?? [];
|
|
5599
5702
|
for (const part of parts) {
|
|
5600
|
-
if (part.type ===
|
|
5703
|
+
if (part.type === import_utils36.AST_NODE_TYPES.TSTypeReference && part.typeName.type === import_utils36.AST_NODE_TYPES.Identifier) {
|
|
5601
5704
|
inherited.push(part.typeName.name);
|
|
5602
5705
|
continue;
|
|
5603
5706
|
}
|
|
5604
|
-
if (part.type ===
|
|
5707
|
+
if (part.type === import_utils36.AST_NODE_TYPES.TSTypeReference) {
|
|
5605
5708
|
inherited.push("*");
|
|
5606
5709
|
continue;
|
|
5607
5710
|
}
|
|
5608
|
-
if (part.type !==
|
|
5711
|
+
if (part.type !== import_utils36.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
5609
5712
|
addCallableMembers(part.members, callables2);
|
|
5610
5713
|
}
|
|
5611
5714
|
interfaces.set(declaration.id.name, callables2);
|
|
5612
5715
|
parents.set(declaration.id.name, inherited);
|
|
5613
5716
|
return;
|
|
5614
5717
|
}
|
|
5615
|
-
if (declaration?.type !==
|
|
5718
|
+
if (declaration?.type !== import_utils36.AST_NODE_TYPES.TSInterfaceDeclaration) return;
|
|
5616
5719
|
const callables = interfaces.get(declaration.id.name) ?? /* @__PURE__ */ new Set();
|
|
5617
5720
|
addCallableMembers(declaration.body.body, callables);
|
|
5618
5721
|
interfaces.set(declaration.id.name, callables);
|
|
5619
5722
|
parents.set(declaration.id.name, [
|
|
5620
5723
|
...parents.get(declaration.id.name) ?? [],
|
|
5621
5724
|
...declaration.extends.flatMap(
|
|
5622
|
-
(heritage) => heritage.expression.type ===
|
|
5725
|
+
(heritage) => heritage.expression.type === import_utils36.AST_NODE_TYPES.Identifier ? [heritage.expression.name] : ["*"]
|
|
5623
5726
|
)
|
|
5624
5727
|
]);
|
|
5625
5728
|
}
|
|
@@ -5628,17 +5731,17 @@ function localInterfaceSurfaces(program) {
|
|
|
5628
5731
|
}
|
|
5629
5732
|
function addCallableMembers(members, callables) {
|
|
5630
5733
|
for (const member3 of members) {
|
|
5631
|
-
if (member3.type !==
|
|
5734
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.TSMethodSignature && member3.type !== import_utils36.AST_NODE_TYPES.TSPropertySignature)
|
|
5632
5735
|
continue;
|
|
5633
5736
|
const name = declaredMemberName(member3);
|
|
5634
5737
|
if (name === null) continue;
|
|
5635
|
-
if (member3.type ===
|
|
5738
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.TSMethodSignature) {
|
|
5636
5739
|
callables.add(name);
|
|
5637
5740
|
continue;
|
|
5638
5741
|
}
|
|
5639
|
-
if (member3.type !==
|
|
5742
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
5640
5743
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5641
|
-
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))
|
|
5642
5745
|
callables.add(name);
|
|
5643
5746
|
}
|
|
5644
5747
|
}
|
|
@@ -5668,7 +5771,7 @@ function localInterfaceSurfaces(program) {
|
|
|
5668
5771
|
}
|
|
5669
5772
|
function hasServicePort(node, methods, classes, interfaces) {
|
|
5670
5773
|
if (node.superClass !== null) {
|
|
5671
|
-
if (node.superClass.type !==
|
|
5774
|
+
if (node.superClass.type !== import_utils36.AST_NODE_TYPES.Identifier) return true;
|
|
5672
5775
|
const localAbstract = classes.get(node.superClass.name);
|
|
5673
5776
|
if (localAbstract === void 0 || localAbstract) return true;
|
|
5674
5777
|
}
|
|
@@ -5707,7 +5810,7 @@ var require_port_for_service_default = createRule({
|
|
|
5707
5810
|
if (node.abstract === true) return;
|
|
5708
5811
|
if (node.decorators.length > 0) return;
|
|
5709
5812
|
const ctor = node.body.body.find(
|
|
5710
|
-
(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
|
|
5711
5814
|
);
|
|
5712
5815
|
if (ctor === void 0) return;
|
|
5713
5816
|
const constructorFacts = readConstructor(
|
|
@@ -5757,7 +5860,7 @@ var require_port_for_service_default = createRule({
|
|
|
5757
5860
|
function implementedSurfaceCovers(node, methods, classes, interfaces) {
|
|
5758
5861
|
const combined = /* @__PURE__ */ new Set();
|
|
5759
5862
|
for (const implementation of node.implements) {
|
|
5760
|
-
if (implementation.expression.type !==
|
|
5863
|
+
if (implementation.expression.type !== import_utils36.AST_NODE_TYPES.Identifier)
|
|
5761
5864
|
return true;
|
|
5762
5865
|
const name = implementation.expression.name;
|
|
5763
5866
|
const localAbstract = classes.get(name);
|
|
@@ -5774,7 +5877,7 @@ function createServiceOperationResolver(program) {
|
|
|
5774
5877
|
let declaredTypes = null;
|
|
5775
5878
|
return (node) => {
|
|
5776
5879
|
const ctor = node.body.body.find(
|
|
5777
|
-
(member3) => member3.type ===
|
|
5880
|
+
(member3) => member3.type === import_utils36.AST_NODE_TYPES.MethodDefinition && member3.kind === "constructor" && member3.value.body !== null
|
|
5778
5881
|
);
|
|
5779
5882
|
if (ctor === void 0) return [];
|
|
5780
5883
|
const declared = () => declaredTypes ??= fileTypeIndex(program);
|
|
@@ -5792,7 +5895,7 @@ function createServiceOperationResolver(program) {
|
|
|
5792
5895
|
for (const [name, body3] of serviceOperationBodies(node)) {
|
|
5793
5896
|
forEachServiceCall(body3, (call) => {
|
|
5794
5897
|
if (retained.has(invokedInstanceField(call) ?? "")) active.add(name);
|
|
5795
|
-
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) {
|
|
5796
5899
|
const callee = staticMemberName(call.callee);
|
|
5797
5900
|
if (callee !== null) {
|
|
5798
5901
|
const linked = callers.get(callee) ?? /* @__PURE__ */ new Set();
|
|
@@ -5831,11 +5934,11 @@ function serviceOperationBodies(node) {
|
|
|
5831
5934
|
});
|
|
5832
5935
|
}
|
|
5833
5936
|
for (const member3 of node.body.body) {
|
|
5834
|
-
if (member3.type !==
|
|
5937
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.MethodDefinition && member3.type !== import_utils36.AST_NODE_TYPES.PropertyDefinition)
|
|
5835
5938
|
continue;
|
|
5836
|
-
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")
|
|
5837
5940
|
continue;
|
|
5838
|
-
if (member3.value?.type !==
|
|
5941
|
+
if (member3.value?.type !== import_utils36.AST_NODE_TYPES.FunctionExpression && member3.value?.type !== import_utils36.AST_NODE_TYPES.ArrowFunctionExpression)
|
|
5839
5942
|
continue;
|
|
5840
5943
|
const name = declaredMemberName(member3);
|
|
5841
5944
|
if (name !== null && !written.has(name) && member3.value.body !== null)
|
|
@@ -5844,9 +5947,9 @@ function serviceOperationBodies(node) {
|
|
|
5844
5947
|
return bodies;
|
|
5845
5948
|
}
|
|
5846
5949
|
function forEachServiceCall(node, onCall) {
|
|
5847
|
-
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)
|
|
5848
5951
|
return;
|
|
5849
|
-
if (node.type ===
|
|
5952
|
+
if (node.type === import_utils36.AST_NODE_TYPES.BlockStatement) {
|
|
5850
5953
|
for (const statement of node.body) {
|
|
5851
5954
|
forEachServiceCall(statement, onCall);
|
|
5852
5955
|
if (terminatesOperation(statement)) break;
|
|
@@ -5858,29 +5961,29 @@ function forEachServiceCall(node, onCall) {
|
|
|
5858
5961
|
forEachServiceCall(branch, onCall);
|
|
5859
5962
|
return;
|
|
5860
5963
|
}
|
|
5861
|
-
if (node.type ===
|
|
5964
|
+
if (node.type === import_utils36.AST_NODE_TYPES.CallExpression) onCall(node);
|
|
5862
5965
|
forEachOwnAstChild(node, (child) => {
|
|
5863
5966
|
forEachServiceCall(child, onCall);
|
|
5864
5967
|
});
|
|
5865
5968
|
}
|
|
5866
5969
|
function literalExecutionBranch(node) {
|
|
5867
|
-
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)
|
|
5868
5971
|
return node.test;
|
|
5869
|
-
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") {
|
|
5870
5973
|
return node.test.value ? node.consequent : node.alternate ?? node.test;
|
|
5871
5974
|
}
|
|
5872
|
-
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")
|
|
5873
5976
|
return null;
|
|
5874
5977
|
if (node.operator === "&&") return node.left.value ? node.right : node.left;
|
|
5875
5978
|
if (node.operator === "||") return node.left.value ? node.left : node.right;
|
|
5876
5979
|
return node.left;
|
|
5877
5980
|
}
|
|
5878
5981
|
function terminatesOperation(node) {
|
|
5879
|
-
if (node.type ===
|
|
5982
|
+
if (node.type === import_utils36.AST_NODE_TYPES.ReturnStatement || node.type === import_utils36.AST_NODE_TYPES.ThrowStatement)
|
|
5880
5983
|
return true;
|
|
5881
|
-
if (node.type ===
|
|
5984
|
+
if (node.type === import_utils36.AST_NODE_TYPES.BlockStatement)
|
|
5882
5985
|
return node.body.some(terminatesOperation);
|
|
5883
|
-
if (node.type !==
|
|
5986
|
+
if (node.type !== import_utils36.AST_NODE_TYPES.IfStatement) return false;
|
|
5884
5987
|
const branch = literalExecutionBranch(node);
|
|
5885
5988
|
if (branch !== null) return terminatesOperation(branch);
|
|
5886
5989
|
return node.alternate !== null && terminatesOperation(node.consequent) && terminatesOperation(node.alternate);
|
|
@@ -5894,7 +5997,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5894
5997
|
const seen = /* @__PURE__ */ new Set();
|
|
5895
5998
|
function addImplementedContracts(current) {
|
|
5896
5999
|
for (const implementation of current.implements) {
|
|
5897
|
-
if (implementation.expression.type !==
|
|
6000
|
+
if (implementation.expression.type !== import_utils36.AST_NODE_TYPES.Identifier)
|
|
5898
6001
|
return false;
|
|
5899
6002
|
const name = implementation.expression.name;
|
|
5900
6003
|
const surface = interfaces.get(name);
|
|
@@ -5917,7 +6020,7 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5917
6020
|
}
|
|
5918
6021
|
if (!addImplementedContracts(current)) return null;
|
|
5919
6022
|
if (current.superClass === null) continue;
|
|
5920
|
-
if (current.superClass.type !==
|
|
6023
|
+
if (current.superClass.type !== import_utils36.AST_NODE_TYPES.Identifier) return null;
|
|
5921
6024
|
const base = classes.get(current.superClass.name);
|
|
5922
6025
|
if (base === void 0) return null;
|
|
5923
6026
|
pending.push(base);
|
|
@@ -5927,8 +6030,8 @@ function hasDeclaredServiceContract(node, operations, program) {
|
|
|
5927
6030
|
function localClassDeclarations(program) {
|
|
5928
6031
|
const classes = /* @__PURE__ */ new Map();
|
|
5929
6032
|
for (const statement of program.body) {
|
|
5930
|
-
const declaration = statement.type ===
|
|
5931
|
-
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)
|
|
5932
6035
|
classes.set(declaration.id.name, declaration);
|
|
5933
6036
|
}
|
|
5934
6037
|
return classes;
|
|
@@ -5936,13 +6039,13 @@ function localClassDeclarations(program) {
|
|
|
5936
6039
|
function abstractContractOperations(node, functionAliases) {
|
|
5937
6040
|
const methods = new Set(publicMethodNames(node.body, functionAliases));
|
|
5938
6041
|
for (const member3 of node.body.body) {
|
|
5939
|
-
if (member3.type !==
|
|
6042
|
+
if (member3.type !== import_utils36.AST_NODE_TYPES.TSAbstractMethodDefinition && member3.type !== import_utils36.AST_NODE_TYPES.TSAbstractPropertyDefinition)
|
|
5940
6043
|
continue;
|
|
5941
6044
|
if (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")
|
|
5942
6045
|
continue;
|
|
5943
|
-
if (member3.type ===
|
|
6046
|
+
if (member3.type === import_utils36.AST_NODE_TYPES.TSAbstractPropertyDefinition) {
|
|
5944
6047
|
const annotation = member3.typeAnnotation?.typeAnnotation;
|
|
5945
|
-
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)))
|
|
5946
6049
|
continue;
|
|
5947
6050
|
}
|
|
5948
6051
|
const name = declaredMemberName(member3);
|
|
@@ -6078,7 +6181,7 @@ function isServiceRole(name, filename) {
|
|
|
6078
6181
|
}
|
|
6079
6182
|
|
|
6080
6183
|
// src/rules/no-conditional-empty-object-spread.ts
|
|
6081
|
-
var
|
|
6184
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
6082
6185
|
var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
6083
6186
|
summary: "Build conditional properties explicitly instead of spreading an empty-object branch.",
|
|
6084
6187
|
rationale: "An empty-object conditional spread hides whether a property is omitted, which differs from assigning undefined.",
|
|
@@ -6130,7 +6233,7 @@ var NO_CONDITIONAL_EMPTY_OBJECT_SPREAD_DOCUMENTATION = {
|
|
|
6130
6233
|
]
|
|
6131
6234
|
};
|
|
6132
6235
|
function isEmptyObject(node) {
|
|
6133
|
-
return node.type ===
|
|
6236
|
+
return node.type === import_utils38.AST_NODE_TYPES.ObjectExpression && node.properties.length === 0;
|
|
6134
6237
|
}
|
|
6135
6238
|
var no_conditional_empty_object_spread_default = createRule({
|
|
6136
6239
|
name: "no-conditional-empty-object-spread",
|
|
@@ -6151,13 +6254,13 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
6151
6254
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6152
6255
|
return {
|
|
6153
6256
|
SpreadElement(node) {
|
|
6154
|
-
if (node.parent.type !==
|
|
6257
|
+
if (node.parent.type !== import_utils38.AST_NODE_TYPES.ObjectExpression || node.argument.type !== import_utils38.AST_NODE_TYPES.ConditionalExpression)
|
|
6155
6258
|
return;
|
|
6156
6259
|
if (isEmptyObject(node.argument.consequent) || isEmptyObject(node.argument.alternate)) {
|
|
6157
6260
|
const conditional = node.argument;
|
|
6158
6261
|
const emptyConsequent = isEmptyObject(conditional.consequent);
|
|
6159
6262
|
const populated = emptyConsequent ? conditional.alternate : conditional.consequent;
|
|
6160
|
-
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;
|
|
6161
6264
|
context.report({
|
|
6162
6265
|
node,
|
|
6163
6266
|
messageId: "avoid",
|
|
@@ -6173,7 +6276,7 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
6173
6276
|
});
|
|
6174
6277
|
|
|
6175
6278
|
// src/rules/prefer-typed-reflection.ts
|
|
6176
|
-
var
|
|
6279
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
6177
6280
|
var import_typescript12 = __toESM(require("typescript"), 1);
|
|
6178
6281
|
var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
6179
6282
|
summary: "Prefer typed access when Reflect.get or Reflect.apply discards a known contract.",
|
|
@@ -6246,20 +6349,20 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6246
6349
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
6247
6350
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
6248
6351
|
return {};
|
|
6249
|
-
const services =
|
|
6352
|
+
const services = import_utils39.ESLintUtils.getParserServices(context);
|
|
6250
6353
|
if (!services.program) return {};
|
|
6251
6354
|
const checker = services.program.getTypeChecker();
|
|
6252
|
-
const isReflect = (node) => globalName(node, "Reflect") || node.type ===
|
|
6253
|
-
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;
|
|
6254
6357
|
const closedObject = (type) => {
|
|
6255
6358
|
if (type.isUnion()) return type.types.every(closedObject);
|
|
6256
6359
|
return knownType(type) && type.getProperties().length > 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
6257
6360
|
};
|
|
6258
6361
|
const inspectGet = (node, type) => {
|
|
6259
6362
|
const key = node.arguments[1] === void 0 ? void 0 : unwrapExpression(node.arguments[1]);
|
|
6260
|
-
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);
|
|
6261
6364
|
};
|
|
6262
|
-
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(
|
|
6263
6366
|
(signature) => signature.typeParameters === void 0 && signature.parameters.every(
|
|
6264
6367
|
(parameter) => knownType(
|
|
6265
6368
|
checker.getTypeOfSymbolAtLocation(
|
|
@@ -6270,25 +6373,25 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6270
6373
|
)
|
|
6271
6374
|
);
|
|
6272
6375
|
const getReplacement = (node, type, target) => {
|
|
6273
|
-
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;
|
|
6274
6377
|
let outer = node;
|
|
6275
|
-
while (outer.parent.type ===
|
|
6276
|
-
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;
|
|
6277
6380
|
const writtenKey = node.arguments[1];
|
|
6278
|
-
if (writtenKey === void 0 || writtenKey.type ===
|
|
6381
|
+
if (writtenKey === void 0 || writtenKey.type === import_utils39.AST_NODE_TYPES.SpreadElement) return null;
|
|
6279
6382
|
const key = unwrapExpression(writtenKey);
|
|
6280
|
-
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);
|
|
6281
6384
|
const members = type.isUnion() ? type.types : [type];
|
|
6282
6385
|
if (name === null || !members.every((member3) => (member3.flags & import_typescript12.default.TypeFlags.Object) !== 0 && checker.getPropertyOfType(member3, name) !== void 0)) return null;
|
|
6283
6386
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
6284
6387
|
};
|
|
6285
6388
|
return {
|
|
6286
6389
|
CallExpression(node) {
|
|
6287
|
-
if (node.callee.type !==
|
|
6390
|
+
if (node.callee.type !== import_utils39.AST_NODE_TYPES.MemberExpression || !isReflect(node.callee.object))
|
|
6288
6391
|
return;
|
|
6289
|
-
const method =
|
|
6392
|
+
const method = import_utils39.ASTUtils.getPropertyName(node.callee);
|
|
6290
6393
|
const target = node.arguments[0];
|
|
6291
|
-
if (!target || target.type ===
|
|
6394
|
+
if (!target || target.type === import_utils39.AST_NODE_TYPES.SpreadElement || method !== "get" && method !== "apply")
|
|
6292
6395
|
return;
|
|
6293
6396
|
const type = checker.getTypeAtLocation(
|
|
6294
6397
|
services.esTreeNodeToTSNodeMap.get(target)
|
|
@@ -6305,55 +6408,6 @@ var prefer_typed_reflection_default = createRule({
|
|
|
6305
6408
|
// src/rules/no-broad-return-type.ts
|
|
6306
6409
|
var import_utils40 = require("@typescript-eslint/utils");
|
|
6307
6410
|
var import_typescript13 = __toESM(require("typescript"), 1);
|
|
6308
|
-
|
|
6309
|
-
// src/rules/_unused-private-binding.ts
|
|
6310
|
-
var import_utils39 = require("@typescript-eslint/utils");
|
|
6311
|
-
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
6312
|
-
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
6313
|
-
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
6314
|
-
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;
|
|
6315
|
-
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
6316
|
-
const statement = declaration.type === import_utils39.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
6317
|
-
if (statement.parent.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils39.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
6318
|
-
if (statement.parent.type !== import_utils39.AST_NODE_TYPES.Program) return statement.parent.type === import_utils39.AST_NODE_TYPES.BlockStatement;
|
|
6319
|
-
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);
|
|
6320
|
-
}
|
|
6321
|
-
function hasOnlyDirectFactoryUses(variable) {
|
|
6322
|
-
return variable.references.every((reference) => {
|
|
6323
|
-
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
6324
|
-
const identifier = reference.identifier;
|
|
6325
|
-
const parent = identifier.parent;
|
|
6326
|
-
if (parent.type === import_utils39.AST_NODE_TYPES.CallExpression && parent.callee === identifier) return true;
|
|
6327
|
-
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;
|
|
6328
|
-
});
|
|
6329
|
-
}
|
|
6330
|
-
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
6331
|
-
function hasIdentifierNamed(node, name) {
|
|
6332
|
-
let names = IDENTIFIER_NAMES.get(node);
|
|
6333
|
-
if (names === void 0) {
|
|
6334
|
-
const collected = /* @__PURE__ */ new Set();
|
|
6335
|
-
const pending = [node];
|
|
6336
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
6337
|
-
while (pending.length > 0) {
|
|
6338
|
-
const current = pending.pop();
|
|
6339
|
-
if (current === void 0 || seen.has(current)) continue;
|
|
6340
|
-
seen.add(current);
|
|
6341
|
-
if (current.type === import_utils39.AST_NODE_TYPES.Identifier || current.type === import_utils39.AST_NODE_TYPES.JSXIdentifier) collected.add(current.name);
|
|
6342
|
-
forEachOwnAstChild(current, (child) => {
|
|
6343
|
-
pending.push(child);
|
|
6344
|
-
}, (key) => key !== "tokens" && key !== "comments");
|
|
6345
|
-
}
|
|
6346
|
-
names = collected;
|
|
6347
|
-
IDENTIFIER_NAMES.set(node, names);
|
|
6348
|
-
}
|
|
6349
|
-
return names.has(name);
|
|
6350
|
-
}
|
|
6351
|
-
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
6352
|
-
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;
|
|
6353
|
-
return (fixer) => fixer.replaceText(annotation, `boolean${sourceCode.getText(annotation).replace(/[^\r\n]/gu, "")}`);
|
|
6354
|
-
}
|
|
6355
|
-
|
|
6356
|
-
// src/rules/no-broad-return-type.ts
|
|
6357
6411
|
var NO_BROAD_RETURN_TYPE_DOCUMENTATION = {
|
|
6358
6412
|
summary: "Report explicit broad return annotations that erase a known return value.",
|
|
6359
6413
|
rationale: "An unknown, object, or unknown-valued dictionary return hides fields that the implementation already knows.",
|
|
@@ -7197,7 +7251,7 @@ var NO_CONTRADICTORY_TYPE_PREDICATE_DOCUMENTATION = {
|
|
|
7197
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.",
|
|
7198
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.",
|
|
7199
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.",
|
|
7200
|
-
"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."
|
|
7201
7255
|
],
|
|
7202
7256
|
references: ["https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#inferred-type-predicates"],
|
|
7203
7257
|
examples: [
|
|
@@ -7261,7 +7315,7 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
7261
7315
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(annotation.typeAnnotation.typeAnnotation));
|
|
7262
7316
|
if (!checker.isTypeAssignableTo(target, input)) return;
|
|
7263
7317
|
if (shallowRecordCheck(expression, parameter, input, target, context.sourceCode, checker, services.esTreeNodeToTSNodeMap.get(node).getSourceFile())) {
|
|
7264
|
-
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) } });
|
|
7265
7319
|
return;
|
|
7266
7320
|
}
|
|
7267
7321
|
if (check === void 0) {
|
|
@@ -7487,7 +7541,7 @@ var NO_PARTIAL_TYPE_PREDICATE_DOCUMENTATION = {
|
|
|
7487
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.",
|
|
7488
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.",
|
|
7489
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.",
|
|
7490
|
-
"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.",
|
|
7491
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."
|
|
7492
7546
|
],
|
|
7493
7547
|
references: ["https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#inferred-type-predicates"],
|
|
@@ -7526,7 +7580,7 @@ var no_partial_type_predicate_default = createRule({
|
|
|
7526
7580
|
if (predicate === void 0) return;
|
|
7527
7581
|
const uuidWitness = predicate.kind === "string" ? uuidPredicateWitness(predicate.expression, predicate.parameter, context.sourceCode, services) : void 0;
|
|
7528
7582
|
if (uuidWitness !== void 0) {
|
|
7529
|
-
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" } });
|
|
7530
7584
|
return;
|
|
7531
7585
|
}
|
|
7532
7586
|
const refinement = refinementExpression(predicate, context.sourceCode);
|
|
@@ -11006,7 +11060,16 @@ var no_comment_cruft_default = createRule({
|
|
|
11006
11060
|
while (end + 1 < comments.length && areAdjacentLineComments(comments[end], comments[end + 1])) end += 1;
|
|
11007
11061
|
const removals = comments.slice(start, end + 1).filter(pure).map((candidate2) => ownLineCommentRemovalRange(sourceCode.text, candidate2));
|
|
11008
11062
|
if (removals.some((removal) => removal === null)) return null;
|
|
11009
|
-
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
|
+
};
|
|
11010
11073
|
}
|
|
11011
11074
|
function isSectionJsDoc(comment) {
|
|
11012
11075
|
const texts = comment.value.split("\n").map(stripCommentMarker).filter((line) => line.length > 0 && !isDirective(line));
|
|
@@ -18885,7 +18948,10 @@ var no_restated_comment_default = createRule({
|
|
|
18885
18948
|
context.report({
|
|
18886
18949
|
node: comment,
|
|
18887
18950
|
messageId: "restatesLineBelow",
|
|
18888
|
-
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
|
+
},
|
|
18889
18955
|
suggest: removal === null ? null : [
|
|
18890
18956
|
{
|
|
18891
18957
|
messageId: "deleteComment",
|
|
@@ -19044,7 +19110,10 @@ var no_restated_jsdoc_default = createRule({
|
|
|
19044
19110
|
context.report({
|
|
19045
19111
|
node: comment,
|
|
19046
19112
|
messageId: "restatesSignature",
|
|
19047
|
-
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
|
+
},
|
|
19048
19117
|
suggest: removal === null ? [] : [
|
|
19049
19118
|
{
|
|
19050
19119
|
messageId: "deleteBlock",
|
|
@@ -21863,7 +21932,10 @@ function typedTagEdit(comment, signature, sourceCode) {
|
|
|
21863
21932
|
if (!removed) return null;
|
|
21864
21933
|
while (retained[0]?.trim() === "") retained.shift();
|
|
21865
21934
|
while (retained.at(-1)?.trim() === "") retained.pop();
|
|
21866
|
-
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
|
+
}
|
|
21867
21939
|
const eol = sourceCode.text.includes("\r\n") ? "\r\n" : "\n";
|
|
21868
21940
|
const indent = " ".repeat(comment.loc.start.column);
|
|
21869
21941
|
return {
|
|
@@ -22466,7 +22538,15 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
22466
22538
|
},
|
|
22467
22539
|
messageId: "commentWall",
|
|
22468
22540
|
data: { restated: String(restated), commented: String(commented) },
|
|
22469
|
-
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
|
+
}
|
|
22470
22550
|
});
|
|
22471
22551
|
}
|
|
22472
22552
|
function isGroupLabel(comment, member3, headsRun) {
|
|
@@ -22817,7 +22897,15 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
22817
22897
|
},
|
|
22818
22898
|
messageId: "commentWall",
|
|
22819
22899
|
data: { restated: String(restated), commented: String(commented) },
|
|
22820
|
-
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
|
+
}
|
|
22821
22909
|
});
|
|
22822
22910
|
}
|
|
22823
22911
|
function isGroupLabel(comment, member3, headsRun) {
|
|
@@ -23826,7 +23914,10 @@ var test_phase_label_comment_default = createRule({
|
|
|
23826
23914
|
context.report({
|
|
23827
23915
|
node: comment,
|
|
23828
23916
|
messageId: "removeLabel",
|
|
23829
|
-
fix: (fixer) =>
|
|
23917
|
+
fix: (fixer) => {
|
|
23918
|
+
const endings = commentLineEndings(context.sourceCode.text, removal);
|
|
23919
|
+
return endings === null ? null : fixer.replaceTextRange(removal.range, endings);
|
|
23920
|
+
}
|
|
23830
23921
|
});
|
|
23831
23922
|
}
|
|
23832
23923
|
}
|
|
@@ -36493,8 +36584,10 @@ var RULE_POLICY = {
|
|
|
36493
36584
|
"@sarj/require-pascal-case-zod-schema-name": ["error", "both"]
|
|
36494
36585
|
};
|
|
36495
36586
|
var ADVISORY_RULES = Object.keys(RULE_POLICY).filter(isAdvisoryRuleName).toSorted();
|
|
36496
|
-
var
|
|
36497
|
-
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;
|
|
36498
36591
|
function isAdvisoryRuleName(name) {
|
|
36499
36592
|
return isPolicyName(name) && RULE_POLICY[name][0] === "warn";
|
|
36500
36593
|
}
|
|
@@ -36529,12 +36622,12 @@ var PLUGIN = {
|
|
|
36529
36622
|
recommended: {
|
|
36530
36623
|
name: "@sarj/recommended",
|
|
36531
36624
|
plugins: { "@sarj": PLUGIN },
|
|
36532
|
-
rules:
|
|
36625
|
+
rules: FLAT_RECOMMENDED_RULES
|
|
36533
36626
|
},
|
|
36534
36627
|
strict: {
|
|
36535
36628
|
name: "@sarj/strict",
|
|
36536
36629
|
plugins: { "@sarj": PLUGIN },
|
|
36537
|
-
rules:
|
|
36630
|
+
rules: FLAT_STRICT_RULES
|
|
36538
36631
|
}
|
|
36539
36632
|
};
|
|
36540
36633
|
}
|