Skip to content

Commit cab4e7c

Browse files
authored
fix: improve lint formatting for markdown to handle multiline error messages (#2510)
1 parent 1b0a6d4 commit cab4e7c

4 files changed

Lines changed: 49 additions & 2 deletions

File tree

.changeset/orange-books-clap.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/openapi-core": patch
3+
"@redocly/cli": patch
4+
---
5+
6+
Fixed an issue where multi-line lint error messages could break Markdown formatting.

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,44 @@ describe('format', () => {
145145
`);
146146
});
147147

148+
it('should replace newlines with <br> in markdown messages', () => {
149+
const problems: NormalizedProblem[] = [
150+
{
151+
ruleId: 'multiline-rule',
152+
severity: 'error',
153+
message:
154+
"multiline-rule filed because the Response didn't meet the assertions: \n- Response does not describe header Deprecation\n- Response does not describe header Sunset",
155+
location: [
156+
{
157+
source: { absoluteRef: 'openapi.yaml' } as Source,
158+
start: { line: 10, col: 5 },
159+
end: { line: 10, col: 15 },
160+
} as LocationObject,
161+
],
162+
suggest: [],
163+
},
164+
];
165+
166+
formatProblems(problems, {
167+
format: 'markdown',
168+
version: '2.0.0',
169+
totals: getTotals(problems),
170+
});
171+
172+
expect(output).toMatchInlineSnapshot(`
173+
"## Lint: openapi.yaml
174+
175+
| Severity | Location | Problem | Message |
176+
|---|---|---|---|
177+
| error | line 10:5 | [multiline-rule](https://redocly.com/docs/cli/rules/multiline-rule/) | multiline-rule filed because the Response didn't meet the assertions: <br>- Response does not describe header Deprecation<br>- Response does not describe header Sunset |
178+
179+
Validation failed
180+
Errors: 1
181+
182+
"
183+
`);
184+
});
185+
148186
it('should format problems with suggestions in github-actions format', () => {
149187
const problems = [
150188
{

packages/core/src/config/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export type RawUniversalApiConfig = ApiConfig &
249249

250250
export type ResolvedApiConfig = ApiConfig & Required<ResolvedGovernanceConfig>;
251251

252-
export type RawUniversalConfig = Omit<Partial<RedoclyConfig>, 'apis' | 'plugins'> &
252+
export type RawUniversalConfig = Omit<RedoclyConfig, 'apis' | 'plugins'> &
253253
RawGovernanceConfig & {
254254
plugins?: (string | Plugin)[];
255255
apis?: Record<string, RawUniversalApiConfig>;

packages/core/src/format/format.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ export function formatProblems(
307307
const { start } = problem.location[0];
308308
return `| ${severityName} | line ${`${start.line}:${start.col}`} | [${
309309
problem.ruleId
310-
}](https://redocly.com/docs/cli/rules/${problem.ruleId}/) | ${problem.message} |`;
310+
}](https://redocly.com/docs/cli/rules/${problem.ruleId}/) | ${problem.message.replaceAll(
311+
'\n',
312+
'<br>'
313+
)} |`;
311314
}
312315

313316
function formatCheckstyle(problem: OnlyLineColProblem) {

0 commit comments

Comments
 (0)