From 5598951281d656b7c294fe6f0d0bfc733feb9007 Mon Sep 17 00:00:00 2001 From: alexander-akait <4567934+alexander-akait@users.noreply.github.com> Date: Tue, 8 Sep 2026 10:03:23 +0000 Subject: [PATCH] refactor!: fold quiet into reportAs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `reportAs` says what a check reports its results as. One value covers its errors and its warnings alike, an object sets them apart, and a severity the object leaves out keeps its own: reportAs: "warning" // nothing fails the build reportAs: { warnings: false } // the errors alone (was quiet: true) reportAs: { warnings: "error" } // warnings fail it too reportAs: false // nothing is reported Each severity independently becomes an error, a warning or nothing, so the nine states that gives are the whole space, and every option this replaces has a spelling: `emitError: false` is `{ errors: false }` and `failOnWarning: true` is `{ warnings: "error" }`, neither of which the scalar alone could say. A partial object reading its missing severity from the default is what keeps the common cases short — naming the warnings says nothing about the errors. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01GzZci4NQeiqwdrVfd7dGXy --- .changeset/fold-quiet-into-report-as.md | 5 ++ README.md | 58 +++++++--------- src/check.js | 17 +++-- src/checks/index.js | 2 +- src/index.js | 30 ++++----- src/options.js | 25 ++++++- src/shared-options.json | 26 ++++++-- test/eslint-options.test.js | 1 - test/quiet.test.js | 22 ------- test/report-as.test.js | 84 ++++++++++++++---------- test/stylelint/quiet.test.js | 20 ------ test/stylelint/report-as.test.js | 22 ++++--- test/stylelint/stylelint-options.test.js | 1 - test/unified/unified.test.js | 8 +-- types/checks/index.d.ts | 4 +- types/options.d.ts | 24 +++++-- 16 files changed, 178 insertions(+), 171 deletions(-) create mode 100644 .changeset/fold-quiet-into-report-as.md delete mode 100644 test/quiet.test.js delete mode 100644 test/stylelint/quiet.test.js diff --git a/.changeset/fold-quiet-into-report-as.md b/.changeset/fold-quiet-into-report-as.md new file mode 100644 index 0000000..8cb6b23 --- /dev/null +++ b/.changeset/fold-quiet-into-report-as.md @@ -0,0 +1,5 @@ +--- +"diagnostics-webpack-plugin": major +--- + +`quiet` is gone: `reportAs` says what a check reports its results as, one value covering its errors and its warnings alike and an object setting them apart, so `quiet: true` is `reportAs: { warnings: false }`. diff --git a/README.md b/README.md index 2d51301..29c5764 100644 --- a/README.md +++ b/README.md @@ -235,49 +235,38 @@ See the [ESLint formatters](https://eslint.org/docs/user-guide/formatters/) and ### Errors and warnings -Every check reports its errors as webpack errors and its warnings as webpack warnings, which is what fails the build. `reportAs` overrides that, and `quiet` drops the warnings. +Every check reports its errors as webpack errors and its warnings as webpack warnings, which is what fails the build. `reportAs` overrides that. #### `reportAs` - Type: ```ts -type reportAs = "error" | "warning" | false; +type reportAs = Severity | { errors?: Severity; warnings?: Severity }; +type Severity = "error" | "warning" | false; ``` - Default: unset — each result stays at the severity the check gave it -What a check reports its results as. Left unset, an error is a webpack error and a warning a webpack warning; naming one severity reports every result as that one, and `false` reports nothing. +What a check reports its results as. One value covers its errors and its warnings alike; an object sets them apart, and a severity the object leaves out keeps its own: -| Value | Effect | -| :---------- | :-------------------------------------------------------- | -| unset | Errors fail the build, warnings do not. | -| `"error"` | Everything fails the build, warnings included. | -| `"warning"` | Nothing fails the build; errors are reported as warnings. | -| `false` | Nothing is reported. An `outputReport` is still written. | - -Together with [`quiet`](#quiet), which drops the warnings before any of this, that covers reporting and failing in one option: +| Value | Effect | +| :---------------------- | :--------------------------------------------------------- | +| unset | Errors fail the build, warnings do not. | +| `"error"` | Everything fails the build, warnings included. | +| `"warning"` | Nothing fails the build; errors are reported as warnings. | +| `false` | Nothing is reported. An `outputReport` is still written. | +| `{ warnings: false }` | The errors alone, still failing the build. | +| `{ warnings: "error" }` | Warnings fail the build too, and errors keep failing it. | +| `{ errors: "warning" }` | Errors stop failing the build, and warnings stay warnings. | ```js new DiagnosticsPlugin({ - reportAs: "warning", // report everything without failing the build - quiet: true, // and leave the warnings out of it + reportAs: { warnings: false }, // the errors alone checks: [{ use: "eslint" }], }); ``` -#### `quiet` - -- Type: - -```ts -type quiet = boolean; -``` - -- Default: `false` - -Will process and report errors only and ignore warnings, if set to `true`. It drops the warnings before [`reportAs`](#reportas) decides what the rest is reported as. - #### `outputReport` - Type: @@ -421,7 +410,7 @@ new DiagnosticsPlugin({ }); ``` -Such an adapter is an object with a `name`, and a `create` returning the five functions the plugin drives it through — what to lint, what came back, which results are errors and which warnings, how to format them, and what to release afterwards. It splits its results by their own severity and nothing else; [`reportAs`](#reportas) and [`quiet`](#quiet) are applied to what it returns: +Such an adapter is an object with a `name`, and a `create` returning the five functions the plugin drives it through — what to lint, what came back, which results are errors and which warnings, how to format them, and what to release afterwards. It splits its results by their own severity and nothing else; [`reportAs`](#reportas) is applied to what it returns: ```js module.exports = { @@ -466,15 +455,16 @@ Move the options you were passing into a `checks` entry: `emitError`, `emitWarning`, `failOnError` and `failOnWarning` are one [`reportAs`](#reportas) option now, because reporting a result as a webpack error is what fails the build — there is nothing left for a second option to say: -| Was | Is | -| :------------------------------------------ | :-------------------- | -| `emitWarning: false` | `quiet: true` | -| `emitError: false` and `emitWarning: false` | `reportAs: false` | -| `failOnError: true` | the default | -| `failOnError: false` | `reportAs: "warning"` | -| `failOnWarning: true` | `reportAs: "error"` | +| Was | Is | +| :------------------------------------------ | :-------------------------------- | +| `quiet: true`, `emitWarning: false` | `reportAs: { warnings: false }` | +| `emitError: false` | `reportAs: { errors: false }` | +| `emitError: false` and `emitWarning: false` | `reportAs: false` | +| `failOnError: true` | the default | +| `failOnError: false` | `reportAs: "warning"` | +| `failOnWarning: true` | `reportAs: { warnings: "error" }` | -The build is no longer aborted from inside the plugin: a result reported as a webpack error fails the build the way every other webpack error does, and the assets are still written. `emitError: false` on its own has no counterpart — reporting the warnings of a check while hiding its errors was never useful. +The build is no longer aborted from inside the plugin: a result reported as a webpack error fails the build the way every other webpack error does, and the assets are still written. The shared options — `context`, `files`, `exclude`, `reportAs` and the rest of [Errors and warnings](#errors-and-warnings) — may stay at the top level instead. Everything else behaves as it did, and the default `cacheLocation` moved to `node_modules/.cache/diagnostics-webpack-plugin/.eslintcache`. diff --git a/src/check.js b/src/check.js index 09b0fac..90df7b7 100644 --- a/src/check.js +++ b/src/check.js @@ -1,6 +1,7 @@ import { isAbsolute, join } from "node:path"; import DiagnosticError from "./DiagnosticError.js"; +import { reportedAs } from "./options.js"; /** @typedef {import("webpack").Compilation} Compilation */ /** @typedef {import("./checks/index.js").CheckResult} CheckResult */ @@ -82,16 +83,14 @@ function createCheckRunner(key, { name, adapter, options }, compilation) { /** @type {Report} */ const report = {}; - // `quiet` drops the warnings and `reportAs: false` everything, but an - // `outputReport` is still written from all of the results below. - if (options.reportAs !== false) { - if (warnings.length > 0 && !options.quiet) { - report.warnings = new DiagnosticError(name, await format(warnings)); - } + // What `reportAs` drops is not formatted at all, but an `outputReport` is + // still written from all of the results below. + if (warnings.length > 0 && reportedAs(options.reportAs, "warnings")) { + report.warnings = new DiagnosticError(name, await format(warnings)); + } - if (errors.length > 0) { - report.errors = new DiagnosticError(name, await format(errors)); - } + if (errors.length > 0 && reportedAs(options.reportAs, "errors")) { + report.errors = new DiagnosticError(name, await format(errors)); } const { outputReport } = options; diff --git a/src/checks/index.js b/src/checks/index.js index 4e567d3..2f1263c 100644 --- a/src/checks/index.js +++ b/src/checks/index.js @@ -30,7 +30,7 @@ import stylelint from "./stylelint.js"; * @typedef {object} CheckInstance * @property {(files: string[]) => Promise} lintFiles lints the given files * @property {(results: CheckResult[]) => Promise} getResults turns the raw results of every `lintFiles` call into the results to report - * @property {(results: CheckResult[]) => { errors: CheckResult[], warnings: CheckResult[] }} splitResults splits the results by their own severity, leaving `reportAs` and `quiet` to the plugin + * @property {(results: CheckResult[]) => { errors: CheckResult[], warnings: CheckResult[] }} splitResults splits the results by their own severity, leaving `reportAs` to the plugin * @property {(formatter?: FormatterOption) => Promise} getFormatter loads a formatter, falling back to the tool's default one * @property {() => Promise} cleanup releases whatever the tool holds after a run */ diff --git a/src/index.js b/src/index.js index 722b6f2..2ce10c5 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ import picomatch from "picomatch"; import { globSync } from "tinyglobby"; import createCheckRunner from "./check.js"; -import { getOptions, validateOptions } from "./options.js"; +import { getOptions, reportedAs, validateOptions } from "./options.js"; import { arrify, parseFiles, @@ -257,24 +257,20 @@ class DiagnosticsWebpackPlugin { for (const { options, runner } of runners) { const { errors, warnings, outputReport } = await runner.report(); - // `reportAs` names the one place every result goes; left unset, each - // stays at the severity the check gave it. - if (warnings) { - const reported = - options.reportAs === "error" - ? compilation.errors - : compilation.warnings; + // `reportAs` has already dropped whatever it reports as `false`, + // so what is left only needs putting where it belongs. + for (const [results, reported] of /** @type {const} */ ([ + ["errors", errors], + ["warnings", warnings], + ])) { + if (!reported) continue; - reported.push(warnings); - } - - if (errors) { - const reported = - options.reportAs === "warning" - ? compilation.warnings - : compilation.errors; + const severity = reportedAs(options.reportAs, results); - reported.push(errors); + (severity === "error" + ? compilation.errors + : compilation.warnings + ).push(reported); } if (outputReport) { diff --git a/src/options.js b/src/options.js index 0ce4c11..6aded71 100644 --- a/src/options.js +++ b/src/options.js @@ -13,7 +13,9 @@ const nodeRequire = createRequire(import.meta.url); const PLUGIN_NAME = "Diagnostics Webpack Plugin"; /** @typedef {import("webpack").Compiler} Compiler */ -/** @typedef {"error" | "warning" | false} ReportAs */ +/** @typedef {"error" | "warning" | false} Severity */ +/** @typedef {"errors" | "warnings"} Results */ +/** @typedef {Severity | { errors?: Severity, warnings?: Severity }} ReportAs */ /** @typedef {import("./checks/index.js").FormatterOption} FormatterOption */ /** @typedef {import("./checks/index.js").CheckAdapter} CheckAdapter */ /** @typedef {import("./checks/index.js").CheckAdapterInput} CheckAdapterInput */ @@ -35,7 +37,6 @@ const PLUGIN_NAME = "Diagnostics Webpack Plugin"; * @property {boolean=} fix apply fixes * @property {FormatterOption=} formatter specify the formatter you would like to use to format your results * @property {OutputReport=} outputReport writes the output of the errors to a file - for example, a `json` file for use for reporting - * @property {boolean=} quiet will process and report errors only and ignore warnings * @property {RegExp | RegExp[] | string | string[]=} resourceQueryExclude specify the resource query to exclude */ @@ -113,6 +114,24 @@ function getSchemas() { return schemas; } +/** @type {Record} */ +const REPORT_AS_DEFAULTS = { errors: "error", warnings: "warning" }; + +/** + * A severity covers a check's errors and its warnings alike unless an object + * sets them apart, and one it leaves out keeps its own. + * @param {ReportAs | undefined} reportAs the option as it was given + * @param {Results} results which of a check's results to answer for + * @returns {Severity} what they are reported as + */ +function reportedAs(reportAs, results) { + if (reportAs === undefined) return REPORT_AS_DEFAULTS[results]; + + if (reportAs === false || typeof reportAs === "string") return reportAs; + + return reportAs[results] ?? REPORT_AS_DEFAULTS[results]; +} + /** * A `use` is either the name of a built-in check or an adapter of its own, so * a check can ship outside this package. @@ -231,4 +250,4 @@ function validateOptions(compiler, pluginOptions, checks) { } } -export { getOptions, validateOptions }; +export { getOptions, reportedAs, validateOptions }; diff --git a/src/shared-options.json b/src/shared-options.json index 7f01d45..6f44bcc 100644 --- a/src/shared-options.json +++ b/src/shared-options.json @@ -97,13 +97,27 @@ } ] }, - "quiet": { - "description": "Will process and report errors only and ignore warnings, if set to `true`.", - "type": "boolean" - }, "reportAs": { - "description": "What a check reports its results as: `\"error\"` reports them as webpack errors and fails the build, `\"warning\"` reports them as webpack warnings, `false` reports nothing.", - "enum": ["error", "warning", false] + "description": "What a check reports its results as: `\"error\"` reports them as webpack errors and fails the build, `\"warning\"` reports them as webpack warnings, `false` reports nothing. One value covers a check's errors and its warnings alike, an object sets them apart, and a severity an object leaves out keeps its own.", + "anyOf": [ + { + "enum": ["error", "warning", false] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "errors": { + "description": "What a check's errors are reported as, or `false` to drop them.", + "enum": ["error", "warning", false] + }, + "warnings": { + "description": "What a check's warnings are reported as, or `false` to drop them.", + "enum": ["error", "warning", false] + } + } + } + ] }, "resourceQueryExclude": { "description": "Specify the resource query to exclude.", diff --git a/test/eslint-options.test.js b/test/eslint-options.test.js index c52edb6..c70b7f7 100644 --- a/test/eslint-options.test.js +++ b/test/eslint-options.test.js @@ -21,7 +21,6 @@ describe("eslint options", () => { formatter: "table", fix: true, reportAs: false, - quiet: false, outputReport: true, }; assert.deepStrictEqual(getESLintOptions(options), { diff --git a/test/quiet.test.js b/test/quiet.test.js deleted file mode 100644 index 938f0c3..0000000 --- a/test/quiet.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import assert from "node:assert/strict"; -import { describe, it } from "node:test"; - -import pack from "./utils/pack.js"; - -describe("quiet", () => { - it("should not emit warnings if quiet is set", async () => { - const compiler = pack("warn", { quiet: true }); - - const stats = await compiler.runAsync(); - assert.strictEqual(stats.hasWarnings(), false); - assert.strictEqual(stats.hasErrors(), false); - }); - - it("should emit errors, but not emit warnings if quiet is set", async () => { - const compiler = pack("full-of-problems", { quiet: true }); - - const stats = await compiler.runAsync(); - assert.strictEqual(stats.hasWarnings(), false); - assert.strictEqual(stats.hasErrors(), true); - }); -}); diff --git a/test/report-as.test.js b/test/report-as.test.js index 046b454..9b70252 100644 --- a/test/report-as.test.js +++ b/test/report-as.test.js @@ -13,22 +13,27 @@ describe("report as", () => { assert.strictEqual(stats.hasWarnings(), true); }); - it("should report everything as errors when set to the errors", async () => { - const compiler = pack("full-of-problems", { reportAs: "error" }); + it("should keep the default when written out as undefined", async () => { + const compiler = pack("full-of-problems", { reportAs: undefined }); const stats = await compiler.runAsync(); assert.strictEqual(stats.hasErrors(), true); - assert.strictEqual(stats.hasWarnings(), false); + assert.strictEqual(stats.hasWarnings(), true); }); - it("should report everything as warnings when set to the warnings", async () => { - const compiler = pack("full-of-problems", { reportAs: "warning" }); - - const stats = await compiler.runAsync(); + it("should cover both severities with one value", async () => { + const asErrors = await pack("full-of-problems", { + reportAs: "error", + }).runAsync(); + const asWarnings = await pack("full-of-problems", { + reportAs: "warning", + }).runAsync(); - assert.strictEqual(stats.hasErrors(), false); - assert.strictEqual(stats.hasWarnings(), true); + assert.strictEqual(asErrors.hasErrors(), true); + assert.strictEqual(asErrors.hasWarnings(), false); + assert.strictEqual(asWarnings.hasErrors(), false); + assert.strictEqual(asWarnings.hasWarnings(), true); }); it("should report nothing when set to false", async () => { @@ -40,45 +45,49 @@ describe("report as", () => { assert.strictEqual(stats.hasWarnings(), false); }); - it("should keep the default when written out as undefined", async () => { - const compiler = pack("full-of-problems", { reportAs: undefined }); + it("should set the severities apart with an object", async () => { + const compiler = pack("full-of-problems", { + reportAs: { errors: "warning", warnings: "error" }, + }); const stats = await compiler.runAsync(); - assert.strictEqual(stats.hasErrors(), true); - assert.strictEqual(stats.hasWarnings(), true); + assert.strictEqual(stats.compilation.errors.length, 1); + assert.strictEqual(stats.compilation.warnings.length, 1); + assert.match(stats.compilation.errors[0].message, /warning/u); }); - it("should fail the build on the errors it reports", async () => { - const failing = await pack("error", {}).runAsync(); - const passing = await pack("error", { reportAs: "warning" }).runAsync(); + it("should leave a severity the object does not name at its own", async () => { + const quiet = await pack("full-of-problems", { + reportAs: { warnings: false }, + }).runAsync(); + const noErrors = await pack("full-of-problems", { + reportAs: { errors: false }, + }).runAsync(); - assert.strictEqual(failing.hasErrors(), true); - assert.strictEqual(passing.hasErrors(), false); - assert.strictEqual(passing.hasWarnings(), true); + assert.strictEqual(quiet.hasErrors(), true); + assert.strictEqual(quiet.hasWarnings(), false); + assert.strictEqual(noErrors.hasErrors(), false); + assert.strictEqual(noErrors.hasWarnings(), true); }); - it("should fail the build on a warning set to the errors", async () => { - const stats = await pack("warn", { reportAs: "error" }).runAsync(); + it("should fail the build on a warning reported as an error", async () => { + const stats = await pack("warn", { + reportAs: { warnings: "error" }, + }).runAsync(); assert.strictEqual(stats.hasErrors(), true); }); - it("should ignore the warnings when quiet is set", async () => { - const stats = await pack("full-of-problems", { - reportAs: "error", - quiet: true, - }).runAsync(); + it("should not fail the build on an error reported as a warning", async () => { + const stats = await pack("error", { reportAs: "warning" }).runAsync(); - assert.strictEqual(stats.compilation.errors.length, 1); - assert.doesNotMatch( - stats.compilation.errors[0].message, - /^\s+\d+:\d+\s+warning/mu, - ); + assert.strictEqual(stats.hasErrors(), false); + assert.strictEqual(stats.hasWarnings(), true); }); it("should let a clean build pass whatever it is set to", async () => { - for (const reportAs of ["error", "warning", false]) { + for (const reportAs of ["error", "warning", false, { errors: "warning" }]) { const stats = await pack("good", { reportAs }).runAsync(); assert.strictEqual(stats.hasErrors(), false); @@ -86,12 +95,17 @@ describe("report as", () => { } }); - it("should reject anything but a severity or false", () => { - for (const reportAs of [true, "info", [], ["error"], { error: "error" }]) { + it("should reject anything but a severity or a map of them", () => { + for (const reportAs of [true, "info", [], ["error"], { errors: "info" }]) { assert.throws( () => pack("full-of-problems", { reportAs }), - /reportAs should be one of these:\n *"error" \| "warning" \| false/u, + /reportAs(\.errors)? should be one of these/u, ); } + + assert.throws( + () => pack("full-of-problems", { reportAs: { info: "error" } }), + /reportAs has an unknown property 'info'/u, + ); }); }); diff --git a/test/stylelint/quiet.test.js b/test/stylelint/quiet.test.js deleted file mode 100644 index d6b8301..0000000 --- a/test/stylelint/quiet.test.js +++ /dev/null @@ -1,20 +0,0 @@ -import assert from "node:assert/strict"; -import { describe, it } from "node:test"; - -import pack from "./utils/pack.js"; - -describe("quiet", () => { - it("should not emit warnings if quiet is set", async () => { - const compiler = pack("warning", { quiet: true }); - const stats = await compiler.runAsync(); - assert.strictEqual(stats.hasWarnings(), false); - assert.strictEqual(stats.hasErrors(), false); - }); - - it("should emit errors, but not emit warnings if quiet is set", async () => { - const compiler = pack("full-of-problems", { quiet: true }); - const stats = await compiler.runAsync(); - assert.strictEqual(stats.hasWarnings(), false); - assert.strictEqual(stats.hasErrors(), true); - }); -}); diff --git a/test/stylelint/report-as.test.js b/test/stylelint/report-as.test.js index 73ece28..dc472f0 100644 --- a/test/stylelint/report-as.test.js +++ b/test/stylelint/report-as.test.js @@ -13,22 +13,24 @@ describe("report as", () => { assert.strictEqual(stats.hasWarnings(), true); }); - it("should report everything as errors when set to the errors", async () => { - const compiler = pack("full-of-problems", { reportAs: "error" }); + it("should cover both severities with one value", async () => { + const asErrors = await pack("full-of-problems", { + reportAs: "error", + }).runAsync(); - const stats = await compiler.runAsync(); - - assert.strictEqual(stats.hasErrors(), true); - assert.strictEqual(stats.hasWarnings(), false); + assert.strictEqual(asErrors.hasErrors(), true); + assert.strictEqual(asErrors.hasWarnings(), false); }); - it("should report everything as warnings when set to the warnings", async () => { - const compiler = pack("full-of-problems", { reportAs: "warning" }); + it("should set the severities apart with an object", async () => { + const compiler = pack("full-of-problems", { + reportAs: { warnings: false }, + }); const stats = await compiler.runAsync(); - assert.strictEqual(stats.hasErrors(), false); - assert.strictEqual(stats.hasWarnings(), true); + assert.strictEqual(stats.hasErrors(), true); + assert.strictEqual(stats.hasWarnings(), false); }); it("should report nothing when set to false", async () => { diff --git a/test/stylelint/stylelint-options.test.js b/test/stylelint/stylelint-options.test.js index de4afe1..d7bb998 100644 --- a/test/stylelint/stylelint-options.test.js +++ b/test/stylelint/stylelint-options.test.js @@ -20,7 +20,6 @@ describe("eslint options", () => { formatter: "json", files: ["file.scss"], reportAs: false, - quiet: false, outputReport: true, }; assert.deepStrictEqual(getStylelintOptions(options), { diff --git a/test/unified/unified.test.js b/test/unified/unified.test.js index 8cd2cec..aeb6a34 100644 --- a/test/unified/unified.test.js +++ b/test/unified/unified.test.js @@ -167,7 +167,7 @@ describe("unified plugin", () => { ); }); - it("should apply reportAs and quiet to a check that implements neither", async () => { + it("should apply reportAs to a check that implements it not at all", async () => { const adapter = { name: "made-up", create: async () => ({ @@ -182,14 +182,12 @@ describe("unified plugin", () => { pack("good", { ...options, checks: [{ use: adapter }] }).runAsync(); const reported = await run({}); - const asErrors = await run({ reportAs: "error" }); + const dropped = await run({ reportAs: "error" }); const silent = await run({ reportAs: false }); - const quiet = await run({ quiet: true }); assert.strictEqual(reported.compilation.warnings.length, 1); - assert.strictEqual(asErrors.compilation.errors.length, 1); + assert.strictEqual(dropped.hasWarnings(), false); assert.strictEqual(silent.hasWarnings(), false); - assert.strictEqual(quiet.hasWarnings(), false); }); it("should report every check where a shared reportAs says", async () => { diff --git a/types/checks/index.d.ts b/types/checks/index.d.ts index bb98ddd..58682ae 100644 --- a/types/checks/index.d.ts +++ b/types/checks/index.d.ts @@ -38,7 +38,7 @@ export type CheckInstance = { */ getResults: (results: CheckResult[]) => Promise; /** - * splits the results by their own severity, leaving `reportAs` and `quiet` to the plugin + * splits the results by their own severity, leaving `reportAs` to the plugin */ splitResults: (results: CheckResult[]) => { errors: CheckResult[]; @@ -154,7 +154,7 @@ export type CheckAdapter = { * @typedef {object} CheckInstance * @property {(files: string[]) => Promise} lintFiles lints the given files * @property {(results: CheckResult[]) => Promise} getResults turns the raw results of every `lintFiles` call into the results to report - * @property {(results: CheckResult[]) => { errors: CheckResult[], warnings: CheckResult[] }} splitResults splits the results by their own severity, leaving `reportAs` and `quiet` to the plugin + * @property {(results: CheckResult[]) => { errors: CheckResult[], warnings: CheckResult[] }} splitResults splits the results by their own severity, leaving `reportAs` to the plugin * @property {(formatter?: FormatterOption) => Promise} getFormatter loads a formatter, falling back to the tool's default one * @property {() => Promise} cleanup releases whatever the tool holds after a run */ diff --git a/types/options.d.ts b/types/options.d.ts index d314bce..b4fae79 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -1,6 +1,13 @@ export type EXPECTED_ANY = any; export type Compiler = import("webpack").Compiler; -export type ReportAs = "error" | "warning" | false; +export type Severity = "error" | "warning" | false; +export type Results = "errors" | "warnings"; +export type ReportAs = + | Severity + | { + errors?: Severity; + warnings?: Severity; + }; export type FormatterOption = import("./checks/index.js").FormatterOption; export type CheckAdapter = import("./checks/index.js").CheckAdapter; export type CheckAdapterInput = import("./checks/index.js").CheckAdapterInput; @@ -51,10 +58,6 @@ export type SharedOptions = { * writes the output of the errors to a file - for example, a `json` file for use for reporting */ outputReport?: OutputReport | undefined; - /** - * will process and report errors only and ignore warnings - */ - quiet?: boolean | undefined; /** * specify the resource query to exclude */ @@ -121,6 +124,17 @@ export type NormalizedOptions = { * @returns {NormalizedOptions} normalized plugin options */ export function getOptions(pluginOptions: Options): NormalizedOptions; +/** + * A severity covers a check's errors and its warnings alike unless an object + * sets them apart, and one it leaves out keeps its own. + * @param {ReportAs | undefined} reportAs the option as it was given + * @param {Results} results which of a check's results to answer for + * @returns {Severity} what they are reported as + */ +export function reportedAs( + reportAs: ReportAs | undefined, + results: Results, +): Severity; /** * Runs from `compiler.hooks.validate`, so webpack's own `validate: false` * turns it off the way it does for webpack's plugins.