@@ -3,6 +3,7 @@ import * as vscode from "vscode";
3
3
4
4
import { EXCLUDE_RULE , EXCLUDE_RULE_WORKSPACE } from "../../../commands/excludeRules" ;
5
5
import Configuration from "../../../helper/configuration" ;
6
+ import Utilities from "../../../helper/utilities" ;
6
7
7
8
export default class QuickFixProvider implements vscode . CodeActionProvider {
8
9
public static readonly providedCodeActionKind = [ vscode . CodeActionKind . QuickFix ] ;
@@ -11,7 +12,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
11
12
document : vscode . TextDocument ,
12
13
range : vscode . Range | vscode . Selection ,
13
14
context : vscode . CodeActionContext ,
14
- token : vscode . CancellationToken ,
15
+ token : vscode . CancellationToken
15
16
) : vscode . CodeAction [ ] {
16
17
const noqaSingleRules : vscode . CodeAction [ ] = [ ] ;
17
18
const noqaAllRules : vscode . CodeAction [ ] = [ ] ;
@@ -21,7 +22,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
21
22
if ( Configuration . noqaEnabled ( ) ) {
22
23
const noqaDisabledRules = Configuration . noqaDisabledRules ( ) ;
23
24
context . diagnostics . forEach ( ( diagnostic ) => {
24
- if ( diagnostic . code && ! noqaDisabledRules . includes ( diagnostic . code . toString ( ) ) ) {
25
+ if ( diagnostic . code && ! noqaDisabledRules . includes ( Utilities . getDiagnosticCode ( diagnostic ) ) ) {
25
26
const singleRuleCodeAction = this . createNoqaCodeFix ( document , diagnostic , false ) ;
26
27
const allRulesCodeAction = this . createNoqaCodeFix ( document , diagnostic , true ) ;
27
28
noqaSingleRules . push ( singleRuleCodeAction ) ;
@@ -44,7 +45,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
44
45
private createNoqaCodeFix (
45
46
document : vscode . TextDocument ,
46
47
diagnostic : vscode . Diagnostic ,
47
- allRules : boolean ,
48
+ allRules : boolean
48
49
) : vscode . CodeAction {
49
50
const title = allRules ? "Ignore all rules for this line" : `Ignore rule ${ diagnostic . code } for this line` ;
50
51
const fix = new vscode . CodeAction ( title , vscode . CodeActionKind . QuickFix ) ;
@@ -54,7 +55,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
54
55
const line = document . lineAt ( diagnostic . range . start . line ) ;
55
56
const endPosition = new vscode . Position (
56
57
line . range . end . line ,
57
- line . range . end . character > 0 ? line . range . end . character : 0 ,
58
+ line . range . end . character > 0 ? line . range . end . character : 0
58
59
) ;
59
60
const noqaREGEX = / \s * - - n o q a (?: : ( \s ? \w \d { 3 } , ? ) * ) ? .* / ;
60
61
const noqa = noqaREGEX . exec ( line . text ) ;
@@ -67,20 +68,20 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
67
68
if ( noqa . length > 1 ) {
68
69
if ( noqa [ 1 ] ) {
69
70
if ( noqa [ 1 ] . endsWith ( "," ) ) {
70
- fix . edit . insert ( document . uri , endPosition , ` ${ diagnostic . code } ` ) ;
71
+ fix . edit . insert ( document . uri , endPosition , ` ${ Utilities . getDiagnosticCode ( diagnostic ) } ` ) ;
71
72
} else {
72
- fix . edit . insert ( document . uri , endPosition , `, ${ diagnostic . code } ` ) ;
73
+ fix . edit . insert ( document . uri , endPosition , `, ${ Utilities . getDiagnosticCode ( diagnostic ) } ` ) ;
73
74
}
74
75
} else {
75
- fix . edit . insert ( document . uri , endPosition , `: ${ diagnostic . code } ` ) ;
76
+ fix . edit . insert ( document . uri , endPosition , `: ${ Utilities . getDiagnosticCode ( diagnostic ) } ` ) ;
76
77
}
77
78
}
78
79
}
79
80
} else {
80
81
if ( allRules ) {
81
82
fix . edit . insert ( document . uri , endPosition , " -- noqa" ) ;
82
83
} else {
83
- fix . edit . insert ( document . uri , endPosition , ` -- noqa: ${ diagnostic . code } ` ) ;
84
+ fix . edit . insert ( document . uri , endPosition , ` -- noqa: ${ Utilities . getDiagnosticCode ( diagnostic ) } ` ) ;
84
85
}
85
86
}
86
87
@@ -94,7 +95,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
94
95
command : global ? EXCLUDE_RULE : EXCLUDE_RULE_WORKSPACE ,
95
96
title : title ,
96
97
tooltip : `This will exclude the rule ${ diagnostic . code } in the ${ global ? "Global" : "Workspace" } Settings` ,
97
- arguments : [ diagnostic . code ] ,
98
+ arguments : [ Utilities . getDiagnosticCode ( diagnostic ) ] ,
98
99
} ;
99
100
action . diagnostics = [ diagnostic ] ;
100
101
0 commit comments