Made warning and test messages more consistent.

Made all warnings end in a period.
Made all names have single quotes.
Made all test success messages the same.
This commit is contained in:
Matthew Brennan Jones 2014-06-25 10:37:30 -07:00
parent ade1a718ac
commit 74e087aac3
12 changed files with 69 additions and 69 deletions

View File

@ -30,7 +30,7 @@ class ConstructorCheck : BaseAnalyzer
addErrorMessage(classDeclaration.name.line, addErrorMessage(classDeclaration.name.line,
classDeclaration.name.column, "This class has a zero-argument" classDeclaration.name.column, "This class has a zero-argument"
~ " constructor as well as a constructor with one default" ~ " constructor as well as a constructor with one default"
~ " argument. This can be confusing"); ~ " argument. This can be confusing.");
} }
hasDefaultArgConstructor = oldHasDefault; hasDefaultArgConstructor = oldHasDefault;
hasNoArgConstructor = oldHasNoArg; hasNoArgConstructor = oldHasNoArg;
@ -91,7 +91,7 @@ private:
unittest unittest
{ {
assertAnalyzerWarnings(q{ 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() {}
this(string name = "kittie") {} this(string name = "kittie") {}

View File

@ -12,7 +12,7 @@ import analysis.base;
import analysis.helpers; import analysis.helpers;
/** /**
* Checks for use of the deprecated "delete" keyword * Checks for use of the deprecated 'delete' keyword
*/ */
class DeleteCheck : BaseAnalyzer class DeleteCheck : BaseAnalyzer
{ {
@ -25,7 +25,7 @@ class DeleteCheck : BaseAnalyzer
override void visit(const DeleteExpression d) 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); d.accept(this);
} }
} }
@ -36,10 +36,10 @@ unittest
void testDelete() void testDelete()
{ {
int[int] data = [1 : 2]; 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(); 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); }c, analysis.run.AnalyzerCheck.delete_check);

View File

@ -90,7 +90,7 @@ class DuplicateAttributeCheck : BaseAnalyzer
// Already has that attribute // Already has that attribute
if (hasAttribute) if (hasAttribute)
{ {
string message = "The attribute '%s' is duplicated.".format(attributeName); string message = "Attribute '%s' is duplicated.".format(attributeName);
addErrorMessage(line, column, message); addErrorMessage(line, column, message);
} }
@ -169,25 +169,25 @@ unittest
} }
// Duplicate before // Duplicate before
@property @property bool aaa() // [warn]: The attribute 'property' is duplicated. @property @property bool aaa() // [warn]: Attribute 'property' is duplicated.
{ {
return false; return false;
} }
// Duplicate after // Duplicate after
bool bbb() @safe @safe // [warn]: The attribute 'safe' is duplicated. bool bbb() @safe @safe // [warn]: Attribute 'safe' is duplicated.
{ {
return false; return false;
} }
// Duplicate before and after // 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; return false;
} }
// Duplicate before and after // 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; return false;
} }
@ -200,24 +200,24 @@ unittest
return false; return false;
} }
pure pure bool bbb() // [warn]: The attribute 'pure' is duplicated. pure pure bool bbb() // [warn]: Attribute 'pure' is duplicated.
{ {
return false; return false;
} }
// FIXME: There is no way to get the line/column number of the attribute like this // 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; return false;
} }
nothrow nothrow bool ddd() // [warn]: The attribute 'nothrow' is duplicated. nothrow nothrow bool ddd() // [warn]: Attribute 'nothrow' is duplicated.
{ {
return false; return false;
} }
// FIXME: There is no way to get the line/column number of the attribute like this // 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; return false;
} }

View File

@ -34,7 +34,7 @@ class FloatOperatorCheck : BaseAnalyzer
|| r.operator == tok!"!>=" || r.operator == tok!"!>="
|| 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); r.accept(this);
} }
@ -47,14 +47,14 @@ unittest
{ {
float z = 1.5f; float z = 1.5f;
bool a; 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); }c, analysis.run.AnalyzerCheck.float_operator_check);

View File

@ -29,7 +29,7 @@ class IfElseSameCheck : BaseAnalyzer
{ {
if (ifStatement.thenStatement == ifStatement.elseStatement) if (ifStatement.thenStatement == ifStatement.elseStatement)
addErrorMessage(ifStatement.line, ifStatement.column, addErrorMessage(ifStatement.line, ifStatement.column,
"\"Else\" branch is identical to \"Then\" branch."); "'Else' branch is identical to 'Then' branch.");
ifStatement.accept(this); ifStatement.accept(this);
} }
@ -40,7 +40,7 @@ class IfElseSameCheck : BaseAnalyzer
&& e.ternaryExpression == assignExpression.ternaryExpression) && e.ternaryExpression == assignExpression.ternaryExpression)
{ {
addErrorMessage(assignExpression.line, assignExpression.column, 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); assignExpression.accept(this);
} }
@ -52,7 +52,7 @@ unittest
void testSizeT() void testSizeT()
{ {
string person = "unknown"; 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 person = "bobrick"; // same
else else
person = "bobrick"; // same person = "bobrick"; // same

View File

@ -76,6 +76,6 @@ unittest
l.addLine(35); l.addLine(35);
foreach (i; 33 .. 43) foreach (i; 33 .. 43)
assert (l.containsLine(i)); assert (l.containsLine(i));
stderr.writeln("Unittest for LineSpans passed"); stderr.writeln("Unittest for LineSpans passed.");
} }

