Skip to content

Commit 9913f93

Browse files
authored
fix: add env variable for controls the limit of suggestions (#2403)
* feat: added env variable to control the limit of suggestions in lint
1 parent 769e2a1 commit 9913f93

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

.changeset/clever-hoops-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/openapi-core": minor
3+
---
4+
5+
Added `REDOCLY_CLI_LINT_MAX_SUGGESTIONS` environment variable to limit displayed suggestions (default: 5).

docs/@v2/commands/lint.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ If the number of detected problems exceeds the specified threshold, the remainin
333333

334334
Note that the default value is `100`.
335335

336+
### Limit the displayed suggestions count
337+
338+
When lint errors include suggestions (such as "Did you mean: propertyName?"), you can control how many suggestions are displayed using the `REDOCLY_CLI_LINT_MAX_SUGGESTIONS` environment variable.
339+
340+
```bash
341+
REDOCLY_CLI_LINT_MAX_SUGGESTIONS=10 redocly lint openapi.yaml
342+
```
343+
344+
The default value is `5`. This is useful when working with rules that provide many suggestions (like typo corrections for property names), allowing you to see more or fewer alternatives as needed.
345+
336346
### Generate ignore file
337347

338348
With this option, you can generate the `.redocly.lint-ignore.yaml` file to suppress error and warning severity problems in the output.

packages/core/src/__tests__/format.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,73 @@ describe('format', () => {
144144
"
145145
`);
146146
});
147+
148+
it('should format problems with suggestions in github-actions format', () => {
149+
const problems = [
150+
{
151+
ruleId: 'invalid-property',
152+
message: 'Property is invalid',
153+
severity: 'error' as const,
154+
location: [
155+
{
156+
source: { absoluteRef: 'openapi.yaml' } as Source,
157+
start: { line: 5, col: 10 },
158+
end: { line: 5, col: 20 },
159+
} as LocationObject,
160+
],
161+
suggest: ['validProperty', 'anotherValidProperty', 'oneMoreProperty'],
162+
},
163+
];
164+
165+
formatProblems(problems, {
166+
format: 'github-actions',
167+
version: '1.0.0',
168+
totals: getTotals(problems),
169+
});
170+
171+
expect(output).toMatchInlineSnapshot(`
172+
"::error title=invalid-property,file=openapi.yaml,line=5,col=10,endLine=5,endColumn=20::Property is invalid%0A%0ADid you mean:%0A - validProperty%0A - anotherValidProperty%0A - oneMoreProperty%0A%0A
173+
"
174+
`);
175+
});
176+
177+
it('should limit suggestions based on REDOCLY_CLI_LINT_MAX_SUGGESTIONS constant', () => {
178+
const problems: NormalizedProblem[] = [
179+
{
180+
ruleId: 'test-rule',
181+
message: 'Test message',
182+
severity: 'error' as const,
183+
location: [
184+
{
185+
source: { absoluteRef: 'test.yaml' } as Source,
186+
start: { line: 1, col: 1 },
187+
end: { line: 1, col: 10 },
188+
} as LocationObject,
189+
],
190+
suggest: [
191+
'suggestion1',
192+
'suggestion2',
193+
'suggestion3',
194+
'suggestion4',
195+
'suggestion5',
196+
'suggestion6',
197+
'suggestion7',
198+
'suggestion8',
199+
'suggestion9',
200+
'suggestion10',
201+
],
202+
},
203+
];
204+
205+
formatProblems(problems, {
206+
format: 'github-actions',
207+
version: '1.0.0',
208+
totals: getTotals(problems),
209+
});
210+
211+
expect(output).toMatchInlineSnapshot(`
212+
"::error title=test-rule,file=test.yaml,line=1,col=1,endLine=1,endColumn=10::Test message%0A%0ADid you mean:%0A - suggestion1%0A - suggestion2%0A - suggestion3%0A - suggestion4%0A - suggestion5%0A%0A
213+
"
214+
`);
215+
});
147216
});

packages/core/src/format/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const CODECLIMATE_SEVERITY_MAPPING = {
4141
warn: 'minor',
4242
};
4343

44-
const MAX_SUGGEST = 5;
44+
const MAX_SUGGEST = +(env.REDOCLY_CLI_LINT_MAX_SUGGESTIONS ?? 5);
4545

4646
function severityToNumber(severity: ProblemSeverity) {
4747
return severity === 'error' ? 1 : 2;

0 commit comments

Comments
 (0)