mirror of
https://github.com/microsoft/pyright.git
synced 2024-08-17 03:40:44 +03:00
Changed reveal_type to use an information diagnostic severity rather than warning. Added support in CLI for information diagnostic severity. These were previously dropped.
This commit is contained in:
parent
43f4eae985
commit
6378f7761f
@ -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: {
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user