@stateward/core 1.1.0 → 1.2.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.
@@ -729,7 +729,8 @@ function compareLabels(a, b) {
729
729
  return -1;
730
730
  return a.label > b.label ? 1 : 0;
731
731
  }
732
- function literalOf(checker, member) {
732
+ function literalOf(checker, found) {
733
+ const member = withoutMarkers(checker, found);
733
734
  const label = checker.typeToString(member);
734
735
  if (member.isStringLiteral() || member.isNumberLiteral())
735
736
  return { value: member.value, label };
@@ -741,6 +742,14 @@ function literalOf(checker, member) {
741
742
  return { value: undefined, label };
742
743
  return undefined;
743
744
  }
745
+ /** The literal of `"paid" & { "__guarantee:open-union"?: true }`; any other type as it is. */
746
+ function withoutMarkers(checker, type) {
747
+ if (!type.isIntersection())
748
+ return type;
749
+ const rest = type.types.filter((part) => !isMarkerOnly(checker, part));
750
+ const [only] = rest;
751
+ return rest.length === 1 && only !== undefined && rest.length < type.types.length ? only : type;
752
+ }
744
753
  /** The types compared by value: `===` on two of them never tells apart equal values. */
745
754
  const PRIMITIVE_FLAGS = ts.TypeFlags.StringLike |
746
755
  ts.TypeFlags.NumberLike |
@@ -793,10 +802,119 @@ function isPromiseType(checker, type) {
793
802
  return awaited !== undefined && awaited !== type;
794
803
  }
795
804
  const NULLISH = ts.TypeFlags.Null | ts.TypeFlags.Undefined;
796
- /** The property a stated guarantee is written in (`TypeQueries.guaranteesOf`). */
805
+ /** The property a stated guarantee is written in by 1.1.0 (`__guarantee?: "owned"`). */
797
806
  const GUARANTEE_PROPERTY = "__guarantee";
798
- /** The guarantee names of one type that is not a union: its optional `__guarantee` literals. */
807
+ /** The prefix of the property each trait is written in from 1.2 (`"__guarantee:owned"?: true`). */
808
+ const GUARANTEE_PREFIX = "__guarantee:";
809
+ /** Whether `file` declares a property named `marker` (`"__guarantee:opaque"?: …`) in a type or class. */
810
+ function declaresMarkerProperty(file, marker) {
811
+ let found = false;
812
+ const visit = (node) => {
813
+ if (found)
814
+ return;
815
+ if ((ts.isPropertySignature(node) || ts.isPropertyDeclaration(node)) &&
816
+ (ts.isStringLiteral(node.name) || ts.isIdentifier(node.name)) &&
817
+ node.name.text === marker) {
818
+ found = true;
819
+ return;
820
+ }
821
+ ts.forEachChild(node, visit);
822
+ };
823
+ visit(file);
824
+ return found;
825
+ }
826
+ /** Adds the `as` names a file's import and export specifiers give: `onSnapshot` → `listen`. */
827
+ function addRenamed(file, renamed) {
828
+ const add = (specifier) => {
829
+ const from = specifier.propertyName;
830
+ if (from === undefined || !ts.isIdentifier(from))
831
+ return;
832
+ const names = renamed.get(from.text) ?? new Set();
833
+ names.add(specifier.name.text);
834
+ renamed.set(from.text, names);
835
+ };
836
+ const addName = (from, to) => {
837
+ if (from === to)
838
+ return;
839
+ const names = renamed.get(from) ?? new Set();
840
+ names.add(to);
841
+ renamed.set(from, names);
842
+ };
843
+ for (const statement of file.statements) {
844
+ if (ts.isImportDeclaration(statement)) {
845
+ const bindings = statement.importClause?.namedBindings;
846
+ if (bindings !== undefined && ts.isNamedImports(bindings))
847
+ bindings.elements.forEach(add);
848
+ }
849
+ else if (ts.isExportDeclaration(statement) &&
850
+ statement.exportClause !== undefined &&
851
+ ts.isNamedExports(statement.exportClause)) {
852
+ statement.exportClause.elements.forEach(add);
853
+ }
854
+ }
855
+ // `const listen = onSnapshot`, `const listen = db.onSnapshot` and
856
+ // `const { onSnapshot: listen } = db`, anywhere in the file.
857
+ const visit = (node) => {
858
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
859
+ let value = node.initializer;
860
+ while (ts.isParenthesizedExpression(value) ||
861
+ ts.isAsExpression(value) ||
862
+ ts.isSatisfiesExpression(value) ||
863
+ ts.isNonNullExpression(value)) {
864
+ value = value.expression;
865
+ }
866
+ if (ts.isIdentifier(value))
867
+ addName(value.text, node.name.text);
868
+ else if (ts.isPropertyAccessExpression(value))
869
+ addName(value.name.text, node.name.text);
870
+ }
871
+ else if (ts.isBindingElement(node) &&
872
+ node.propertyName !== undefined &&
873
+ ts.isIdentifier(node.propertyName) &&
874
+ ts.isIdentifier(node.name)) {
875
+ addName(node.propertyName.text, node.name.text);
876
+ }
877
+ ts.forEachChild(node, visit);
878
+ };
879
+ visit(file);
880
+ }
881
+ /** Whether a file declares a member named `[Symbol.dispose]` or `[Symbol.asyncDispose]`. */
882
+ function declaresDisposeMember(file) {
883
+ let found = false;
884
+ const visit = (node) => {
885
+ if (found)
886
+ return;
887
+ if (ts.isComputedPropertyName(node) &&
888
+ ts.isPropertyAccessExpression(node.expression) &&
889
+ ts.isIdentifier(node.expression.expression) &&
890
+ node.expression.expression.text === "Symbol" &&
891
+ (node.expression.name.text === "dispose" || node.expression.name.text === "asyncDispose")) {
892
+ found = true;
893
+ return;
894
+ }
895
+ ts.forEachChild(node, visit);
896
+ };
897
+ visit(file);
898
+ return found;
899
+ }
900
+ /**
901
+ * The guarantee names of one type that is not a union: one per optional `"__guarantee:<name>"`
902
+ * property, and the string literals of an optional `__guarantee` property (the 1.1.0 form).
903
+ */
799
904
  function memberGuarantees(checker, type) {
905
+ const names = [];
906
+ for (const property of checker.getPropertiesOfType(type)) {
907
+ const name = property.getName();
908
+ if (!name.startsWith(GUARANTEE_PREFIX) || !(property.flags & ts.SymbolFlags.Optional))
909
+ continue;
910
+ const trait = name.slice(GUARANTEE_PREFIX.length);
911
+ if (trait !== "")
912
+ names.push(trait);
913
+ }
914
+ return [...names, ...legacyGuarantees(checker, type)];
915
+ }
916
+ /** The names of the 1.1.0 form, `__guarantee?: "owned"`; none when it is required or not literals (a brand). */
917
+ function legacyGuarantees(checker, type) {
800
918
  const property = checker.getPropertyOfType(type, GUARANTEE_PROPERTY);
801
919
  if (property === undefined || !(property.flags & ts.SymbolFlags.Optional))
802
920
  return [];
@@ -811,6 +929,22 @@ function memberGuarantees(checker, type) {
811
929
  }
812
930
  return names;
813
931
  }
932
+ /**
933
+ * Whether an object type only states guarantees: every property is a guarantee marker. A literal
934
+ * intersected with one (`"paid" & { "__guarantee:open-union"?: true }`, what `OpenUnion<T>` gives
935
+ * each member) is still that literal.
936
+ */
937
+ function isMarkerOnly(checker, type) {
938
+ if (!(type.flags & ts.TypeFlags.Object))
939
+ return false;
940
+ const properties = checker.getPropertiesOfType(type);
941
+ return (properties.length > 0 &&
942
+ properties.every((property) => {
943
+ const name = property.getName();
944
+ return ((name === GUARANTEE_PROPERTY || name.startsWith(GUARANTEE_PREFIX)) &&
945
+ (property.flags & ts.SymbolFlags.Optional) !== 0);
946
+ }));
947
+ }
814
948
  /**
815
949
  * The guarantees every member of `type` states (`null` and `undefined` left out), sorted. A
816
950
  * member that states none makes the whole type state none.
@@ -829,6 +963,66 @@ function guaranteesOfType(checker, found) {
829
963
  }
830
964
  return [...new Set(shared ?? [])].sort();
831
965
  }
966
+ /**
967
+ * The literals of the `"__guarantee:<name>"` property of `type` (its first member that states it),
968
+ * without the `undefined` the optional property adds; undefined when no member states it.
969
+ */
970
+ function guaranteeValuesOfType(checker, found, name) {
971
+ const type = widened(checker, found);
972
+ if (type === undefined)
973
+ return undefined;
974
+ for (const member of type.isUnion() ? type.types : [type]) {
975
+ if (member.flags & NULLISH)
976
+ continue;
977
+ const property = checker.getPropertyOfType(member, `${GUARANTEE_PREFIX}${name}`);
978
+ if (property === undefined || !(property.flags & ts.SymbolFlags.Optional))
979
+ continue;
980
+ const value = checker.getTypeOfSymbol(property);
981
+ const literals = [];
982
+ for (const part of value.isUnion() ? value.types : [value]) {
983
+ if (part.flags & ts.TypeFlags.Undefined)
984
+ continue;
985
+ const literal = literalOf(checker, part);
986
+ if (literal === undefined)
987
+ return "not-finite";
988
+ literals.push(literal);
989
+ }
990
+ return literals.sort(compareLabels);
991
+ }
992
+ return undefined;
993
+ }
994
+ /**
995
+ * How a value of `type` is disposed, read from its well-known symbol methods: `[Symbol.dispose]`
996
+ * (`"sync"`), `[Symbol.asyncDispose]` (`"async"`), with the file that declares the method. Every
997
+ * member but `null` and `undefined` must have the same. `any` and `unknown` have neither.
998
+ */
999
+ function disposeOfType(checker, found) {
1000
+ const type = widened(checker, found);
1001
+ if (type === undefined || type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
1002
+ return undefined;
1003
+ }
1004
+ const members = (type.isUnion() ? type.types : [type]).filter((member) => (member.flags & NULLISH) === 0);
1005
+ const kindOf = (member) => {
1006
+ const properties = checker.getPropertiesOfType(member);
1007
+ for (const [prefix, kind] of [
1008
+ ["__@dispose@", "sync"],
1009
+ ["__@asyncDispose@", "async"],
1010
+ ]) {
1011
+ const property = properties.find((one) => String(one.escapedName).startsWith(prefix));
1012
+ const file = property?.declarations?.[0]?.getSourceFile().fileName;
1013
+ if (file !== undefined)
1014
+ return { kind, file };
1015
+ }
1016
+ return undefined;
1017
+ };
1018
+ const found2 = members.map(kindOf);
1019
+ const [first] = found2;
1020
+ if (first === undefined)
1021
+ return undefined;
1022
+ return found2.every((one) => one?.kind === first.kind && one.file === first.file)
1023
+ ? first
1024
+ : undefined;
1025
+ }
832
1026
  /** The declared type of a declaration: a variable's or property's type, or a type alias's. */
833
1027
  function declaredTypeOf(checker, declaration) {
834
1028
  const name = ts.isDeclarationStatement(declaration) || ts.isVariableDeclaration(declaration)
@@ -871,6 +1065,37 @@ function hasGenericKeys(checker, type) {
871
1065
  checker.getPropertiesOfType(part).length === 0 &&
872
1066
  checker.getIndexInfosOfType(part).length === 0);
873
1067
  }
1068
+ /**
1069
+ * Whether a mapped part of `type` takes its keys from a type that does not resolve:
1070
+ * `{ [k in keyof typeof NAMES]: … }` where `NAMES` comes from a package that is not installed.
1071
+ * TypeScript then gives it index signatures for every key, which says nothing about its keys.
1072
+ */
1073
+ function hasUnresolvedKeys(checker, type) {
1074
+ const parts = type.isIntersection() ? type.types : [type];
1075
+ return parts.some((part) => (part.getSymbol()?.declarations ?? []).some((declaration) => {
1076
+ if (!ts.isMappedTypeNode(declaration))
1077
+ return false;
1078
+ const constraint = declaration.typeParameter.constraint;
1079
+ if (constraint === undefined)
1080
+ return false;
1081
+ let unresolved = false;
1082
+ const visit = (node) => {
1083
+ if (unresolved)
1084
+ return;
1085
+ if (ts.isTypeNode(node) && isErrorTypeOf(checker.getTypeFromTypeNode(node))) {
1086
+ unresolved = true;
1087
+ return;
1088
+ }
1089
+ ts.forEachChild(node, visit);
1090
+ };
1091
+ visit(constraint);
1092
+ return unresolved;
1093
+ }));
1094
+ }
1095
+ /** TypeScript's error type: an `any` whose intrinsic name is "error"; it has no public flag. */
1096
+ function isErrorTypeOf(type) {
1097
+ return !!(type.flags & ts.TypeFlags.Any) && Reflect.get(type, "intrinsicName") === "error";
1098
+ }
874
1099
  function includesUndefined(type) {
875
1100
  const open = ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Undefined | ts.TypeFlags.Void;
876
1101
  return (type.isUnion() ? type.types : [type]).some((member) => (member.flags & open) !== 0);
@@ -1274,6 +1499,11 @@ export function idFileNames(root) {
1274
1499
  return name;
1275
1500
  };
1276
1501
  }
1502
+ /**
1503
+ * TypeScript's errors for a function whose end can be reached although it must return a value:
1504
+ * TS2366, TS2355, TS2534 and TS7030 (`TypeQueries.reportsReachableEnd`).
1505
+ */
1506
+ const REACHABLE_END_CODES = new Set([2366, 2355, 2534, 7030]);
1277
1507
  export function createTypeQueries(program, own,
1278
1508
  /** The project folder qualified ids are relative to. */
1279
1509
  root, packageOf, isEntry, dependenciesOf) {
@@ -1282,6 +1512,11 @@ root, packageOf, isEntry, dependenciesOf) {
1282
1512
  let created;
1283
1513
  const typeChecker = () => (created ??= program.getTypeChecker());
1284
1514
  const declarations = new Map();
1515
+ const declaredTraits = new Map();
1516
+ // The starts of TypeScript's "end of the function can be reached" errors, per file asked about.
1517
+ const reachableEndErrors = new WeakMap();
1518
+ let declaredDispose;
1519
+ let renamedNames;
1285
1520
  const idFileName = idFileNames(root);
1286
1521
  // symbolAt is asked about the same node by several rules (on excalidraw 570,000 questions about
1287
1522
  // 170,000 nodes, 52,000 symbols): the program does not change under these queries, so each
@@ -1346,8 +1581,9 @@ root, packageOf, isEntry, dependenciesOf) {
1346
1581
  }
1347
1582
  if (isArrayLike(typeChecker(), type))
1348
1583
  return "not-object";
1349
- if (hasGenericKeys(typeChecker(), type))
1584
+ if (hasGenericKeys(typeChecker(), type) || hasUnresolvedKeys(typeChecker(), type)) {
1350
1585
  return "generic";
1586
+ }
1351
1587
  const required = [];
1352
1588
  const optional = [];
1353
1589
  for (const property of typeChecker().getPropertiesOfType(type)) {
@@ -1473,6 +1709,90 @@ root, packageOf, isEntry, dependenciesOf) {
1473
1709
  const type = declaration === undefined ? undefined : declaredTypeOf(checker, declaration);
1474
1710
  return type === undefined ? [] : guaranteesOfType(checker, type);
1475
1711
  },
1712
+ contextualGuaranteesOf(node) {
1713
+ const checker = typeChecker();
1714
+ const type = checker.getContextualType(node);
1715
+ return type === undefined ? [] : guaranteesOfType(checker, type);
1716
+ },
1717
+ guaranteeValuesOf(target, name, contextual = false) {
1718
+ const checker = typeChecker();
1719
+ if ("kind" in target) {
1720
+ const type = contextual && ts.isExpression(target)
1721
+ ? checker.getContextualType(target)
1722
+ : checker.getTypeAtLocation(target);
1723
+ return type === undefined ? undefined : guaranteeValuesOfType(checker, type, name);
1724
+ }
1725
+ const declaration = declarations.get(target.id);
1726
+ const type = declaration === undefined ? undefined : declaredTypeOf(checker, declaration);
1727
+ return type === undefined ? undefined : guaranteeValuesOfType(checker, type, name);
1728
+ },
1729
+ contextualAliasOf(node) {
1730
+ const checker = typeChecker();
1731
+ const found = checker.getContextualType(node);
1732
+ const type = found === undefined ? undefined : widened(checker, found);
1733
+ if (type === undefined)
1734
+ return undefined;
1735
+ const aliasOf = (member) => member.aliasSymbol?.declarations?.some(ts.isTypeAliasDeclaration) === true &&
1736
+ (member.aliasTypeArguments?.length ?? 0) === 0
1737
+ ? member.aliasSymbol
1738
+ : undefined;
1739
+ const whole = aliasOf(type);
1740
+ if (whole !== undefined)
1741
+ return refOfSymbol(whole);
1742
+ const members = (type.isUnion() ? type.types : [type]).filter((member) => (member.flags & NULLISH) === 0);
1743
+ const aliases = new Set(members.map(aliasOf));
1744
+ const [only] = aliases;
1745
+ return aliases.size === 1 && only !== undefined ? refOfSymbol(only) : undefined;
1746
+ },
1747
+ bindingPropertyOf(element) {
1748
+ const pattern = element.parent;
1749
+ if (!ts.isObjectBindingPattern(pattern) || element.dotDotDotToken !== undefined) {
1750
+ return undefined;
1751
+ }
1752
+ const key = element.propertyName ?? element.name;
1753
+ if (!ts.isIdentifier(key) && !ts.isStringLiteral(key))
1754
+ return undefined;
1755
+ const checker = typeChecker();
1756
+ const property = checker.getTypeAtLocation(pattern).getProperty(key.text);
1757
+ return property === undefined ? undefined : refOfSymbol(property);
1758
+ },
1759
+ declaresDispose() {
1760
+ // The text is only a quick filter, as for markers: the member must be declared.
1761
+ declaredDispose ??= program
1762
+ .getSourceFiles()
1763
+ .some((file) => own.has(toTypeScriptPath(file.fileName)) &&
1764
+ (file.text.includes("Symbol.dispose") || file.text.includes("Symbol.asyncDispose")) &&
1765
+ declaresDisposeMember(file));
1766
+ return declaredDispose;
1767
+ },
1768
+ renamedBindings() {
1769
+ if (renamedNames === undefined) {
1770
+ const found = new Map();
1771
+ for (const file of program.getSourceFiles()) {
1772
+ if (own.has(toTypeScriptPath(file.fileName)))
1773
+ addRenamed(file, found);
1774
+ }
1775
+ renamedNames = found;
1776
+ }
1777
+ return renamedNames;
1778
+ },
1779
+ declaresTrait(name) {
1780
+ const known = declaredTraits.get(name);
1781
+ if (known !== undefined)
1782
+ return known;
1783
+ const text = `${GUARANTEE_PREFIX}${name}`;
1784
+ // The text is only a quick filter: the marker counts as a property of a type, never inside a
1785
+ // string or a comment (stateward's own packages quote it, and a project's program can
1786
+ // include them through its config file).
1787
+ const found = program
1788
+ .getSourceFiles()
1789
+ .some((file) => file.text.includes(text) && declaresMarkerProperty(file, text));
1790
+ declaredTraits.set(name, found);
1791
+ return found;
1792
+ },
1793
+ disposeOf(node) {
1794
+ return disposeOfType(typeChecker(), typeChecker().getTypeAtLocation(node));
1795
+ },
1476
1796
  awaitedAliasOf(node) {
1477
1797
  return aliasOfType(typeChecker(), typeChecker().getTypeAtLocation(node));
1478
1798
  },
@@ -1490,7 +1810,7 @@ root, packageOf, isEntry, dependenciesOf) {
1490
1810
  return undefined;
1491
1811
  if ((type?.aliasTypeArguments?.length ?? 0) > 0)
1492
1812
  return undefined;
1493
- return { name: alias.getName(), file: declaration.getSourceFile().fileName };
1813
+ return { name: alias.getName(), file: declaration.getSourceFile().fileName, declaration };
1494
1814
  },
