Skip to content

fix: make sure validation of invalid document exits 1 #877

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion src/commands/validate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Flags } from '@oclif/core';

import Command from '../base';
import { validate, validationFlags } from '../parser';
import { ValidationStatus, validate, validationFlags } from '../parser';
import { load } from '../models/SpecificationFile';
import { specWatcher } from '../globals';
import { watchFlag } from '../flags';
Expand Down Expand Up @@ -30,5 +30,9 @@ export default class Validate extends Command {
}

await validate(this, specFile, flags);
if(await validate(this, specFile, flags) == ValidationStatus.Invalid) {
Copy link
Member

Choose a reason for hiding this comment

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

actually why validate twice?

also this.exit(0) is not really necessary

Copy link
Author

Choose a reason for hiding this comment

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

@derberg changed it

this.exit(1);
}
this.exit(0);
}
}
9 changes: 7 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface ValidationFlagsOptions {
logDiagnostics?: boolean;
}

export enum ValidationStatus {
Invalid = "invalid",
Valid = "valid",
}

export function validationFlags({ logDiagnostics = true }: ValidationFlagsOptions = {}) {
return {
'log-diagnostics': Flags.boolean({
Expand Down Expand Up @@ -82,7 +87,7 @@ function logDiagnostics(diagnostics: Diagnostic[], command: Command, specFile: S
command.logToStderr(`\n${sourceString} and/or referenced documents have governance issues.`);
command.logToStderr(formatOutput(diagnostics, diagnosticsFormat, failSeverity));
}
return 'invalid';
return ValidationStatus.Invalid;
}

if (logDiagnostics) {
Expand All @@ -93,7 +98,7 @@ function logDiagnostics(diagnostics: Diagnostic[], command: Command, specFile: S
command.log(`\n${sourceString} is valid! ${sourceString} and referenced documents don't have governance issues.`);
}

return 'valid';
return ValidationStatus.Valid;
}

export function formatOutput(diagnostics: Diagnostic[], format: `${OutputFormat}`, failSeverity: SeveritytKind) {
Expand Down