Merge remote-tracking branch 'upstream/master' into phobos
This commit is contained in:
commit
16bbab1320
2
dub.json
2
dub.json
|
@ -12,7 +12,7 @@
|
||||||
"StdLoggerDisableWarning"
|
"StdLoggerDisableWarning"
|
||||||
],
|
],
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"libdparse" : "~>0.7.2-alpha.1",
|
"libdparse" : "~>0.7.2-alpha.2",
|
||||||
"dsymbol" : "~>0.2.9",
|
"dsymbol" : "~>0.2.9",
|
||||||
"inifiled" : ">=1.0.2",
|
"inifiled" : ">=1.0.2",
|
||||||
"emsi_containers" : "~>0.5.3",
|
"emsi_containers" : "~>0.5.3",
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 222548fe610ee33dc60a87c9c1322aedd487dcdb
|
Subproject commit 0bd3235f852454a1c1c6dfe55e26786ad13bc4b5
|
|
@ -42,8 +42,14 @@ class HasPublicExampleCheck : BaseAnalyzer
|
||||||
}
|
}
|
||||||
|
|
||||||
// check all public top-level declarations
|
// check all public top-level declarations
|
||||||
foreach (decl; mod.declarations.filter!(decl => isPublic(decl.attributes)))
|
foreach (decl; mod.declarations)
|
||||||
{
|
{
|
||||||
|
if (!isPublic(decl.attributes))
|
||||||
|
{
|
||||||
|
checkLastDecl();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const bool hasDdocHeader = hasDdocHeader(decl);
|
const bool hasDdocHeader = hasDdocHeader(decl);
|
||||||
|
|
||||||
// check the documentation of a unittest declaration
|
// check the documentation of a unittest declaration
|
||||||
|
@ -281,14 +287,18 @@ unittest
|
||||||
unittest {}
|
unittest {}
|
||||||
}, sac);
|
}, sac);
|
||||||
|
|
||||||
/// check intermediate private declarations and ditto-ed declarations
|
// check intermediate private declarations
|
||||||
assertAnalyzerWarnings(q{
|
// removed for issue #500
|
||||||
|
/*assertAnalyzerWarnings(q{
|
||||||
/// C
|
/// C
|
||||||
class C{}
|
class C{}
|
||||||
private void foo(){}
|
private void foo(){}
|
||||||
///
|
///
|
||||||
unittest {}
|
unittest {}
|
||||||
|
}, sac);*/
|
||||||
|
|
||||||
|
// check intermediate ditto-ed declarations
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
/// I
|
/// I
|
||||||
interface I{}
|
interface I{}
|
||||||
/// ditto
|
/// ditto
|
||||||
|
@ -297,6 +307,15 @@ unittest
|
||||||
unittest {}
|
unittest {}
|
||||||
}, sac);
|
}, sac);
|
||||||
|
|
||||||
|
// test reset on private symbols (#500)
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
|
///
|
||||||
|
void dirName(C)(C[] path) {} // [warn]: Public declaration 'dirName' has no documented example.
|
||||||
|
private void _dirName(R)(R path) {}
|
||||||
|
///
|
||||||
|
unittest {}
|
||||||
|
}, sac);
|
||||||
|
|
||||||
stderr.writeln("Unittest for HasPublicExampleCheck passed.");
|
stderr.writeln("Unittest for HasPublicExampleCheck passed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@ class UnmodifiedFinder : BaseAnalyzer
|
||||||
{
|
{
|
||||||
if (initializedFromCast(d.initializer))
|
if (initializedFromCast(d.initializer))
|
||||||
continue;
|
continue;
|
||||||
|
if (initializedFromNew(d.initializer))
|
||||||
|
continue;
|
||||||
tree[$ - 1].insert(new VariableInfo(d.name.text, d.name.line,
|
tree[$ - 1].insert(new VariableInfo(d.name.text, d.name.line,
|
||||||
d.name.column, isValueTypeSimple(dec.type)));
|
d.name.column, isValueTypeSimple(dec.type)));
|
||||||
}
|
}
|
||||||
|
@ -77,6 +79,8 @@ class UnmodifiedFinder : BaseAnalyzer
|
||||||
{
|
{
|
||||||
if (initializedFromCast(part.initializer))
|
if (initializedFromCast(part.initializer))
|
||||||
continue;
|
continue;
|
||||||
|
if (initializedFromNew(part.initializer))
|
||||||
|
continue;
|
||||||
tree[$ - 1].insert(new VariableInfo(part.identifier.text,
|
tree[$ - 1].insert(new VariableInfo(part.identifier.text,
|
||||||
part.identifier.line, part.identifier.column));
|
part.identifier.line, part.identifier.column));
|
||||||
}
|
}
|
||||||
|
@ -211,6 +215,19 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool initializedFromNew(const Initializer initializer)
|
||||||
|
{
|
||||||
|
if (initializer && initializer.nonVoidInitializer &&
|
||||||
|
initializer.nonVoidInitializer.assignExpression &&
|
||||||
|
cast(UnaryExpression) initializer.nonVoidInitializer.assignExpression)
|
||||||
|
{
|
||||||
|
const UnaryExpression ue =
|
||||||
|
cast(UnaryExpression) initializer.nonVoidInitializer.assignExpression;
|
||||||
|
return ue.newExpression !is null;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool initializedFromCast(const Initializer initializer)
|
bool initializedFromCast(const Initializer initializer)
|
||||||
{
|
{
|
||||||
import std.typecons : scoped;
|
import std.typecons : scoped;
|
||||||
|
@ -325,6 +342,12 @@ bool isValueTypeSimple(const Type type) pure nothrow @nogc
|
||||||
StaticAnalysisConfig sac = disabledConfig();
|
StaticAnalysisConfig sac = disabledConfig();
|
||||||
sac.could_be_immutable_check = Check.enabled;
|
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);
|
||||||
|
|
||||||
// pass
|
// pass
|
||||||
|
|
||||||
assertAnalyzerWarnings(q{
|
assertAnalyzerWarnings(q{
|
||||||
|
@ -339,4 +362,12 @@ bool isValueTypeSimple(const Type type) pure nothrow @nogc
|
||||||
void foo(){enum i = 1;}
|
void foo(){enum i = 1;}
|
||||||
}, sac);
|
}, sac);
|
||||||
|
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
|
void foo(){E e = new E;}
|
||||||
|
}, sac);
|
||||||
|
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
|
void foo(){auto e = new E;}
|
||||||
|
}, sac);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue