mirror of
https://github.com/microsoft/pyright.git
synced 2024-08-17 03:40:44 +03:00
Added new "strict" configuration setting.
This commit is contained in:
parent
fbaf6ac0e6
commit
f24806a985
@ -44,6 +44,17 @@
|
||||
"pattern": "^(.*)$"
|
||||
}
|
||||
},
|
||||
"strict": {
|
||||
"$id": "#/properties/strict",
|
||||
"type": "array",
|
||||
"title": "Files and directories that should use 'strict' type checking rules",
|
||||
"items": {
|
||||
"$id": "#/properties/strict/items",
|
||||
"type": "string",
|
||||
"title": "File or directory that should use 'strict' type checking rules",
|
||||
"pattern": "^(.*)$"
|
||||
}
|
||||
},
|
||||
"typeshedPath": {
|
||||
"$id": "#/properties/typingsPath",
|
||||
"type": "string",
|
||||
|
@ -10,6 +10,8 @@ Pyright offers flexible configuration options specified in a JSON-formatted text
|
||||
|
||||
**ignore** [array of paths, optional]: Paths of directories or files whose diagnostic output (errors and warnings) should be suppressed even if they are an included file or within the transitive closure of an included file.
|
||||
|
||||
**strict** [array of paths, optional]: Paths of directories or files that should use “strict” analysis if they are included. This is the same as manually adding a “# pyright: strict” comment. In strict mode, all type-checking rules are enabled.
|
||||
|
||||
**typeshedPath** [path, optional]: Path to a directory that contains typeshed type stub files. Pyright ships with an internal copy of some typeshed type stubs (those that cover the Python stdlib packages). If you want to use a full copy of the typeshed type stubs (including those for third-party packages), you can clone the [typeshed github repo](https://github.com/python/typeshed) to a local directory and reference the location with this path.
|
||||
|
||||
**typingsPath** [path, optional]: Path to a directory that contains custom type stubs. Each package's type stub file(s) are expected to be in its own subdirectory.
|
||||
|
@ -15,9 +15,11 @@ import { Token } from '../parser/tokenizerTypes';
|
||||
|
||||
export class CommentUtils {
|
||||
static getFileLevelDirectives(tokens: TextRangeCollection<Token>,
|
||||
defaultSettings: DiagnosticSettings): DiagnosticSettings {
|
||||
defaultSettings: DiagnosticSettings, useStrict: boolean): DiagnosticSettings {
|
||||
|
||||
let settings = cloneDiagnosticSettings(defaultSettings);
|
||||
let settings = useStrict ?
|
||||
getStrictDiagnosticSettings() :
|
||||
cloneDiagnosticSettings(defaultSettings);
|
||||
|
||||
for (let i = 0; i < tokens.count; i++) {
|
||||
const token = tokens.getItemAt(i);
|
||||
|
@ -425,8 +425,13 @@ export class SourceFile {
|
||||
this._resolveImports(walker.getImportedModules(), configOptions, execEnvironment);
|
||||
this._analysisJob.parseDiagnostics = diagSink.diagnostics;
|
||||
|
||||
// Is this file in a "strict" path?
|
||||
const useStrict = configOptions.strict.find(
|
||||
strictPath => this._filePath.startsWith(strictPath)) !== undefined;
|
||||
|
||||
this._analysisJob.diagnosticSettings = CommentUtils.getFileLevelDirectives(
|
||||
this._analysisJob.parseResults.tokens, configOptions.diagnosticSettings);
|
||||
this._analysisJob.parseResults.tokens, configOptions.diagnosticSettings,
|
||||
useStrict);
|
||||
} catch (e) {
|
||||
let message: string;
|
||||
if (e instanceof Error) {
|
||||
|
@ -272,6 +272,9 @@ export class ConfigOptions {
|
||||
// if they are included in the transitive closure of included files.
|
||||
ignore: string[] = [];
|
||||
|
||||
// A list of file sepcs that should be analyzed using "strict" mode.
|
||||
strict: string[] = [];
|
||||
|
||||
// Emit verbose information to console?
|
||||
verboseOutput: boolean;
|
||||
|
||||
@ -386,6 +389,25 @@ export class ConfigOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// Read the "strict" entry.
|
||||
this.strict = [];
|
||||
if (configObj.strict !== undefined) {
|
||||
if (!Array.isArray(configObj.strict)) {
|
||||
console.log(`Config "strict" entry must contain an array.`);
|
||||
} else {
|
||||
let filesList = configObj.strict as string[];
|
||||
filesList.forEach((fileSpec, index) => {
|
||||
if (typeof fileSpec !== 'string') {
|
||||
console.log(`Index ${ index } of "strict" array should be a string.`);
|
||||
} else if (isAbsolute(fileSpec)) {
|
||||
console.log(`Ignoring path "${ fileSpec }" in "strict" array because it is not relative.`);
|
||||
} else {
|
||||
this.strict.push(this._normalizeRelativeFileSpec(fileSpec));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const defaultSettings = getDefaultDiagnosticSettings();
|
||||
|
||||
this.diagnosticSettings = {
|
||||
|
Loading…
Reference in New Issue
Block a user