Skip to content

Commit a5351f2

Browse files
committed
feat: add unsafe mode
1 parent 92d9e97 commit a5351f2

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

Diff for: src/biome.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,21 @@ const convertBiomeResult = (
108108
};
109109
};
110110

111-
const biomeLintFile = async (biome: Biome, filePath: string, fix = true) => {
111+
const biomeLintFile = async (
112+
biome: Biome,
113+
filePath: string,
114+
fix = true,
115+
unsafe = false,
116+
) => {
112117
const initialContent = await readFile(filePath, "utf8");
113118

114119
const result = biome.lintContent(initialContent, {
115120
filePath,
116-
fixFileMode: fix ? "SafeFixes" : undefined,
121+
fixFileMode: fix
122+
? unsafe
123+
? "SafeAndUnsafeFixes"
124+
: "SafeFixes"
125+
: undefined,
117126
});
118127

119128
if (fix) {
@@ -132,13 +141,14 @@ const biomeLintFile = async (biome: Biome, filePath: string, fix = true) => {
132141
const biomeLintFiles = async (
133142
biome: Biome,
134143
files: string[],
135-
fix = true,
136144
concurrency: number = os.cpus().length,
145+
fix = true,
146+
unsafe = false,
137147
) => {
138148
const limit = pLimit(concurrency);
139149
const results = await Promise.all(
140150
files.map((file) =>
141-
limit(async () => await biomeLintFile(biome, file, fix)),
151+
limit(async () => await biomeLintFile(biome, file, fix, unsafe)),
142152
),
143153
);
144154

@@ -229,6 +239,7 @@ export const lintWithBiome = async (
229239
concurrency: number = os.cpus().length,
230240
fix = true,
231241
debug = false,
242+
unsafe = false,
232243
) => {
233244
if (debug) {
234245
performance.mark("biome-start");
@@ -240,7 +251,13 @@ export const lintWithBiome = async (
240251

241252
biome.applyConfiguration(getBiomeConfig());
242253

243-
const biomeResults = await biomeLintFiles(biome, files, fix, concurrency);
254+
const biomeResults = await biomeLintFiles(
255+
biome,
256+
files,
257+
concurrency,
258+
fix,
259+
unsafe,
260+
);
244261

245262
if (debug) {
246263
performance.mark("biome-end");

Diff for: src/index.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ const instance = yargs(hideBin(process.argv))
4343
description:
4444
"Number of concurrent linting processes (default: number of CPU cores)",
4545
})
46+
.option("unsafe", {
47+
type: "boolean",
48+
default: false,
49+
description: "Allow unsafe fixes",
50+
})
4651
.help(),
4752
async (args) => {
53+
const { files: files_, fix, debug, concurrency, unsafe } = args;
4854
try {
49-
const { files: files_, fix, debug, concurrency } = args;
5055
const patterns = Array.isArray(files_) ? files_ : [files_];
5156

5257
const eslint = new ESLint({
@@ -71,6 +76,7 @@ const instance = yargs(hideBin(process.argv))
7176
concurrency,
7277
fix,
7378
debug,
79+
unsafe,
7480
);
7581

7682
const resultText = await formatter.format(
@@ -86,7 +92,16 @@ const instance = yargs(hideBin(process.argv))
8692
}
8793
}
8894
} catch (error) {
89-
console.error(error);
95+
if (debug) {
96+
console.error(error);
97+
} else {
98+
console.error(
99+
"An error occurred during linting:",
100+
(error as Error).message,
101+
);
102+
console.error("Run with --debug for more information");
103+
}
104+
90105
process.exit(1);
91106
}
92107
},

0 commit comments

Comments
 (0)