void;
enabledLinting: boolean;
setEnabledLinting: (value: boolean) => void;
+ analyzerFixMode: FixFileMode;
+ setAnalyzerFixMode: (value: FixFileMode) => void;
}) {
return (
<>
@@ -833,6 +845,21 @@ function LinterSettings({
+
+
+
+
>
);
diff --git a/src/playground/types.ts b/src/playground/types.ts
index 39cbcd185..64cb1ce3d 100644
--- a/src/playground/types.ts
+++ b/src/playground/types.ts
@@ -1,4 +1,4 @@
-import type { Diagnostic } from "@biomejs/wasm-web";
+import type { Diagnostic, FixFileMode } from "@biomejs/wasm-web";
import type { parser } from "codemirror-lang-rome-ast";
import type { Dispatch, SetStateAction } from "react";
@@ -12,6 +12,7 @@ export enum PlaygroundTab {
ImportSorting = "import-sorting",
Console = "console",
Settings = "settings",
+ AnalyzerFixes = "analyzer-fixes",
}
export type { Options as PrettierOptions } from "prettier";
@@ -92,6 +93,8 @@ export interface BiomeOutput {
};
analysis: {
controlFlowGraph: string;
+ /** The snippet with lint fixes applied. */
+ fixed: string;
};
importSorting: {
code: string;
@@ -113,6 +116,7 @@ export const emptyBiomeOutput: BiomeOutput = {
},
analysis: {
controlFlowGraph: "",
+ fixed: "",
},
importSorting: {
code: "",
@@ -134,6 +138,7 @@ export interface PlaygroundSettings {
bracketSameLine: boolean;
lintRules: LintRules;
enabledLinting: boolean;
+ analyzerFixMode: FixFileMode;
importSortingEnabled: boolean;
unsafeParameterDecoratorsEnabled: boolean;
allowComments: boolean;
@@ -181,6 +186,7 @@ export const defaultPlaygroundState: PlaygroundState = {
bracketSameLine: false,
lintRules: LintRules.Recommended,
enabledLinting: true,
+ analyzerFixMode: "SafeFixes",
importSortingEnabled: true,
unsafeParameterDecoratorsEnabled: true,
allowComments: true,
diff --git a/src/playground/workers/biomeWorker.ts b/src/playground/workers/biomeWorker.ts
index f271f3f79..dffc44507 100644
--- a/src/playground/workers/biomeWorker.ts
+++ b/src/playground/workers/biomeWorker.ts
@@ -31,6 +31,7 @@ type File = {
const files: Map = new Map();
let configuration: undefined | Configuration;
+let fullSettings: undefined | PlaygroundSettings;
function getPathForFile(file: File): BiomePath {
return {
@@ -72,6 +73,8 @@ self.addEventListener("message", async (e) => {
break;
}
+ fullSettings = e.data.settings;
+
const {
lineWidth,
indentStyle,
@@ -302,6 +305,28 @@ self.addEventListener("message", async (e) => {
};
}
+ let fixed = {
+ code: "",
+ };
+ try {
+ fixed =
+ fileFeatures.features_supported.get("Lint") === "Supported"
+ ? workspace.fixFile({
+ path,
+ only: [],
+ skip: [],
+ rule_categories: ["Lint"],
+ should_format: false,
+ fix_file_mode: fullSettings?.analyzerFixMode ?? "SafeFixes",
+ })
+ : { code: "Not supported" };
+ } catch (e) {
+ console.error(e);
+ fixed = {
+ code: "Can't apply fixes with errors",
+ };
+ }
+
const biomeOutput: BiomeOutput = {
syntax: {
// Replace 4 spaced indentation with 2
@@ -319,6 +344,7 @@ self.addEventListener("message", async (e) => {
},
analysis: {
controlFlowGraph,
+ fixed: fixed.code,
},
importSorting: {
code: importSorting.code,