Added new configuration setting reportImplicitStringConcatenation.

This commit is contained in:
Eric Traut 2020-01-09 00:38:23 -08:00
parent 5816ec1702
commit e03712be1c
5 changed files with 32 additions and 5 deletions

View File

@ -294,6 +294,12 @@
"title": "Controls reporting assert expressions that will always evaluate to true",
"default": "warning"
},
"reportImplicitStringConcatenation": {
"$id": "#/properties/reportImplicitStringConcatenation",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting usage of implicit concatenation of string literals",
"default": "warning"
},
"pythonVersion": {
"$id": "#/properties/pythonVersion",
"type": "string",

View File

@ -106,6 +106,8 @@ The following settings control pyrights diagnostic output (warnings or errors
**reportSelfClsParameterName** [boolean or string, optional]: Generate or suppress diagnostics for a missing or misnamed “self” parameter in instance methods and “cls” parameter in class methods. Instance methods in metaclasses (classes that derive from “type”) are allowed to use “cls” for instance methods. The default value for this setting is 'warning'.
**reportImplicitStringConcatenation** [boolean or string, optional]: Generate or suppress diagnostics for two or more string literals that follow each other, indicating an implicit concatenation. This is considered a bad practice and often masks bugs such as missing commas. The default value for this setting is 'none'.
## Execution Environment Options
Pyright allows multiple “execution environments” to be defined for different portions of your source tree. For example, a subtree may be designed to run with different import search paths or a different version of the python interpreter than the rest of the source base.

View File

@ -497,6 +497,13 @@ export class Checker extends ParseTreeWalker {
this._evaluator.getType(node);
}
if (node.strings.length > 1) {
this._evaluator.addDiagnosticForTextRange(this._fileInfo,
this._fileInfo.diagnosticSettings.reportImplicitStringConcatenation,
DiagnosticRule.reportImplicitStringConcatenation,
`Implicit string concatenation not allowed`, node);
}
return true;
}

View File

@ -158,6 +158,9 @@ export interface DiagnosticSettings {
// Report when "self" or "cls" parameter is missing or is misnamed.
reportSelfClsParameterName: DiagnosticLevel;
// Report implicit concatenation of string literals.
reportImplicitStringConcatenation: DiagnosticLevel;
}
export function cloneDiagnosticSettings(
@ -214,7 +217,8 @@ export function getDiagLevelSettings() {
DiagnosticRule.reportUnnecessaryIsInstance,
DiagnosticRule.reportUnnecessaryCast,
DiagnosticRule.reportAssertAlwaysTrue,
DiagnosticRule.reportSelfClsParameterName
DiagnosticRule.reportSelfClsParameterName,
DiagnosticRule.reportImplicitStringConcatenation
];
}
@ -256,7 +260,8 @@ export function getStrictDiagnosticSettings(): DiagnosticSettings {
reportUnnecessaryIsInstance: 'error',
reportUnnecessaryCast: 'error',
reportAssertAlwaysTrue: 'error',
reportSelfClsParameterName: 'error'
reportSelfClsParameterName: 'error',
reportImplicitStringConcatenation: 'none'
};
return diagSettings;
@ -300,7 +305,8 @@ export function getDefaultDiagnosticSettings(): DiagnosticSettings {
reportUnnecessaryIsInstance: 'none',
reportUnnecessaryCast: 'none',
reportAssertAlwaysTrue: 'warning',
reportSelfClsParameterName: 'warning'
reportSelfClsParameterName: 'warning',
reportImplicitStringConcatenation: 'none'
};
return diagSettings;
@ -671,7 +677,12 @@ export class ConfigOptions {
// Read the "reportSelfClsParameterName" entry.
reportSelfClsParameterName: this._convertDiagnosticLevel(
configObj.reportSelfClsParameterName, DiagnosticRule.reportSelfClsParameterName,
defaultSettings.reportSelfClsParameterName)
defaultSettings.reportSelfClsParameterName),
// Read the "reportImplicitStringConcatenation" entry.
reportImplicitStringConcatenation: this._convertDiagnosticLevel(
configObj.reportImplicitStringConcatenation, DiagnosticRule.reportImplicitStringConcatenation,
defaultSettings.reportImplicitStringConcatenation)
};
// Read the "venvPath".

View File

@ -46,5 +46,6 @@ export const enum DiagnosticRule {
reportUnnecessaryIsInstance = 'reportUnnecessaryIsInstance',
reportUnnecessaryCast = 'reportUnnecessaryCast',
reportAssertAlwaysTrue = 'reportAssertAlwaysTrue',
reportSelfClsParameterName = 'reportSelfClsParameterName'
reportSelfClsParameterName = 'reportSelfClsParameterName',
reportImplicitStringConcatenation = 'reportImplicitStringConcatenation'
}