Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): do not show 'or higher' if severity equals error #2172

Merged
merged 1 commit into from Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/cli/src/commands/lint.ts
@@ -1,7 +1,7 @@
import { Dictionary } from '@stoplight/types';
import { DiagnosticSeverity, Dictionary } from '@stoplight/types';
import { isPlainObject } from '@stoplight/json';
import { getDiagnosticSeverity, IRuleResult } from '@stoplight/spectral-core';
import { isError, difference, pick } from 'lodash';
import { difference, isError, pick } from 'lodash';
import type { ReadStream } from 'tty';
import type { CommandModule } from 'yargs';
import * as process from 'process';
Expand Down Expand Up @@ -207,7 +207,10 @@ const lintCommand: CommandModule = {
if (results.length > 0) {
process.exit(severeEnoughToFail(results, failSeverity) ? 1 : 0);
} else if (config.quiet !== true) {
process.stdout.write(`No results with a severity of '${failSeverity}' or higher found!`);
const isErrorSeverity = getDiagnosticSeverity(failSeverity) === DiagnosticSeverity.Error;
process.stdout.write(
`No results with a severity of '${failSeverity}' ${isErrorSeverity ? '' : 'or higher '}found!`,
);
}
} catch (ex) {
fail(isError(ex) ? ex : new Error(String(ex)), config.verbose === true);
Expand Down
2 changes: 1 addition & 1 deletion test-harness/scenarios/custom-ref-resolver.scenario
Expand Up @@ -31,4 +31,4 @@ module.exports = {
====command====
{bin} lint {document} --ruleset "{asset:ruleset}" --resolver "{asset:resolver.js}" --ignore-unknown-format
====stdout====
No results with a severity of 'error' or higher found!
No results with a severity of 'error' found!
Expand Up @@ -11,4 +11,4 @@ module.exports = {
====command====
{bin} lint {document} --ruleset "{asset:ruleset}" --ignore-unknown-format
====stdout====
No results with a severity of 'error' or higher found!
No results with a severity of 'error' found!
2 changes: 1 addition & 1 deletion test-harness/scenarios/oas3.1/petstore.scenario
Expand Up @@ -196,4 +196,4 @@ rules:
====command====
{bin} lint {document} --ruleset {asset:ruleset.yaml}
====stdout====
No results with a severity of 'error' or higher found!
No results with a severity of 'error' found!
Expand Up @@ -40,4 +40,4 @@ components:
====command====
{bin} lint {document} --ruleset "{asset:ruleset}"
====stdout====
No results with a severity of 'error' or higher found!
No results with a severity of 'error' found!
Expand Up @@ -33,4 +33,4 @@ module.exports = {
====command====
{bin} lint --ruleset "{asset:ruleset}" {document}
====stdout====
No results with a severity of 'error' or higher found!
No results with a severity of 'error' found!
2 changes: 1 addition & 1 deletion test-harness/scenarios/severity/display-errors.scenario
Expand Up @@ -43,4 +43,4 @@ servers:
====status====
0
====stdout====
No results with a severity of 'error' or higher found!
No results with a severity of 'error' found!
28 changes: 28 additions & 0 deletions test-harness/scenarios/severity/fail-on-warn-no-warn.scenario
@@ -0,0 +1,28 @@
====test====
Will fail and return 1 as exit code because warnings exist
====document====
- type: string
- type: array
====asset:ruleset.json====
{
"rules": {
"valid-type": {
"given": "$..type",
"severity": "hint",
"then": {
"function": "enumeration",
"functionOptions": {
"values": ["array", "string"]
}
}
}
}
}
====command-nix====
{bin} lint {document} --ruleset "{asset:ruleset.json}" --fail-severity=warn
====command-win====
{bin} lint {document} --ruleset "{asset:ruleset.json}" --fail-severity warn
====status====
0
====stdout====
No results with a severity of 'warn' or higher found!
2 changes: 1 addition & 1 deletion test-harness/scenarios/valid-no-errors.oas2.scenario
Expand Up @@ -20,4 +20,4 @@ module.exports = oas;
====command====
{bin} lint {document} --ruleset "{asset:ruleset}"
====stdout====
No results with a severity of 'error' or higher found!
No results with a severity of 'error' found!