mirror of
https://github.com/dlang-community/D-Scanner.git
synced 2025-04-26 21:30:14 +03:00
Add style checker (#9)
This commit is contained in:
parent
d7623ebbb4
commit
6cf762624d
4 changed files with 46 additions and 3 deletions
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
|
@ -17,8 +17,12 @@ jobs:
|
|||
#- name: Setup upterm session
|
||||
#uses: lhotari/action-upterm@v1
|
||||
|
||||
- name: Run style checks
|
||||
run: |
|
||||
source ~/dlang/*/activate
|
||||
make style
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
source ~/dlang/*/activate
|
||||
make test
|
||||
|
||||
|
|
39
makefile
39
makefile
|
@ -175,3 +175,42 @@ report: all
|
|||
|
||||
release:
|
||||
./release.sh
|
||||
|
||||
# Add source files here as we transition to DMD-as-a-library
|
||||
STYLE_CHECKED_SRC := \
|
||||
src/dscanner/imports.d \
|
||||
src/dscanner/main.d
|
||||
|
||||
style:
|
||||
@echo "Check for trailing whitespace"
|
||||
grep -nr '[[:blank:]]$$' ${STYLE_CHECKED_SRC}; test $$? -eq 1
|
||||
|
||||
@echo "Enforce whitespace before opening parenthesis"
|
||||
grep -nrE "\<(for|foreach|foreach_reverse|if|while|switch|catch|version)\(" ${STYLE_CHECKED_SRC} ; test $$? -eq 1
|
||||
|
||||
@echo "Enforce no whitespace after opening parenthesis"
|
||||
grep -nrE "\<(version) \( " ${STYLE_CHECKED_SRC} ; test $$? -eq 1
|
||||
|
||||
@echo "Enforce whitespace between colon(:) for import statements (doesn't catch everything)"
|
||||
grep -nr 'import [^/,=]*:.*;' ${STYLE_CHECKED_SRC} | grep -vE "import ([^ ]+) :\s"; test $$? -eq 1
|
||||
|
||||
@echo "Check for package wide std.algorithm imports"
|
||||
grep -nr 'import std.algorithm : ' ${STYLE_CHECKED_SRC} ; test $$? -eq 1
|
||||
|
||||
@echo "Enforce Allman style"
|
||||
grep -nrE '(if|for|foreach|foreach_reverse|while|unittest|switch|else|version) .*{$$' ${STYLE_CHECKED_SRC}; test $$? -eq 1
|
||||
|
||||
@echo "Enforce do { to be in Allman style"
|
||||
grep -nr 'do *{$$' ${STYLE_CHECKED_SRC} ; test $$? -eq 1
|
||||
|
||||
@echo "Enforce no space between assert and the opening brace, i.e. assert("
|
||||
grep -nrE 'assert +\(' ${STYLE_CHECKED_SRC} ; test $$? -eq 1
|
||||
|
||||
@echo "Enforce space after cast(...)"
|
||||
grep -nrE '[^"]cast\([^)]*?\)[[:alnum:]]' ${STYLE_CHECKED_SRC} ; test $$? -eq 1
|
||||
|
||||
@echo "Enforce space between a .. b"
|
||||
grep -nrE '[[:alnum:]][.][.][[:alnum:]]|[[:alnum:]] [.][.][[:alnum:]]|[[:alnum:]][.][.] [[:alnum:]]' ${STYLE_CHECKED_SRC}; test $$? -eq 1
|
||||
|
||||
@echo "Enforce space between binary operators"
|
||||
grep -nrE "[[:alnum:]](==|!=|<=|<<|>>|>>>|^^)[[:alnum:]]|[[:alnum:]] (==|!=|<=|<<|>>|>>>|^^)[[:alnum:]]|[[:alnum:]](==|!=|<=|<<|>>|>>>|^^) [[:alnum:]]" ${STYLE_CHECKED_SRC}; test $$? -eq 1
|
||||
|
|
|
@ -36,7 +36,7 @@ extern(C++) class ImportVisitor(AST) : ParseTimeTransitiveVisitor!AST
|
|||
{
|
||||
import std.conv;
|
||||
string s;
|
||||
|
||||
|
||||
foreach (const pid; imp.packages)
|
||||
s = s ~ to!string(pid.toChars()) ~ ".";
|
||||
|
||||
|
|
|
@ -599,7 +599,7 @@ string getDefaultConfigurationLocation()
|
|||
configDir = buildPath(configDir, "dscanner", CONFIG_FILE_NAME);
|
||||
return configDir;
|
||||
}
|
||||
else version(Windows)
|
||||
else version (Windows)
|
||||
{
|
||||
string configDir = environment.get("APPDATA", null);
|
||||
enforce(configDir !is null, "%APPDATA% is unset");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue