Fix and add tests for fix decisions - fixes
MODIFY
internal/compiler/lib/CompilerContext.ts
internal/compiler/lib/CompilerContext.ts
@@ -229,7 +229,7 @@ export default class CompilerContext {
public reduceRoot(
visitors: AnyVisitor | AnyVisitors,
- pathOpts?: PathOptions,
+ ast: AnyRoot = this.ast,
): AnyRoot {
if (this.reducedRoot) {
throw new Error("reduceRoot has already been called");
@@ -237,7 +237,7 @@ export default class CompilerContext {
const node = assertSingleNode(
reduceNode(
- this.ast,
+ ast,
[
createSuppressionsVisitor(),
...helperVisitors,
@@ -245,7 +245,6 @@ export default class CompilerContext {
...(Array.isArray(visitors) ? visitors : [visitors]),
],
this,
- pathOpts,
),
);
if (!isRoot(node)) {

ADD
internal/compiler/lint/decisions.test.md
+# `decisions.test.ts`
+
+**DO NOT MODIFY**. This file has been autogenerated. Run `rome test internal/compiler/lint/decisions.test.ts --update-snapshots` to update.
+
+## `apply single autofix`
+
+```
+let foo;
+foo === "bar";
+
+```

ADD
internal/compiler/lint/decisions.test.ts
+import {test} from "rome";
+import {dedent} from "@internal/string-utils";
+import {parseDecisionStrings} from "@internal/compiler";
+import {createAbsoluteFilePath} from "@internal/path";
+import lint from "./index";
+import {parseJS} from "@internal/js-parser";
+import {createDefaultProjectConfig} from "@internal/project";
+
+test(
+ "apply single autofix",
+ async (t) => {
+ const {lintCompilerOptionsPerFile} = parseDecisionStrings(
+ ["fix-lint/js/doubleEquals-foo.ts-2:0-0"],
+ createAbsoluteFilePath("/"),
+ () => {},
+ );
+ const compilerOptions = lintCompilerOptionsPerFile["/foo.ts"];
+
+ const sourceText = dedent`
+ let foo;
+ foo == "bar";
+ `;
+
+ const res = await lint({
+ applySafeFixes: true,
+ project: {
+ directory: undefined,
+ config: createDefaultProjectConfig(),
+ },
+ options: {
+ lint: compilerOptions,
+ },
+ sourceText,
+ ast: parseJS({path: "unknown", input: sourceText}),
+ });
+ t.is(res.diagnostics.length, 1);
+ t.snapshot(res.src);
+ },
+);

MODIFY
internal/compiler/lint/suppressions.ts
internal/compiler/lint/suppressions.ts
@@ -102,7 +102,8 @@ export function addSuppressions(context: CompilerContext, ast: AnyRoot): AnyRoot
}
// Find the best node to attach comments to. This is generally the node with the largest range per line.
- return context.reduceRoot({
+ return context.reduceRoot(
+ {
name: "suppressionVisitor",
enter(path) {
const {node} = path;
@@ -129,5 +130,7 @@ export function addSuppressions(context: CompilerContext, ast: AnyRoot): AnyRoot
visitedLines.add(line);
return signals.replace(addComment(path, node, decisions));
},
- });
+ },
+ ast,
+ );
}

Fix and add tests for fix decisions - fixes #932 (#948)