Skip to content

Commit cd42b50

Browse files
authored
Use col offset in bandit output to tag the correct node in the AST (microsoft#15003)
* Use col offset in bandit output * Add news item * Format linter input to keep the linter happy * Update test assertion for bandit call
1 parent 3fd3b9e commit cd42b50

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

news/1 Enhancements/15003.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Integration with the bandit linter will highlight the variable, function or method for an issue instead of the entire line.
2+
Requires latest version of the bandit package to be installed.
3+
(thanks [Anthony Shaw](https://github.com/tonybaloney))

src/client/linters/bandit.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ export class Bandit extends BaseLinter {
2424
protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
2525
// View all errors in bandit <= 1.5.1 (https://github.com/PyCQA/bandit/issues/371)
2626
const messages = await this.run(
27-
['-f', 'custom', '--msg-template', '{line},0,{severity},{test_id}:{msg}', '-n', '-1', document.uri.fsPath],
27+
[
28+
'-f',
29+
'custom',
30+
'--msg-template',
31+
'{line},{col},{severity},{test_id}:{msg}',
32+
'-n',
33+
'-1',
34+
document.uri.fsPath
35+
],
2836
document,
2937
cancellation,
3038
);

src/test/linters/lint.args.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ suite('Linting - Arguments', () => {
200200
'-f',
201201
'custom',
202202
'--msg-template',
203-
'{line},0,{severity},{test_id}:{msg}',
203+
'{line},{col},{severity},{test_id}:{msg}',
204204
'-n',
205205
'-1',
206206
fileUri.fsPath,

0 commit comments

Comments
 (0)