|
6 | 6 | module dscanner.analysis.del; |
7 | 7 |
|
8 | 8 | import std.stdio; |
9 | | -import dparse.ast; |
10 | | -import dparse.lexer; |
11 | 9 | import dscanner.analysis.base; |
| 10 | +import dscanner.analysis.helpers; |
12 | 11 | import dsymbol.scope_; |
13 | 12 |
|
14 | 13 | /** |
15 | 14 | * Checks for use of the deprecated 'delete' keyword |
16 | 15 | */ |
17 | | -final class DeleteCheck : BaseAnalyzer |
| 16 | +extern(C++) class DeleteCheck(AST) : BaseAnalyzerDmd |
18 | 17 | { |
19 | | - alias visit = BaseAnalyzer.visit; |
20 | | - |
| 18 | + // alias visit = BaseAnalyzerDmd!AST.visit; |
| 19 | + alias visit = BaseAnalyzerDmd.visit; |
21 | 20 | mixin AnalyzerInfo!"delete_check"; |
22 | 21 |
|
23 | | - this(BaseAnalyzerArguments args) |
| 22 | + extern(D) this(string fileName) |
24 | 23 | { |
25 | | - super(args); |
| 24 | + super(fileName); |
26 | 25 | } |
27 | 26 |
|
28 | | - override void visit(const DeleteExpression d) |
| 27 | + override void visit(AST.DeleteExp d) |
29 | 28 | { |
30 | | - addErrorMessage(d.tokens[0], KEY, |
31 | | - "Avoid using the 'delete' keyword.", |
32 | | - [AutoFix.replacement(d.tokens[0], `destroy(`, "Replace delete with destroy()") |
33 | | - .concat(AutoFix.insertionAfter(d.tokens[$ - 1], ")"))]); |
34 | | - d.accept(this); |
| 29 | + addErrorMessage(cast(ulong) d.loc.linnum, cast(ulong) d.loc.charnum, "dscanner.deprecated.delete_keyword", |
| 30 | + "Avoid using the 'delete' keyword."); |
| 31 | + super.visit(d); |
35 | 32 | } |
36 | | - |
37 | | - private enum string KEY = "dscanner.deprecated.delete_keyword"; |
38 | 33 | } |
39 | 34 |
|
40 | 35 | unittest |
41 | 36 | { |
42 | | - import dscanner.analysis.config : Check, disabledConfig, StaticAnalysisConfig; |
43 | | - import dscanner.analysis.helpers : assertAnalyzerWarnings, assertAutoFix; |
| 37 | + import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig; |
| 38 | + import dscanner.analysis.helpers : assertAnalyzerWarnings; |
44 | 39 |
|
45 | 40 | StaticAnalysisConfig sac = disabledConfig(); |
46 | 41 | sac.delete_check = Check.enabled; |
47 | | - assertAnalyzerWarnings(q{ |
48 | | - void testDelete() |
49 | | - { |
50 | | - int[int] data = [1 : 2]; |
51 | | - delete data[1]; /+ |
52 | | - ^^^^^^ [warn]: Avoid using the 'delete' keyword. +/ |
53 | | - |
54 | | - auto a = new Class(); |
55 | | - delete a; /+ |
56 | | - ^^^^^^ [warn]: Avoid using the 'delete' keyword. +/ |
57 | | - } |
58 | | - }c, sac); |
59 | | - |
60 | | - assertAutoFix(q{ |
61 | | - void testDelete() |
62 | | - { |
63 | | - int[int] data = [1 : 2]; |
64 | | - delete data[1]; // fix |
65 | | - |
66 | | - auto a = new Class(); |
67 | | - delete a; // fix |
68 | | - } |
69 | | - }c, q{ |
| 42 | + assertAnalyzerWarningsDMD(q{ |
70 | 43 | void testDelete() |
71 | 44 | { |
72 | 45 | int[int] data = [1 : 2]; |
73 | | - destroy(data[1]); // fix |
| 46 | + delete data[1]; // [warn]: Avoid using the 'delete' keyword. |
74 | 47 |
|
75 | 48 | auto a = new Class(); |
76 | | - destroy(a); // fix |
| 49 | + delete a; // [warn]: Avoid using the 'delete' keyword. |
77 | 50 | } |
78 | 51 | }c, sac); |
79 | 52 |
|
|
0 commit comments