mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Simplified some code for logging diagnostics in checker and binder.
This commit is contained in:
parent
32076952c7
commit
a4873a6a83
@ -367,7 +367,6 @@ export class Binder extends ParseTreeWalker {
|
|||||||
|
|
||||||
if (!importResult.isImportFound) {
|
if (!importResult.isImportFound) {
|
||||||
this._addDiagnostic(
|
this._addDiagnostic(
|
||||||
this._fileInfo.diagnosticRuleSet.reportMissingImports,
|
|
||||||
DiagnosticRule.reportMissingImports,
|
DiagnosticRule.reportMissingImports,
|
||||||
LocMessage.importResolveFailure().format({
|
LocMessage.importResolveFailure().format({
|
||||||
importName: importResult.importName,
|
importName: importResult.importName,
|
||||||
@ -385,7 +384,6 @@ export class Binder extends ParseTreeWalker {
|
|||||||
!importResult.pyTypedInfo
|
!importResult.pyTypedInfo
|
||||||
) {
|
) {
|
||||||
const diagnostic = this._addDiagnostic(
|
const diagnostic = this._addDiagnostic(
|
||||||
this._fileInfo.diagnosticRuleSet.reportMissingTypeStubs,
|
|
||||||
DiagnosticRule.reportMissingTypeStubs,
|
DiagnosticRule.reportMissingTypeStubs,
|
||||||
LocMessage.stubFileMissing().format({ importName: importResult.importName }),
|
LocMessage.stubFileMissing().format({ importName: importResult.importName }),
|
||||||
node
|
node
|
||||||
@ -752,7 +750,6 @@ export class Binder extends ParseTreeWalker {
|
|||||||
this._usesUnsupportedDunderAllForm = true;
|
this._usesUnsupportedDunderAllForm = true;
|
||||||
|
|
||||||
this._addDiagnostic(
|
this._addDiagnostic(
|
||||||
this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
|
|
||||||
DiagnosticRule.reportUnsupportedDunderAll,
|
DiagnosticRule.reportUnsupportedDunderAll,
|
||||||
LocMessage.unsupportedDunderAllOperation(),
|
LocMessage.unsupportedDunderAllOperation(),
|
||||||
node
|
node
|
||||||
@ -863,7 +860,6 @@ export class Binder extends ParseTreeWalker {
|
|||||||
|
|
||||||
if (node.chainedTypeAnnotationComment) {
|
if (node.chainedTypeAnnotationComment) {
|
||||||
this._addDiagnostic(
|
this._addDiagnostic(
|
||||||
this._fileInfo.diagnosticRuleSet.reportInvalidTypeForm,
|
|
||||||
DiagnosticRule.reportInvalidTypeForm,
|
DiagnosticRule.reportInvalidTypeForm,
|
||||||
LocMessage.annotationNotSupported(),
|
LocMessage.annotationNotSupported(),
|
||||||
node.chainedTypeAnnotationComment
|
node.chainedTypeAnnotationComment
|
||||||
@ -956,7 +952,6 @@ export class Binder extends ParseTreeWalker {
|
|||||||
this._usesUnsupportedDunderAllForm = true;
|
this._usesUnsupportedDunderAllForm = true;
|
||||||
|
|
||||||
this._addDiagnostic(
|
this._addDiagnostic(
|
||||||
this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
|
|
||||||
DiagnosticRule.reportUnsupportedDunderAll,
|
DiagnosticRule.reportUnsupportedDunderAll,
|
||||||
LocMessage.unsupportedDunderAllOperation(),
|
LocMessage.unsupportedDunderAllOperation(),
|
||||||
node
|
node
|
||||||
@ -1111,7 +1106,6 @@ export class Binder extends ParseTreeWalker {
|
|||||||
this._usesUnsupportedDunderAllForm = true;
|
this._usesUnsupportedDunderAllForm = true;
|
||||||
|
|
||||||
this._addDiagnostic(
|
this._addDiagnostic(
|
||||||
this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
|
|
||||||
DiagnosticRule.reportUnsupportedDunderAll,
|
DiagnosticRule.reportUnsupportedDunderAll,
|
||||||
LocMessage.unsupportedDunderAllOperation(),
|
LocMessage.unsupportedDunderAllOperation(),
|
||||||
node
|
node
|
||||||
@ -3842,7 +3836,6 @@ export class Binder extends ParseTreeWalker {
|
|||||||
|
|
||||||
if (!declarationHandled) {
|
if (!declarationHandled) {
|
||||||
this._addDiagnostic(
|
this._addDiagnostic(
|
||||||
this._fileInfo.diagnosticRuleSet.reportInvalidTypeForm,
|
|
||||||
DiagnosticRule.reportInvalidTypeForm,
|
DiagnosticRule.reportInvalidTypeForm,
|
||||||
LocMessage.annotationNotSupported(),
|
LocMessage.annotationNotSupported(),
|
||||||
typeAnnotation
|
typeAnnotation
|
||||||
@ -4224,7 +4217,9 @@ export class Binder extends ParseTreeWalker {
|
|||||||
return getUniqueFlowNodeId();
|
return getUniqueFlowNodeId();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _addDiagnostic(diagLevel: DiagnosticLevel, rule: DiagnosticRule, message: string, textRange: TextRange) {
|
private _addDiagnostic(rule: DiagnosticRule, message: string, textRange: TextRange) {
|
||||||
|
const diagLevel = this._fileInfo.diagnosticRuleSet[rule] as DiagnosticLevel;
|
||||||
|
|
||||||
let diagnostic: Diagnostic | undefined;
|
let diagnostic: Diagnostic | undefined;
|
||||||
switch (diagLevel) {
|
switch (diagLevel) {
|
||||||
case 'error':
|
case 'error':
|
||||||
|
@ -251,7 +251,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
if (codeComplexity > maxCodeComplexity) {
|
if (codeComplexity > maxCodeComplexity) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues,
|
|
||||||
DiagnosticRule.reportGeneralTypeIssues,
|
DiagnosticRule.reportGeneralTypeIssues,
|
||||||
LocMessage.codeTooComplexToAnalyze(),
|
LocMessage.codeTooComplexToAnalyze(),
|
||||||
{ start: 0, length: 0 }
|
{ start: 0, length: 0 }
|
||||||
@ -844,7 +843,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
if (node.typeComment) {
|
if (node.typeComment) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportInvalidTypeForm,
|
|
||||||
DiagnosticRule.reportInvalidTypeForm,
|
DiagnosticRule.reportInvalidTypeForm,
|
||||||
LocMessage.annotationNotSupported(),
|
LocMessage.annotationNotSupported(),
|
||||||
node.typeComment
|
node.typeComment
|
||||||
@ -899,7 +897,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
if (node.typeComment) {
|
if (node.typeComment) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportInvalidTypeForm,
|
|
||||||
DiagnosticRule.reportInvalidTypeForm,
|
DiagnosticRule.reportInvalidTypeForm,
|
||||||
LocMessage.annotationNotSupported(),
|
LocMessage.annotationNotSupported(),
|
||||||
node.typeComment
|
node.typeComment
|
||||||
@ -1169,7 +1166,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
if (!isUnboundedTupleClass(type)) {
|
if (!isUnboundedTupleClass(type)) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportAssertAlwaysTrue,
|
|
||||||
DiagnosticRule.reportAssertAlwaysTrue,
|
DiagnosticRule.reportAssertAlwaysTrue,
|
||||||
LocMessage.assertAlwaysTrue(),
|
LocMessage.assertAlwaysTrue(),
|
||||||
node.testExpression
|
node.testExpression
|
||||||
@ -1386,7 +1382,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
if (error.errorType === UnescapeErrorType.InvalidEscapeSequence) {
|
if (error.errorType === UnescapeErrorType.InvalidEscapeSequence) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportInvalidStringEscapeSequence,
|
|
||||||
DiagnosticRule.reportInvalidStringEscapeSequence,
|
DiagnosticRule.reportInvalidStringEscapeSequence,
|
||||||
LocMessage.stringUnsupportedEscape(),
|
LocMessage.stringUnsupportedEscape(),
|
||||||
{ start: start + error.offset, length: error.length }
|
{ start: start + error.offset, length: error.length }
|
||||||
@ -1400,7 +1395,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
if (escapeOffset >= 0) {
|
if (escapeOffset >= 0) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues,
|
|
||||||
DiagnosticRule.reportGeneralTypeIssues,
|
DiagnosticRule.reportGeneralTypeIssues,
|
||||||
LocMessage.formatStringEscape(),
|
LocMessage.formatStringEscape(),
|
||||||
{ start, length: 1 }
|
{ start, length: 1 }
|
||||||
@ -1436,7 +1430,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
if (node.strings.length > 1 && !node.isParenthesized) {
|
if (node.strings.length > 1 && !node.isParenthesized) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportImplicitStringConcatenation,
|
|
||||||
DiagnosticRule.reportImplicitStringConcatenation,
|
DiagnosticRule.reportImplicitStringConcatenation,
|
||||||
LocMessage.implicitStringConcat(),
|
LocMessage.implicitStringConcat(),
|
||||||
node
|
node
|
||||||
@ -1571,7 +1564,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
) {
|
) {
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportWildcardImportFromLibrary,
|
|
||||||
DiagnosticRule.reportWildcardImportFromLibrary,
|
DiagnosticRule.reportWildcardImportFromLibrary,
|
||||||
LocMessage.wildcardLibraryImport(),
|
LocMessage.wildcardLibraryImport(),
|
||||||
node.wildcardToken || node
|
node.wildcardToken || node
|
||||||
@ -3610,7 +3602,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
|
|
||||||
this._evaluator.addDiagnosticForTextRange(
|
this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportUnusedImport,
|
|
||||||
DiagnosticRule.reportUnusedImport,
|
DiagnosticRule.reportUnusedImport,
|
||||||
LocMessage.unaccessedImport().format({ name: multipartName }),
|
LocMessage.unaccessedImport().format({ name: multipartName }),
|
||||||
textRange
|
textRange
|
||||||
@ -4437,7 +4428,6 @@ export class Checker extends ParseTreeWalker {
|
|||||||
// This means the user has a module that is overwriting the stdlib module.
|
// This means the user has a module that is overwriting the stdlib module.
|
||||||
const diag = this._evaluator.addDiagnosticForTextRange(
|
const diag = this._evaluator.addDiagnosticForTextRange(
|
||||||
this._fileInfo,
|
this._fileInfo,
|
||||||
this._fileInfo.diagnosticRuleSet.reportShadowedImports,
|
|
||||||
DiagnosticRule.reportShadowedImports,
|
DiagnosticRule.reportShadowedImports,
|
||||||
LocMessage.stdlibModuleOverridden().format({
|
LocMessage.stdlibModuleOverridden().format({
|
||||||
name: moduleName,
|
name: moduleName,
|
||||||
|
@ -3038,7 +3038,6 @@ export function createTypeEvaluator(
|
|||||||
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
||||||
addDiagnosticForTextRange(
|
addDiagnosticForTextRange(
|
||||||
fileInfo,
|
fileInfo,
|
||||||
fileInfo.diagnosticRuleSet.reportGeneralTypeIssues,
|
|
||||||
DiagnosticRule.reportGeneralTypeIssues,
|
DiagnosticRule.reportGeneralTypeIssues,
|
||||||
LocMessage.codeTooComplexToAnalyze(),
|
LocMessage.codeTooComplexToAnalyze(),
|
||||||
errorRange
|
errorRange
|
||||||
@ -3235,11 +3234,12 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
function addDiagnosticForTextRange(
|
function addDiagnosticForTextRange(
|
||||||
fileInfo: AnalyzerFileInfo,
|
fileInfo: AnalyzerFileInfo,
|
||||||
diagLevel: DiagnosticLevel,
|
rule: DiagnosticRule,
|
||||||
rule: DiagnosticRule | '',
|
|
||||||
message: string,
|
message: string,
|
||||||
range: TextRange
|
range: TextRange
|
||||||
) {
|
) {
|
||||||
|
const diagLevel = fileInfo.diagnosticRuleSet[rule] as DiagnosticLevel;
|
||||||
|
|
||||||
if (diagLevel === 'none') {
|
if (diagLevel === 'none') {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
import { CancellationToken } from 'vscode-languageserver-protocol';
|
import { CancellationToken } from 'vscode-languageserver-protocol';
|
||||||
|
|
||||||
import { DiagnosticLevel } from '../common/configOptions';
|
|
||||||
import { ConsoleInterface } from '../common/console';
|
import { ConsoleInterface } from '../common/console';
|
||||||
import { Diagnostic, DiagnosticAddendum } from '../common/diagnostic';
|
import { Diagnostic, DiagnosticAddendum } from '../common/diagnostic';
|
||||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||||
@ -676,8 +675,7 @@ export interface TypeEvaluator {
|
|||||||
) => Diagnostic | undefined;
|
) => Diagnostic | undefined;
|
||||||
addDiagnosticForTextRange: (
|
addDiagnosticForTextRange: (
|
||||||
fileInfo: AnalyzerFileInfo,
|
fileInfo: AnalyzerFileInfo,
|
||||||
diagLevel: DiagnosticLevel,
|
rule: DiagnosticRule,
|
||||||
rule: DiagnosticRule | '',
|
|
||||||
message: string,
|
message: string,
|
||||||
range: TextRange
|
range: TextRange
|
||||||
) => Diagnostic | undefined;
|
) => Diagnostic | undefined;
|
||||||
|
@ -10,11 +10,11 @@ import assert from 'assert';
|
|||||||
|
|
||||||
import { combinePaths, getFileName, normalizeSlashes } from '../common/pathUtils';
|
import { combinePaths, getFileName, normalizeSlashes } from '../common/pathUtils';
|
||||||
import { compareStringsCaseSensitive } from '../common/stringUtils';
|
import { compareStringsCaseSensitive } from '../common/stringUtils';
|
||||||
|
import { Uri } from '../common/uri/uri';
|
||||||
import { Range } from './harness/fourslash/fourSlashTypes';
|
import { Range } from './harness/fourslash/fourSlashTypes';
|
||||||
import { runFourSlashTestContent } from './harness/fourslash/runner';
|
import { runFourSlashTestContent } from './harness/fourslash/runner';
|
||||||
import { parseAndGetTestState } from './harness/fourslash/testState';
|
import { parseAndGetTestState } from './harness/fourslash/testState';
|
||||||
import * as factory from './harness/vfs/factory';
|
import * as factory from './harness/vfs/factory';
|
||||||
import { Uri } from '../common/uri/uri';
|
|
||||||
|
|
||||||
test('Create', () => {
|
test('Create', () => {
|
||||||
const code = `
|
const code = `
|
||||||
|
Loading…
Reference in New Issue
Block a user