Skip to content

Commit

Permalink
Fixes issue that causes linter to fail when file path contains spaces…
Browse files Browse the repository at this point in the history
…. (#1241) (DonJayamanne#1243)

Forward-port from 2018.3.1
Fixes #1239
  • Loading branch information
brettcannon authored and Aman Agarwal committed Aug 30, 2018
1 parent ab19036 commit 2d3bef1
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2018.3.1 (29 Mar 2018)

### Fixes

1. Fixes issue that causes linter to fail when file path contains spaces.
([#1239](https://github.com/Microsoft/vscode-python/issues/1239))

## 2018.3.0 (28 Mar 2018)

### Enhancements
Expand Down Expand Up @@ -829,4 +836,3 @@ the following people who contributed code:

## Version 0.0.3
* Added support for debugging using PDB

2 changes: 1 addition & 1 deletion src/client/linters/flake8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Flake8 extends BaseLinter {
}

protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
const messages = await this.run(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath.fileToCommandArgument()], document, cancellation);
const messages = await this.run(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath], document, cancellation);
messages.forEach(msg => {
msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.flake8CategorySeverity);
});
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/mypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class MyPy extends BaseLinter {
}

protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
const messages = await this.run([document.uri.fsPath.fileToCommandArgument()], document, cancellation, REGEX);
const messages = await this.run([document.uri.fsPath], document, cancellation, REGEX);
messages.forEach(msg => {
msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.mypyCategorySeverity);
msg.code = msg.type;
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/pep8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Pep8 extends BaseLinter {
}

protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
const messages = await this.run(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath.fileToCommandArgument()], document, cancellation);
const messages = await this.run(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath], document, cancellation);
messages.forEach(msg => {
msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.pep8CategorySeverity);
});
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/prospector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Prospector extends BaseLinter {
}

protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
return this.run(['--absolute-paths', '--output-format=json', document.uri.fsPath.fileToCommandArgument()], document, cancellation);
return this.run(['--absolute-paths', '--output-format=json', document.uri.fsPath], document, cancellation);
}
protected async parseMessages(output: string, document: TextDocument, token: CancellationToken, regEx: string) {
let parsedData: IProspectorResponse;
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/pydocstyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class PyDocStyle extends BaseLinter {
}

protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
const messages = await this.run([document.uri.fsPath.fileToCommandArgument()], document, cancellation);
const messages = await this.run([document.uri.fsPath], document, cancellation);
// All messages in pep8 are treated as warnings for now.
messages.forEach(msg => {
msg.severity = LintMessageSeverity.Warning;
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/pylama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class PyLama extends BaseLinter {
}

protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
const messages = await this.run(['--format=parsable', document.uri.fsPath.fileToCommandArgument()], document, cancellation, REGEX);
const messages = await this.run(['--format=parsable', document.uri.fsPath], document, cancellation, REGEX);
// All messages in pylama are treated as warnings for now.
messages.forEach(msg => {
msg.severity = LintMessageSeverity.Warning;
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/pylint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Pylint extends BaseLinter {
'--msg-template=\'{line},{column},{category},{msg_id}:{msg}\'',
'--reports=n',
'--output-format=text',
uri.fsPath.fileToCommandArgument()
uri.fsPath
];
const messages = await this.run(minArgs.concat(args), document, cancellation);
messages.forEach(msg => {
Expand Down
14 changes: 7 additions & 7 deletions src/test/linters/lint.args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,32 @@ suite('Linting - Arguments', () => {
[Uri.file(path.join('users', 'development path to', 'one.py')), Uri.file(path.join('users', 'development', 'one.py'))].forEach(fileUri => {
test(`Flake8 (${fileUri.fsPath.indexOf(' ') > 0 ? 'with spaces' : 'without spaces'})`, async () => {
const linter = new Flake8(outputChannel.object, serviceContainer);
const expectedArgs = ['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', fileUri.fsPath.fileToCommandArgument()];
const expectedArgs = ['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', fileUri.fsPath];
await testLinter(linter, fileUri, expectedArgs);
});
test(`Pep8 (${fileUri.fsPath.indexOf(' ') > 0 ? 'with spaces' : 'without spaces'})`, async () => {
const linter = new Pep8(outputChannel.object, serviceContainer);
const expectedArgs = ['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', fileUri.fsPath.fileToCommandArgument()];
const expectedArgs = ['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', fileUri.fsPath];
await testLinter(linter, fileUri, expectedArgs);
});
test(`Prospector (${fileUri.fsPath.indexOf(' ') > 0 ? 'with spaces' : 'without spaces'})`, async () => {
const linter = new Prospector(outputChannel.object, serviceContainer);
const expectedArgs = ['--absolute-paths', '--output-format=json', fileUri.fsPath.fileToCommandArgument()];
const expectedArgs = ['--absolute-paths', '--output-format=json', fileUri.fsPath];
await testLinter(linter, fileUri, expectedArgs);
});
test(`Pylama (${fileUri.fsPath.indexOf(' ') > 0 ? 'with spaces' : 'without spaces'})`, async () => {
const linter = new PyLama(outputChannel.object, serviceContainer);
const expectedArgs = ['--format=parsable', fileUri.fsPath.fileToCommandArgument()];
const expectedArgs = ['--format=parsable', fileUri.fsPath];
await testLinter(linter, fileUri, expectedArgs);
});
test(`MyPy (${fileUri.fsPath.indexOf(' ') > 0 ? 'with spaces' : 'without spaces'})`, async () => {
const linter = new MyPy(outputChannel.object, serviceContainer);
const expectedArgs = [fileUri.fsPath.fileToCommandArgument()];
const expectedArgs = [fileUri.fsPath];
await testLinter(linter, fileUri, expectedArgs);
});
test(`Pydocstyle (${fileUri.fsPath.indexOf(' ') > 0 ? 'with spaces' : 'without spaces'})`, async () => {
const linter = new PyDocStyle(outputChannel.object, serviceContainer);
const expectedArgs = [fileUri.fsPath.fileToCommandArgument()];
const expectedArgs = [fileUri.fsPath];
await testLinter(linter, fileUri, expectedArgs);
});
test(`Pylint (${fileUri.fsPath.indexOf(' ') > 0 ? 'with spaces' : 'without spaces'})`, async () => {
Expand All @@ -144,7 +144,7 @@ suite('Linting - Arguments', () => {

let invoked = false;
(linter as any).run = (args, doc, token) => {
expect(args[args.length - 1]).to.equal(fileUri.fsPath.fileToCommandArgument());
expect(args[args.length - 1]).to.equal(fileUri.fsPath);
invoked = true;
return Promise.resolve([]);
};
Expand Down

0 comments on commit 2d3bef1

Please sign in to comment.