Skip to content

Commit fe94dda

Browse files
authored
Add column offset to fix mypy linter pointing to wrong column number (off by one) (microsoft#15505)
* Fix mypy column offset off by one * Add news item * Fix unit test * Update the expected output
1 parent 0aa58b7 commit fe94dda

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

news/2 Fixes/14978.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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))

src/client/linters/mypy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { BaseLinter } from './baseLinter';
66
import { ILintMessage } from './types';
77

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

1011
export class MyPy extends BaseLinter {
1112
constructor(outputChannel: OutputChannel, serviceContainer: IServiceContainer) {
12-
super(Product.mypy, outputChannel, serviceContainer);
13+
super(Product.mypy, outputChannel, serviceContainer, COLUMN_OFF_SET);
1314
}
1415

1516
protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {

src/test/linters/mypy.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ suite('Linting - MyPy', () => {
4747
{
4848
code: undefined,
4949
message: 'Expression has type "Any"',
50-
column: 21,
50+
column: 20,
5151
line: 12,
5252
type: 'error',
5353
provider: 'mypy',
5454
} as ILintMessage,
5555
],
5656
];
5757
for (const [line, expected] of tests) {
58-
const msg = parseLine(line, REGEX, LinterId.MyPy);
58+
const msg = parseLine(line, REGEX, LinterId.MyPy, 1);
5959

6060
expect(msg).to.deep.equal(expected);
6161
}

0 commit comments

Comments
 (0)