Merge pull request #608 from BBasile/spaces2tabs

fix all cases of mixed tabs and spaces
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2018-04-07 22:34:16 +02:00 committed by GitHub
commit cc39546be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 463 additions and 463 deletions

View File

@ -57,7 +57,7 @@ class AllManCheck : BaseAnalyzer
addErrorMessage(tokens[i].line, tokens[i].column, KEY, MESSAGE);
}
}
}
}
enum string KEY = "dscanner.style.allman";
enum string MESSAGE = "Braces should be on their own line";

View File

@ -30,7 +30,7 @@ private:
bool[] _returns;
size_t _mixinDepth;
string[] _literalWithReturn;
string[] _literalWithReturn;
public:
@ -98,59 +98,59 @@ public:
import std.algorithm.searching : canFind;
if (_returns.length && _mixinDepth)
{
if (findReturnInLiteral(exp.primary.text))
{
if (findReturnInLiteral(exp.primary.text))
_returns[$-1] = true;
else if (exp.identifierOrTemplateInstance &&
_literalWithReturn.canFind(exp.identifierOrTemplateInstance.identifier.text))
_returns[$-1] = true;
}
else if (exp.identifierOrTemplateInstance &&
_literalWithReturn.canFind(exp.identifierOrTemplateInstance.identifier.text))
_returns[$-1] = true;
}
}
bool findReturnInLiteral(const(string) value)
{
import std.algorithm.searching : find;
import std.range : empty;
bool findReturnInLiteral(const(string) value)
{
import std.algorithm.searching : find;
import std.range : empty;
return value == "return" || !value.find("return ").empty;
}
return value == "return" || !value.find("return ").empty;
}
bool stringliteralHasReturn(const(NonVoidInitializer) nvi)
{
bool result;
if (!nvi.assignExpression || (cast(UnaryExpression) nvi.assignExpression) is null)
return result;
bool stringliteralHasReturn(const(NonVoidInitializer) nvi)
{
bool result;
if (!nvi.assignExpression || (cast(UnaryExpression) nvi.assignExpression) is null)
return result;
const(UnaryExpression) u = cast(UnaryExpression) nvi.assignExpression;
if (u.primaryExpression &&
u.primaryExpression.primary.type.isStringLiteral &&
findReturnInLiteral(u.primaryExpression.primary.text))
result = true;
const(UnaryExpression) u = cast(UnaryExpression) nvi.assignExpression;
if (u.primaryExpression &&
u.primaryExpression.primary.type.isStringLiteral &&
findReturnInLiteral(u.primaryExpression.primary.text))
result = true;
return result;
}
return result;
}
override void visit(const(AutoDeclaration) decl)
{
decl.accept(this);
override void visit(const(AutoDeclaration) decl)
{
decl.accept(this);
foreach(const(AutoDeclarationPart) p; decl.parts)
if (p.initializer &&
p.initializer.nonVoidInitializer &&
stringliteralHasReturn(p.initializer.nonVoidInitializer))
_literalWithReturn ~= p.identifier.text.idup;
}
foreach(const(AutoDeclarationPart) p; decl.parts)
if (p.initializer &&
p.initializer.nonVoidInitializer &&
stringliteralHasReturn(p.initializer.nonVoidInitializer))
_literalWithReturn ~= p.identifier.text.idup;
}
override void visit(const(VariableDeclaration) decl)
{
decl.accept(this);
override void visit(const(VariableDeclaration) decl)
{
decl.accept(this);
foreach(const(Declarator) d; decl.declarators)
if (d.initializer &&
d.initializer.nonVoidInitializer &&
stringliteralHasReturn(d.initializer.nonVoidInitializer))
_literalWithReturn ~= d.name.text.idup;
}
foreach(const(Declarator) d; decl.declarators)
if (d.initializer &&
d.initializer.nonVoidInitializer &&
stringliteralHasReturn(d.initializer.nonVoidInitializer))
_literalWithReturn ~= d.name.text.idup;
}
}
unittest
@ -202,24 +202,24 @@ unittest
AutoFunctionChecker.MESSAGE,
), sac);
assertAnalyzerWarnings(q{
auto doStuff(){} // [warn]: %s
extern(C) auto doStuff();
}c.format(
AutoFunctionChecker.MESSAGE,
), sac);
assertAnalyzerWarnings(q{
auto doStuff(){} // [warn]: %s
extern(C) auto doStuff();
}c.format(
AutoFunctionChecker.MESSAGE,
), sac);
assertAnalyzerWarnings(q{
auto doStuff(){} // [warn]: %s
@disable auto doStuff();
}c.format(
AutoFunctionChecker.MESSAGE,
), sac);
assertAnalyzerWarnings(q{
auto doStuff(){} // [warn]: %s
@disable auto doStuff();
}c.format(
AutoFunctionChecker.MESSAGE,
), sac);
assertAnalyzerWarnings(q{
enum _genSave = "return true;";
auto doStuff(){ mixin(_genSave);}
}, sac);
assertAnalyzerWarnings(q{
enum _genSave = "return true;";
auto doStuff(){ mixin(_genSave);}
}, sac);
stderr.writeln("Unittest for AutoFunctionChecker passed.");
}

