Skip to content

Commit ecc3353

Browse files
committed
Fix code to match expectations of other tests
- ensure only valid linters can be set (we can't default to pylint anymore) - ensure await is called for isLintingEnabled.
1 parent afaafe3 commit ecc3353

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@
12471247
},
12481248
"python.linting.pylintEnabled": {
12491249
"type": "boolean",
1250-
"default": false,
1250+
"default": true,
12511251
"description": "Whether to lint Python files using pylint.",
12521252
"scope": "resource"
12531253
},

src/client/linters/linterManager.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,36 @@ export class LinterManager implements ILinterManager {
8181
if (!silent) {
8282
await this.enableUnconfiguredLinters(resource);
8383
}
84-
return this.linters.filter(x => x.isEnabled(resource));
84+
return this.linters.filter(x => {
85+
let enabled = x.isEnabled(resource);
86+
if (x.id === 'pylint') {
87+
enabled = enabled === true;
88+
}
89+
return enabled === true;
90+
});
8591
}
8692

8793
public async setActiveLintersAsync(products: Product[], resource?: Uri): Promise<void> {
88-
const active = await this.getActiveLinters(true, resource);
89-
for (const x of active) {
90-
await x.enableAsync(false, resource);
91-
}
92-
if (products.length > 0) {
93-
const toActivate = this.linters.filter(x => products.findIndex(p => x.product === p) >= 0);
94-
for (const x of toActivate) {
95-
await x.enableAsync(true, resource);
94+
// ensure we only allow valid linters to be set, otherwise leave things alone.
95+
// filter out any invalid products:
96+
const validProducts = products.filter(product => {
97+
const foundIndex = this.linters.findIndex(validLinter => validLinter.product === product);
98+
return foundIndex !== -1;
99+
});
100+
101+
// if we have valid linter product(s), enable only those
102+
if (validProducts.length > 0) {
103+
const active = await this.getActiveLinters(true, resource);
104+
for (const x of active) {
105+
await x.enableAsync(false, resource);
106+
}
107+
if (products.length > 0) {
108+
const toActivate = this.linters.filter(x => products.findIndex(p => x.product === p) >= 0);
109+
for (const x of toActivate) {
110+
await x.enableAsync(true, resource);
111+
}
112+
await this.enableLintingAsync(true, resource);
96113
}
97-
await this.enableLintingAsync(true, resource);
98114
}
99115
}
100116

src/test/linters/lint.manager.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ suite('Linting - Manager', () => {
8181

8282
test('Enable/disable linting', async () => {
8383
await lm.enableLintingAsync(false);
84-
assert.equal(lm.isLintingEnabled(true), false, 'Linting not disabled');
84+
assert.equal(await lm.isLintingEnabled(true), false, 'Linting not disabled');
8585
await lm.enableLintingAsync(true);
86-
assert.equal(lm.isLintingEnabled(true), true, 'Linting not enabled');
86+
assert.equal(await lm.isLintingEnabled(true), true, 'Linting not enabled');
8787
});
8888

8989
test('Set single linter', async () => {

0 commit comments

Comments
 (0)