fix(formatters) fix invalid json when no results found (#2912)#2913
Open
Pentusha wants to merge 3 commits intostoplightio:developfrom
Open
fix(formatters) fix invalid json when no results found (#2912)#2913Pentusha wants to merge 3 commits intostoplightio:developfrom
Pentusha wants to merge 3 commits intostoplightio:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes spectral lint --format json producing invalid JSON when there are no findings by preventing the “No results…” informational message from being appended to JSON output on stdout.
Changes:
- Suppress the “No results…” stdout informational message when JSON output format is selected.
- Add CLI tests covering the no-results behavior for
jsonvsstylishformats.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/cli/src/commands/lint.ts | Prevents the “No results…” message from being written to stdout when JSON formatting is requested. |
| packages/cli/src/commands/tests/lint.test.ts | Adds regression tests ensuring stdout messaging differs between json and stylish formats when there are no results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (linterResult.results.length > 0) { | ||
| process.exit(severeEnoughToFail(linterResult.results, failSeverity) ? 1 : 0); | ||
| } else if (config.quiet !== true) { | ||
| } else if (config.quiet !== true && !format.includes(OutputFormat.JSON)) { |
Comment on lines
+265
to
+280
| it('does not write informational message to stdout when format is json and no results found', async () => { | ||
| (lint as jest.Mock).mockReset(); | ||
| (lint as jest.Mock).mockResolvedValueOnce({ results: [], resolvedRuleset: {} }); | ||
| (formatOutput as jest.Mock).mockReturnValueOnce('[]'); | ||
| (writeOutput as jest.Mock).mockResolvedValueOnce(undefined); | ||
|
|
||
| await run(`lint -f json ./__fixtures__/empty-oas2-document.json`); | ||
| expect(process.stdout.write).not.toHaveBeenCalledWith(expect.stringContaining('No results')); | ||
| }); | ||
|
|
||
| it('writes informational message to stdout when format is stylish and no results found', async () => { | ||
| (lint as jest.Mock).mockReset(); | ||
| (lint as jest.Mock).mockResolvedValueOnce({ results: [], resolvedRuleset: {} }); | ||
| (formatOutput as jest.Mock).mockReturnValueOnce(''); | ||
| (writeOutput as jest.Mock).mockResolvedValueOnce(undefined); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2912.
Checklist
Does this PR introduce a breaking change?