From 6378f7761f8f7d962609be4426bf0b758a3a1076 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 16 Sep 2020 09:11:31 -0700 Subject: [PATCH] Changed reveal_type to use an information diagnostic severity rather than warning. Added support in CLI for information diagnostic severity. These were previously dropped. --- docs/command-line.md | 3 +- .../src/analyzer/typeEvaluator.ts | 2 +- packages/pyright-internal/src/pyright.ts | 43 +++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/docs/command-line.md b/docs/command-line.md index 619bb1275..20ccb7593 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -50,6 +50,7 @@ If the “--outputjson” option is specified on the command line, diagnostics a filesAnalyzed: number, errorCount: number, warningCount: number, + informationCount: number, timeInSec: number } } @@ -60,7 +61,7 @@ Each Diagnostic is formatted output in the following format: ```javascript { file: string, - severity: 'error' | 'warning', + severity: 'error' | 'warning' | 'information', message: string, range: { start: { diff --git a/packages/pyright-internal/src/analyzer/typeEvaluator.ts b/packages/pyright-internal/src/analyzer/typeEvaluator.ts index d0aef0ae2..bbcbc7b48 100644 --- a/packages/pyright-internal/src/analyzer/typeEvaluator.ts +++ b/packages/pyright-internal/src/analyzer/typeEvaluator.ts @@ -4640,7 +4640,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions const type = getTypeOfExpression(node.arguments[0].valueExpression).type; const exprString = ParseTreeUtils.printExpression(node.arguments[0].valueExpression); const typeString = printType(type); - addWarning(`Type of "${exprString}" is "${typeString}"`, node.arguments[0]); + addInformation(`Type of "${exprString}" is "${typeString}"`, node.arguments[0]); // Return a literal string with the type. We can use this in unit tests // to validate the exact type. diff --git a/packages/pyright-internal/src/pyright.ts b/packages/pyright-internal/src/pyright.ts index 3b10db482..44f50da85 100644 --- a/packages/pyright-internal/src/pyright.ts +++ b/packages/pyright-internal/src/pyright.ts @@ -45,7 +45,7 @@ interface PyrightJsonResults { interface PyrightJsonDiagnostic { file: string; - severity: 'error' | 'warning'; + severity: 'error' | 'warning' | 'information'; message: string; range: Range; } @@ -54,12 +54,14 @@ interface PyrightJsonSummary { filesAnalyzed: number; errorCount: number; warningCount: number; + informationCount: number; timeInSec: number; } interface DiagnosticResult { errorCount: number; warningCount: number; + informationCount: number; diagnosticCount: number; } @@ -289,27 +291,40 @@ function reportDiagnosticsAsJson( filesAnalyzed: filesInProgram, errorCount: 0, warningCount: 0, + informationCount: 0, timeInSec, }, }; let errorCount = 0; let warningCount = 0; + let informationCount = 0; fileDiagnostics.forEach((fileDiag) => { fileDiag.diagnostics.forEach((diag) => { - if (diag.category === DiagnosticCategory.Error || diag.category === DiagnosticCategory.Warning) { + if ( + diag.category === DiagnosticCategory.Error || + diag.category === DiagnosticCategory.Warning || + diag.category === DiagnosticCategory.Information + ) { report.diagnostics.push({ file: fileDiag.filePath, - severity: diag.category === DiagnosticCategory.Error ? 'error' : 'warning', + severity: + diag.category === DiagnosticCategory.Error + ? 'error' + : DiagnosticCategory.Warning + ? 'warning' + : 'information', message: diag.message, range: diag.range, }); if (diag.category === DiagnosticCategory.Error) { errorCount++; - } else { + } else if (diag.category === DiagnosticCategory.Warning) { warningCount++; + } else if (diag.category === DiagnosticCategory.Information) { + informationCount++; } } }); @@ -317,19 +332,22 @@ function reportDiagnosticsAsJson( report.summary.errorCount = errorCount; report.summary.warningCount = warningCount; + report.summary.informationCount = informationCount; console.log(JSON.stringify(report, undefined, 4)); return { errorCount, warningCount, - diagnosticCount: errorCount + warningCount, + informationCount, + diagnosticCount: errorCount + warningCount + informationCount, }; } function reportDiagnosticsAsText(fileDiagnostics: FileDiagnostics[]): DiagnosticResult { let errorCount = 0; let warningCount = 0; + let informationCount = 0; fileDiagnostics.forEach((fileDiagnostics) => { // Don't report unused code diagnostics. @@ -349,7 +367,12 @@ function reportDiagnosticsAsText(fileDiagnostics: FileDiagnostics[]): Diagnostic ' - '; } - message += diag.category === DiagnosticCategory.Error ? chalk.red('error') : chalk.green('warning'); + message += + diag.category === DiagnosticCategory.Error + ? chalk.red('error') + : diag.category === DiagnosticCategory.Warning + ? chalk.green('warning') + : chalk.blue('info'); message += `: ${diag.message}`; const rule = diag.getRule(); @@ -363,6 +386,8 @@ function reportDiagnosticsAsText(fileDiagnostics: FileDiagnostics[]): Diagnostic errorCount++; } else if (diag.category === DiagnosticCategory.Warning) { warningCount++; + } else if (diag.category === DiagnosticCategory.Information) { + informationCount++; } }); } @@ -370,13 +395,15 @@ function reportDiagnosticsAsText(fileDiagnostics: FileDiagnostics[]): Diagnostic console.log( `${errorCount.toString()} ${errorCount === 1 ? 'error' : 'errors'}, ` + - `${warningCount.toString()} ${warningCount === 1 ? 'warning' : 'warnings'} ` + `${warningCount.toString()} ${warningCount === 1 ? 'warning' : 'warnings'}, ` + + `${informationCount.toString()} ${informationCount === 1 ? 'info' : 'infos'} ` ); return { errorCount, warningCount, - diagnosticCount: errorCount + warningCount, + informationCount, + diagnosticCount: errorCount + warningCount + informationCount, }; }