View File

@ -31,7 +31,7 @@ public:
{
this.sc = sc;
this.fileName = fileName;
this.skipTests = skipTests;
this.skipTests = skipTests;
_messages = new MessageSet;
}
@ -40,24 +40,24 @@ public:
return _messages[].array;
}
alias visit = ASTVisitor.visit;
alias visit = ASTVisitor.visit;
/**
* Visits a unittest.
*
* When overriden, the protected bool "skipTests" should be handled
* so that the content of the test is not analyzed.
*/
override void visit(const Unittest unittest_)
{
if (!skipTests)
unittest_.accept(this);
}
/**
* Visits a unittest.
*
* When overriden, the protected bool "skipTests" should be handled
* so that the content of the test is not analyzed.
*/
override void visit(const Unittest unittest_)
{
if (!skipTests)
unittest_.accept(this);
}
protected:
bool inAggregate;
bool skipTests;
bool skipTests;
template visitTemplate(T)
{

View File

@ -20,387 +20,387 @@ final class FinalAttributeChecker : BaseAnalyzer
private:
enum string KEY = "dscanner.useless.final";
enum string MSGB = "Useless final attribute, %s";
enum string KEY = "dscanner.useless.final";
enum string MSGB = "Useless final attribute, %s";
static struct MESSAGE
{
static immutable struct_i = "structs cannot be subclassed";
static immutable union_i = "unions cannot be subclassed";
static immutable class_t = "templated functions declared within a class are never virtual";
static immutable class_p = "private functions declared within a class are never virtual";
static immutable class_f = "functions declared within a final class are never virtual";
static immutable class_s = "static functions are never virtual";
static immutable interface_t = "templated functions declared within an interface are never virtual";
static immutable struct_f = "functions declared within a struct are never virtual";
static immutable union_f = "functions declared within an union are never virtual";
static immutable func_n = "nested functions are never virtual";
static immutable func_g = "global functions are never virtual";
}
static struct MESSAGE
{
static immutable struct_i = "structs cannot be subclassed";
static immutable union_i = "unions cannot be subclassed";
static immutable class_t = "templated functions declared within a class are never virtual";
static immutable class_p = "private functions declared within a class are never virtual";
static immutable class_f = "functions declared within a final class are never virtual";
static immutable class_s = "static functions are never virtual";
static immutable interface_t = "templated functions declared within an interface are never virtual";
static immutable struct_f = "functions declared within a struct are never virtual";
static immutable union_f = "functions declared within an union are never virtual";
static immutable func_n = "nested functions are never virtual";
static immutable func_g = "global functions are never virtual";
}
enum Parent
{
module_,
struct_,
union_,
class_,
function_,
interface_
}
enum Parent
{
module_,
struct_,
union_,
class_,
function_,
interface_
}
bool[] _private;
bool _finalAggregate;
bool _alwaysStatic;
bool _blockStatic;
Parent _parent = Parent.module_;
bool[] _private;
bool _finalAggregate;
bool _alwaysStatic;
bool _blockStatic;
Parent _parent = Parent.module_;
void addError(T)(T t, string msg)
{
import std.format : format;
const size_t lne = t.name.line;
const size_t col = t.name.column;
addErrorMessage(lne, col, KEY, MSGB.format(msg));
}
void addError(T)(T t, string msg)
{
import std.format : format;
const size_t lne = t.name.line;
const size_t col = t.name.column;
addErrorMessage(lne, col, KEY, MSGB.format(msg));
}
public:
alias visit = BaseAnalyzer.visit;
alias visit = BaseAnalyzer.visit;
///
this(string fileName, bool skipTests = false)
{
super(fileName, null, skipTests);
_private.length = 1;
}
///
this(string fileName, bool skipTests = false)
{
super(fileName, null, skipTests);
_private.length = 1;
}
override void visit(const(StructDeclaration) sd)
{
const Parent saved = _parent;
_parent = Parent.struct_;
_private.length += 1;
_alwaysStatic = false;
sd.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(StructDeclaration) sd)
{
const Parent saved = _parent;
_parent = Parent.struct_;
_private.length += 1;
_alwaysStatic = false;
sd.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(InterfaceDeclaration) id)
{
const Parent saved = _parent;
_parent = Parent.interface_;
_private.length += 1;
_alwaysStatic = false;
id.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(InterfaceDeclaration) id)
{
const Parent saved = _parent;
_parent = Parent.interface_;
_private.length += 1;
_alwaysStatic = false;
id.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(UnionDeclaration) ud)
{
const Parent saved = _parent;
_parent = Parent.union_;
_private.length += 1;
_alwaysStatic = false;
ud.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(UnionDeclaration) ud)
{
const Parent saved = _parent;
_parent = Parent.union_;
_private.length += 1;
_alwaysStatic = false;
ud.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(ClassDeclaration) cd)
{
const Parent saved = _parent;
_parent = Parent.class_;
_private.length += 1;
_alwaysStatic = false;
cd.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(ClassDeclaration) cd)
{
const Parent saved = _parent;
_parent = Parent.class_;
_private.length += 1;
_alwaysStatic = false;
cd.accept(this);
_private.length -= 1;
_parent = saved;
}
override void visit(const(MixinTemplateDeclaration) mtd)
{
// can't really know where it'll be mixed (class |final class | struct ?)
}
override void visit(const(MixinTemplateDeclaration) mtd)
{
// can't really know where it'll be mixed (class |final class | struct ?)
}
override void visit(const(TemplateDeclaration) mtd)
{
// regular template are also mixable
}
override void visit(const(TemplateDeclaration) mtd)
{
// regular template are also mixable
}
override void visit(const(AttributeDeclaration) decl)
{
if (_parent == Parent.class_ && decl.attribute &&
decl.attribute.attribute == tok!"static")
_alwaysStatic = true;
}
override void visit(const(AttributeDeclaration) decl)
{
if (_parent == Parent.class_ && decl.attribute &&
decl.attribute.attribute == tok!"static")
_alwaysStatic = true;
}
override void visit(const(Declaration) d)
{
import std.algorithm.iteration : filter;
import std.algorithm.searching : canFind;
override void visit(const(Declaration) d)
{
import std.algorithm.iteration : filter;
import std.algorithm.searching : canFind;
const Parent savedParent = _parent;
const Parent savedParent = _parent;
bool undoBlockStatic;
if (_parent == Parent.class_ && d.attributes &&
d.attributes.canFind!(a => a.attribute == tok!"static"))
{
_blockStatic = true;
undoBlockStatic = true;
}
bool undoBlockStatic;
if (_parent == Parent.class_ && d.attributes &&
d.attributes.canFind!(a => a.attribute == tok!"static"))
{
_blockStatic = true;
undoBlockStatic = true;
}
scope(exit)
{
d.accept(this);
_parent = savedParent;
if (undoBlockStatic)
_blockStatic = false;
}
scope(exit)
{
d.accept(this);
_parent = savedParent;
if (undoBlockStatic)
_blockStatic = false;
}
if (!d.attributeDeclaration &&
!d.classDeclaration &&
!d.structDeclaration &&
!d.unionDeclaration &&
!d.interfaceDeclaration &&
!d.functionDeclaration)
return;
if (!d.attributeDeclaration &&
!d.classDeclaration &&
!d.structDeclaration &&
!d.unionDeclaration &&
!d.interfaceDeclaration &&
!d.functionDeclaration)
return;
if (d.attributeDeclaration && d.attributeDeclaration.attribute)
{
const tp = d.attributeDeclaration.attribute.attribute.type;
_private[$-1] = isProtection(tp) & (tp == tok!"private");
}
if (d.attributeDeclaration && d.attributeDeclaration.attribute)
{
const tp = d.attributeDeclaration.attribute.attribute.type;
_private[$-1] = isProtection(tp) & (tp == tok!"private");
}
const bool isFinal = d.attributes
.canFind!(a => a.attribute.type == tok!"final");
const bool isFinal = d.attributes
.canFind!(a => a.attribute.type == tok!"final");
const bool isStaticOnce = d.attributes
.canFind!(a => a.attribute.type == tok!"static");
const bool isStaticOnce = d.attributes
.canFind!(a => a.attribute.type == tok!"static");
// determine if private
const bool changeProtectionOnce = d.attributes
.canFind!(a => a.attribute.type.isProtection);
// determine if private
const bool changeProtectionOnce = d.attributes
.canFind!(a => a.attribute.type.isProtection);
const bool isPrivateOnce = d.attributes
.canFind!(a => a.attribute.type == tok!"private");
const bool isPrivateOnce = d.attributes
.canFind!(a => a.attribute.type == tok!"private");
bool isPrivate;
bool isPrivate;
if (isPrivateOnce)
isPrivate = true;
else if (_private[$-1] && !changeProtectionOnce)
isPrivate = true;
if (isPrivateOnce)
isPrivate = true;
else if (_private[$-1] && !changeProtectionOnce)
isPrivate = true;
// check final aggregate type
if (d.classDeclaration || d.structDeclaration || d.unionDeclaration)
{
_finalAggregate = isFinal;
if (_finalAggregate && savedParent == Parent.module_)
{
if (d.structDeclaration)
addError(d.structDeclaration, MESSAGE.struct_i);
else if (d.unionDeclaration)
addError(d.unionDeclaration, MESSAGE.union_i);
}
}
// check final aggregate type
if (d.classDeclaration || d.structDeclaration || d.unionDeclaration)
{
_finalAggregate = isFinal;
if (_finalAggregate && savedParent == Parent.module_)
{
if (d.structDeclaration)
addError(d.structDeclaration, MESSAGE.struct_i);
else if (d.unionDeclaration)
addError(d.unionDeclaration, MESSAGE.union_i);
}
}
if (!d.functionDeclaration)
return;
if (!d.functionDeclaration)
return;
// check final functions
_parent = Parent.function_;
const(FunctionDeclaration) fd = d.functionDeclaration;
// check final functions
_parent = Parent.function_;
const(FunctionDeclaration) fd = d.functionDeclaration;
if (isFinal) final switch(savedParent)
{
case Parent.class_:
if (fd.templateParameters)
addError(fd, MESSAGE.class_t);
if (isPrivate)
addError(fd, MESSAGE.class_p);
else if (isStaticOnce || _alwaysStatic || _blockStatic)
addError(fd, MESSAGE.class_s);
else if (_finalAggregate)
addError(fd, MESSAGE.class_f);
break;
case Parent.interface_:
if (fd.templateParameters)
addError(fd, MESSAGE.interface_t);
break;
case Parent.struct_:
addError(fd, MESSAGE.struct_f);
break;
case Parent.union_:
addError(fd, MESSAGE.union_f);
break;
case Parent.function_:
addError(fd, MESSAGE.func_n);
break;
case Parent.module_:
addError(fd, MESSAGE.func_g);
break;
}
if (isFinal) final switch(savedParent)
{
case Parent.class_:
if (fd.templateParameters)
addError(fd, MESSAGE.class_t);
if (isPrivate)
addError(fd, MESSAGE.class_p);
else if (isStaticOnce || _alwaysStatic || _blockStatic)
addError(fd, MESSAGE.class_s);
else if (_finalAggregate)
addError(fd, MESSAGE.class_f);
break;
case Parent.interface_:
if (fd.templateParameters)
addError(fd, MESSAGE.interface_t);
break;
case Parent.struct_:
addError(fd, MESSAGE.struct_f);
break;
case Parent.union_:
addError(fd, MESSAGE.union_f);
break;
case Parent.function_:
addError(fd, MESSAGE.func_n);
break;
case Parent.module_:
addError(fd, MESSAGE.func_g);
break;
}
}
}
@system unittest
{
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
import dscanner.analysis.helpers : assertAnalyzerWarnings;
import std.stdio : stderr;
import std.format : format;
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
import dscanner.analysis.helpers : assertAnalyzerWarnings;
import std.stdio : stderr;
import std.format : format;
StaticAnalysisConfig sac = disabledConfig();
sac.final_attribute_check = Check.enabled;
StaticAnalysisConfig sac = disabledConfig();
sac.final_attribute_check = Check.enabled;
// pass
// pass
assertAnalyzerWarnings(q{
void foo(){}
}, sac);
assertAnalyzerWarnings(q{
void foo(){}
}, sac);
assertAnalyzerWarnings(q{
void foo(){void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
void foo(){void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
struct S{}
}, sac);
assertAnalyzerWarnings(q{
struct S{}
}, sac);
assertAnalyzerWarnings(q{
union U{}
}, sac);
assertAnalyzerWarnings(q{
union U{}
}, sac);
assertAnalyzerWarnings(q{
class Foo{public final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
class Foo{public final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
final class Foo{static struct Bar{}}
}, sac);
assertAnalyzerWarnings(q{
final class Foo{static struct Bar{}}
}, sac);
assertAnalyzerWarnings(q{
class Foo{private: public final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
class Foo{private: public final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
class Foo{private: public: final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
class Foo{private: public: final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
class Foo{private: public: final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
class Foo{private: public: final void foo(){}}
}, sac);
assertAnalyzerWarnings(q{
class Impl
{
private:
static if (true)
{
protected final void _wrap_getSource() {}
}
}
}, sac);
assertAnalyzerWarnings(q{
class Impl
{
private:
static if (true)
{
protected final void _wrap_getSource() {}
}
}
}, sac);
assertAnalyzerWarnings(q{
mixin template Impl()
{
protected final void mixin_template_can() {}
}
}, sac);
assertAnalyzerWarnings(q{
mixin template Impl()
{
protected final void mixin_template_can() {}
}
}, sac);
// fail
// fail
assertAnalyzerWarnings(q{
final void foo(){} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.func_g)
), sac);
assertAnalyzerWarnings(q{
final void foo(){} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.func_g)
), sac);
assertAnalyzerWarnings(q{
void foo(){final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.func_n)
), sac);
assertAnalyzerWarnings(q{
void foo(){final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.func_n)
), sac);
assertAnalyzerWarnings(q{
void foo()
{
static if (true)
final class A{ private: final protected void foo(){}} // [warn]: %s
}
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_f)
), sac);
assertAnalyzerWarnings(q{
void foo()
{
static if (true)
final class A{ private: final protected void foo(){}} // [warn]: %s
}
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_f)
), sac);
assertAnalyzerWarnings(q{
final struct Foo{} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.struct_i)
), sac);
assertAnalyzerWarnings(q{
final struct Foo{} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.struct_i)
), sac);
assertAnalyzerWarnings(q{
final union Foo{} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.union_i)
), sac);
assertAnalyzerWarnings(q{
final union Foo{} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.union_i)
), sac);
assertAnalyzerWarnings(q{
class Foo{private final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_p)
), sac);
assertAnalyzerWarnings(q{
class Foo{private final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_p)
), sac);
assertAnalyzerWarnings(q{
class Foo{private: final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_p)
), sac);
assertAnalyzerWarnings(q{
class Foo{private: final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_p)
), sac);
assertAnalyzerWarnings(q{
interface Foo{final void foo(T)(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.interface_t)
), sac);
assertAnalyzerWarnings(q{
interface Foo{final void foo(T)(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.interface_t)
), sac);
assertAnalyzerWarnings(q{
final class Foo{final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_f)
), sac);
assertAnalyzerWarnings(q{
final class Foo{final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_f)
), sac);
assertAnalyzerWarnings(q{
private: final class Foo {public: private final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_p)
), sac);
assertAnalyzerWarnings(q{
private: final class Foo {public: private final void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_p)
), sac);
assertAnalyzerWarnings(q{
class Foo {final static void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_s)
), sac);
assertAnalyzerWarnings(q{
class Foo {final static void foo(){}} // [warn]: %s
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_s)
), sac);
assertAnalyzerWarnings(q{
class Foo
{
void foo(){}
static: final void foo(){} // [warn]: %s
}
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_s)
), sac);
assertAnalyzerWarnings(q{
class Foo
{
void foo(){}
static: final void foo(){} // [warn]: %s
}
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_s)
), sac);
assertAnalyzerWarnings(q{
class Foo
{
void foo(){}
static{ final void foo(){}} // [warn]: %s
void foo(){}
}
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_s)
), sac);
assertAnalyzerWarnings(q{
class Foo
{
void foo(){}
static{ final void foo(){}} // [warn]: %s
void foo(){}
}
}c.format(
FinalAttributeChecker.MSGB.format(FinalAttributeChecker.MESSAGE.class_s)
), sac);
stderr.writeln("Unittest for FinalAttributeChecker passed.");
stderr.writeln("Unittest for FinalAttributeChecker passed.");
}

View File

@ -174,13 +174,13 @@ if (R == int) // [warn]: %s
assertAnalyzerWarnings(q{
Num abs(Num)(Num x) @safe pure nothrow
if (is(typeof(Num.init >= 0)) && is(typeof(-Num.init)) &&
!(is(Num* : const(ifloat*)) || is(Num* : const(idouble*))
|| is(Num* : const(ireal*))))
!(is(Num* : const(ifloat*)) || is(Num* : const(idouble*))
|| is(Num* : const(ireal*))))
{
static if (isFloatingPoint!(Num))
return fabs(x);
else
return x >= 0 ? x : -x;
static if (isFloatingPoint!(Num))
return fabs(x);
else
return x >= 0 ? x : -x;
}
}, sac);

View File

@ -347,8 +347,8 @@ unittest
import foo;
import foo.bar;
import fooa;
import std.range : Take;
import std.range.primitives : isInputRange, walkLength;
import std.range : Take;
import std.range.primitives : isInputRange, walkLength;
}, sac);
// condition declaration

View File

@ -228,7 +228,7 @@ unittest
unittest
{
version(LittleEndian) { enum string NAME = "UTF-16LE"; }
version(LittleEndian) { enum string NAME = "UTF-16LE"; }
else version(BigEndian) { enum string NAME = "UTF-16BE"; }
}
@ -267,8 +267,8 @@ unittest
unittest
{
int aa;
struct a { int a; }
int aa;
struct a { int a; }
}
}c, sac);

