Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,29 @@ For more readable output, pipe the command through [xmllint](http://xmlsoft.org/
using its formatting switch.

$ dscanner --ast helloworld.d | xmllint --format -

Selecting modules for a specific check
--------------------------------------

It is possible to create a new section `analysis.config.ModuleFilters` in the `.dscanner.ini`.
In this optional section a comma-separated list of inclusion and exclusion selectors can
be specified for every check on which selective filtering should be applied.
These given selectors match on the module name and partial matches (`std.` or `.foo.`) are possible.
Moreover, every selectors must begin with either `+` (inclusion) or `-` (exclusion).
Exclusion selectors take precedence over all inclusion operators.
Of course, for every check a different selector set can given:

```ini
[analysis.config.ModuleFilters]
final_attribute_check = "+std.foo,+std.bar"
useless_initializer = "-std."
```

A few examples:

- `+std.`: Includes all modules matching `std.`
- `+std.bitmanip,+std.json`: Applies the check only for these two modules
- `-std.bitmanip,-std.json`: Applies the check for all modules, but these two
- `+.bar`: Includes all modules matching `.bar` (e.g. `foo.bar`, `a.b.c.barros`)
- `-etc.`: Excludes all modules from `.etc`
- `+std,-std.internal`: Includes entire `std`, except for the internal modules
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"libdparse": "~>0.7.1-beta.4",
"dsymbol": "~>0.2.0",
"inifiled": ">=0.0.6",
"inifiled": ">=1.0.2",
"emsi_containers": "~>0.5.3",
"libddoc": "~>0.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion inifiled
17 changes: 11 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ DMD := $(DC)
GDC := gdc
LDC := ldc2
OBJ_DIR := obj
SRC := \
LIB_SRC := \
$(shell find containers/src -name "*.d")\
$(shell find dsymbol/src -name "*.d")\
$(shell find inifiled/source/ -name "*.d")\
$(shell find libdparse/src/std/experimental/ -name "*.d")\
$(shell find libdparse/src/dparse/ -name "*.d")\
$(shell find libddoc/src -name "*.d")\
$(shell find src/ -name "*.d")
$(shell find libddoc/src -name "*.d")
PROJECT_SRC := $(shell find src/ -name "*.d")
SRC := $(LIB_SRC) $(PROJECT_SRC)
INCLUDE_PATHS = \
-Iinifiled/source -Isrc\
-Ilibdparse/src\
Expand All @@ -21,7 +22,7 @@ INCLUDE_PATHS = \
VERSIONS =
DEBUG_VERSIONS = -version=dparse_verbose
DMD_FLAGS = -w -inline -release -O -J. -od${OBJ_DIR} -version=StdLoggerDisableWarning
DMD_TEST_FLAGS = -w -g -unittest -J.
DMD_TEST_FLAGS = -w -g -J. -version=StdLoggerDisableWarning

all: dmdbuild
ldc: ldcbuild
Expand All @@ -46,8 +47,12 @@ ldcbuild: githash
mkdir -p bin
${LDC} -O5 -release -oq -of=bin/dscanner ${VERSIONS} ${INCLUDE_PATHS} ${SRC} -J.

test: githash
${DC} -w -g -J. -unittest ${INCLUDE_PATHS} ${SRC} -ofbin/dscanner-unittest -version=StdLoggerDisableWarning
# compile the dependencies separately, s.t. their unittests don't get executed
bin/dscanner-unittest-lib.a: ${LIB_SRC}
${DC} ${DMD_TEST_FLAGS} -c ${INCLUDE_PATHS} ${LIB_SRC} -of$@

test: bin/dscanner-unittest-lib.a githash
${DC} ${DMD_TEST_FLAGS} -unittest ${INCLUDE_PATHS} bin/dscanner-unittest-lib.a ${PROJECT_SRC} -ofbin/dscanner-unittest
./bin/dscanner-unittest
rm -f bin/dscanner-unittest

Expand Down
21 changes: 21 additions & 0 deletions src/analysis/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,25 @@ struct StaticAnalysisConfig

@INI("Check public declarations without a documented unittest")
string has_public_example = Check.disabled;

@INI("Module-specific filters")
ModuleFilters filters;
}

private template ModuleFiltersMixin(A)
{
const string ModuleFiltersMixin = () {
string s;
foreach (mem; __traits(allMembers, StaticAnalysisConfig))
static if (is(typeof(__traits(getMember, StaticAnalysisConfig, mem)) == string))
s ~= `@INI("Exclude/Import modules") string[] ` ~ mem ~ ";\n";

return s;
}();
}

@INI("ModuleFilters. +std.,-std.internal")
struct ModuleFilters
{
mixin(ModuleFiltersMixin!int);
}
Loading