Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping checks for dscanner.suspicious.unmodified with nolint #946

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/dscanner/analysis/unmodified.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module dscanner.analysis.unmodified;

import dscanner.analysis.base;
import dscanner.analysis.nolint;
import dscanner.utils : safeAccess;
import dsymbol.scope_ : Scope;
import std.container;
Expand Down Expand Up @@ -114,11 +115,15 @@ final class UnmodifiedFinder : BaseAnalyzer
if (canFindImmutableOrConst(dec))
{
isImmutable++;
dec.accept(this);
with (noLint.push(NoLintFactory.fromDeclaration(dec)))
dec.accept(this);
isImmutable--;
}
else
dec.accept(this);
{
with (noLint.push(NoLintFactory.fromDeclaration(dec)))
dec.accept(this);
}
}

override void visit(const IdentifierChain ic)
Expand Down Expand Up @@ -189,6 +194,8 @@ final class UnmodifiedFinder : BaseAnalyzer

private:

enum string KEY = "dscanner.suspicious.unmodified";

template PartsMightModify(T)
{
override void visit(const T t)
Expand Down Expand Up @@ -300,7 +307,7 @@ private:
{
immutable string errorMessage = "Variable " ~ vi.name
~ " 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];
}
Expand Down Expand Up @@ -379,5 +386,12 @@ bool isValueTypeSimple(const Type type) pure nothrow @nogc
foo(i2);
}
}, sac);

assertAnalyzerWarnings(q{
@("nolint(dscanner.suspicious.unmodified)")
void foo(){
int i = 1;
}
}, sac);
}

Loading