View File

@ -11,37 +11,37 @@ import dscanner.analysis.base;
class LambdaReturnCheck : BaseAnalyzer
{
alias visit = BaseAnalyzer.visit;
alias visit = BaseAnalyzer.visit;
this(string fileName, bool skipTests = false)
{
super(fileName, null, skipTests);
}
override void visit(const FunctionLiteralExpression fLit)
{
if (fLit.assignExpression is null)
return;
const UnaryExpression unary = cast(const UnaryExpression) fLit.assignExpression;
if (unary is null)
return;
if (unary.primaryExpression is null)
return;
if (unary.primaryExpression.functionLiteralExpression is null)
return;
if (unary.primaryExpression.functionLiteralExpression.parameters !is null)
return;
if (unary.primaryExpression.functionLiteralExpression.identifier != tok!"")
return;
if (unary.primaryExpression.functionLiteralExpression.functionBody is null)
return;
if (unary.primaryExpression.functionLiteralExpression.functionBody.blockStatement is null)
return;
addErrorMessage(fLit.line, fLit.column, KEY, "This lambda returns a lambda. Add parenthesis to clarify.");
}
override void visit(const FunctionLiteralExpression fLit)
{
if (fLit.assignExpression is null)
return;
const UnaryExpression unary = cast(const UnaryExpression) fLit.assignExpression;
if (unary is null)
return;
if (unary.primaryExpression is null)
return;
if (unary.primaryExpression.functionLiteralExpression is null)
return;
if (unary.primaryExpression.functionLiteralExpression.parameters !is null)
return;
if (unary.primaryExpression.functionLiteralExpression.identifier != tok!"")
return;
if (unary.primaryExpression.functionLiteralExpression.functionBody is null)
return;
if (unary.primaryExpression.functionLiteralExpression.functionBody.blockStatement is null)
return;
addErrorMessage(fLit.line, fLit.column, KEY, "This lambda returns a lambda. Add parenthesis to clarify.");
}
private:
enum KEY = "dscanner.confusing.lambda_returns_lambda";
enum KEY = "dscanner.confusing.lambda_returns_lambda";
}
version(Windows) {/*because of newline in code*/} else

View File

@ -122,12 +122,12 @@ unittest
class Bat
{
const: override string toString() { return "foo"; } // ok
const: override string toString() { return "foo"; } // ok
}
class Fox
{
const{ override string toString() { return "foo"; }} // ok
const{ override string toString() { return "foo"; }} // ok
}
// Will warn, because none are const

View File

@ -718,28 +718,28 @@ unittest
assertAnalyzerWarnings(q{
/++
Counts elements in the given
$(REF_ALTTEXT forward range, isForwardRange, std,range,primitives)
until the given predicate is true for one of the given $(D needles).
Counts elements in the given
$(REF_ALTTEXT forward range, isForwardRange, std,range,primitives)
until the given predicate is true for one of the given $(D needles).
Params:
Params:
val = A stupid parameter
Returns: Awesome values.
Returns: Awesome values.
+/
string bar(string val){}
}c, sac);
assertAnalyzerWarnings(q{
/++
Counts elements in the given
$(REF_ALTTEXT forward range, isForwardRange, std,range,primitives)
until the given predicate is true for one of the given $(D needles).
Counts elements in the given
$(REF_ALTTEXT forward range, isForwardRange, std,range,primitives)
until the given predicate is true for one of the given $(D needles).
Params:
Params:
val = A stupid parameter
Returns: Awesome values.
Returns: Awesome values.
+/
template bar(string val){}
}c, sac);
@ -835,10 +835,10 @@ unittest
Implements the homonym function (also known as `accumulate`)
Returns:
the accumulated `result`
the accumulated `result`
Params:
fun = one or more functions
fun = one or more functions
+/
template reduce(fun...)
if (fun.length >= 1)

