diff --git a/news/1 Enhancements/3597.md b/news/1 Enhancements/3597.md new file mode 100644 index 000000000000..728727722619 --- /dev/null +++ b/news/1 Enhancements/3597.md @@ -0,0 +1,2 @@ +Add support for column numbers for problems returned by `mypy`. +(thanks [Eric Traut](https://github.com/erictraut)) diff --git a/package.json b/package.json index 051c17cb29c9..2d601ac80393 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/client/linters/mypy.ts b/src/client/linters/mypy.ts index 21b8af3796be..7c8559881a42 100644 --- a/src/client/linters/mypy.ts +++ b/src/client/linters/mypy.ts @@ -5,7 +5,7 @@ import { IServiceContainer } from '../ioc/types'; import { BaseLinter } from './baseLinter'; import { ILintMessage } from './types'; -export const REGEX = '(?.+):(?\\d+): (?\\w+): (?.*)\\r?(\\n|$)'; +export const REGEX = '(?[^:]+):(?\\d+)(:(?\\d+))?: (?\\w+): (?.*)\\r?(\\n|$)'; export class MyPy extends BaseLinter { constructor(outputChannel: OutputChannel, serviceContainer: IServiceContainer) { diff --git a/src/test/linters/mypy.unit.test.ts b/src/test/linters/mypy.unit.test.ts index 44dd2076fd08..1f6e36146c1b 100644 --- a/src/test/linters/mypy.unit.test.ts +++ b/src/test/linters/mypy.unit.test.ts @@ -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', () => { @@ -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) {