Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/cli/src/commands/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,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);

Comment on lines +265 to +280
await run(`lint -f stylish ./__fixtures__/empty-oas2-document.json`);
expect(process.stdout.write).toHaveBeenCalledWith(expect.stringContaining('No results'));
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/src/arazzo/schemas/validators.ts

Large diffs are not rendered by default.

Loading