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

Add style checker #9

Merged
merged 1 commit into from
Feb 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -109,3 +109,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