Skip to content

Commit 2da1d8a

Browse files
committed
Add ignore option
1 parent db472d8 commit 2da1d8a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ You will also need to install `typescript` for building and `vitest` for testing
5353
Configuration can get specified in your `package.json` file under `ts-scripts`:
5454

5555
- `src` - An array of source directories used for `format` and `lint` (default: `["src"]`)
56+
- `ignore` - An array of patterns to ignore for `format` and `lint` (default: `[]`)
5657
- `dist` - An array of output directories to clean before `build` (default: `["dist"]`)
5758
- `project` An array of `tsconfig.json` project files to build using TypeScript (default: `["tsconfig.json"]`)
59+
- `checkProject` An array of `tsconfig.json` project files to type check using TypeScript (default: `["tsconfig.json"]`)
5860
- `test` An array of test configuration objects (default: `[{}]`)
5961
- `dir` The directory to read tests from (default: `undefined`, root directory)
6062
- `config` The configuration file to use for this test (default: `undefined`, discovered by `vitest`)
61-
- `project` The `tsconfig.json` project file to use for type checking (default: `"tsconfig.json"`)
6263

6364
Specific configuration can be disabled for customized configuration by setting `src`, `dist`, `project`, or `test` to an empty array.
6465

src/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { findUp } from "find-up";
1313
export interface Test {
1414
dir: string | undefined;
1515
config: string | undefined;
16-
project: string;
1716
}
1817

1918
/**
@@ -23,8 +22,10 @@ export interface Config {
2322
debug: boolean;
2423
dir: string;
2524
src: string[];
25+
ignore: string[];
2626
dist: string[];
2727
project: string[];
28+
checkProject: string[];
2829
test: Test[];
2930
}
3031

@@ -235,7 +236,12 @@ export async function lint(argv: string[], config: Config) {
235236
const eslintPaths = getEslintPaths(paths, filterPaths, config);
236237
await run(
237238
await PATHS.eslint(),
238-
args(!check && "--fix", ["--config", getEslintConfig()], eslintPaths),
239+
args(
240+
!check && "--fix",
241+
["--config", getEslintConfig()],
242+
config.ignore.flatMap((ignore) => ["--ignore-pattern", ignore]),
243+
eslintPaths
244+
),
239245
{
240246
name: "eslint",
241247
config,
@@ -251,7 +257,7 @@ export async function check(argv: string[], config: Config) {
251257
await format(["--check"], config);
252258

253259
// Type check with typescript.
254-
for (const { project } of config.test) {
260+
for (const project of config.checkProject) {
255261
await run(await PATHS.typescript(), ["--noEmit", "--project", project], {
256262
name: `tsc --noEmit --project ${project}`,
257263
config,
@@ -362,6 +368,10 @@ export async function format(argv: string[], config: Config) {
362368
}
363369
}
364370

371+
for (const ignore of config.ignore) {
372+
paths.push(`!${ignore}`);
373+
}
374+
365375
const [prettierPath, prettierPluginPackage] = await Promise.all([
366376
PATHS.prettier(),
367377
PATHS.prettierPluginPackage(),
@@ -436,6 +446,7 @@ const arrayify = <T>(value: T | T[]) => {
436446
const configSchema = object({
437447
debug: boolean().optional(),
438448
src: arrayifySchema(string()).optional(),
449+
ignore: arrayifySchema(string()).optional(),
439450
dist: arrayifySchema(string()).optional(),
440451
project: arrayifySchema(string()).optional(),
441452
test: arrayifySchema(
@@ -458,12 +469,13 @@ export async function getConfig(cwd: string): Promise<Config> {
458469
debug: schema.debug ?? false,
459470
dir: dirname(packageJsonPath(config) ?? cwd),
460471
src: arrayify(schema.src ?? "src"),
472+
ignore: arrayify(schema.ignore ?? []),
461473
dist: arrayify(schema.dist ?? "dist"),
462474
project: arrayify(schema.project ?? "tsconfig.json"),
475+
checkProject: arrayify(schema.project ?? "tsconfig.json"),
463476
test: arrayify(schema.test ?? {}).map((testSchema) => ({
464477
dir: testSchema.dir,
465478
config: testSchema.config,
466-
project: testSchema.project ?? "tsconfig.json",
467479
})),
468480
};
469481
}

0 commit comments

Comments
 (0)