Skip to content

fix(cli): lint with multiple api files results in invalid output#2744

Open
harshit078 wants to merge 15 commits into
Redocly:mainfrom
harshit078:fix-lint-multiple-files
Open

fix(cli): lint with multiple api files results in invalid output#2744
harshit078 wants to merge 15 commits into
Redocly:mainfrom
harshit078:fix-lint-multiple-files

Conversation

@harshit078
Copy link
Copy Markdown
Contributor

@harshit078 harshit078 commented Apr 15, 2026

What/Why/How?

  • Added logic to gather all lint results into allResults during per-file loop, then call formatProblems() once after with the combined totals.

Reference

#2692

Testing

Screenshots (optional)

Check yourself

  • This PR 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

Note

Medium Risk
Changes lint output behavior when multiple API files are provided by aggregating results into one formatProblems call, which can affect downstream tooling that parses structured formats. Logic is straightforward and covered by updated unit/e2e snapshots, but it impacts a core CLI command.

Overview
redocly lint now produces valid structured output when linting multiple APIs in one run. Instead of calling formatProblems() per API, the command accumulates all lint problems and prints one combined checkstyle/json/other structured document with overall totals.

Tests were updated to expect a single formatProblems call and new problem ordering/indices, docs (@v1/@v2) were revised to describe the combined structured output behavior, and a patch changeset was added.

Reviewed by Cursor Bugbot for commit 0c7cf32. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: 0c7cf32

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 Patch
@redocly/openapi-core Patch
@redocly/respect-core Patch

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

@harshit078 harshit078 changed the title fix(cli): lint with multiple api files results in invalid checkstyle/json output fix(cli): lint with multiple api files results in invalid output Apr 15, 2026
@harshit078 harshit078 marked this pull request as ready for review April 15, 2026 12:24
@harshit078 harshit078 requested review from a team as code owners April 15, 2026 12:24
Comment thread packages/cli/src/commands/lint.ts
Comment thread packages/cli/src/commands/lint.ts Outdated
Copy link
Copy Markdown
Contributor

@Daryna-del Daryna-del left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! The overall approach looks good, but there are
a couple of things worth addressing before merging. Could you also take a
look at why the build and test job is failing? Left a few comments.

Comment thread packages/cli/src/commands/lint.ts Outdated
const totals: Totals = { errors: 0, warnings: 0, ignored: 0 };
let totalIgnored = 0;
const allLintRes: Awaited<ReturnType<typeof lint>> = [];
let loopCompleted = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same here, I don't think we need this additional variable.

Comment thread packages/cli/src/commands/lint.ts Outdated
const allLintRes: Awaited<ReturnType<typeof lint>> = [];
let loopCompleted = false;

try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The try/finally adds complexity that I don't think is needed here.

Comment thread packages/core/src/format/format.ts Outdated
case 'markdown': {
const groupedByFile = groupByFiles(problems);
for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
let fileErrors = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changes here unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree ! fixed it. thanks for pointing it out

@harshit078 harshit078 requested a review from Daryna-del May 7, 2026 08:37
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0c7cf32. Configure here.

version,
command: 'lint',
});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maxProblems truncation now applies globally, hiding problems

Medium Severity

Moving formatProblems outside the per-file loop changes the semantics of --max-problems from a per-file cap to a global cap. formatProblems internally calls .slice(0, maxProblems) on the combined results. With the default of 100, linting several API files that together exceed 100 problems will now silently hide problems that were previously shown. For example, 5 files × 30 problems each = 150 total, but only 100 are displayed. This is a user-facing regression where legitimate lint issues go unreported without the user realizing it.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0c7cf32. Configure here.

Copy link
Copy Markdown
Contributor

@Daryna-del Daryna-del left a comment

Choose a reason for hiding this comment

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

Hey @harshit078
Left some comments, could you, please, take a look?

Comment thread docs/@v1/commands/lint.md
{% admonition type="warning" name="Lint one API at a time" %}
Some formats, such as `checkstyle` or `json`, don't work well when multiple APIs are linted in a single command. Try linting each API separately when you pass the command output to another tool.
{% /admonition %}
The standard `codeframe` output format works well in most situations, but `redocly` can also produce output to integrate with other tools. When multiple APIs are linted in a single command, all structured formats (such as `checkstyle` and `json`) produce a single combined document that groups problems per file.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You don't need to make changes in v1 docs

"@redocly/cli": patch
---

When multiple APIs are linted in a single command, all structured formats (such as `checkstyle` and `json`) produce a single combined document that groups problems per file.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We would like to have combined output only for checkstyle format. Could you please adjust it?

Comment thread docs/@v2/commands/lint.md
Some formats, such as `checkstyle` or `json`, don't work well when multiple APIs are linted in a single command.
Try linting each API separately when you pass the command output to another tool.
{% /admonition %}
When multiple APIs are linted in a single command, all structured formats (such as `checkstyle` and `json`) produce a single combined document that groups problems per file.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, only for checkstyle format. Could you please adjust docs?

version,
command: 'lint',
});
allLintRes.push(...results);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We would like to have combined output only for checkstyle format. Could you please adjust a solution?

}
}

if (!argv['generate-ignore-file']) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, only for checkstyle format



[1] split/info.yaml:1:1 at #/contact
[3] split/info.yaml:1:1 at #/contact
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file shouldn't be changed



[1] openapi-oas32-2020.yaml:36:26 at #/paths/~1test/get/responses/200/content/application~1json/examples/exclusiveMinInvalid/value/age
[4] openapi-oas32-2020.yaml:36:26 at #/paths/~1test/get/responses/200/content/application~1json/examples/exclusiveMinInvalid/value/age
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file shouldn't be changed

@@ -29,7 +29,7 @@ referenced from openapi-oas30-draft4.yaml:43:7 at #/components/parameters/RefInv
Error was generated by the no-invalid-parameter-examples rule.


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file shouldn't be changed

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