-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CLI command to run validation (#820)
Closes #703 ### Summary of Changes Add a new `check` command to validate Safe-DS files without generating code for them.
- Loading branch information
1 parent
d8fdde6
commit 7c2526d
Showing
72 changed files
with
781 additions
and
158 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createSafeDsServicesWithBuiltins } from '@safe-ds/lang'; | ||
import { NodeFileSystem } from 'langium/node'; | ||
import { extractDocuments } from '../helpers/documents.js'; | ||
import { diagnosticToString, getDiagnostics } from '../helpers/diagnostics.js'; | ||
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver'; | ||
import chalk from 'chalk'; | ||
import { ExitCode } from './exitCode.js'; | ||
|
||
export const check = async (fsPaths: string[], options: CheckOptions): Promise<void> => { | ||
const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs; | ||
|
||
let errorCount = 0; | ||
|
||
for (const document of await extractDocuments(services, fsPaths)) { | ||
for (const diagnostic of getDiagnostics(document)) { | ||
console.log(diagnosticToString(document.uri, diagnostic, options)); | ||
|
||
if (isError(diagnostic, options)) { | ||
errorCount++; | ||
} | ||
} | ||
} | ||
|
||
if (errorCount > 0) { | ||
console.error(chalk.red(`Found ${errorCount} ${errorCount === 1 ? 'error' : 'errors'}.`)); | ||
process.exit(ExitCode.FileHasErrors); | ||
} else { | ||
console.log(chalk.green(`No errors found.`)); | ||
} | ||
}; | ||
|
||
/** | ||
* Command line options for the `check` command. | ||
*/ | ||
export interface CheckOptions { | ||
/** | ||
* Whether the program should fail on warnings. | ||
*/ | ||
strict: boolean; | ||
} | ||
|
||
const isError = (diagnostic: Diagnostic, options: CheckOptions) => { | ||
return ( | ||
diagnostic.severity === DiagnosticSeverity.Error || | ||
(diagnostic.severity === DiagnosticSeverity.Warning && options.strict) | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Exit codes for the CLI. | ||
*/ | ||
export enum ExitCode { | ||
/** | ||
* Everything went well. | ||
*/ | ||
Success = 0, | ||
|
||
/** | ||
* The given path does not exist. | ||
*/ | ||
MissingPath = 100, | ||
|
||
/** | ||
* The given path is not a file or directory. | ||
*/ | ||
NotAFileOrDirectory = 101, | ||
|
||
/** | ||
* The given file does not have a Safe-DS extension. | ||
*/ | ||
FileWithoutSafeDsExtension = 102, | ||
|
||
/** | ||
* The given file has errors. | ||
*/ | ||
FileHasErrors = 103, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.