diff --git a/packages/cli/src/commands/__tests__/lint.test.ts b/packages/cli/src/commands/__tests__/lint.test.ts index 240a547bc..9f419d20a 100644 --- a/packages/cli/src/commands/__tests__/lint.test.ts +++ b/packages/cli/src/commands/__tests__/lint.test.ts @@ -281,4 +281,24 @@ describe('lint', () => { expect(process.stderr.write).nthCalledWith(6, `Error #3: ${chalk.red('original exception')}\n`); }); + + 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); + + await run(`lint -f stylish ./__fixtures__/empty-oas2-document.json`); + expect(process.stdout.write).toHaveBeenCalledWith(expect.stringContaining('No results')); + }); }); diff --git a/packages/cli/src/commands/lint.ts b/packages/cli/src/commands/lint.ts index 2528c4a80..61fb203ab 100644 --- a/packages/cli/src/commands/lint.ts +++ b/packages/cli/src/commands/lint.ts @@ -223,7 +223,7 @@ const lintCommand: CommandModule = { 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)) { const isErrorSeverity = getDiagnosticSeverity(failSeverity) === DiagnosticSeverity.Error; process.stdout.write( `No results with a severity of '${failSeverity}' ${isErrorSeverity ? '' : 'or higher '}found!\n`,