1495
1815
  importSpecifierFor(alias, fromFile) {
1496
1816
  const from = toTypeScriptPath(fromFile);
@@ -1642,6 +1962,23 @@ root, packageOf, isEntry, dependenciesOf) {
1642
1962
  signalParameterOf(call) {
1643
1963
  return signalParameter(typeChecker(), call);
1644
1964
  },
1965
+ reportsReachableEnd(fn) {
1966
+ const body = fn.body;
1967
+ if (body === undefined)
1968
+ return false;
1969
+ const sourceFile = fn.getSourceFile();
1970
+ let starts = reachableEndErrors.get(sourceFile);
1971
+ if (starts === undefined) {
1972
+ starts = program
1973
+ .getSemanticDiagnostics(sourceFile)
1974
+ .filter((diagnostic) => REACHABLE_END_CODES.has(diagnostic.code))
1975
+ .flatMap((diagnostic) => (diagnostic.start === undefined ? [] : [diagnostic.start]));
1976
+ reachableEndErrors.set(sourceFile, starts);
1977
+ }
1978
+ const from = fn.getStart(sourceFile);
1979
+ const to = body.getStart(sourceFile);
1980
+ return starts.some((start) => start >= from && start < to);
1981
+ },
1645
1982
  narrowedBy(reference, test) {
1646
1983
  return narrowedMembers(program, typeChecker(), reference, test);
1647
1984
  },
@@ -1652,9 +1989,7 @@ root, packageOf, isEntry, dependenciesOf) {
1652
1989
  return predicate === undefined ? undefined : call.arguments[predicate.parameterIndex];
1653
1990
  },
