From cbf09cf08fd70d32712f3e2f6dd405f6846d8b4b Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:41:11 +0900 Subject: [PATCH 1/7] Change exit code for CLI flag error --- .changeset/grumpy-adults-crash.md | 5 +++++ docs/migration-guide/to-16.md | 4 ++++ docs/user-guide/cli.md | 3 ++- lib/__tests__/cli.test.mjs | 12 +++++++++++- lib/cli.mjs | 19 ++++++++++--------- lib/constants.cjs | 9 +++++++-- lib/constants.mjs | 5 ++++- lib/utils/configurationError.cjs | 4 +++- lib/utils/configurationError.mjs | 4 +++- 9 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 .changeset/grumpy-adults-crash.md diff --git a/.changeset/grumpy-adults-crash.md b/.changeset/grumpy-adults-crash.md new file mode 100644 index 0000000000..6fac83347f --- /dev/null +++ b/.changeset/grumpy-adults-crash.md @@ -0,0 +1,5 @@ +--- +"stylelint": major +--- + +Changed: exit code for CLI flag error diff --git a/docs/migration-guide/to-16.md b/docs/migration-guide/to-16.md index 273b660070..9d70b1db09 100644 --- a/docs/migration-guide/to-16.md +++ b/docs/migration-guide/to-16.md @@ -13,6 +13,10 @@ Node.js 14 has reached end-of-life. We've removed support for it so that we coul - 16.13.0 - 18.0.0 +## Changed CLI exit code for flag error + +When there was some CLI flag error, the CLI newly exits with `64` instead of `2`. This change clarifies the exit code by rule problems. + ## Changed CLI to print problems to stderr instead of stdout If you use the CLI to fix a source string by using the [`--fix`](../user-guide/cli.md#--fix) and [`--stdin`](../user-guide/cli.md#--stdin) options, the CLI will print the fixed code to stdout and any problems to stderr. diff --git a/docs/user-guide/cli.md b/docs/user-guide/cli.md index 3737967cac..433e99787c 100644 --- a/docs/user-guide/cli.md +++ b/docs/user-guide/cli.md @@ -219,5 +219,6 @@ stylelint test.css --print-config The CLI can exit the process with the following exit codes: - `1` - something unknown went wrong -- `2` - there was at least one rule problem or CLI flag error +- `2` - there was at least one rule problem +- `64` - there was some CLI flag error - `78` - there was some problem with the configuration file diff --git a/lib/__tests__/cli.test.mjs b/lib/__tests__/cli.test.mjs index 37fe1439e7..be256f6d04 100644 --- a/lib/__tests__/cli.test.mjs +++ b/lib/__tests__/cli.test.mjs @@ -440,7 +440,7 @@ describe('CLI', () => { it('output a message when wrong --globby-options provided', async () => { await cli(['--globby-options=wrong']); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(64); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -571,4 +571,14 @@ describe('CLI', () => { expect(process.stderr.write).toHaveBeenCalledTimes(1); expect(process.stderr.write).toHaveBeenCalledWith(expect.stringMatching(/block-no-empty/)); }); + + it('exits with an error message when an invalid flag is specified', async () => { + await cli(['--foo']); + + expect(process.exitCode).toBe(64); + + expect(process.stdout.write).not.toHaveBeenCalled(); + expect(process.stderr.write).toHaveBeenCalledTimes(1); + expect(process.stderr.write).toHaveBeenCalledWith(expect.stringMatching(/--foo/)); + }); }); diff --git a/lib/cli.mjs b/lib/cli.mjs index 7cebdf39cf..382fbea38f 100644 --- a/lib/cli.mjs +++ b/lib/cli.mjs @@ -19,9 +19,10 @@ import { DEFAULT_CACHE_LOCATION, DEFAULT_FORMATTER, DEFAULT_IGNORE_FILENAME, - EXIT_CODE_ERROR, EXIT_CODE_FATAL, EXIT_CODE_SUCCESS, + EXIT_CODE_USAGE, + EXIT_CODE_VIOLATION, } from './constants.mjs'; import { createRequire } from 'module'; @@ -161,22 +162,22 @@ const helpText = ` --report-needless-disables, --rd Also report errors for "stylelint-disable" comments that are not blocking - a lint warning. The process will exit with code ${EXIT_CODE_ERROR} if needless disables are found. + a lint warning. The process will exit with code ${EXIT_CODE_VIOLATION} if needless disables are found. --report-invalid-scope-disables, --risd Report "stylelint-disable" comments that used for rules that don't exist - within the configuration object. The process will exit with code ${EXIT_CODE_ERROR} if invalid + within the configuration object. The process will exit with code ${EXIT_CODE_VIOLATION} if invalid scope disables are found. --report-descriptionless-disables, --rdd Report "stylelint-disable" comments without a description. The process will - exit with code ${EXIT_CODE_ERROR} if descriptionless disables are found. + exit with code ${EXIT_CODE_VIOLATION} if descriptionless disables are found. --max-warnings, --mw - The number of warnings above which the process will exit with code ${EXIT_CODE_ERROR}. + The number of warnings above which the process will exit with code ${EXIT_CODE_VIOLATION}. Useful when setting "defaultSeverity" to "warning" and expecting the process to fail on warnings (e.g. CI build). @@ -318,7 +319,7 @@ export default async function main(argv) { if (invalidOptionsMessage) { process.stderr.write(invalidOptionsMessage); - process.exitCode = EXIT_CODE_ERROR; + process.exitCode = EXIT_CODE_USAGE; return; } @@ -415,7 +416,7 @@ export default async function main(argv) { } catch (error) { if (typeof error === 'string') { process.stderr.write(`${error}${EOL}`); - process.exitCode = EXIT_CODE_ERROR; + process.exitCode = EXIT_CODE_USAGE; return; } @@ -522,7 +523,7 @@ export default async function main(argv) { } if (errored) { - process.exitCode = EXIT_CODE_ERROR; + process.exitCode = EXIT_CODE_VIOLATION; } else if (isNumber(maxWarnings) && maxWarningsExceeded) { const foundWarnings = maxWarningsExceeded.foundWarnings; @@ -531,7 +532,7 @@ export default async function main(argv) { `${maxWarnings} allowed${EOL}${EOL}`, )}`, ); - process.exitCode = EXIT_CODE_ERROR; + process.exitCode = EXIT_CODE_VIOLATION; } }) .catch(handleError); diff --git a/lib/constants.cjs b/lib/constants.cjs index cb4e0f0feb..53a5991385 100644 --- a/lib/constants.cjs +++ b/lib/constants.cjs @@ -9,9 +9,12 @@ const DEFAULT_IGNORE_FILENAME = '.stylelintignore'; const DEFAULT_FORMATTER = 'string'; +// NOTE: Partially based on `sysexits.h`. const EXIT_CODE_SUCCESS = 0; const EXIT_CODE_FATAL = 1; -const EXIT_CODE_ERROR = 2; +const EXIT_CODE_VIOLATION = 2; +const EXIT_CODE_USAGE = 64; +const EXIT_CODE_CONFIG = 78; exports.CACHE_STRATEGY_CONTENT = CACHE_STRATEGY_CONTENT; exports.CACHE_STRATEGY_METADATA = CACHE_STRATEGY_METADATA; @@ -19,6 +22,8 @@ exports.DEFAULT_CACHE_LOCATION = DEFAULT_CACHE_LOCATION; exports.DEFAULT_CACHE_STRATEGY = DEFAULT_CACHE_STRATEGY; exports.DEFAULT_FORMATTER = DEFAULT_FORMATTER; exports.DEFAULT_IGNORE_FILENAME = DEFAULT_IGNORE_FILENAME; -exports.EXIT_CODE_ERROR = EXIT_CODE_ERROR; +exports.EXIT_CODE_CONFIG = EXIT_CODE_CONFIG; exports.EXIT_CODE_FATAL = EXIT_CODE_FATAL; exports.EXIT_CODE_SUCCESS = EXIT_CODE_SUCCESS; +exports.EXIT_CODE_USAGE = EXIT_CODE_USAGE; +exports.EXIT_CODE_VIOLATION = EXIT_CODE_VIOLATION; diff --git a/lib/constants.mjs b/lib/constants.mjs index 4c65c4d05c..84146fb456 100644 --- a/lib/constants.mjs +++ b/lib/constants.mjs @@ -7,6 +7,9 @@ export const DEFAULT_IGNORE_FILENAME = '.stylelintignore'; export const DEFAULT_FORMATTER = 'string'; +// NOTE: Partially based on `sysexits.h`. export const EXIT_CODE_SUCCESS = 0; export const EXIT_CODE_FATAL = 1; -export const EXIT_CODE_ERROR = 2; +export const EXIT_CODE_VIOLATION = 2; +export const EXIT_CODE_USAGE = 64; +export const EXIT_CODE_CONFIG = 78; diff --git a/lib/utils/configurationError.cjs b/lib/utils/configurationError.cjs index 30aaa99ac1..a94bb0a776 100644 --- a/lib/utils/configurationError.cjs +++ b/lib/utils/configurationError.cjs @@ -1,5 +1,7 @@ 'use strict'; +const constants = require('../constants.cjs'); + /** @typedef {Error & { code: number }} ConfigurationError */ /** @@ -11,7 +13,7 @@ function configurationError(text) { const err = /** @type {ConfigurationError} */ (new Error(text)); - err.code = 78; + err.code = constants.EXIT_CODE_CONFIG; return err; } diff --git a/lib/utils/configurationError.mjs b/lib/utils/configurationError.mjs index acf93b1ea0..61f3bf1465 100644 --- a/lib/utils/configurationError.mjs +++ b/lib/utils/configurationError.mjs @@ -1,3 +1,5 @@ +import { EXIT_CODE_CONFIG } from '../constants.mjs'; + /** @typedef {Error & { code: number }} ConfigurationError */ /** @@ -9,7 +11,7 @@ export default function configurationError(text) { const err = /** @type {ConfigurationError} */ (new Error(text)); - err.code = 78; + err.code = EXIT_CODE_CONFIG; return err; } From 8405cb8aaacd99a6d484e9e292c73457323651de Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 15 Aug 2023 08:39:45 +0900 Subject: [PATCH 2/7] Rename `EXIT_CODE_*` constants to clarify --- lib/cli.mjs | 24 ++++++++++++------------ lib/constants.cjs | 16 ++++++++-------- lib/constants.mjs | 8 ++++---- lib/utils/configurationError.cjs | 2 +- lib/utils/configurationError.mjs | 4 ++-- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/cli.mjs b/lib/cli.mjs index 382fbea38f..72c46c9c4c 100644 --- a/lib/cli.mjs +++ b/lib/cli.mjs @@ -19,10 +19,10 @@ import { DEFAULT_CACHE_LOCATION, DEFAULT_FORMATTER, DEFAULT_IGNORE_FILENAME, - EXIT_CODE_FATAL, + EXIT_CODE_FATAL_ERROR, + EXIT_CODE_INVALID_USAGE, + EXIT_CODE_LINT_PROBLEM, EXIT_CODE_SUCCESS, - EXIT_CODE_USAGE, - EXIT_CODE_VIOLATION, } from './constants.mjs'; import { createRequire } from 'module'; @@ -162,22 +162,22 @@ const helpText = ` --report-needless-disables, --rd Also report errors for "stylelint-disable" comments that are not blocking - a lint warning. The process will exit with code ${EXIT_CODE_VIOLATION} if needless disables are found. + a lint warning. The process will exit with code ${EXIT_CODE_LINT_PROBLEM} if needless disables are found. --report-invalid-scope-disables, --risd Report "stylelint-disable" comments that used for rules that don't exist - within the configuration object. The process will exit with code ${EXIT_CODE_VIOLATION} if invalid + within the configuration object. The process will exit with code ${EXIT_CODE_LINT_PROBLEM} if invalid scope disables are found. --report-descriptionless-disables, --rdd Report "stylelint-disable" comments without a description. The process will - exit with code ${EXIT_CODE_VIOLATION} if descriptionless disables are found. + exit with code ${EXIT_CODE_LINT_PROBLEM} if descriptionless disables are found. --max-warnings, --mw - The number of warnings above which the process will exit with code ${EXIT_CODE_VIOLATION}. + The number of warnings above which the process will exit with code ${EXIT_CODE_LINT_PROBLEM}. Useful when setting "defaultSeverity" to "warning" and expecting the process to fail on warnings (e.g. CI build). @@ -319,7 +319,7 @@ export default async function main(argv) { if (invalidOptionsMessage) { process.stderr.write(invalidOptionsMessage); - process.exitCode = EXIT_CODE_USAGE; + process.exitCode = EXIT_CODE_INVALID_USAGE; return; } @@ -416,7 +416,7 @@ export default async function main(argv) { } catch (error) { if (typeof error === 'string') { process.stderr.write(`${error}${EOL}`); - process.exitCode = EXIT_CODE_USAGE; + process.exitCode = EXIT_CODE_INVALID_USAGE; return; } @@ -523,7 +523,7 @@ export default async function main(argv) { } if (errored) { - process.exitCode = EXIT_CODE_VIOLATION; + process.exitCode = EXIT_CODE_LINT_PROBLEM; } else if (isNumber(maxWarnings) && maxWarningsExceeded) { const foundWarnings = maxWarningsExceeded.foundWarnings; @@ -532,7 +532,7 @@ export default async function main(argv) { `${maxWarnings} allowed${EOL}${EOL}`, )}`, ); - process.exitCode = EXIT_CODE_VIOLATION; + process.exitCode = EXIT_CODE_LINT_PROBLEM; } }) .catch(handleError); @@ -551,7 +551,7 @@ function handleError(err) { process.stderr.write(err.stack + EOL); } - const exitCode = 'code' in err && isNumber(err.code) ? err.code : EXIT_CODE_FATAL; + const exitCode = 'code' in err && isNumber(err.code) ? err.code : EXIT_CODE_FATAL_ERROR; process.exitCode = exitCode; } diff --git a/lib/constants.cjs b/lib/constants.cjs index 53a5991385..496e68c068 100644 --- a/lib/constants.cjs +++ b/lib/constants.cjs @@ -11,10 +11,10 @@ const DEFAULT_FORMATTER = 'string'; // NOTE: Partially based on `sysexits.h`. const EXIT_CODE_SUCCESS = 0; -const EXIT_CODE_FATAL = 1; -const EXIT_CODE_VIOLATION = 2; -const EXIT_CODE_USAGE = 64; -const EXIT_CODE_CONFIG = 78; +const EXIT_CODE_FATAL_ERROR = 1; +const EXIT_CODE_LINT_PROBLEM = 2; +const EXIT_CODE_INVALID_USAGE = 64; +const EXIT_CODE_INVALID_CONFIG = 78; exports.CACHE_STRATEGY_CONTENT = CACHE_STRATEGY_CONTENT; exports.CACHE_STRATEGY_METADATA = CACHE_STRATEGY_METADATA; @@ -22,8 +22,8 @@ exports.DEFAULT_CACHE_LOCATION = DEFAULT_CACHE_LOCATION; exports.DEFAULT_CACHE_STRATEGY = DEFAULT_CACHE_STRATEGY; exports.DEFAULT_FORMATTER = DEFAULT_FORMATTER; exports.DEFAULT_IGNORE_FILENAME = DEFAULT_IGNORE_FILENAME; -exports.EXIT_CODE_CONFIG = EXIT_CODE_CONFIG; -exports.EXIT_CODE_FATAL = EXIT_CODE_FATAL; +exports.EXIT_CODE_FATAL_ERROR = EXIT_CODE_FATAL_ERROR; +exports.EXIT_CODE_INVALID_CONFIG = EXIT_CODE_INVALID_CONFIG; +exports.EXIT_CODE_INVALID_USAGE = EXIT_CODE_INVALID_USAGE; +exports.EXIT_CODE_LINT_PROBLEM = EXIT_CODE_LINT_PROBLEM; exports.EXIT_CODE_SUCCESS = EXIT_CODE_SUCCESS; -exports.EXIT_CODE_USAGE = EXIT_CODE_USAGE; -exports.EXIT_CODE_VIOLATION = EXIT_CODE_VIOLATION; diff --git a/lib/constants.mjs b/lib/constants.mjs index 84146fb456..74ef44a99d 100644 --- a/lib/constants.mjs +++ b/lib/constants.mjs @@ -9,7 +9,7 @@ export const DEFAULT_FORMATTER = 'string'; // NOTE: Partially based on `sysexits.h`. export const EXIT_CODE_SUCCESS = 0; -export const EXIT_CODE_FATAL = 1; -export const EXIT_CODE_VIOLATION = 2; -export const EXIT_CODE_USAGE = 64; -export const EXIT_CODE_CONFIG = 78; +export const EXIT_CODE_FATAL_ERROR = 1; +export const EXIT_CODE_LINT_PROBLEM = 2; +export const EXIT_CODE_INVALID_USAGE = 64; +export const EXIT_CODE_INVALID_CONFIG = 78; diff --git a/lib/utils/configurationError.cjs b/lib/utils/configurationError.cjs index a94bb0a776..7356959842 100644 --- a/lib/utils/configurationError.cjs +++ b/lib/utils/configurationError.cjs @@ -13,7 +13,7 @@ const constants = require('../constants.cjs'); function configurationError(text) { const err = /** @type {ConfigurationError} */ (new Error(text)); - err.code = constants.EXIT_CODE_CONFIG; + err.code = constants.EXIT_CODE_INVALID_CONFIG; return err; } diff --git a/lib/utils/configurationError.mjs b/lib/utils/configurationError.mjs index 61f3bf1465..8ae72704f1 100644 --- a/lib/utils/configurationError.mjs +++ b/lib/utils/configurationError.mjs @@ -1,4 +1,4 @@ -import { EXIT_CODE_CONFIG } from '../constants.mjs'; +import { EXIT_CODE_INVALID_CONFIG } from '../constants.mjs'; /** @typedef {Error & { code: number }} ConfigurationError */ @@ -11,7 +11,7 @@ import { EXIT_CODE_CONFIG } from '../constants.mjs'; export default function configurationError(text) { const err = /** @type {ConfigurationError} */ (new Error(text)); - err.code = EXIT_CODE_CONFIG; + err.code = EXIT_CODE_INVALID_CONFIG; return err; } From a5ecd4ea48514e921a025af0b4db68838fac8c14 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 15 Aug 2023 08:50:05 +0900 Subject: [PATCH 3/7] Explicitly enable meow's `allowUnknownFlags` with comment --- lib/cli.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/cli.mjs b/lib/cli.mjs index 72c46c9c4c..e111f8ed7a 100644 --- a/lib/cli.mjs +++ b/lib/cli.mjs @@ -615,6 +615,11 @@ export function buildCLI(argv) { // @ts-expect-error -- TS2322: Type '{ allowEmptyInput: {...} }' is not assignable to type 'AnyFlags'. flags, + // NOTE: We must enable `allowUnknownFlags` because meow exits with `2` if `allowUnknownFlags` is disabled. + // Instead, we use our different exit code with `checkInvalidCLIOptions()`. + // See also https://github.com/sindresorhus/meow/blob/v12.0.1/source/validate.js#L75 + allowUnknownFlags: true, + // @ts-expect-error -- TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'. importMeta: import.meta, }); From 3e72d6bbc5c438e7bc06047c753790e342aa63c1 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 15 Aug 2023 09:01:44 +0900 Subject: [PATCH 4/7] Simplify descriptions of exit codes --- docs/user-guide/cli.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/user-guide/cli.md b/docs/user-guide/cli.md index 433e99787c..0d7df3acc0 100644 --- a/docs/user-guide/cli.md +++ b/docs/user-guide/cli.md @@ -218,7 +218,7 @@ stylelint test.css --print-config The CLI can exit the process with the following exit codes: -- `1` - something unknown went wrong -- `2` - there was at least one rule problem -- `64` - there was some CLI flag error -- `78` - there was some problem with the configuration file +- `1` - fatal error +- `2` - lint problem +- `64` - invalid CLI usage +- `78` - invalid configuration file From 88147f6b1e7a088e822ec89d5fc158eb20fbba17 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:34:17 +0900 Subject: [PATCH 5/7] Update docs/migration-guide/to-16.md Co-authored-by: Richard Hallows --- docs/migration-guide/to-16.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration-guide/to-16.md b/docs/migration-guide/to-16.md index 9d70b1db09..bc5af23526 100644 --- a/docs/migration-guide/to-16.md +++ b/docs/migration-guide/to-16.md @@ -15,7 +15,7 @@ Node.js 14 has reached end-of-life. We've removed support for it so that we coul ## Changed CLI exit code for flag error -When there was some CLI flag error, the CLI newly exits with `64` instead of `2`. This change clarifies the exit code by rule problems. +We've changed the exit code for CLI flag errors from `2` to `64` so that `2` is only used for lint problems. ## Changed CLI to print problems to stderr instead of stdout From 42ab635f2319d6b0e419f002c31e75a4be8df19f Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:36:35 +0900 Subject: [PATCH 6/7] Fix lint error in `to-16.md` --- docs/migration-guide/to-16.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration-guide/to-16.md b/docs/migration-guide/to-16.md index bc5af23526..2e846f9b55 100644 --- a/docs/migration-guide/to-16.md +++ b/docs/migration-guide/to-16.md @@ -15,7 +15,7 @@ Node.js 14 has reached end-of-life. We've removed support for it so that we coul ## Changed CLI exit code for flag error -We've changed the exit code for CLI flag errors from `2` to `64` so that `2` is only used for lint problems. +We've changed the exit code for CLI flag errors from `2` to `64` so that `2` is only used for lint problems. ## Changed CLI to print problems to stderr instead of stdout From 722f648fdfb8127098ffcfb9507840fccb733bea Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 15 Aug 2023 21:45:09 +0900 Subject: [PATCH 7/7] Use `EXIT_CODE_*` constants also for test code --- lib/__tests__/cli.test.mjs | 37 +++++++++++++++++++--------------- lib/__tests__/extends.test.mjs | 3 ++- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/__tests__/cli.test.mjs b/lib/__tests__/cli.test.mjs index be256f6d04..685135d467 100644 --- a/lib/__tests__/cli.test.mjs +++ b/lib/__tests__/cli.test.mjs @@ -9,6 +9,11 @@ import { jest } from '@jest/globals'; import stripAnsi from 'strip-ansi'; import { stripIndent } from 'common-tags'; +import { + EXIT_CODE_FATAL_ERROR, + EXIT_CODE_INVALID_USAGE, + EXIT_CODE_LINT_PROBLEM, +} from '../constants.mjs'; import readJSONFile from '../testUtils/readJSONFile.mjs'; import replaceBackslashes from '../testUtils/replaceBackslashes.mjs'; @@ -259,7 +264,7 @@ describe('CLI', () => { fixturesPath('empty-block-with-disables.css'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -275,7 +280,7 @@ describe('CLI', () => { fixturesPath('empty-block-with-relevant-disable.css'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -292,7 +297,7 @@ describe('CLI', () => { fixturesPath('empty-block-with-relevant-disable.css'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -306,7 +311,7 @@ describe('CLI', () => { await cli(['--stdin', '--config', fixturesPath('config-no-empty-source.json')]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -320,7 +325,7 @@ describe('CLI', () => { await cli(['--stdin']); - expect(process.exitCode).toBe(1); + expect(process.exitCode).toBe(EXIT_CODE_FATAL_ERROR); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -334,7 +339,7 @@ describe('CLI', () => { await cli(['--config', fixturesPath('config-no-empty-source.json')]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -348,7 +353,7 @@ describe('CLI', () => { fixturesPath('empty-block-with-disables.css'), ]); - expect(process.exitCode).toBe(1); + expect(process.exitCode).toBe(EXIT_CODE_FATAL_ERROR); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -366,7 +371,7 @@ describe('CLI', () => { fixturesPath('empty-block.css'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(2); @@ -402,7 +407,7 @@ describe('CLI', () => { fixturesPath('quiet-deprecation-warnings/style.css'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -440,7 +445,7 @@ describe('CLI', () => { it('output a message when wrong --globby-options provided', async () => { await cli(['--globby-options=wrong']); - expect(process.exitCode).toBe(64); + expect(process.exitCode).toBe(EXIT_CODE_INVALID_USAGE); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -457,7 +462,7 @@ describe('CLI', () => { fixturesPath('globby-options'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -472,7 +477,7 @@ describe('CLI', () => { fixturesPath('invalid-hex.scss'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -491,7 +496,7 @@ describe('CLI', () => { fixturesPath('invalid-hex.scss'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -520,7 +525,7 @@ describe('CLI', () => { fixturesPath('empty-block.css'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); @@ -561,7 +566,7 @@ describe('CLI', () => { fixturesPath('config-block-no-empty-and-color-hex-length-short.json'), ]); - expect(process.exitCode).toBe(2); + expect(process.exitCode).toBe(EXIT_CODE_LINT_PROBLEM); expect(process.stdout.write).toHaveBeenCalledTimes(1); expect(process.stdout.write).toHaveBeenCalledWith(stripIndent` @@ -575,7 +580,7 @@ describe('CLI', () => { it('exits with an error message when an invalid flag is specified', async () => { await cli(['--foo']); - expect(process.exitCode).toBe(64); + expect(process.exitCode).toBe(EXIT_CODE_INVALID_USAGE); expect(process.stdout.write).not.toHaveBeenCalled(); expect(process.stderr.write).toHaveBeenCalledTimes(1); diff --git a/lib/__tests__/extends.test.mjs b/lib/__tests__/extends.test.mjs index f471bc1025..06ded9e506 100644 --- a/lib/__tests__/extends.test.mjs +++ b/lib/__tests__/extends.test.mjs @@ -1,5 +1,6 @@ import { fileURLToPath } from 'node:url'; +import { EXIT_CODE_INVALID_CONFIG } from '../constants.mjs'; import configExtendingWithObject from './fixtures/config-extending-with-object.mjs'; import readJSONFile from '../testUtils/readJSONFile.mjs'; import safeChdir from '../testUtils/safeChdir.mjs'; @@ -72,7 +73,7 @@ it('extending configuration and no configBasedir', () => { code: 'a {}', config: configExtendingOne, }), - ).rejects.toHaveProperty('code', 78); + ).rejects.toHaveProperty('code', EXIT_CODE_INVALID_CONFIG); }); it('extending a config that is overridden', async () => {