View File

@ -32,7 +32,7 @@ class NumberStyleCheck : BaseAnalyzer
|| !t.text.matchFirst(badDecimalRegex).empty)) || !t.text.matchFirst(badDecimalRegex).empty))
{ {
addErrorMessage(t.line, t.column, 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 = 10; // ok
a = 100; // ok a = 100; // ok
a = 1000; // FIXME: boom a = 1000; // FIXME: boom
a = 10000; // [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 = 100000; // [warn]: Use underscores to improve number constant readability.
a = 1000000; // [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); }c, analysis.run.AnalyzerCheck.number_style_check);

View File

@ -38,8 +38,8 @@ class ObjectConstCheck : BaseAnalyzer
&& !hasConst(d.functionDeclaration.memberFunctionAttributes))) && !hasConst(d.functionDeclaration.memberFunctionAttributes)))
{ {
addErrorMessage(d.functionDeclaration.name.line, addErrorMessage(d.functionDeclaration.name.line,
d.functionDeclaration.name.column, "opCmp, toHash, opEquals," d.functionDeclaration.name.column, "Methods 'opCmp', 'toHash',"
~ " and toString should be declared const"); ~ " 'opEquals', and 'toString' should be declared const.");
} }
d.accept(this); d.accept(this);
} }
@ -101,22 +101,22 @@ unittest
// Will warn, because none are const // Will warn, because none are const
class Dog 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; 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; 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; 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"; return "Dog";
} }

View File

@ -66,13 +66,13 @@ class OpEqualsWithoutToHashCheck : BaseAnalyzer
// Warn if has opEquals, but not toHash // Warn if has opEquals, but not toHash
if (hasOpEquals && !hasToHash) 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); addErrorMessage(name.line, name.column, message);
} }
// Warn if has toHash, but not opEquals // Warn if has toHash, but not opEquals
else if (!hasOpEquals && hasToHash) 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); addErrorMessage(name.line, name.column, message);
} }
} }
@ -96,7 +96,7 @@ unittest
} }
// Fail on class opEquals // 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) const bool opEquals(Object a, Object b)
{ {
@ -105,7 +105,7 @@ unittest
} }
// Fail on class toHash // 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() override const hash_t toHash()
{ {
@ -114,7 +114,7 @@ unittest
} }
// Fail on struct opEquals // 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) const bool opEquals(Object a, Object b)
{ {
@ -123,7 +123,7 @@ unittest
} }
// Fail on struct toHash // 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() const nothrow @safe hash_t toHash()
{ {

View File

@ -25,7 +25,7 @@ import analysis.helpers;
*/ */
class PokemonExceptionCheck : BaseAnalyzer 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; 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.
{ {
} }
} }

View File

@ -36,7 +36,7 @@ class StyleChecker : BaseAnalyzer
{ {
if (part.text.matchFirst(moduleNameRegex).length == 0) if (part.text.matchFirst(moduleNameRegex).length == 0)
addErrorMessage(part.line, part.column, "Module/package name '" 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) void checkLowercaseName(string type, ref const Token name)
{ {
if (name.text.matchFirst(varFunNameRegex).length == 0) if (name.text.matchFirst(varFunNameRegex).length == 0)
addErrorMessage(name.line, name.column, type ~ " name " addErrorMessage(name.line, name.column, type ~ " name '"
~ name.text ~ " does not match style guidelines"); ~ name.text ~ "' does not match style guidelines.");
} }
override void visit(const ClassDeclaration dec) override void visit(const ClassDeclaration dec)
@ -87,24 +87,24 @@ class StyleChecker : BaseAnalyzer
{ {
if (name.text.matchFirst(aggregateNameRegex).length == 0) if (name.text.matchFirst(aggregateNameRegex).length == 0)
addErrorMessage(name.line, name.column, aggregateType addErrorMessage(name.line, name.column, aggregateType
~ " name '" ~ name.text ~ "' does not match style guidelines"); ~ " name '" ~ name.text ~ "' does not match style guidelines.");
} }
} }
unittest unittest
{ {
assertAnalyzerWarnings(q{ 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; // FIXME:
bool a_variable; // ok bool a_variable; // ok
bool aVariable; // ok bool aVariable; // ok
void A_FUNCTION() {} // FIXME: void A_FUNCTION() {} // FIXME:
class cat {} // [warn]: Class name 'cat' 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 interface puma {} // [warn]: Interface name 'puma' does not match style guidelines.
struct dog {} // [warn]: Struct name 'dog' 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 enum racoon {} // [warn]: Enum name 'racoon' does not match style guidelines.
}c, analysis.run.AnalyzerCheck.style_check); }c, analysis.run.AnalyzerCheck.style_check);
stderr.writeln("Unittest for StyleChecker passed."); stderr.writeln("Unittest for StyleChecker passed.");

