Skip to content

Commit

Permalink
chore: set default severity for lint config (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorKarpiuk authored Oct 19, 2023
1 parent fcae48e commit 0c52110
Show file tree
Hide file tree
Showing 28 changed files with 293 additions and 110 deletions.
7 changes: 7 additions & 0 deletions .changeset/witty-taxis-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@redocly/cli': minor
'@redocly/openapi-core': minor
---

Added the possibility to configure the linting severity level of the configuration file for all CLI commands.
Redocly CLI will exit with an error if there are any issues with the configuration file, and the severity is set to `error`.
26 changes: 20 additions & 6 deletions __tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ describe('E2E', () => {
{ dirName: 'invalid-config--lint-config-error', option: 'error' },
{ dirName: 'invalid-lint-config-severity', option: 'something' },
{ dirName: 'invalid-config--no-option', option: null },
{ dirName: 'invalid-config-assertation-name', option: 'error' },
{ dirName: 'invalid-config-assertation-config-type', option: 'error' },
{ dirName: 'invalid-config-assertation-name', option: 'warn' },
{ dirName: 'invalid-config-assertation-config-type', option: 'warn' },
{ dirName: 'invalid-config-format-json', option: 'warn', format: 'json' },
];

Expand All @@ -85,15 +85,29 @@ describe('E2E', () => {
(expect(result) as any).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});

test('invalid-definition-and-config', () => {
const folderPath = join(__dirname, 'lint-config/invalid-definition-and-config');
const configSeverityOptions: { dirName: string; option: string | null; snapshot: string }[] = [
{
dirName: 'invalid-definition-and-config',
option: 'error',
snapshot: 'config-with-error.snapshot.js',
},
{
dirName: 'invalid-definition-and-config',
option: 'warn',
snapshot: 'config-with-warn.snapshot.js',
},
];

test.each(configSeverityOptions)('invalid-definition-and-config: %s', (severityOption) => {
const { dirName, option, snapshot } = severityOption;
const folderPath = join(__dirname, `lint-config/${dirName}`);
const relativeInvalidOpenapiFile = relative(folderPath, invalidOpenapiFile);
const args = [relativeInvalidOpenapiFile, `--lint-config=error`];
const args = [relativeInvalidOpenapiFile, `--lint-config=${option}`];
const passedArgs = getParams('../../../packages/cli/src/index.ts', 'lint', args);

const result = getCommandOutput(passedArgs, folderPath);

(expect(result) as any).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
(expect(result) as any).toMatchSpecificSnapshot(join(folderPath, snapshot));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ Error was generated by the configuration spec rule.
❌ Your config has 1 error.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms
Woohoo! Your API description is valid. 🎉
[WARNING] Unused rules found in .redocly.yaml: context.
Check the spelling and verify the added plugin prefix.
`;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Property \`context\` is not expected here.
Warning was generated by the configuration spec rule.
You have 1 warning.
⚠️ Your config has 1 warning.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Property \`context\` is not expected here.
Warning was generated by the configuration spec rule.
You have 1 warning.
⚠️ Your config has 1 warning.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-config-type', option: 'error' } 1`] = `
exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-config-type', option: 'warn' } 1`] = `
[1] .redocly.yaml:8:17 at #/rules/assert~1path-item-mutually-required/where/0/subject/type
Expand All @@ -13,10 +13,10 @@ exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertatio
9 | property: property
10 | assertions:
Error was generated by the configuration spec rule.
Warning was generated by the configuration spec rule.
Your config has 1 error.
⚠️ Your config has 1 warning.
The 'assert/' syntax in assert/path-item-mutually-required is deprecated. Update your configuration to use 'rule/' instead. Examples and more information: https://redocly.com/docs/cli/rules/configurable-rules/
validating ../__fixtures__/valid-openapi.yaml...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-name', option: 'error' } 1`] = `
exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-name', option: 'warn' } 1`] = `
[1] .redocly.yaml:5:3 at #/rules/asset~1path-item-mutually-required
Expand All @@ -13,10 +13,10 @@ The field \`severity\` must be present on this level.
6 | context:
7 | - type: PathItem
Error was generated by the configuration spec rule.
Warning was generated by the configuration spec rule.
Your config has 1 error.
⚠️ Your config has 1 warning.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint-config invalid-definition-and-config: {
dirName: 'invalid-definition-and-config',
option: 'error',
snapshot: 'config-with-error.snapshot.js'
} 1`] = `
[1] .redocly.yaml:5:3 at #/rules/context
Property \`context\` is not expected here.
3 | root: ./openapi.yaml
4 | rules:
5 | context: null
| ^^^^^^^
6 | extends:
7 | - recommended
Error was generated by the configuration spec rule.
❌ Your config has 1 error.
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint-config invalid-definition-and-config 1`] = `
exports[`E2E lint-config invalid-definition-and-config: {
dirName: 'invalid-definition-and-config',
option: 'warn',
snapshot: 'config-with-warn.snapshot.js'
} 1`] = `
[1] .redocly.yaml:5:3 at #/rules/context
Expand All @@ -13,10 +17,10 @@ Property \`context\` is not expected here.
6 | extends:
7 | - recommended
Error was generated by the configuration spec rule.
Warning was generated by the configuration spec rule.
Your config has 1 error.
⚠️ Your config has 1 warning.
validating ../__fixtures__/invalid-openapi.yaml...
[1] ../__fixtures__/invalid-openapi.yaml:4:1 at #/info
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lint/deprecated-apiDefinitions/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Did you mean: env ?
Warning was generated by the configuration spec rule.
You have 2 warnings.
⚠️ Your config has 2 warnings.
The 'apiDefinitions' field is deprecated. Use apis instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
The 'lint' field is deprecated. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
validating /openapi.yaml...
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lint/deprecated-lint/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Did you mean: env ?
Warning was generated by the configuration spec rule.
You have 1 warning.
⚠️ Your config has 1 warning.
The 'lint' field is deprecated. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
validating /openapi.yaml...
[1] openapi.yaml:11:7 at #/paths/~1pet~1findByStatus/get/responses
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lint/deprecated-styleguide/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Property \`styleguide\` is not expected here.
Warning was generated by the configuration spec rule.
You have 1 warning.
⚠️ Your config has 1 warning.
The 'styleguide' field is deprecated. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
validating /openapi.yaml...
[1] openapi.yaml:11:7 at #/paths/~1pet~1findByStatus/get/responses
Expand Down
13 changes: 8 additions & 5 deletions __tests__/split/missing-outDir/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ Positionals:
api API description file that you want to split [string] [required]
Options:
--version Show version number. [boolean]
--help Show help. [boolean]
--outDir Output directory where files will be saved. [string] [required]
--separator File path separator used while splitting. [string] [default: "_"]
--config Path to the config file. [string]
--version Show version number. [boolean]
--help Show help. [boolean]
--outDir Output directory where files will be saved. [string] [required]
--separator File path separator used while splitting.
[string] [default: "_"]
--config Path to the config file. [string]
--lint-config Severity level for config file linting.
[choices: "warn", "error", "off"] [default: "warn"]
Missing required argument: outDir
Expand Down
25 changes: 13 additions & 12 deletions docs/commands/build-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ redocly build-docs <api> -t custom.hbs --templateOptions.metaDescription "Page m

## Options

| Option | Type | Description |
| ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| api | string | Path to the API description filename or alias that you want to generate the build for. Refer to the [API examples](#api-examples) for more information. |
| --output, -o | string | Sets the path and name of the output file. The default value is `redoc-static.html`. |
| --title | string | Sets the page title. |
| --disableGoogleFont | boolean | Disables Google fonts. The default value is `false`. |
| --template, -t | string | Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI description. |
| --templateOptions | string | Adds template options you want to pass to your custom Handlebars template. To add options, use dot notation. |
| --theme.openapi | string | Customizes your output with [Redoc functionality options](https://redocly.com/docs/api-reference-docs/configuration/functionality/) or [Redoc theming options](https://redocly.com/docs/api-reference-docs/configuration/theming/). |
| --config | string | Specifies path to the [configuration file](#custom-configuration-file). |
| --help | boolean | Shows help. |
| --version | boolean | Shows version number. |
| Option | Type | Description |
| ------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| api | string | Path to the API description filename or alias that you want to generate the build for. Refer to the [API examples](#api-examples) for more information.<br/> |
| --config | string | Specifies path to the [configuration file](#custom-configuration-file). |
| --disableGoogleFont | boolean | Disables Google fonts. The default value is false. |
| --help | boolean | Shows help. |
| --lint-config | string | Specify the severity level for the configuration file. Possible values: warn, error, off. Default value is warn |
| --output, -o | string | Sets the path and name of the output file. The default value is redoc-static.html. |
| --template, -t | string | Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI description. |
| --templateOptions | string | Adds template options you want to pass to your custom Handlebars template. To add options, use dot notation. |
| --theme.openapi | string | Customizes your output with [Redoc functionality options](https://redocly.com/docs/api-reference-docs/configuration/functionality/) or [Redoc theming options](https://redocly.com/docs/api-reference-docs/configuration/theming/). |
| --title | string | Sets the page title. |
| --version | boolean | Shows version number. |

## Examples

Expand Down
Loading

1 comment on commit 0c52110

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 75.89% 4013/5288
🟡 Branches 65.78% 2138/3250
🟡 Functions 67.95% 651/958
🟡 Lines 76.07% 3761/4944

Test suite run success

640 tests passing in 93 suites.

Report generated by 🧪jest coverage report action from 0c52110

Please sign in to comment.