Skip to content

fix: enhance linting process to preserve existing files#2716

Open
harshit078 wants to merge 10 commits intoRedocly:mainfrom
harshit078:fix-cli-command-override-file
Open

fix: enhance linting process to preserve existing files#2716
harshit078 wants to merge 10 commits intoRedocly:mainfrom
harshit078:fix-cli-command-override-file

Conversation

@harshit078
Copy link
Copy Markdown

@harshit078 harshit078 commented Apr 3, 2026

What/Why/How?

  • redocly lint api1.yaml --generate-ignore-file updates only entries related to api1.yaml and its referenced files

Reference

Testing

Screenshots (optional)

Check yourself

  • Code follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

@harshit078 harshit078 requested a review from a team as a code owner April 3, 2026 12:40
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2026

🦋 Changeset detected

Latest commit: f7df653

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/cli Minor
@redocly/openapi-core Minor
@redocly/respect-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tatomyr
Copy link
Copy Markdown
Collaborator

tatomyr commented Apr 3, 2026

Thank you for your contribution, @harshit078!
Will this clean up other ignored entries related to that API file?
Could you add a test with ignored rules for two files, and then re-generate the entries only for one file, assuming that one of the problems in this file has been resolved, so when ignoring, it only adds entries that are relevant to the new version of the linted file.

Say, the starting ignore file:

ignore-bar.yaml:
  no-empty-servers:
    - '#/servers'
  operation-summary:
    - '#/paths/~1items/get/summary'
ignore-foo.yaml:
  no-empty-servers:
    - '#/servers'

Then you fix the operation-summary rule in ignore-bar.yaml and re-generate the ignore file only for it.
What you should get is this (the ignore entry for foo is preserved, and bar is updated):

ignore-bar.yaml:
  no-empty-servers:
    - '#/servers'
ignore-foo.yaml:
  no-empty-servers:
    - '#/servers'

@harshit078
Copy link
Copy Markdown
Author

@tatomyr Yes, it will clean up entries for the linted API file but only for files that still have problems in current run. Got it, I'll add the test

@harshit078 harshit078 requested a review from a team as a code owner April 6, 2026 13:20
Copy link
Copy Markdown
Collaborator

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

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

Left a couple of suggestions for improvement. Could you also check if the corresponding docs need to be updated?

@harshit078 harshit078 requested a review from tatomyr April 6, 2026 16:30
Copy link
Copy Markdown
Collaborator

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

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

Please do consider updating the corresponding docs in docs/@v2/commands/lint.md.


// TODO: use shared externalRef resolver, blocked by preprocessors now as they can mutate documents
for (const { path, alias } of apis) {
for (const { path: apiPath, alias } of apis) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the need for renaming path? Could you revert that so there's fewer changes?

totals.ignored += fileTotals.ignored;

if (argv['generate-ignore-file']) {
const apiAbsRef = isAbsoluteUrl(apiPath) ? apiPath : resolvePath(apiPath);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This check seems incorrect. The ref should align with mappedDefinitionName from Config.saveIgnore. I believe it would be cleaner to move this and the following lines into a new cleanup method next to saveIgnore and use it here.

"@redocly/cli": minor
---

redocly lint api1.yaml --generate-ignore-file updates only entries related to api1.yaml and its referenced files
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
redocly lint api1.yaml --generate-ignore-file updates only entries related to api1.yaml and its referenced files
Changed lint behavior with the `--generate-ignore-file` option — now it updates only the entries related to the file being linted, leaving other files' entries untouched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants