Skip to content

Commit

Permalink
chore: cover linting issue with not linting depening on other problem…
Browse files Browse the repository at this point in the history
…s and added basic tests
  • Loading branch information
tatomyr committed Dec 1, 2023
1 parent 2b9c103 commit d7fc2eb
Show file tree
Hide file tree
Showing 24 changed files with 236 additions and 83 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Before submitting a pull request, please make sure the following is done:
1. Fork the repository and create your branch from `main`.
1. Run `npm install` in the repository root.
1. If you’ve fixed a bug or added code that should be tested, don't forget to add tests!
1. Ensure the test suite passes (`npm test`). Tip: `npm test -- --watch TestName` is helpful in development.
1. Ensure the test suite passes (`npm test`). Tip: `npm test -- --watch TestName` is helpful in development. To update snapshots, run `npm run unit -- -u` for unit tests or `npm run e2e -- -u` for e2e tests.
1. Format your code with prettier (`npm run prettier`).
1. Each feat/fix PR should also contain a changeset (to create one, run `npx changeset`; if your changes are scoped to `packages/core` but also affect Redocly CLI behavior, please include the `@redocly/cli` package as well). Please describe what you've done in this PR using sentence case (you can refer to our [changelog](https://redocly.com/docs/cli/changelog/)). This produces a file in `.changeset` folder. Please commit this file along with your changes.

