fix(cli): lint with multiple api files results in invalid output#2744
fix(cli): lint with multiple api files results in invalid output#2744harshit078 wants to merge 15 commits into
Conversation
🦋 Changeset detectedLatest commit: 0c7cf32 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Daryna-del
left a comment
There was a problem hiding this comment.
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.
| const totals: Totals = { errors: 0, warnings: 0, ignored: 0 }; | ||
| let totalIgnored = 0; | ||
| const allLintRes: Awaited<ReturnType<typeof lint>> = []; | ||
| let loopCompleted = false; |
There was a problem hiding this comment.
The same here, I don't think we need this additional variable.
| const allLintRes: Awaited<ReturnType<typeof lint>> = []; | ||
| let loopCompleted = false; | ||
|
|
||
| try { |
There was a problem hiding this comment.
The try/finally adds complexity that I don't think is needed here.
| case 'markdown': { | ||
| const groupedByFile = groupByFiles(problems); | ||
| for (const [file, { fileProblems }] of Object.entries(groupedByFile)) { | ||
| let fileErrors = 0; |
There was a problem hiding this comment.
The changes here unnecessary.
There was a problem hiding this comment.
Agree ! fixed it. thanks for pointing it out
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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', | ||
| }); | ||
| } |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 0c7cf32. Configure here.
Daryna-del
left a comment
There was a problem hiding this comment.
Hey @harshit078
Left some comments, could you, please, take a look?
| {% 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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
We would like to have combined output only for checkstyle format. Could you please adjust it?
| 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. |
There was a problem hiding this comment.
Same here, only for checkstyle format. Could you please adjust docs?
| version, | ||
| command: 'lint', | ||
| }); | ||
| allLintRes.push(...results); |
There was a problem hiding this comment.
We would like to have combined output only for checkstyle format. Could you please adjust a solution?
| } | ||
| } | ||
|
|
||
| if (!argv['generate-ignore-file']) { |
There was a problem hiding this comment.
Same here, only for checkstyle format
|
|
||
|
|
||
| [1] split/info.yaml:1:1 at #/contact | ||
| [3] split/info.yaml:1:1 at #/contact |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
This file shouldn't be changed


What/Why/How?
Reference
#2692
Testing
Screenshots (optional)
Check yourself
Security
Note
Medium Risk
Changes
lintoutput behavior when multiple API files are provided by aggregating results into oneformatProblemscall, 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 lintnow produces valid structured output when linting multiple APIs in one run. Instead of callingformatProblems()per API, the command accumulates all lint problems and prints one combinedcheckstyle/json/other structured document with overall totals.Tests were updated to expect a single
formatProblemscall 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.