Skip to content

Commit

Permalink
Add style checker (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
edi33416 committed Apr 29, 2022
1 parent c576c29 commit d368d5e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 39 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/dscanner/imports.d
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ~ ".";

Expand Down
2 changes: 1 addition & 1 deletion src/dscanner/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,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");
Expand Down

0 comments on commit d368d5e

Please sign in to comment.