1654
1991
  isErrorType(node) {
1655
- // TypeScript's error type is an `any` whose intrinsic name is "error"; it has no public flag.
1656
- const type = typeChecker().getTypeAtLocation(node);
1657
- return !!(type.flags & ts.TypeFlags.Any) && Reflect.get(type, "intrinsicName") === "error";
1992
+ return isErrorTypeOf(typeChecker().getTypeAtLocation(node));
1658
1993
  },
1659
1994
  isPromiseLike(node) {
1660
1995
  return isPromiseType(typeChecker(), typeChecker().getTypeAtLocation(node));
package/dist/baseline.js CHANGED
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { limitFindings } from "./engine.js";
5
+ import { renamedRule } from "./renamed.js";
5
6
  export const BASELINE_FILE = "stateward.baseline.json";
6
7
  /**
7
8
  * Version 2 fingerprints a finding by its rule, file and code only, so rewording a message never
@@ -246,6 +247,15 @@ function parseEntry(value, file, version) {
246
247
  entryFile,
247
248
  typeof fingerprint === "string" ? fingerprint : "",
248
249
  ]);
250
+ // An entry of a renamed rule: its fingerprint hashed the old id, so it is matched by rule and
251
+ // file, under the new id, until the next `baseline` writes it again.
252
+ const renamed = renamedRule(ruleId);
253
+ if (renamed !== undefined) {
254
+ return {
255
+ entry: { kind: "legacy", ruleId: renamed, file: entryFile, message, count },
256
+ key: raw,
257
+ };
258
+ }
249
259
  if (!old && typeof fingerprint === "string") {
250
260
  return {
251
261
  entry: { kind: "fingerprint", ruleId, file: entryFile, fingerprint, message, count },
package/dist/checker.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createBackend, toTypeScriptPath } from "./backend/typescript6.js";
2
2
  import { emptyCache } from "./cache.js";
3
3
  import { reviewFixes, verifyFixSet } from "./fixes.js";
4
+ import { legacyMarkerRewrite } from "./guarantee-markers.js";
4
5
  import { drain, filePhaseRun, needsJsDoc, projectPhaseSteps, projectRuleIds, runFileRules, silentReasons, } from "./engine.js";
5
6
  /** The default slice: short against the editor's 200 ms budget, long against a pause's cost. */
6
7
  export const SLICE_MS = 20;
@@ -170,13 +171,18 @@ export function createChecker({ config, cwd, rules = { kind: "configured" }, cac
170
171
  const found = lookup(file);
171
172
  if (found === undefined)
172
173
  return [];
173
- const offered = config.plugins.flatMap((plugin) => plugin.editor?.codeActions?.({
174
- file,
175
- start,
176
- end,
177
- ...found,
178
- projectSummaries: (ruleId) => summaries.get(ruleId)?.(),
179
- }) ?? []);
174
+ const rewrite = legacyMarkerRewrite(found.sourceFile, start, end);
175
+ const offered = [
176
+ ...config.plugins.flatMap((plugin) => plugin.editor?.codeActions?.({
177
+ file,
178
+ start,
179
+ end,
180
+ ...found,
181
+ projectSummaries: (ruleId) => summaries.get(ruleId)?.(),
182
+ }) ?? []),
183
+ // Core reads both marker forms, so it offers the rewrite itself: the markers are no pack's.
184
+ ...(rewrite === undefined ? [] : [rewrite]),
185
+ ];
180
186
  // A finding only to reuse the fix review: it is never reported.
181
187
  const findings = offered.map((action) => ({
182
188
  kind: "problem",
@@ -1,6 +1,12 @@
1
1
  import type { Config, ParseResult } from "./types.js";
2
2
  /** The path of the config file in `cwd`, if there is one. */
3
3
  export declare function findConfigFile(cwd: string): string | undefined;
4
+ /**
5
+ * One warning per other config file in the folder of `configFile`, when `configFile` is the one
6
+ * the search picks (`CONFIG_FILE_NAMES` order): the others are never read. A config named with
7
+ * `--config` is a choice, and gets none.
8
+ */
9
+ export declare function ignoredConfigWarnings(configFile: string): readonly string[];
4
10
  /**
5
11
  * What went wrong while loading the config file, and what to do: a package it imports that is not
6
12
  * installed, or a syntax error, each in one or two lines; any other failure keeps its own message.
@@ -7,12 +7,25 @@ import { MessageChannel } from "node:worker_threads";
7
7
  import { createJiti } from "jiti";
8
8
  import { configLocalImports, foreignTypeScriptWarnings } from "./implementation.js";
9
9
  import { parseConfig } from "./config.js";
10
+ import { renamedIdsIn } from "./renamed.js";
10
11
  import { RuleDeclarationError, RuleLoadError, loadRules } from "./lazy.js";
11
12
  import { CONFIG_FILE_NAMES, CONFIG_FILE_PATTERN } from "./vocabulary.js";
12
13
  /** The path of the config file in `cwd`, if there is one. */
13
14
  export function findConfigFile(cwd) {
14
15
  return CONFIG_FILE_NAMES.map((name) => path.join(cwd, name)).find((file) => existsSync(file));
15
16
  }
17
+ /**
18
+ * One warning per other config file in the folder of `configFile`, when `configFile` is the one
19
+ * the search picks (`CONFIG_FILE_NAMES` order): the others are never read. A config named with
20
+ * `--config` is a choice, and gets none.
21
+ */
22
+ export function ignoredConfigWarnings(configFile) {
23
+ const dir = path.dirname(configFile);
24
+ if (findConfigFile(dir) !== configFile)
25
+ return [];
26
+ const used = path.basename(configFile);
27
+ return CONFIG_FILE_NAMES.filter((name) => name !== used && existsSync(path.join(dir, name))).map((name) => `\`${name}\` is ignored: \`${used}\` in the same folder is the config used; delete the one not wanted`);
28
+ }
16
29
  /**
17
30
  * What went wrong while loading the config file, and what to do: a package it imports that is not
18
31
  * installed, or a syntax error, each in one or two lines; any other failure keeps its own message.
@@ -203,7 +216,9 @@ export async function loadConfigFile(configFile) {
203
216
  errors: [`${name} must export the config: export default defineConfig({ ... })`],
204
217
  };
205
218
  }
206
- const parsed = parseConfig(exported, path.dirname(configFile));
219
+ // The first line that names each old rule id, for the notice that says where to rename it.
220
+ const places = renamedIdsIn(readFileSync(configFile, "utf8"));
221
+ const parsed = parseConfig(exported, path.dirname(configFile), path.basename(configFile), (id) => places.find((place) => place.before === id)?.line);
207
222
  if (!parsed.ok)
208
223
  return { ok: false, errors: parsed.errors.map((e) => `${configFile}: ${e}`) };
209
224
  // The rules that are on are loaded now, so a check can run them; the rest never load.
@@ -216,7 +231,11 @@ export async function loadConfigFile(configFile) {
216
231
  }
217
232
  throw error;
218
233
  }
219
- const warnings = [...parsed.value.warnings, ...foreignTypeScriptWarnings(configFile)];
234
+ const warnings = [
235
+ ...ignoredConfigWarnings(configFile),
236
+ ...parsed.value.warnings,
237
+ ...foreignTypeScriptWarnings(configFile),
238
+ ];
220
239
  return { ok: true, value: { ...parsed.value, warnings, configFile } };
221
240
  }
222
241
  //# sourceMappingURL=config-file.js.map
package/dist/config.d.ts CHANGED
@@ -19,5 +19,7 @@ export declare function isMaxMemory(value: unknown): value is number;
19
19
  * Validates untrusted config input once. `tsconfig` is resolved against `configDir`, so the
20
20
  * returned value holds absolute paths (and absolute globs).
21
21
  */
22
- export declare function parseConfig(given: unknown, configDir: string): ParseResult<Config>;
22
+ export declare function parseConfig(given: unknown, configDir: string, configName?: string,
23
+ /** The line the config file names an old rule id on, so the notice says where to rename it. */
24
+ lineOf?: (id: string) => number | undefined): ParseResult<Config>;
23
25
  //# sourceMappingURL=config.d.ts.map