Skip to content

Commit

Permalink
Fix code to match expectations of other tests
Browse files Browse the repository at this point in the history
- ensure only valid linters can be set (we can't default to pylint anymore)
- ensure await is called for isLintingEnabled.
  • Loading branch information
d3r3kk committed Oct 24, 2018
1 parent 4f545bb commit fac640a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@
},
"python.linting.pylintEnabled": {
"type": "boolean",
"default": false,
"default": true,
"description": "Whether to lint Python files using pylint.",
"scope": "resource"
},
Expand Down
36 changes: 26 additions & 10 deletions src/client/linters/linterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,36 @@ export class LinterManager implements ILinterManager {
if (!silent) {
await this.enableUnconfiguredLinters(resource);
}
return this.linters.filter(x => x.isEnabled(resource));
return this.linters.filter(x => {
let enabled = x.isEnabled(resource);
if (x.id === 'pylint') {
enabled = enabled === true;
}
return enabled === true;
});
}

public async setActiveLintersAsync(products: Product[], resource?: Uri): Promise<void> {
const active = await this.getActiveLinters(true, resource);
for (const x of active) {
await x.enableAsync(false, resource);
}
if (products.length > 0) {
const toActivate = this.linters.filter(x => products.findIndex(p => x.product === p) >= 0);
for (const x of toActivate) {
await x.enableAsync(true, resource);
// ensure we only allow valid linters to be set, otherwise leave things alone.
// filter out any invalid products:
const validProducts = products.filter(product => {
const foundIndex = this.linters.findIndex(validLinter => validLinter.product === product);
return foundIndex !== -1;
});

// if we have valid linter product(s), enable only those
if (validProducts.length > 0) {
const active = await this.getActiveLinters(true, resource);
for (const x of active) {
await x.enableAsync(false, resource);
}
if (products.length > 0) {
const toActivate = this.linters.filter(x => products.findIndex(p => x.product === p) >= 0);
for (const x of toActivate) {
await x.enableAsync(true, resource);
}
await this.enableLintingAsync(true, resource);
}
await this.enableLintingAsync(true, resource);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/linters/lint.manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ suite('Linting - Manager', () => {

test('Enable/disable linting', async () => {
await lm.enableLintingAsync(false);
assert.equal(lm.isLintingEnabled(true), false, 'Linting not disabled');
assert.equal(await lm.isLintingEnabled(true), false, 'Linting not disabled');
await lm.enableLintingAsync(true);
assert.equal(lm.isLintingEnabled(true), true, 'Linting not enabled');
assert.equal(await lm.isLintingEnabled(true), true, 'Linting not enabled');
});

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

0 comments on commit fac640a

Please sign in to comment.