From 6107de90907a053cfa39525d74d138f32403a5c3 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 6 Oct 2021 20:12:15 -0700 Subject: [PATCH] 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. --- docs/command-line.md | 1 + packages/pyright-internal/src/pyright.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/command-line.md b/docs/command-line.md index 1bdff9681..5a1278c4d 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -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 `` | 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. diff --git a/packages/pyright-internal/src/pyright.ts b/packages/pyright-internal/src/pyright.ts index 694272c8d..dd2f8fafa 100644 --- a/packages/pyright-internal/src/pyright.ts +++ b/packages/pyright-internal/src/pyright.ts @@ -136,6 +136,7 @@ async function processArgs(): Promise { { 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 { } 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 { 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 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' ); }