mirror of
https://github.com/dlang-community/D-Scanner.git
synced 2025-04-29 06:40:01 +03:00
allow @nolint(dscanner)
to disable all scanners
among groups like dscanner.abc would disable all of dscanner.abc.*
This commit is contained in:
parent
1d19731f82
commit
45db7a9bf9
1 changed files with 18 additions and 3 deletions
|
@ -7,14 +7,24 @@ import dparse.lexer;
|
||||||
|
|
||||||
import std.algorithm : canFind;
|
import std.algorithm : canFind;
|
||||||
import std.regex : matchAll, regex;
|
import std.regex : matchAll, regex;
|
||||||
import std.string : strip;
|
import std.string : lastIndexOf, strip;
|
||||||
import std.typecons;
|
import std.typecons;
|
||||||
|
|
||||||
struct NoLint
|
struct NoLint
|
||||||
{
|
{
|
||||||
bool containsCheck(in string check) const
|
bool containsCheck(scope const(char)[] check) const
|
||||||
{
|
{
|
||||||
return disabledChecks.get(check, 0) > 0;
|
while (true)
|
||||||
|
{
|
||||||
|
if (disabledChecks.get((() @trusted => cast(string) check)(), 0) > 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
auto dot = check.lastIndexOf('.');
|
||||||
|
if (dot == -1)
|
||||||
|
break;
|
||||||
|
check = check[0 .. dot];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// automatic pop when returned value goes out of scope
|
// automatic pop when returned value goes out of scope
|
||||||
|
@ -236,6 +246,7 @@ unittest
|
||||||
const s3 = " nolint ( abc , efg ) ";
|
const s3 = " nolint ( abc , efg ) ";
|
||||||
const s4 = "nolint(dscanner.style.abc_efg-ijh)";
|
const s4 = "nolint(dscanner.style.abc_efg-ijh)";
|
||||||
const s5 = "OtherUda(abc)";
|
const s5 = "OtherUda(abc)";
|
||||||
|
const s6 = "nolint(dscanner)";
|
||||||
|
|
||||||
assert(NoLintFactory.fromString(s1).get.containsCheck("abc"));
|
assert(NoLintFactory.fromString(s1).get.containsCheck("abc"));
|
||||||
|
|
||||||
|
@ -250,6 +261,10 @@ unittest
|
||||||
|
|
||||||
assert(NoLintFactory.fromString(s5).isNull);
|
assert(NoLintFactory.fromString(s5).isNull);
|
||||||
|
|
||||||
|
assert(NoLintFactory.fromString(s6).get.containsCheck("dscanner"));
|
||||||
|
assert(!NoLintFactory.fromString(s6).get.containsCheck("dscanner2"));
|
||||||
|
assert(NoLintFactory.fromString(s6).get.containsCheck("dscanner.foo"));
|
||||||
|
|
||||||
import std.stdio : stderr, writeln;
|
import std.stdio : stderr, writeln;
|
||||||
|
|
||||||
(() @trusted => stderr.writeln("Unittest for NoLint passed."))();
|
(() @trusted => stderr.writeln("Unittest for NoLint passed."))();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue