-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.task.ts
More file actions
39 lines (33 loc) · 1.25 KB
/
lint.task.ts
File metadata and controls
39 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {args_serialize} from '@fuzdev/fuz_util/args.js';
import {print_spawn_result} from '@fuzdev/fuz_util/process.js';
import {z} from 'zod';
import {to_forwarded_args} from './args.ts';
import {find_cli, spawn_cli} from './cli.ts';
import {TaskError, type Task} from './task.ts';
const ESLINT_CLI = 'eslint';
/** @nodocs */
export const Args = z.strictObject({
_: z.array(z.string()).meta({description: 'paths to serve'}).default([]),
eslint_cli: z.string().meta({description: 'the ESLint CLI to use'}).default(ESLINT_CLI),
});
export type Args = z.infer<typeof Args>;
/** @nodocs */
export const task: Task<Args> = {
summary: 'run eslint',
Args,
run: async ({log, args}): Promise<void> => {
const {_, eslint_cli} = args;
const found_eslint_cli = await find_cli(eslint_cli);
if (!found_eslint_cli) {
// TODO maybe make this an option?
log.info('ESLint is not installed; skipping linting');
return;
}
const forwarded_args = {_, 'max-warnings': 0, ...to_forwarded_args(eslint_cli)};
const serialized_args = args_serialize(forwarded_args);
const eslintResult = await spawn_cli(found_eslint_cli, serialized_args, log);
if (!eslintResult?.ok) {
throw new TaskError(`ESLint found some problems. ${print_spawn_result(eslintResult!)}`);
}
},
};