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 class DeleteCheck : BaseAnalyzer
18 {
19 	alias visit = BaseAnalyzer.visit;
20 
21 	this(string fileName, const(Scope)* sc, bool skipTests = false)
22 	{
23 		super(fileName, sc, skipTests);
24 	}
25 
26 	override void visit(const DeleteExpression d)
27 	{
28 		addErrorMessage(d.line, d.column, "dscanner.deprecated.delete_keyword",
29 				"Avoid using the 'delete' keyword.");
30 		d.accept(this);
31 	}
32 }
33 
34 unittest
35 {
36 	import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
37 	import dscanner.analysis.helpers : assertAnalyzerWarnings;
38 
39 	StaticAnalysisConfig sac = disabledConfig();
40 	sac.delete_check = Check.enabled;
41 	assertAnalyzerWarnings(q{
42 		void testDelete()
43 		{
44 			int[int] data = [1 : 2];
45 			delete data[1]; // [warn]: Avoid using the 'delete' keyword.
46 
47 			auto a = new Class();
48 			delete a; // [warn]: Avoid using the 'delete' keyword.
49 		}
50 	}c, sac);
51 
52 	stderr.writeln("Unittest for DeleteCheck passed.");
53 }