View File

@ -133,7 +133,7 @@ alias core.sys.posix.stdio.fileno fileno;
assert (d !is null); assert (d !is null);
assert (p.errorCount == 0); assert (p.errorCount == 0);
stderr.writeln("Unittest for parseAliasDeclaration() passed."); stderr.writeln("Unittest for parseAliasDeclaration passed.");
} }
/** /**
@ -168,7 +168,7 @@ alias core.sys.posix.stdio.fileno fileno;
auto initializer = p.parseAliasInitializer(); auto initializer = p.parseAliasInitializer();
assert (initializer !is null); assert (initializer !is null);
assert (p.errorCount == 0); assert (p.errorCount == 0);
stderr.writeln("Unittest for parseAliasInitializer() passed."); stderr.writeln("Unittest for parseAliasInitializer passed.");
} }
/** /**
@ -197,7 +197,7 @@ alias core.sys.posix.stdio.fileno fileno;
auto aliasThis = p.parseAliasThisDeclaration(); auto aliasThis = p.parseAliasThisDeclaration();
assert (aliasThis !is null); assert (aliasThis !is null);
assert (p.errorCount == 0); assert (p.errorCount == 0);
stderr.writeln("Unittest for parseAliasThisDeclaration() passed."); stderr.writeln("Unittest for parseAliasThisDeclaration passed.");
} }
/** /**
@ -231,7 +231,7 @@ alias core.sys.posix.stdio.fileno fileno;
attribute = p.parseAlignAttribute(); attribute = p.parseAlignAttribute();
assert (attribute !is null); assert (attribute !is null);
assert (p.errorCount == 0); assert (p.errorCount == 0);
stderr.writeln("Unittest for parseAlignAttribute() passed."); stderr.writeln("Unittest for parseAlignAttribute passed.");
} }
/** /**
@ -1146,7 +1146,7 @@ incorrect;
assert (nine is null); assert (nine is null);
assert (p.errorCount > 0); assert (p.errorCount > 0);
stderr.writeln("Unittest for parseCastQualifier() passed."); stderr.writeln("Unittest for parseCastQualifier passed.");
} }
/** /**
@ -1298,7 +1298,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c;
assert (classFour.structBody.declarations.length == 0, assert (classFour.structBody.declarations.length == 0,
to!string(classFour.structBody.declarations.length)); to!string(classFour.structBody.declarations.length));
stderr.writeln("Unittest for parseClassDeclaration() passed."); stderr.writeln("Unittest for parseClassDeclaration passed.");
} }
/** /**
@ -2027,7 +2027,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c;
assert (d !is null); assert (d !is null);
assert (d.functionBody !is null); assert (d.functionBody !is null);
assert (p.errorCount == 0); assert (p.errorCount == 0);
stderr.writeln("Unittest for parseDestructor() passed."); stderr.writeln("Unittest for parseDestructor passed.");
} }
/** /**
@ -2486,7 +2486,7 @@ body {} // six
assert (functionBodySix.outStatement is null); assert (functionBodySix.outStatement is null);
assert (functionBodySix.bodyStatement !is null); assert (functionBodySix.bodyStatement !is null);
stderr.writeln("Unittest for parseFunctionBody() passed."); stderr.writeln("Unittest for parseFunctionBody passed.");
} }
/** /**
@ -3025,7 +3025,7 @@ import core.stdc.stdio, std.string : KeepTerminator;
assert (seven.importBindings !is null); assert (seven.importBindings !is null);
assert (p.errorCount == 0); assert (p.errorCount == 0);
stderr.writeln("Unittest for parseImportDeclaration() passed."); stderr.writeln("Unittest for parseImportDeclaration passed.");
} }
/** /**
@ -3216,7 +3216,7 @@ interface "Four"
assert (four is null); assert (four is null);
assert (p.errorCount > 0); assert (p.errorCount > 0);
stderr.writeln("Unittest for parseInterfaceDeclaration() passed."); stderr.writeln("Unittest for parseInterfaceDeclaration passed.");
} }
/** /**
@ -4134,7 +4134,7 @@ q{(int a, ...)
assert (!params3.parameters[0].vararg); assert (!params3.parameters[0].vararg);
assert (params3.parameters[0].type !is null); assert (params3.parameters[0].type !is null);
stderr.writeln("Unittest for parseParameters() passed."); stderr.writeln("Unittest for parseParameters passed.");
} }
/** /**
@ -6067,7 +6067,7 @@ q{doStuff(5)}c;
auto unary = p.parseUnaryExpression(); auto unary = p.parseUnaryExpression();
assert (unary !is null); assert (unary !is null);
assert (unary.functionCallExpression !is null); assert (unary.functionCallExpression !is null);
stderr.writeln("Unittest for parseUnaryExpression() passed."); stderr.writeln("Unittest for parseUnaryExpression passed.");
} }
/** /**