From a7b6ed1aec1fe70d34ac961a4681cb17f6423a07 Mon Sep 17 00:00:00 2001 From: IhorKarpiuk Date: Thu, 7 Dec 2023 17:50:40 +0200 Subject: [PATCH] chore: deprecate lint option in the join command --- .changeset/new-books-cross.md | 5 +++++ docs/commands/join.md | 7 ++++++- packages/cli/src/__mocks__/utils.ts | 1 + packages/cli/src/commands/bundle.ts | 30 +++++++++-------------------- packages/cli/src/commands/join.ts | 4 +++- packages/cli/src/index.ts | 2 +- packages/cli/src/utils.ts | 14 ++++++++++++++ 7 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 .changeset/new-books-cross.md diff --git a/.changeset/new-books-cross.md b/.changeset/new-books-cross.md new file mode 100644 index 0000000000..c11541b7f0 --- /dev/null +++ b/.changeset/new-books-cross.md @@ -0,0 +1,5 @@ +--- +"@redocly/cli": patch +--- + +Deprecated `--lint` option in the `join` command. The options are marked for removal in a future release. Use the [lint command](https://redocly.com/docs/cli/commands/lint/) separately to lint your APIs. diff --git a/docs/commands/join.md b/docs/commands/join.md index 1e8c5bc3a4..79ef2bfd96 100644 --- a/docs/commands/join.md +++ b/docs/commands/join.md @@ -35,13 +35,18 @@ redocly join --version ## Options +{% admonition type="warning" name="Important" %} +The `--lint` option is deprecated and is marked for removal in future releases. +Use the [lint command](./lint.md) separately to lint your APIs before bundling. +{% /admonition %} + | Option | Type | Description | | ---------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | apis | [string] | **REQUIRED.** 1. Array of paths to API description files that you want to join. At least two input files are required.
2. A wildcard pattern to match API description files within a specific folder. | | --config | string | Specify path to the [config file](../configuration/index.md). | | --decorate | boolean | Run decorators. | | --help | boolean | Show help. | -| --lint | boolean | Lint API description files. | +| --lint (**Deprecated**) | boolean | Lint API description files. | | --lint-config | string | Specify the severity level for the configuration file.
**Possible values:** `warn`, `error`, `off`. Default value is `warn`. | | --output, -o | string | Name for the joined output file. Defaults to `openapi.yaml` or `openapi.json` (Depends on the extension of the first input file). **If the file already exists, it's overwritten.** | | --prefix-components-with-info-prop | string | Prefix components with property value from info object. See the [prefix-components-with-info-prop section](#prefix-components-with-info-prop) below. | diff --git a/packages/cli/src/__mocks__/utils.ts b/packages/cli/src/__mocks__/utils.ts index 83824b25cf..48bf562a82 100644 --- a/packages/cli/src/__mocks__/utils.ts +++ b/packages/cli/src/__mocks__/utils.ts @@ -19,3 +19,4 @@ export const checkIfRulesetExist = jest.fn(); export const sortTopLevelKeysForOas = jest.fn((document) => document); export const getAndValidateFileExtension = jest.fn((fileName: string) => fileName.split('.').pop()); export const writeToFileByExtension = jest.fn(); +export const checkForDeprecatedOptions = jest.fn(); diff --git a/packages/cli/src/commands/bundle.ts b/packages/cli/src/commands/bundle.ts index 060f5f4886..aade0ab890 100644 --- a/packages/cli/src/commands/bundle.ts +++ b/packages/cli/src/commands/bundle.ts @@ -23,6 +23,7 @@ import type { OutputExtensions, Skips, Totals } from '../types'; import { performance } from 'perf_hooks'; import { blue, gray, green, yellow } from 'colorette'; import { writeFileSync } from 'fs'; +import { checkForDeprecatedOptions } from '../utils'; export type BundleOptions = { apis?: string[]; @@ -47,8 +48,15 @@ export async function handleBundle(argv: BundleOptions, config: Config, version: const apis = await getFallbackApisOrExit(argv.apis, config); const totals: Totals = { errors: 0, warnings: 0, ignored: 0 }; const maxProblems = argv['max-problems']; + const deprecatedOptions: Array = [ + 'lint', + 'format', + 'skip-rule', + 'extends', + 'max-problems', + ]; - checkForDeprecatedOptions(argv); + checkForDeprecatedOptions(argv, deprecatedOptions); for (const { path, alias } of apis) { try { @@ -177,23 +185,3 @@ export async function handleBundle(argv: BundleOptions, config: Config, version: throw new Error('Bundle failed.'); } } - -function checkForDeprecatedOptions(argv: BundleOptions) { - const deprecatedOptions: Array = [ - 'lint', - 'format', - 'skip-rule', - 'extends', - 'max-problems', - ]; - - for (const option of deprecatedOptions) { - if (argv[option]) { - process.stderr.write( - yellow( - `[WARNING] "${option}" option is deprecated and will be removed in a future release. \n\n` - ) - ); - } - } -} diff --git a/packages/cli/src/commands/join.ts b/packages/cli/src/commands/join.ts index 49e230013c..e7b6981d69 100644 --- a/packages/cli/src/commands/join.ts +++ b/packages/cli/src/commands/join.ts @@ -29,6 +29,7 @@ import { sortTopLevelKeysForOas, getAndValidateFileExtension, writeToFileByExtension, + checkForDeprecatedOptions, } from '../utils'; import { isObject, isString, keysOf } from '../js-utils'; import { @@ -65,7 +66,6 @@ export type JoinOptions = { 'without-x-tag-groups'?: boolean; output?: string; config?: string; - extends?: undefined; 'lint-config'?: RuleSeverity; }; @@ -76,6 +76,8 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi return exitWithError(`At least 2 apis should be provided. \n\n`); } + checkForDeprecatedOptions(argv, ['lint'] as Array); + const fileExtension = getAndValidateFileExtension(argv.output || argv.apis[0]); const { diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index a8daeae33a..838bc564d0 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -101,7 +101,7 @@ yargs demandOption: true, }) .option({ - lint: { description: 'Lint definitions', type: 'boolean', default: false }, + lint: { description: 'Lint definitions', type: 'boolean', default: false, hidden: true }, decorate: { description: 'Run decorators', type: 'boolean', default: false }, preprocess: { description: 'Run preprocessors', type: 'boolean', default: false }, 'prefix-tags-with-info-prop': { diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 2743165373..7ee0fff26b 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -626,3 +626,17 @@ export function cleanArgs(args: CommandOptions) { export function cleanRawInput(argv: string[]) { return argv.map((entry) => entry.split('=').map(cleanString).join('=')).join(' '); } + +export function checkForDeprecatedOptions(argv: T, deprecatedOptions: Array) { + for (const option of deprecatedOptions) { + if (argv[option]) { + process.stderr.write( + yellow( + `[WARNING] "${String( + option + )}" option is deprecated and will be removed in a future release. \n\n` + ) + ); + } + } +}