Merge branch 'master' of https://github.com/Hackerpilot/Dscanner
Conflicts: std/d/parser.d
This commit is contained in:
commit
d71fd8addc
|
@ -30,7 +30,7 @@ class ConstructorCheck : BaseAnalyzer
|
|||
addErrorMessage(classDeclaration.name.line,
|
||||
classDeclaration.name.column, "This class has a zero-argument"
|
||||
~ " constructor as well as a constructor with one default"
|
||||
~ " argument. This can be confusing");
|
||||
~ " argument. This can be confusing.");
|
||||
}
|
||||
hasDefaultArgConstructor = oldHasDefault;
|
||||
hasNoArgConstructor = oldHasNoArg;
|
||||
|
@ -91,7 +91,7 @@ private:
|
|||
unittest
|
||||
{
|
||||
assertAnalyzerWarnings(q{
|
||||
class Cat // [warn]: This class has a zero-argument constructor as well as a constructor with one default argument. This can be confusing
|
||||
class Cat // [warn]: This class has a zero-argument constructor as well as a constructor with one default argument. This can be confusing.
|
||||
{
|
||||
this() {}
|
||||
this(string name = "kittie") {}
|
||||
|
|
|
@ -12,7 +12,7 @@ import analysis.base;
|
|||
import analysis.helpers;
|
||||
|
||||
/**
|
||||
* Checks for use of the deprecated "delete" keyword
|
||||
* Checks for use of the deprecated 'delete' keyword
|
||||
*/
|
||||
class DeleteCheck : BaseAnalyzer
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ class DeleteCheck : BaseAnalyzer
|
|||
|
||||
override void visit(const DeleteExpression d)
|
||||
{
|
||||
addErrorMessage(d.line, d.column, "Avoid using the delete keyword");
|
||||
addErrorMessage(d.line, d.column, "Avoid using the 'delete' keyword.");
|
||||
d.accept(this);
|
||||
}
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ unittest
|
|||
void testDelete()
|
||||
{
|
||||
int[int] data = [1 : 2];
|
||||
delete data[1]; // [warn]: Avoid using the delete keyword
|
||||
delete data[1]; // [warn]: Avoid using the 'delete' keyword.
|
||||
|
||||
auto a = new Class();
|
||||
delete a; // [warn]: Avoid using the delete keyword
|
||||
delete a; // [warn]: Avoid using the 'delete' keyword.
|
||||
}
|
||||
}c, analysis.run.AnalyzerCheck.delete_check);
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ class DuplicateAttributeCheck : BaseAnalyzer
|
|||
// Already has that attribute
|
||||
if (hasAttribute)
|
||||
{
|
||||
string message = "The attribute '%s' is duplicated.".format(attributeName);
|
||||
string message = "Attribute '%s' is duplicated.".format(attributeName);
|
||||
addErrorMessage(line, column, message);
|
||||
}
|
||||
|
||||
|
@ -169,25 +169,25 @@ unittest
|
|||
}
|
||||
|
||||
// Duplicate before
|
||||
@property @property bool aaa() // [warn]: The attribute 'property' is duplicated.
|
||||
@property @property bool aaa() // [warn]: Attribute 'property' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Duplicate after
|
||||
bool bbb() @safe @safe // [warn]: The attribute 'safe' is duplicated.
|
||||
bool bbb() @safe @safe // [warn]: Attribute 'safe' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Duplicate before and after
|
||||
@system bool ccc() @system // [warn]: The attribute 'system' is duplicated.
|
||||
@system bool ccc() @system // [warn]: Attribute 'system' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Duplicate before and after
|
||||
@trusted bool ddd() @trusted // [warn]: The attribute 'trusted' is duplicated.
|
||||
@trusted bool ddd() @trusted // [warn]: Attribute 'trusted' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -200,24 +200,24 @@ unittest
|
|||
return false;
|
||||
}
|
||||
|
||||
pure pure bool bbb() // [warn]: The attribute 'pure' is duplicated.
|
||||
pure pure bool bbb() // [warn]: Attribute 'pure' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: There is no way to get the line/column number of the attribute like this
|
||||
bool ccc() pure pure // FIXME: [warn]: The attribute 'pure' is duplicated.
|
||||
bool ccc() pure pure // FIXME: [warn]: Attribute 'pure' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
nothrow nothrow bool ddd() // [warn]: The attribute 'nothrow' is duplicated.
|
||||
nothrow nothrow bool ddd() // [warn]: Attribute 'nothrow' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: There is no way to get the line/column number of the attribute like this
|
||||
bool eee() nothrow nothrow // FIXME: [warn]: The attribute 'nothrow' is duplicated.
|
||||
bool eee() nothrow nothrow // FIXME: [warn]: Attribute 'nothrow' is duplicated.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class FloatOperatorCheck : BaseAnalyzer
|
|||
|| r.operator == tok!"!>="
|
||||
|| r.operator == tok!"!<=")
|
||||
{
|
||||
addErrorMessage(r.line, r.column, "Avoid using the deprecated floating-point operators");
|
||||
addErrorMessage(r.line, r.column, "Avoid using the deprecated floating-point operators.");
|
||||
}
|
||||
r.accept(this);
|
||||
}
|
||||
|
@ -47,14 +47,14 @@ unittest
|
|||
{
|
||||
float z = 1.5f;
|
||||
bool a;
|
||||
a = z !<>= z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z !<> z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z <> z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z <>= z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z !> z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z !>= z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z !< z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z !<= z; // [warn]: Avoid using the deprecated floating-point operators
|
||||
a = z !<>= z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
a = z !<> z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
a = z <> z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
a = z <>= z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
a = z !> z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
a = z !>= z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
a = z !< z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
a = z !<= z; // [warn]: Avoid using the deprecated floating-point operators.
|
||||
}
|
||||
}c, analysis.run.AnalyzerCheck.float_operator_check);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class IfElseSameCheck : BaseAnalyzer
|
|||
{
|
||||
if (ifStatement.thenStatement == ifStatement.elseStatement)
|
||||
addErrorMessage(ifStatement.line, ifStatement.column,
|
||||
"\"Else\" branch is identical to \"Then\" branch.");
|
||||
"'Else' branch is identical to 'Then' branch.");
|
||||
ifStatement.accept(this);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class IfElseSameCheck : BaseAnalyzer
|
|||
&& e.ternaryExpression == assignExpression.ternaryExpression)
|
||||
{
|
||||
addErrorMessage(assignExpression.line, assignExpression.column,
|
||||
"Left side of assignment operatior is identical to the right side");
|
||||
"Left side of assignment operatior is identical to the right side.");
|
||||
}
|
||||
assignExpression.accept(this);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ unittest
|
|||
void testSizeT()
|
||||
{
|
||||
string person = "unknown";
|
||||
if (person == "unknown") // [warn]: "Else" branch is identical to "Then" branch.
|
||||
if (person == "unknown") // [warn]: 'Else' branch is identical to 'Then' branch.
|
||||
person = "bobrick"; // same
|
||||
else
|
||||
person = "bobrick"; // same
|
||||
|
|
|
@ -76,6 +76,6 @@ unittest
|
|||
l.addLine(35);
|
||||
foreach (i; 33 .. 43)
|
||||
assert (l.containsLine(i));
|
||||
stderr.writeln("Unittest for LineSpans passed");
|
||||
stderr.writeln("Unittest for LineSpans passed.");
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class NumberStyleCheck : BaseAnalyzer
|
|||
|| !t.text.matchFirst(badDecimalRegex).empty))
|
||||
{
|
||||
addErrorMessage(t.line, t.column,
|
||||
"Use underscores to improve number constant readability");
|
||||
"Use underscores to improve number constant readability.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,9 @@ unittest
|
|||
a = 10; // ok
|
||||
a = 100; // ok
|
||||
a = 1000; // FIXME: boom
|
||||
a = 10000; // [warn]: Use underscores to improve number constant readability
|
||||
a = 100000; // [warn]: Use underscores to improve number constant readability
|
||||
a = 1000000; // [warn]: Use underscores to improve number constant readability
|
||||
a = 10000; // [warn]: Use underscores to improve number constant readability.
|
||||
a = 100000; // [warn]: Use underscores to improve number constant readability.
|
||||
a = 1000000; // [warn]: Use underscores to improve number constant readability.
|
||||
}
|
||||
}c, analysis.run.AnalyzerCheck.number_style_check);
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ class ObjectConstCheck : BaseAnalyzer
|
|||
&& !hasConst(d.functionDeclaration.memberFunctionAttributes)))
|
||||
{
|
||||
addErrorMessage(d.functionDeclaration.name.line,
|
||||
d.functionDeclaration.name.column, "opCmp, toHash, opEquals,"
|
||||
~ " and toString should be declared const");
|
||||
d.functionDeclaration.name.column, "Methods 'opCmp', 'toHash',"
|
||||
~ " 'opEquals', and 'toString' should be declared const.");
|
||||
}
|
||||
d.accept(this);
|
||||
}
|
||||
|
@ -101,22 +101,22 @@ unittest
|
|||
// Will warn, because none are const
|
||||
class Dog
|
||||
{
|
||||
bool opEquals(Object a, Object b) // [warn]: opCmp, toHash, opEquals, and toString should be declared const
|
||||
bool opEquals(Object a, Object b) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const.
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int opCmp(Object o) // [warn]: opCmp, toHash, opEquals, and toString should be declared const
|
||||
int opCmp(Object o) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const.
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
hash_t toHash() // [warn]: opCmp, toHash, opEquals, and toString should be declared const
|
||||
hash_t toHash() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const.
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
string toString() // [warn]: opCmp, toHash, opEquals, and toString should be declared const
|
||||
string toString() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' should be declared const.
|
||||
{
|
||||
return "Dog";
|
||||
}
|
||||
|
|
|
@ -66,13 +66,13 @@ class OpEqualsWithoutToHashCheck : BaseAnalyzer
|
|||
// Warn if has opEquals, but not toHash
|
||||
if (hasOpEquals && !hasToHash)
|
||||
{
|
||||
string message = "Has method opEquals, but not toHash";
|
||||
string message = "Has method 'opEquals', but not 'toHash'.";
|
||||
addErrorMessage(name.line, name.column, message);
|
||||
}
|
||||
// Warn if has toHash, but not opEquals
|
||||
else if (!hasOpEquals && hasToHash)
|
||||
{
|
||||
string message = "Has method toHash, but not opEquals";
|
||||
string message = "Has method 'toHash', but not 'opEquals'.";
|
||||
addErrorMessage(name.line, name.column, message);
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ unittest
|
|||
}
|
||||
|
||||
// Fail on class opEquals
|
||||
class Rabbit // [warn]: Has method opEquals, but not toHash
|
||||
class Rabbit // [warn]: Has method 'opEquals', but not 'toHash'.
|
||||
{
|
||||
const bool opEquals(Object a, Object b)
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ unittest
|
|||
}
|
||||
|
||||
// Fail on class toHash
|
||||
class Kangaroo // [warn]: Has method toHash, but not opEquals
|
||||
class Kangaroo // [warn]: Has method 'toHash', but not 'opEquals'.
|
||||
{
|
||||
override const hash_t toHash()
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ unittest
|
|||
}
|
||||
|
||||
// Fail on struct opEquals
|
||||
struct Tarantula // [warn]: Has method opEquals, but not toHash
|
||||
struct Tarantula // [warn]: Has method 'opEquals', but not 'toHash'.
|
||||
{
|
||||
const bool opEquals(Object a, Object b)
|
||||
{
|
||||
|
@ -123,7 +123,7 @@ unittest
|
|||
}
|
||||
|
||||
// Fail on struct toHash
|
||||
struct Puma // [warn]: Has method toHash, but not opEquals
|
||||
struct Puma // [warn]: Has method 'toHash', but not 'opEquals'.
|
||||
{
|
||||
const nothrow @safe hash_t toHash()
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@ import analysis.helpers;
|
|||
*/
|
||||
class PokemonExceptionCheck : BaseAnalyzer
|
||||
{
|
||||
enum message = "Catching Error or Throwable is almost always a bad idea";
|
||||
enum message = "Catching Error or Throwable is almost always a bad idea.";
|
||||
|
||||
alias visit = BaseAnalyzer.visit;
|
||||
|
||||
|
@ -81,15 +81,15 @@ unittest
|
|||
{
|
||||
|
||||
}
|
||||
catch (Error err) // [warn]: Catching Error or Throwable is almost always a bad idea
|
||||
catch (Error err) // [warn]: Catching Error or Throwable is almost always a bad idea.
|
||||
{
|
||||
|
||||
}
|
||||
catch (Throwable err) // [warn]: Catching Error or Throwable is almost always a bad idea
|
||||
catch (Throwable err) // [warn]: Catching Error or Throwable is almost always a bad idea.
|
||||
{
|
||||
|
||||
}
|
||||
catch // [warn]: Catching Error or Throwable is almost always a bad idea
|
||||
catch // [warn]: Catching Error or Throwable is almost always a bad idea.
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class StyleChecker : BaseAnalyzer
|
|||
{
|
||||
if (part.text.matchFirst(moduleNameRegex).length == 0)
|
||||
addErrorMessage(part.line, part.column, "Module/package name '"
|
||||
~ part.text ~ "' does not match style guidelines");
|
||||
~ part.text ~ "' does not match style guidelines.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ class StyleChecker : BaseAnalyzer
|
|||
void checkLowercaseName(string type, ref const Token name)
|
||||
{
|
||||
if (name.text.matchFirst(varFunNameRegex).length == 0)
|
||||
addErrorMessage(name.line, name.column, type ~ " name "
|
||||
~ name.text ~ " does not match style guidelines");
|
||||
addErrorMessage(name.line, name.column, type ~ " name '"
|
||||
~ name.text ~ "' does not match style guidelines.");
|
||||
}
|
||||
|
||||
override void visit(const ClassDeclaration dec)
|
||||
|
@ -87,24 +87,24 @@ class StyleChecker : BaseAnalyzer
|
|||
{
|
||||
if (name.text.matchFirst(aggregateNameRegex).length == 0)
|
||||
addErrorMessage(name.line, name.column, aggregateType
|
||||
~ " name '" ~ name.text ~ "' does not match style guidelines");
|
||||
~ " name '" ~ name.text ~ "' does not match style guidelines.");
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
assertAnalyzerWarnings(q{
|
||||
module AMODULE; // [warn]: Module/package name 'AMODULE' does not match style guidelines
|
||||
module AMODULE; // [warn]: Module/package name 'AMODULE' does not match style guidelines.
|
||||
|
||||
bool A_VARIABLE; // FIXME:
|
||||
bool a_variable; // ok
|
||||
bool aVariable; // ok
|
||||
|
||||
void A_FUNCTION() {} // FIXME:
|
||||
class cat {} // [warn]: Class name 'cat' does not match style guidelines
|
||||
interface puma {} // [warn]: Interface name 'puma' does not match style guidelines
|
||||
struct dog {} // [warn]: Struct name 'dog' does not match style guidelines
|
||||
enum racoon {} // [warn]: Enum name 'racoon' does not match style guidelines
|
||||
class cat {} // [warn]: Class name 'cat' does not match style guidelines.
|
||||
interface puma {} // [warn]: Interface name 'puma' does not match style guidelines.
|
||||
struct dog {} // [warn]: Struct name 'dog' does not match style guidelines.
|
||||
enum racoon {} // [warn]: Enum name 'racoon' does not match style guidelines.
|
||||
}c, analysis.run.AnalyzerCheck.style_check);
|
||||
|
||||
stderr.writeln("Unittest for StyleChecker passed.");
|
||||
|
|
10
ctags.d
10
ctags.d
|
@ -156,6 +156,16 @@ class CTagsPrinter : ASTVisitor
|
|||
dec.accept(this);
|
||||
}
|
||||
|
||||
override void visit(const AutoDeclaration dec)
|
||||
{
|
||||
foreach (i; dec.identifiers)
|
||||
{
|
||||
tagLines ~= "%s\t%s\t%d;\"\tv%s\n".format(i.text, fileName,
|
||||
i.line, context);
|
||||
}
|
||||
dec.accept(this);
|
||||
}
|
||||
|
||||
override void visit(const Invariant dec)
|
||||
{
|
||||
tagLines ~= "invariant\t%s\t%d;\"\tv%s\n".format(fileName, dec.line, context);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue