Added new "--warnings" command-line option that generates an exit code of 1 if one or more warnings are emitted. By default, only errors generate an exit code of 1.

This commit is contained in:
Eric Traut 2021-10-06 20:12:15 -07:00
parent d5878534fc
commit 6107de9090
2 changed files with 10 additions and 0 deletions

View File

@ -21,6 +21,7 @@ Pyright can be run as either a VS Code extension or as a node-based command-line
| --verbose | Emit verbose diagnostics |
| --verifytypes `<IMPORT>` | Verify completeness of types in py.typed package |
| --version | Print pyright version |
| --warnings | Use exit code of 1 if warnings are reported |
| -w, --watch | Continue to run and watch for changes (4) |
(1) If specific files are specified on the command line, the pyrightconfig.json file is ignored.

View File

@ -136,6 +136,7 @@ async function processArgs(): Promise<ExitStatus> {
{ name: 'verifytypes', type: String },
{ name: 'verbose', type: Boolean },
{ name: 'version', type: Boolean },
{ name: 'warnings', type: Boolean },
{ name: 'watch', alias: 'w', type: Boolean },
];
@ -249,6 +250,7 @@ async function processArgs(): Promise<ExitStatus> {
}
options.checkOnlyOpenFiles = false;
const treatWarningsAsErrors = !!args.warnings;
const output = args.outputjson ? new StderrConsole() : undefined;
const fileSystem = new PyrightFileSystem(createFromRealFileSystem(output));
@ -293,9 +295,15 @@ async function processArgs(): Promise<ExitStatus> {
results.elapsedTime
);
errorCount += report.errorCount;
if (treatWarningsAsErrors) {
errorCount += report.warningCount;
}
} else {
const report = reportDiagnosticsAsText(results.diagnostics);
errorCount += report.errorCount;
if (treatWarningsAsErrors) {
errorCount += report.warningCount;
}
}
}
@ -600,6 +608,7 @@ function printUsage() {
' --verbose Emit verbose diagnostics\n' +
' --verifytypes <PACKAGE> Verify type completeness of a py.typed package\n' +
' --version Print Pyright version\n' +
' --warnings Use exit code of 1 if warnings are reported\n' +
' -w,--watch Continue to run and watch for changes\n'
);
}