diff --git a/news/2 Fixes/14978.md b/news/2 Fixes/14978.md new file mode 100644 index 000000000000..27990540844c --- /dev/null +++ b/news/2 Fixes/14978.md @@ -0,0 +1 @@ +Fix Mypy linter pointing to wrong column number (off by one). (thanks [anttipessa](https://github.com/anttipessa/), [haalto](https://github.com/haalto/), [JeonCD](https://github.com/JeonCD/) and [junskU](https://github.com/junskU)) diff --git a/src/client/linters/mypy.ts b/src/client/linters/mypy.ts index eff5c71be37a..b1da30513b1d 100644 --- a/src/client/linters/mypy.ts +++ b/src/client/linters/mypy.ts @@ -6,10 +6,11 @@ import { BaseLinter } from './baseLinter'; import { ILintMessage } from './types'; export const REGEX = '(?[^:]+):(?\\d+)(:(?\\d+))?: (?\\w+): (?.*)\\r?(\\n|$)'; +const COLUMN_OFF_SET = 1; export class MyPy extends BaseLinter { constructor(outputChannel: OutputChannel, serviceContainer: IServiceContainer) { - super(Product.mypy, outputChannel, serviceContainer); + super(Product.mypy, outputChannel, serviceContainer, COLUMN_OFF_SET); } protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise { diff --git a/src/test/linters/mypy.unit.test.ts b/src/test/linters/mypy.unit.test.ts index 5da759cb7108..63bd5c8c34b8 100644 --- a/src/test/linters/mypy.unit.test.ts +++ b/src/test/linters/mypy.unit.test.ts @@ -47,7 +47,7 @@ suite('Linting - MyPy', () => { { code: undefined, message: 'Expression has type "Any"', - column: 21, + column: 20, line: 12, type: 'error', provider: 'mypy', @@ -55,7 +55,7 @@ suite('Linting - MyPy', () => { ], ]; for (const [line, expected] of tests) { - const msg = parseLine(line, REGEX, LinterId.MyPy); + const msg = parseLine(line, REGEX, LinterId.MyPy, 1); expect(msg).to.deep.equal(expected); }