mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Added support for "ignore" array in config.
This commit is contained in:
parent
15b02f816b
commit
1e47cbe1a7
@ -29,7 +29,18 @@
|
||||
"items": {
|
||||
"$id": "#/properties/exclude/items",
|
||||
"type": "string",
|
||||
"title": "File or directory to excluded from type analysis",
|
||||
"title": "File or directory to exclude from type analysis",
|
||||
"pattern": "^(.*)$"
|
||||
}
|
||||
},
|
||||
"ignore": {
|
||||
"$id": "#/properties/ignore",
|
||||
"type": "array",
|
||||
"title": "Files and directories whose diagnostics are suppressed",
|
||||
"items": {
|
||||
"$id": "#/properties/ignore/items",
|
||||
"type": "string",
|
||||
"title": "File or directory where diagnostics should be suppressed",
|
||||
"pattern": "^(.*)$"
|
||||
}
|
||||
},
|
||||
@ -54,19 +65,19 @@
|
||||
"$id": "#/properties/reportTypeshedErrors",
|
||||
"$ref": "#/definitions/diagnostic",
|
||||
"title": "Enables reporting of errors found within typeshed stub files",
|
||||
"default": false
|
||||
"default": "none"
|
||||
},
|
||||
"reportMissingImports": {
|
||||
"$id": "#/properties/reportMissingImports",
|
||||
"$ref": "#/definitions/diagnostic",
|
||||
"title": "Enables reporting of imports that cannot be resolved",
|
||||
"default": true
|
||||
"default": "error"
|
||||
},
|
||||
"reportMissingTypeStubs": {
|
||||
"$id": "#/properties/reportMissingTypeStubs",
|
||||
"$ref": "#/definitions/diagnostic",
|
||||
"title": "Enables reporting of imports that cannot be resolved to type stub files",
|
||||
"default": false
|
||||
"default": "none"
|
||||
},
|
||||
"pythonVersion": {
|
||||
"$id": "#/properties/pythonVersion",
|
||||
|
@ -4,9 +4,11 @@ Pyright offers flexible configuration options specified in a JSON-formatted text
|
||||
|
||||
## Master Pyright Config Options
|
||||
|
||||
**include** [array of paths, optional]: Paths of directories that should be included. If no paths are specified, pyright defaults to the directory that contains the config file.
|
||||
**include** [array of paths, optional]: Paths of directories or files that should be included. If no paths are specified, pyright defaults to the directory that contains the config file.
|
||||
|
||||
**exclude** [array of paths, optional]: Paths of directories that should not be included. These override the includes directories, allowing specific subdirectories to be ignored. Note that files in the exclude paths may still be included in the analysis if they are referenced (imported) by source files that are not excluded.
|
||||
**exclude** [array of paths, optional]: Paths of directories or files that should not be included. These override the includes directories, allowing specific subdirectories to be ignored. Note that files in the exclude paths may still be included in the analysis if they are referenced (imported) by source files that are not excluded.
|
||||
|
||||
**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.
|
||||
|
||||
**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.
|
||||
|
||||
|
@ -278,40 +278,30 @@ export class AnalyzerService {
|
||||
for (const file of files) {
|
||||
const filePath = combinePaths(absolutePath, file);
|
||||
|
||||
if (!this._isInExcludePath(filePath, excludePaths) && includeFileRegex.test(filePath)) {
|
||||
if (!this._isInExcludePath(filePath, exclude) && includeFileRegex.test(filePath)) {
|
||||
results.push(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
for (const directory of directories) {
|
||||
const dirPath = combinePaths(absolutePath, directory);
|
||||
if (!this._isInExcludePath(absolutePath, excludePaths)) {
|
||||
if (!this._isInExcludePath(absolutePath, exclude)) {
|
||||
visitDirectory(dirPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Build a normalized list of exclusion paths.
|
||||
let excludePaths = exclude.map(excludeSpec => {
|
||||
let absolutePath = normalizePath(combinePaths(basePath, excludeSpec));
|
||||
if (!absolutePath.endsWith('.py')) {
|
||||
absolutePath = ensureTrailingDirectorySeparator(absolutePath);
|
||||
}
|
||||
return absolutePath;
|
||||
});
|
||||
|
||||
include.forEach(includeSpec => {
|
||||
let absolutePath = normalizePath(combinePaths(basePath, includeSpec));
|
||||
let foundFileSpec = false;
|
||||
|
||||
if (!this._isInExcludePath(absolutePath, excludePaths) && fs.existsSync(absolutePath)) {
|
||||
if (!this._isInExcludePath(includeSpec, exclude) && fs.existsSync(includeSpec)) {
|
||||
try {
|
||||
let stat = fs.statSync(absolutePath);
|
||||
let stat = fs.statSync(includeSpec);
|
||||
if (stat.isFile()) {
|
||||
results.push(absolutePath);
|
||||
results.push(includeSpec);
|
||||
foundFileSpec = true;
|
||||
} else if (stat.isDirectory()) {
|
||||
visitDirectory(absolutePath);
|
||||
visitDirectory(includeSpec);
|
||||
foundFileSpec = true;
|
||||
}
|
||||
} catch {
|
||||
|
@ -153,7 +153,9 @@ export class SourceFile {
|
||||
// Returns a list of cached diagnostics from the latest analysis job.
|
||||
// If the prevVersion is specified, the method returns undefined if
|
||||
// the diagnostics haven't changed.
|
||||
getDiagnostics(options: ConfigOptions, prevDiagnosticVersion?: number): Diagnostic[] | undefined {
|
||||
getDiagnostics(options: ConfigOptions, prevDiagnosticVersion?: number):
|
||||
Diagnostic[] | undefined {
|
||||
|
||||
if (this._diagnosticVersion === prevDiagnosticVersion) {
|
||||
return undefined;
|
||||
}
|
||||
@ -180,6 +182,11 @@ export class SourceFile {
|
||||
}
|
||||
}
|
||||
|
||||
// If the file is in the ignore list, clear the diagnostic list.
|
||||
if (options.ignore.find(ignorePath => this._filePath.startsWith(ignorePath))) {
|
||||
diagList = [];
|
||||
}
|
||||
|
||||
return diagList;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,10 @@ export class ConfigOptions {
|
||||
// within those directories are included.
|
||||
exclude: string[] = [];
|
||||
|
||||
// A list of file sepcs whose errors and warnings should be ignored even
|
||||
// if they are included in the transitive closure of included files.
|
||||
ignore: string[] = [];
|
||||
|
||||
// Report diagnostics in typeshed files?
|
||||
reportTypeshedErrors: DiagnosticLevel = 'none';
|
||||
|
||||
@ -130,7 +134,7 @@ export class ConfigOptions {
|
||||
if (typeof fileSpec !== 'string') {
|
||||
console.log(`Index ${ index } of "include" array should be a string.`);
|
||||
} else {
|
||||
this.include.push(fileSpec);
|
||||
this.include.push(this._normalizeFileSpec(fileSpec));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -147,7 +151,24 @@ export class ConfigOptions {
|
||||
if (typeof fileSpec !== 'string') {
|
||||
console.log(`Index ${ index } of "exclude" array should be a string.`);
|
||||
} else {
|
||||
this.exclude.push(fileSpec);
|
||||
this.exclude.push(this._normalizeFileSpec(fileSpec));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Read the "ignore" entry.
|
||||
this.ignore = [];
|
||||
if (configObj.ignore !== undefined) {
|
||||
if (!Array.isArray(configObj.ignore)) {
|
||||
console.log(`Config "ignore" entry must contain an array.`);
|
||||
} else {
|
||||
let filesList = configObj.ignore as string[];
|
||||
filesList.forEach((fileSpec, index) => {
|
||||
if (typeof fileSpec !== 'string') {
|
||||
console.log(`Index ${ index } of "ignore" array should be a string.`);
|
||||
} else {
|
||||
this.ignore.push(this._normalizeFileSpec(fileSpec));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -258,6 +279,14 @@ export class ConfigOptions {
|
||||
}
|
||||
}
|
||||
|
||||
private _normalizeFileSpec(fileSpec: string): string {
|
||||
let absolutePath = normalizePath(combinePaths(this.projectRoot, fileSpec));
|
||||
if (!absolutePath.endsWith('.py') && !absolutePath.endsWith('.pyi')) {
|
||||
absolutePath = ensureTrailingDirectorySeparator(absolutePath);
|
||||
}
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
private _convertDiagnosticLevel(value: any, fieldName: string,
|
||||
defaultValue: DiagnosticLevel): DiagnosticLevel {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user