Skip to content

Commit e7ac94c

Browse files
committed
feat: ignore resolutions option
Add option to ignore resolution modes such as `Node10`. Via config: `ignoreResolutions` Via cli: `--ignoreResolutions` Option to skip validation for Node10 #112
1 parent 93912ad commit e7ac94c

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

.changeset/fuzzy-cats-shed.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/core": minor
3+
---
4+
5+
Add --ignore-resolutions cli option. Example: --ignore-resolutions node10

packages/cli/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ attw <file-name> --ignore-rules <rules...>
181181

182182
In the config file, `ignoreRules` can be an array of strings.
183183

184+
#### Ignore Resolutions
185+
186+
Specifies resolution modes to ignore (i.e. do not evaluate).
187+
188+
The available values are:
189+
190+
- `node10`
191+
- `node16-cjs`
192+
- `node16-esm`
193+
- `bundler`
194+
195+
In the CLI: `--ignore-resolutions`
196+
197+
```shell
198+
attw <file-name> --ignore-resolutions <resolutions...>
199+
```
200+
201+
In the config file, `ignoreResolutions` can be an array of strings.
202+
184203
#### Summary/No Summary
185204

186205
Whether to display a summary of what the different errors/problems mean. Defaults to showing the summary (`--summary`).

packages/cli/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { readFile, stat, unlink } from "fs/promises";
1010
import { createRequire } from "module";
1111
import path from "path";
1212
import readline from "readline";
13-
import { problemFlags } from "./problemUtils.js";
13+
import { problemFlags, resolutionKinds } from "./problemUtils.js";
1414
import { readConfig } from "./readConfig.js";
1515
import * as render from "./render/index.js";
1616
import { major, minor } from "semver";
@@ -80,6 +80,11 @@ particularly ESM-related module resolution issues.`,
8080
.addOption(
8181
new Option("--ignore-rules <rules...>", "Specify rules to ignore").choices(Object.values(problemFlags)).default([]),
8282
)
83+
.addOption(
84+
new Option("--ignore-resolutions <resolutions...>", "Specify resolutions to ignore")
85+
.choices(Object.keys(resolutionKinds))
86+
.default([]),
87+
)
8388
.option("--summary, --no-summary", "Whether to print summary information about the different errors")
8489
.option("--emoji, --no-emoji", "Whether to use any emojis")
8590
.option("--color, --no-color", "Whether to use any colors (the FORCE_COLOR env variable is also available)")

packages/cli/src/readConfig.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command } from "commander";
22
import { readFile } from "fs/promises";
3-
import { problemFlags } from "./problemUtils.js";
3+
import { problemFlags, resolutionKinds } from "./problemUtils.js";
44

55
export async function readConfig(program: Command, alternate = ".attw.json") {
66
try {
@@ -25,6 +25,17 @@ export async function readConfig(program: Command, alternate = ".attw.json") {
2525
);
2626
}
2727

28+
if (key === "ignoreResolutions") {
29+
if (!Array.isArray(value)) program.error(`error: config option 'ignoreResolutions' should be an array.`);
30+
const invalid = value.find((resolution) => !Object.keys(resolutionKinds).includes(resolution));
31+
if (invalid)
32+
program.error(
33+
`error: config option 'ignoreResolutions' argument '${invalid}' is invalid. Allowed choices are ${Object.keys(
34+
resolutionKinds,
35+
).join(", ")}.`,
36+
);
37+
}
38+
2839
if (Array.isArray(value)) {
2940
const opt = program.getOptionValue(key);
3041

packages/cli/src/render/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type { problemFlags } from "../problemUtils.js";
1+
import type { problemFlags, resolutionKinds } from "../problemUtils.js";
22

33
export type Format = "auto" | "table" | "table-flipped" | "ascii" | "json";
44
export interface RenderOptions {
55
ignoreRules?: (typeof problemFlags)[keyof typeof problemFlags][];
6+
ignoreResolutions?: (keyof typeof resolutionKinds)[];
67
format?: Format;
78
color?: boolean;
89
summary?: boolean;

packages/cli/src/render/typed.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import type { RenderOptions } from "./index.js";
1111

1212
export async function typed(
1313
analysis: core.Analysis,
14-
{ emoji = true, summary = true, format = "auto", ignoreRules = [] }: RenderOptions,
14+
{ emoji = true, summary = true, format = "auto", ignoreRules = [], ignoreResolutions = [] }: RenderOptions,
1515
): Promise<string> {
1616
let output = "";
1717
const problems = analysis.problems.filter(
1818
(problem) => !ignoreRules || !ignoreRules.includes(problemFlags[problem.kind]),
1919
);
20+
const resolutions = allResolutionKinds.filter((kind) => !ignoreResolutions.includes(kind));
2021
const grouped = groupProblemsByKind(problems);
2122
const entrypoints = Object.keys(analysis.entrypoints);
2223
marked.setOptions({
@@ -43,6 +44,11 @@ export async function typed(
4344
if (ignoreRules && ignoreRules.length) {
4445
out(chalk.gray(` (ignoring rules: ${ignoreRules.map((rule) => `'${rule}'`).join(", ")})\n`));
4546
}
47+
if (ignoreResolutions && ignoreResolutions.length) {
48+
out(
49+
chalk.gray(` (ignoring resolutions: ${ignoreResolutions.map((resolution) => `'${resolution}'`).join(", ")})\n`),
50+
);
51+
}
4652

4753
if (summary) {
4854
const defaultSummary = marked(!emoji ? " No problems found" : " No problems found 🌟");
@@ -93,14 +99,14 @@ export async function typed(
9399
const flippedTable =
94100
format === "auto" || format === "table-flipped"
95101
? new Table({
96-
head: ["", ...allResolutionKinds.map((kind) => chalk.reset(resolutionKinds[kind]))],
102+
head: ["", ...resolutions.map((kind) => chalk.reset(resolutionKinds[kind]))],
97103
})
98104
: undefined;
99105
if (flippedTable) {
100106
entrypoints.forEach((subpath, i) => {
101107
flippedTable.push([
102108
entrypointHeaders[i],
103-
...allResolutionKinds.map((resolutionKind) => getCellContents(subpath, resolutionKind)),
109+
...resolutions.map((resolutionKind) => getCellContents(subpath, resolutionKind)),
104110
]);
105111
});
106112
}
@@ -112,7 +118,7 @@ export async function typed(
112118
}) as GenericTable<HorizontalTableRow>)
113119
: undefined;
114120
if (table) {
115-
allResolutionKinds.forEach((kind) => {
121+
resolutions.forEach((kind) => {
116122
table.push([resolutionKinds[kind], ...entrypoints.map((entrypoint) => getCellContents(entrypoint, kind))]);
117123
});
118124
}

0 commit comments

Comments
 (0)