Skip to content

Commit 0eeaf0b

Browse files
committed
fix #763
1 parent ab9a330 commit 0eeaf0b

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,11 @@
882882
"default": true,
883883
"description": "Whether to lint Python files."
884884
},
885+
"python.linting.enabledWithoutWorkspace": {
886+
"type": "boolean",
887+
"default": true,
888+
"description": "Whether to lint Python files when no workspace is opened."
889+
},
885890
"python.linting.prospectorEnabled": {
886891
"type": "boolean",
887892
"default": false,

src/client/common/configSettings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface IPylintCategorySeverity {
4949
}
5050
export interface ILintingSettings {
5151
enabled: boolean;
52+
enabledWithoutWorkspace: boolean;
5253
ignorePatterns: string[];
5354
prospectorEnabled: boolean;
5455
prospectorArgs: string[];
@@ -162,6 +163,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
162163
// Support for travis
163164
this.linting = this.linting ? this.linting : {
164165
enabled: false,
166+
enabledWithoutWorkspace: false,
165167
ignorePatterns: [],
166168
flake8Args: [], flake8Enabled: false, flake8Path: 'flake',
167169
lintOnSave: false, lintOnTextChange: false, maxNumberOfProblems: 100,

src/client/common/installer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ProductNames.set(Product.pytest, 'py.test');
6464
ProductNames.set(Product.yapf, 'yapf');
6565

6666
const SettingToDisableProduct = new Map<Product, string>();
67-
SettingToDisableProduct.set(Product.autopep8, '');
67+
SettingToDisableProduct.set(Product.autopep8, 'autopep8');
6868
SettingToDisableProduct.set(Product.flake8, 'linting.flake8Enabled');
6969
SettingToDisableProduct.set(Product.mypy, 'linting.mypyEnabled');
7070
SettingToDisableProduct.set(Product.nosetest, 'unitTest.nosetestsEnabled');
@@ -176,7 +176,12 @@ export class Installer {
176176
export function disableLinter(product: Product) {
177177
const pythonConfig = vscode.workspace.getConfiguration('python');
178178
const settingToDisable = SettingToDisableProduct.get(product);
179-
pythonConfig.update(settingToDisable, false);
179+
if (vscode.workspace.rootPath) {
180+
return pythonConfig.update(settingToDisable, false);
181+
}
182+
else {
183+
return pythonConfig.update('linting.enabledWithoutWorkspace', false, true);
184+
}
180185
}
181186

182187
function isTestFrameworkInstalled(product: Product): Promise<boolean> {

src/client/providers/lintProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export class LintProvider extends vscode.Disposable {
157157
this.pendingLintings.set(document.uri.fsPath, cancelToken);
158158
this.outputChannel.clear();
159159
let promises: Promise<linter.ILintMessage[]>[] = this.linters.map(linter => {
160+
if (!vscode.workspace.rootPath && !this.settings.linting.enabledWithoutWorkspace) {
161+
return Promise.resolve([]);
162+
}
160163
if (!linter.isEnabled()) {
161164
return Promise.resolve([]);
162165
}

0 commit comments

Comments
 (0)