1 // Copyright Brian Schott (Hackerpilot) 2014. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 module dscanner.analysis.del; 7 8 import std.stdio; 9 import dparse.ast; 10 import dparse.lexer; 11 import dscanner.analysis.base; 12 import dsymbol.scope_; 13 14 /** 15 * Checks for use of the deprecated 'delete' keyword 16 */ 17 final class DeleteCheck : BaseAnalyzer 18 { 19 alias visit = BaseAnalyzer.visit; 20 21 mixin AnalyzerInfo!"delete_check"; 22 23 this(string fileName, const(Scope)* sc, bool skipTests = false) 24 { 25 super(fileName, sc, skipTests); 26 } 27 28 override void visit(const DeleteExpression d) 29 { 30 addErrorMessage(d.line, d.column, "dscanner.deprecated.delete_keyword", 31 "Avoid using the 'delete' keyword."); 32 d.accept(this); 33 } 34 } 35 36 unittest 37 { 38 import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig; 39 import dscanner.analysis.helpers : assertAnalyzerWarnings; 40 41 StaticAnalysisConfig sac = disabledConfig(); 42 sac.delete_check = Check.enabled; 43 assertAnalyzerWarnings(q{ 44 void testDelete() 45 { 46 int[int] data = [1 : 2]; 47 delete data[1]; // [warn]: Avoid using the 'delete' keyword. 48 49 auto a = new Class(); 50 delete a; // [warn]: Avoid using the 'delete' keyword. 51 } 52 }}, sac); 53 54 stderr.writeln("Unittest for DeleteCheck passed."); 55 }