Move old alias syntax warning out of the parser, see Hackerpilot/libdparse#80

This commit is contained in:
Hackerpilot 2016-03-02 21:11:38 -08:00
parent 829d20fcd3
commit 76765a621d
4 changed files with 61 additions and 1 deletions

@ -1 +1 @@
Subproject commit adb134c054ffcb05c74d7033e59617dedba1493b
Subproject commit a10f5988b2b130ad2cae28c90a668067f98c82a7

View File

@ -0,0 +1,54 @@
// Copyright Brian Schott (Hackerpilot) 2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
module analysis.alias_syntax_check;
import dparse.ast;
import dparse.lexer;
import analysis.base;
/**
* Checks for uses of the old alias syntax.
*/
class AliasSyntaxCheck : BaseAnalyzer
{
alias visit = BaseAnalyzer.visit;
this(string fileName)
{
super(fileName, null);
}
override void visit(const AliasDeclaration ad)
{
if (ad.identifierList is null)
return;
assert(ad.identifierList.identifiers.length > 0,
"Identifier list length is zero, libdparse has a bug");
addErrorMessage(ad.identifierList.identifiers[0].line,
ad.identifierList.identifiers[0].column, KEY,
"Prefer the new \"'alias' identifier '=' type ';'\" syntax"
~ " to the old \"'alias' type identifier ';'\" syntax.");
}
private:
enum KEY = "dscanner.style.alias_syntax";
}
unittest
{
import analysis.helpers : assertAnalyzerWarnings;
import analysis.config : StaticAnalysisConfig;
import std.stdio : stderr;
StaticAnalysisConfig sac;
sac.alias_syntax_check = true;
assertAnalyzerWarnings(q{
alias int abcde; // [warn]: Prefer the new "'alias' identifier '=' type ';'" syntax to the old "'alias' type identifier ';'" syntax.
alias abcde = int;
}c, sac);
stderr.writeln("Unittest for AliasSyntaxCheck passed.");
}

View File

@ -110,4 +110,7 @@ struct StaticAnalysisConfig
@INI("Checks for asserts that are always true")
bool useless_assert_check;
@INI("Check for uses of the old-style alias syntax")
bool alias_syntax_check;
}

View File

@ -55,6 +55,7 @@ import analysis.line_length;
import analysis.auto_ref_assignment;
import analysis.incorrect_infinite_range;
import analysis.useless_assert;
import analysis.alias_syntax_check;
import dsymbol.string_interning : internString;
import dsymbol.scope_;
@ -266,6 +267,8 @@ MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig a
checks ~= new IncorrectInfiniteRangeCheck(fileName);
if (analysisConfig.useless_assert_check)
checks ~= new UselessAssertCheck(fileName);
if (analysisConfig.alias_syntax_check)
checks ~= new AliasSyntaxCheck(fileName);
version (none)
if (analysisConfig.redundant_if_check)
checks ~= new IfStatementCheck(fileName, moduleScope);