Skip to content

Commit

Permalink
fix(cli): do not show 'or higher' if severity equals error (#2172)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Jun 1, 2022
1 parent 60770d1 commit f31ec63
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 10 deletions.
9 changes: 6 additions & 3 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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!
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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!
Original file line number Diff line number Diff line change
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!
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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!

0 comments on commit f31ec63

Please sign in to comment.