Skip to content

Commit

Permalink
Add column support to mypy (#3699)
Browse files Browse the repository at this point in the history
* #3597: Modified mypy linter plugin to support column numbers for reported errors.
* Add news entry
  • Loading branch information
erictraut authored and DonJayamanne committed Dec 18, 2018
1 parent 4dab144 commit 7de3383
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions news/1 Enhancements/3597.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add support for column numbers for problems returned by `mypy`.
(thanks [Eric Traut](https://github.com/erictraut))
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,8 @@
"description": "Arguments passed in. Each argument is a separate item in the array.",
"default": [
"--ignore-missing-imports",
"--follow-imports=silent"
"--follow-imports=silent",
"--show-column-numbers"
],
"items": {
"type": "string"
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 @@ -5,7 +5,7 @@ import { IServiceContainer } from '../ioc/types';
import { BaseLinter } from './baseLinter';
import { ILintMessage } from './types';

export const REGEX = '(?<file>.+):(?<line>\\d+): (?<type>\\w+): (?<message>.*)\\r?(\\n|$)';
export const REGEX = '(?<file>[^:]+):(?<line>\\d+)(:(?<column>\\d+))?: (?<type>\\w+): (?<message>.*)\\r?(\\n|$)';

export class MyPy extends BaseLinter {
constructor(outputChannel: OutputChannel, serviceContainer: IServiceContainer) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/linters/mypy.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ILintMessage } from '../../client/linters/types';
const output = `
provider.pyi:10: error: Incompatible types in assignment (expression has type "str", variable has type "int")
provider.pyi:11: error: Name 'not_declared_var' is not defined
provider.pyi:12:21: error: Expression has type "Any"
`;

suite('Linting - MyPy', () => {
Expand All @@ -36,6 +37,14 @@ suite('Linting - MyPy', () => {
line: 11,
type: 'error',
provider: 'mypy'
} as ILintMessage],
[lines[3], {
code: undefined,
message: 'Expression has type "Any"',
column: 21,
line: 12,
type: 'error',
provider: 'mypy'
} as ILintMessage]
];
for (const [line, expected] of tests) {
Expand Down

0 comments on commit 7de3383

Please sign in to comment.