Allow skipping checks for dscanner.suspicious.unmodified with nolint
This commit is contained in:
parent
433d1eb73e
commit
156b3836ac
|
|
@ -5,6 +5,7 @@
|
||||||
module dscanner.analysis.unmodified;
|
module dscanner.analysis.unmodified;
|
||||||
|
|
||||||
import dscanner.analysis.base;
|
import dscanner.analysis.base;
|
||||||
|
import dscanner.analysis.nolint;
|
||||||
import dscanner.utils : safeAccess;
|
import dscanner.utils : safeAccess;
|
||||||
import dsymbol.scope_ : Scope;
|
import dsymbol.scope_ : Scope;
|
||||||
import std.container;
|
import std.container;
|
||||||
|
|
@ -114,11 +115,15 @@ final class UnmodifiedFinder : BaseAnalyzer
|
||||||
if (canFindImmutableOrConst(dec))
|
if (canFindImmutableOrConst(dec))
|
||||||
{
|
{
|
||||||
isImmutable++;
|
isImmutable++;
|
||||||
dec.accept(this);
|
with (noLint.push(NoLintFactory.fromDeclaration(dec)))
|
||||||
|
dec.accept(this);
|
||||||
isImmutable--;
|
isImmutable--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dec.accept(this);
|
{
|
||||||
|
with (noLint.push(NoLintFactory.fromDeclaration(dec)))
|
||||||
|
dec.accept(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const IdentifierChain ic)
|
override void visit(const IdentifierChain ic)
|
||||||
|
|
@ -189,6 +194,8 @@ final class UnmodifiedFinder : BaseAnalyzer
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
enum string KEY = "dscanner.suspicious.unmodified";
|
||||||
|
|
||||||
template PartsMightModify(T)
|
template PartsMightModify(T)
|
||||||
{
|
{
|
||||||
override void visit(const T t)
|
override void visit(const T t)
|
||||||
|
|
@ -300,7 +307,7 @@ private:
|
||||||
{
|
{
|
||||||
immutable string errorMessage = "Variable " ~ vi.name
|
immutable string errorMessage = "Variable " ~ vi.name
|
||||||
~ " is never modified and could have been declared const or immutable.";
|
~ " is never modified and could have been declared const or immutable.";
|
||||||
addErrorMessage(vi.token, "dscanner.suspicious.unmodified", errorMessage);
|
addErrorMessage(vi.token, KEY, errorMessage);
|
||||||
}
|
}
|
||||||
tree = tree[0 .. $ - 1];
|
tree = tree[0 .. $ - 1];
|
||||||
}
|
}
|
||||||
|
|
@ -379,5 +386,12 @@ bool isValueTypeSimple(const Type type) pure nothrow @nogc
|
||||||
foo(i2);
|
foo(i2);
|
||||||
}
|
}
|
||||||
}, sac);
|
}, sac);
|
||||||
|
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
|
@("nolint(dscanner.suspicious.unmodified)")
|
||||||
|
void foo(){
|
||||||
|
int i = 1;
|
||||||
|
}
|
||||||
|
}, sac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue