Skip to content

Commit d421dd3

Browse files
authored
Fix linter installation (#557)
* remove duplicate registration
1 parent 7a36147 commit d421dd3

File tree

5 files changed

+195
-4
lines changed

5 files changed

+195
-4
lines changed

src/client/common/serviceRegistry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ export function registerTypes(serviceManager: IServiceManager) {
2828
serviceManager.addSingleton<IApplicationShell>(IApplicationShell, ApplicationShell);
2929
serviceManager.addSingleton<ICurrentProcess>(ICurrentProcess, CurrentProcess);
3030
serviceManager.addSingleton<IInstaller>(IInstaller, Installer);
31-
serviceManager.addSingleton<IFileSystem>(IFileSystem, FileSystem);
3231
}

src/client/formatters/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export class FormatterHelper implements IFormatterHelper {
3838

3939
// If path information is not available, then treat it as a module,
4040
// except for prospector as that needs to be run as an executable (it's a Python package).
41-
if (path.basename(execPath) === execPath && formatter !== Product.prospector) {
41+
if (path.basename(execPath) === execPath) {
4242
moduleName = execPath;
4343
}
4444

45-
return { execPath, moduleName, args };
45+
return { execPath, moduleName, args, product: formatter };
4646
}
4747
}

src/client/linters/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class LinterHelper implements ILinterHelper {
3535
moduleName = execPath;
3636
}
3737

38-
return { execPath, moduleName, args };
38+
return { execPath, moduleName, args, product: linter };
3939
}
4040
public translateToId(linter: Product): LinterId {
4141
if (this.linterIdMapping.has(linter)) {

src/test/format/format.helper.test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import * as assert from 'assert';
2+
import * as path from 'path';
3+
import { IFormattingSettings, PythonSettings } from '../../client/common/configSettings';
4+
import { EnumEx } from '../../client/common/enumUtils';
5+
import { Product } from '../../client/common/types';
6+
import { FormatterHelper } from '../../client/formatters/helper';
7+
import { FormatterId } from '../../client/formatters/types';
8+
import { initialize } from '../initialize';
9+
10+
// tslint:disable-next-line:max-func-body-length
11+
suite('Formatting - Helper', () => {
12+
const formatHelper = new FormatterHelper();
13+
suiteSetup(initialize);
14+
15+
test('Ensure product is set in Execution Info', async () => {
16+
[Product.autopep8, Product.yapf].forEach(formatter => {
17+
const info = formatHelper.getExecutionInfo(formatter, []);
18+
assert.equal(info.product, formatter, `Incorrect products for ${formatHelper.translateToId(formatter)}`);
19+
});
20+
});
21+
22+
test('Ensure executable is set in Execution Info', async () => {
23+
const settings = PythonSettings.getInstance();
24+
25+
[Product.autopep8, Product.yapf].forEach(formatter => {
26+
const info = formatHelper.getExecutionInfo(formatter, []);
27+
const names = formatHelper.getSettingsPropertyNames(formatter);
28+
const execPath = settings.formatting[names.pathName] as string;
29+
let moduleName: string | undefined;
30+
if (path.basename(execPath) === execPath) {
31+
moduleName = execPath;
32+
}
33+
34+
assert.equal(info.execPath, execPath, `Incorrect executable paths for product ${formatHelper.translateToId(formatter)}`);
35+
});
36+
});
37+
38+
test('Ensure arguments are set in Execution Info', async () => {
39+
const settings = PythonSettings.getInstance();
40+
const customArgs = ['1', '2', '3'];
41+
42+
[Product.autopep8, Product.yapf].forEach(formatter => {
43+
const info = formatHelper.getExecutionInfo(formatter, []);
44+
const names = formatHelper.getSettingsPropertyNames(formatter);
45+
const args: string[] = Array.isArray(settings.formatting[names.argsName]) ? settings.formatting[names.argsName] as string[] : [];
46+
const expectedArgs = args.concat(customArgs).join(',');
47+
48+
assert.equal(expectedArgs.endsWith(customArgs.join(',')), true, `Incorrect custom arguments for product ${formatHelper.translateToId(formatter)}`);
49+
50+
});
51+
});
52+
53+
test('Ensure correct setting names are returned', async () => {
54+
[Product.autopep8, Product.yapf].forEach(formatter => {
55+
const translatedId = formatHelper.translateToId(formatter)!;
56+
const settings = {
57+
argsName: `${translatedId}Args` as keyof IFormattingSettings,
58+
pathName: `${translatedId}Path` as keyof IFormattingSettings
59+
};
60+
61+
assert.deepEqual(formatHelper.getSettingsPropertyNames(formatter), settings, `Incorrect settings for product ${formatHelper.translateToId(formatter)}`);
62+
});
63+
});
64+
65+
test('Ensure translation of ids works', async () => {
66+
const formatterMapping = new Map<Product, FormatterId>();
67+
formatterMapping.set(Product.autopep8, 'autopep8');
68+
formatterMapping.set(Product.yapf, 'yapf');
69+
70+
[Product.autopep8, Product.yapf].forEach(formatter => {
71+
const translatedId = formatHelper.translateToId(formatter);
72+
assert.equal(translatedId, formatterMapping.get(formatter)!, `Incorrect translation for product ${formatHelper.translateToId(formatter)}`);
73+
});
74+
});
75+
76+
EnumEx.getValues<Product>(Product).forEach(product => {
77+
const formatterMapping = new Map<Product, FormatterId>();
78+
formatterMapping.set(Product.autopep8, 'autopep8');
79+
formatterMapping.set(Product.yapf, 'yapf');
80+
if (formatterMapping.has(product)) {
81+
return;
82+
}
83+
84+
test(`Ensure translation of ids throws exceptions for unknown formatters (${product})`, async () => {
85+
assert.throws(() => formatHelper.translateToId(product));
86+
});
87+
});
88+
});

src/test/linters/lint.helper.test.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import * as assert from 'assert';
2+
import * as path from 'path';
3+
import { ILintingSettings, PythonSettings } from '../../client/common/configSettings';
4+
import { EnumEx } from '../../client/common/enumUtils';
5+
import { Product } from '../../client/common/types';
6+
import { LinterHelper } from '../../client/linters/helper';
7+
import { LinterId } from '../../client/linters/types';
8+
import { initialize } from '../initialize';
9+
10+
// tslint:disable-next-line:max-func-body-length
11+
suite('Linting - Helper', () => {
12+
const linterHelper = new LinterHelper();
13+
suiteSetup(initialize);
14+
15+
test('Ensure product is set in Execution Info', async () => {
16+
[Product.flake8, Product.mypy, Product.pep8,
17+
Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => {
18+
const info = linterHelper.getExecutionInfo(linter, []);
19+
assert.equal(info.product, linter, `Incorrect products for ${linterHelper.translateToId(linter)}`);
20+
});
21+
});
22+
23+
test('Ensure executable is set in Execution Info', async () => {
24+
const settings = PythonSettings.getInstance();
25+
26+
[Product.flake8, Product.mypy, Product.pep8,
27+
Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => {
28+
const info = linterHelper.getExecutionInfo(linter, []);
29+
const names = linterHelper.getSettingsPropertyNames(linter);
30+
const execPath = settings.linting[names.pathName] as string;
31+
let moduleName: string | undefined;
32+
if (path.basename(execPath) === execPath && linter !== Product.prospector) {
33+
moduleName = execPath;
34+
}
35+
36+
assert.equal(info.execPath, execPath, `Incorrect executable paths for product ${linterHelper.translateToId(linter)}`);
37+
});
38+
});
39+
40+
test('Ensure arguments are set in Execution Info', async () => {
41+
const settings = PythonSettings.getInstance();
42+
const customArgs = ['1', '2', '3'];
43+
44+
[Product.flake8, Product.mypy, Product.pep8,
45+
Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => {
46+
const info = linterHelper.getExecutionInfo(linter, []);
47+
const names = linterHelper.getSettingsPropertyNames(linter);
48+
const args: string[] = Array.isArray(settings.linting[names.argsName]) ? settings.linting[names.argsName] as string[] : [];
49+
const expectedArgs = args.concat(customArgs).join(',');
50+
51+
assert.equal(expectedArgs.endsWith(customArgs.join(',')), true, `Incorrect custom arguments for product ${linterHelper.translateToId(linter)}`);
52+
53+
});
54+
});
55+
56+
test('Ensure correct setting names are returned', async () => {
57+
[Product.flake8, Product.mypy, Product.pep8,
58+
Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => {
59+
const translatedId = linterHelper.translateToId(linter)!;
60+
const settings = {
61+
argsName: `${translatedId}Args` as keyof ILintingSettings,
62+
pathName: `${translatedId}Path` as keyof ILintingSettings,
63+
enabledName: `${translatedId}Enabled` as keyof ILintingSettings
64+
};
65+
66+
assert.deepEqual(linterHelper.getSettingsPropertyNames(linter), settings, `Incorrect settings for product ${linterHelper.translateToId(linter)}`);
67+
});
68+
});
69+
70+
test('Ensure translation of ids works', async () => {
71+
const linterIdMapping = new Map<Product, LinterId>();
72+
linterIdMapping.set(Product.flake8, 'flake8');
73+
linterIdMapping.set(Product.mypy, 'mypy');
74+
linterIdMapping.set(Product.pep8, 'pep8');
75+
linterIdMapping.set(Product.prospector, 'prospector');
76+
linterIdMapping.set(Product.pydocstyle, 'pydocstyle');
77+
linterIdMapping.set(Product.pylama, 'pylama');
78+
linterIdMapping.set(Product.pylint, 'pylint');
79+
80+
[Product.flake8, Product.mypy, Product.pep8,
81+
Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => {
82+
const translatedId = linterHelper.translateToId(linter);
83+
assert.equal(translatedId, linterIdMapping.get(linter)!, `Incorrect translation for product ${linterHelper.translateToId(linter)}`);
84+
});
85+
});
86+
87+
EnumEx.getValues<Product>(Product).forEach(product => {
88+
const linterIdMapping = new Map<Product, LinterId>();
89+
linterIdMapping.set(Product.flake8, 'flake8');
90+
linterIdMapping.set(Product.mypy, 'mypy');
91+
linterIdMapping.set(Product.pep8, 'pep8');
92+
linterIdMapping.set(Product.prospector, 'prospector');
93+
linterIdMapping.set(Product.pydocstyle, 'pydocstyle');
94+
linterIdMapping.set(Product.pylama, 'pylama');
95+
linterIdMapping.set(Product.pylint, 'pylint');
96+
if (linterIdMapping.has(product)) {
97+
return;
98+
}
99+
100+
test(`Ensure translation of ids throws exceptions for unknown linters (${product})`, async () => {
101+
assert.throws(() => linterHelper.translateToId(product));
102+
});
103+
});
104+
});

0 commit comments

Comments
 (0)