Expand Down
1 change: 1 addition & 0 deletions __tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('E2E', () => {
{ dirName: 'invalid-config-assertation-name', option: 'warn' },
{ dirName: 'invalid-config-assertation-config-type', option: 'warn' },
{ dirName: 'invalid-config-format-json', option: 'warn', format: 'json' },
{ dirName: 'config-with-refs', option: 'warn' },
];

const validOpenapiFile = join(__dirname, 'lint-config/__fixtures__/valid-openapi.yaml');
Expand Down
11 changes: 11 additions & 0 deletions __tests__/lint-config/config-with-refs/.redocly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apis:
main:
root: ./openapi.yaml
rules:
$ref: rules.yaml

non-existing-root-property: Fail

theme:
openapi:
$ref: ./theme-openapi.yaml#/theme
2 changes: 2 additions & 0 deletions __tests__/lint-config/config-with-refs/rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
info-contact: error
wrong-rule: warn
52 changes: 52 additions & 0 deletions __tests__/lint-config/config-with-refs/snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint-config test with option: { dirName: 'config-with-refs', option: 'warn' } 1`] = `
[1] .redocly.yaml:7:1 at #/non-existing-root-property
Property \`non-existing-root-property\` is not expected here.
5 | $ref: rules.yaml
6 |
7 | non-existing-root-property: Fail
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
8 |
9 | theme:
Warning was generated by the configuration spec rule.
[2] theme-openapi.yaml:3:5 at #/theme/logo
Expected type \`string\` but got \`object\`.
1 | theme:
2 | logo:
3 | maxWidth: 100 # Fail - should be a string
| ^^^^^^^^^^^^^
4 |
referenced from .redocly.yaml:11:5 at #/theme/openapi
Warning was generated by the configuration spec rule.
[3] rules.yaml:2:1 at #/wrong-rule
Property \`wrong-rule\` is not expected here.
1 | info-contact: error
2 | wrong-rule: warn
| ^^^^^^^^^^
3 |
referenced from .redocly.yaml:5:7 at #/apis/main/rules
Warning was generated by the configuration spec rule.
⚠️ Your config has 3 warnings.
⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/
`;
3 changes: 3 additions & 0 deletions __tests__/lint-config/config-with-refs/theme-openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
theme:
logo:
maxWidth: 100 # Fail - should be a string
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

exports[`E2E lint-config test with option: { dirName: 'invalid-config--lint-config-error', option: 'error' } 1`] = `
[1] .redocly.yaml:5:3 at #/rules/context
[1] .redocly.yaml:6:3 at #/rules/context
Property \`context\` is not expected here.
3 | root: ./openapi.yaml
4 | rules:
5 | context: null
| ^^^^^^^
6 |
4 |
5 | rules:
6 | context:
| ^^^^^^^^
7 |
Error was generated by the configuration spec rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

exports[`E2E lint-config test with option: { dirName: 'invalid-config--lint-config-warn', option: 'warn' } 1`] = `
[1] .redocly.yaml:5:3 at #/rules/context
[1] .redocly.yaml:6:3 at #/rules/context
Property \`context\` is not expected here.
3 | root: ./openapi.yaml
4 | rules:
5 | context: null
| ^^^^^^^
6 |
4 |
5 | rules:
6 | context:
| ^^^^^^^^
7 |
Warning was generated by the configuration spec rule.
Expand Down
12 changes: 6 additions & 6 deletions __tests__/lint-config/invalid-config--no-option/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

exports[`E2E lint-config test with option: { dirName: 'invalid-config--no-option', option: null } 1`] = `
[1] .redocly.yaml:5:3 at #/rules/context
[1] .redocly.yaml:6:3 at #/rules/context
Property \`context\` is not expected here.
3 | root: ./openapi.yaml
4 | rules:
5 | context: null
| ^^^^^^^
6 |
4 |
5 | rules:
6 | context:
| ^^^^^^^^
7 |
Warning was generated by the configuration spec rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

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
[1] .redocly.yaml:9:17 at #/rules/assert~1path-item-mutually-required/where/0/subject/type
\`type\` can be one of the following only: "any", "Root", "Tag", "TagList", "ExternalDocs", "Server", "ServerList", "ServerVariable", "ServerVariablesMap", "SecurityRequirement", "SecurityRequirementList", "Info", "Contact", "License", "Paths", "PathItem", "Parameter", "ParameterList", "Operation", "Callback", "CallbacksMap", "RequestBody", "MediaTypesMap", "MediaType", "Example", "ExamplesMap", "Encoding", "EncodingMap", "Header", "HeadersMap", "Responses", "Response", "Link", "LinksMap", "Schema", "Xml", "SchemaProperties", "DiscriminatorMapping", "Discriminator", "Components", "NamedSchemas", "NamedResponses", "NamedParameters", "NamedExamples", "NamedRequestBodies", "NamedHeaders", "NamedSecuritySchemes", "NamedLinks", "NamedCallbacks", "ImplicitFlow", "PasswordFlow", "ClientCredentials", "AuthorizationCode", "OAuth2Flows", "SecurityScheme", "XCodeSample", "XCodeSampleList", "WebhooksMap", "SpecExtension", "Message".
6 | where:
7 | - subject:
8 | type: Invalid-type
7 | where:
8 | - subject:
9 | type: Invalid-type
| ^^^^^^^^^^^^
9 | property: property
10 | assertions:
10 | property: property
11 | assertions:
Warning was generated by the configuration spec rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

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
[1] .redocly.yaml:6:3 at #/rules/asset~1path-item-mutually-required
The field \`severity\` must be present on this level.
3 | root: ./openapi.yaml
4 | rules:
5 | asset/path-item-mutually-required:
4 |
5 | rules:
6 | asset/path-item-mutually-required:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 | context:
7 | - type: PathItem
7 | context:
8 | - type: PathItem
Warning was generated by the configuration spec rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ exports[`E2E lint-config invalid-definition-and-config: {
snapshot: 'config-with-error.snapshot.js'
} 1`] = `
[1] .redocly.yaml:5:3 at #/rules/context
[1] .redocly.yaml:6:3 at #/rules/context
Property \`context\` is not expected here.
3 | root: ./openapi.yaml
4 | rules:
5 | context: null
| ^^^^^^^
6 | extends:
7 | - recommended
4 |
5 | rules:
6 | context:
| ^^^^^^^^
7 |
8 | extends:
Error was generated by the configuration spec rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ exports[`E2E lint-config invalid-definition-and-config: {
snapshot: 'config-with-warn.snapshot.js'
} 1`] = `
[1] .redocly.yaml:5:3 at #/rules/context
[1] .redocly.yaml:6:3 at #/rules/context
Property \`context\` is not expected here.
3 | root: ./openapi.yaml
4 | rules:
5 | context: null
| ^^^^^^^
6 | extends:
7 | - recommended
4 |
5 | rules:
6 | context:
| ^^^^^^^^
7 |
8 | extends:
Warning was generated by the configuration spec rule.
Expand Down
12 changes: 6 additions & 6 deletions __tests__/lint/deprecated-apiDefinitions/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ Property \`apiDefinitions\` is not expected here.
1 | apiDefinitions:
| ^^^^^^^^^^^^^^
2 | main: ./openapi.yaml
3 | lint:
3 |
Warning was generated by the configuration spec rule.
[2] redocly.yaml:3:1 at #/lint
[2] redocly.yaml:4:1 at #/lint
Property \`lint\` is not expected here.
Did you mean: env ?
1 | apiDefinitions:
2 | main: ./openapi.yaml
3 | lint:
3 |
4 | lint:
| ^^^^
4 | rules:
5 | info-contact: warn
5 | rules:
6 | info-contact: warn
Warning was generated by the configuration spec rule.
Expand Down
14 changes: 7 additions & 7 deletions __tests__/lint/deprecated-lint/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

exports[`E2E lint deprecated-lint 1`] = `
[1] redocly.yaml:7:1 at #/lint
[1] redocly.yaml:8:1 at #/lint
Property \`lint\` is not expected here.
Did you mean: env ?
5 | rules:
6 | operation-4xx-response: error
7 | lint:
| ^^^^
8 | rules:
9 | info-contact: warn
6 | operation-4xx-response: error
7 |
8 | lint:
| ^^^^
9 | rules:
10 | info-contact: warn
Warning was generated by the configuration spec rule.
Expand Down
14 changes: 7 additions & 7 deletions __tests__/lint/deprecated-styleguide/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

exports[`E2E lint deprecated-styleguide 1`] = `
[1] redocly.yaml:7:1 at #/styleguide
[1] redocly.yaml:8:1 at #/styleguide
Property \`styleguide\` is not expected here.
5 | rules:
6 | operation-4xx-response: error
7 | styleguide:
| ^^^^^^^^^^
8 | rules:
9 | info-contact: warn
6 | operation-4xx-response: error
7 |
8 | styleguide:
| ^^^^^^^^^^
9 | rules:
10 | info-contact: warn
Warning was generated by the configuration spec rule.
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('lint', () => {
servers:
- url: http://redocly-example.com
paths: {}
`,
`,
config: await loadConfig(),
});

Expand Down Expand Up @@ -141,8 +141,8 @@ describe('lint', () => {
"suggest": [
"theme",
"env",
"seo",
"sso",
"seo",
],
},
{
Expand Down Expand Up @@ -206,9 +206,9 @@ describe('lint', () => {
"severity": "error",
"suggest": [
"apis",
"seo",
"sso",
"env",
"seo",
],
},
]
Expand Down
Loading

0 comments on commit d7fc2eb

Please sign in to comment.