Skip to content

fix(formatters) fix invalid json when no results found (#2912)#2913

Open
Pentusha wants to merge 3 commits intostoplightio:developfrom
Pentusha:develop
Open

fix(formatters) fix invalid json when no results found (#2912)#2913
Pentusha wants to merge 3 commits intostoplightio:developfrom
Pentusha:develop

Conversation

@Pentusha
Copy link
Copy Markdown

Fixes #2912.

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

@Pentusha Pentusha requested a review from a team as a code owner March 13, 2026 10:45
Copilot AI review requested due to automatic review settings March 13, 2026 10:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 json vs stylish formats.

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);

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.

spectral lint --format json outputs invalid JSON when no results found (informational message appended to stdout)

4 participants