View File

@ -332,40 +332,40 @@ bool isValueTypeSimple(const Type type) pure nothrow @nogc
@system unittest
{
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
import dscanner.analysis.helpers : assertAnalyzerWarnings;
import std.stdio : stderr;
import std.format : format;
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
import dscanner.analysis.helpers : assertAnalyzerWarnings;
import std.stdio : stderr;
import std.format : format;
StaticAnalysisConfig sac = disabledConfig();
sac.could_be_immutable_check = Check.enabled;
StaticAnalysisConfig sac = disabledConfig();
sac.could_be_immutable_check = Check.enabled;
// fails
assertAnalyzerWarnings(q{
void foo(){int i = 1;} // [warn]: Variable i is never modified and could have been declared const or immutable.
}, sac);
void foo(){int i = 1;} // [warn]: Variable i is never modified and could have been declared const or immutable.
}, sac);
// pass
assertAnalyzerWarnings(q{
void foo(){const(int) i;}
}, sac);
// pass
assertAnalyzerWarnings(q{
void foo(){immutable(int)* i;}
}, sac);
void foo(){const(int) i;}
}, sac);
assertAnalyzerWarnings(q{
void foo(){enum i = 1;}
}, sac);
void foo(){immutable(int)* i;}
}, sac);
assertAnalyzerWarnings(q{
void foo(){E e = new E;}
}, sac);
void foo(){enum i = 1;}
}, sac);
assertAnalyzerWarnings(q{
void foo(){auto e = new E;}
}, sac);
void foo(){E e = new E;}
}, sac);
assertAnalyzerWarnings(q{
void foo(){auto e = new E;}
}, sac);
}

View File

@ -186,7 +186,7 @@ if (is(M == class))
__traits(getMember, m, member) = a;
}
}
}
}
}
/// General usage
@safe unittest