From edab5c39de53a2ce1feb273bc07f0cfeeac26d2a Mon Sep 17 00:00:00 2001 From: Samuel El-Borai Date: Fri, 1 May 2020 20:07:59 +0200 Subject: [PATCH 1/5] Add inputs for D-Scanner and dub flags --- .github/workflows/test.yml | 6 ++ README.md | 22 +++- action.yml | 10 ++ entrypoint.sh | 2 +- testdata/dscanner.ini | 204 +++++++++++++++++++++++++++++++++++++ 5 files changed, 238 insertions(+), 6 deletions(-) create mode 100644 testdata/dscanner.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 85da3b5..c556973 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,6 +16,8 @@ jobs: reporter: github-check level: info path: ./testdata + flags: '--config ./testdata/dscanner.ini' + dub_flags: '--config ./testdata/dub.sdl' test-pr-check: if: github.event_name == 'pull_request' @@ -29,6 +31,8 @@ jobs: reporter: github-pr-check level: error path: ./testdata + flags: '--config ./testdata/dscanner.ini' + dub_flags: '--config ./testdata/dub.sdl' test-pr-review: if: github.event_name == 'pull_request' @@ -42,3 +46,5 @@ jobs: reporter: github-pr-review level: error path: ./testdata + flags: '--config ./testdata/dscanner.ini' + dub_flags: '--config ./testdata/dub.sdl' diff --git a/README.md b/README.md index a8201bd..d196671 100644 --- a/README.md +++ b/README.md @@ -22,17 +22,29 @@ inputs: github_token: description: 'GITHUB_TOKEN' default: '${{ github.token }}' - # reviewdog flags + + ### Flags for reviewdog ### level: description: 'Report level for reviewdog [info,warning,error]' default: 'error' reporter: - description: 'Reporter of reviewdog command [github-pr-check,github-check,github-pr-review].' - default: 'github-pr-check' - # D-Scanner flags + description: 'Reporter of reviewdog command [github-pr-check,github-pr-review]' + default: 'github-pr-review' + + ### Flags for D-Scanner ### path: description: 'Root directory where D-Scanner should be run from' default: '' + flags: + description: | + List of arguments to pass to D-Scanner. + Exemple: '--config path/to/dscanner.ini' + default: '' + dub_flags: + description: | + List of arguments to pass to dub. + Exemple: '--config path/to/dub.json' + default: '' ``` ## Usage @@ -55,5 +67,5 @@ jobs: level: warning # D-Scanner config - path: 'path/to/my/project' + path: 'path/to/my/dub/project' ``` diff --git a/action.yml b/action.yml index a5b99bd..7f23b95 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,16 @@ inputs: path: description: 'Root directory where D-Scanner should be run from' default: '' + flags: + description: | + List of arguments to pass to D-Scanner. + Exemple: '--config path/to/dscanner.ini' + default: '' + dub_flags: + description: | + List of arguments to pass to dub. + Exemple: '--config path/to/dub.json' + default: '' runs: using: 'docker' diff --git a/entrypoint.sh b/entrypoint.sh index 9343c06..7f3e904 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,4 +7,4 @@ fi export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" -dub lint --root="${INPUT_PATH:-PWD}" | reviewdog -efm="%f(%l:%c)[%tarn]: %m" -efm="%f(%l:%c)[%trror]: %m" -name="dscanner" -reporter="${INPUT_REPORTER:-github-pr-check}" -level="${INPUT_LEVEL}" +dub lint --root="${INPUT_PATH:-PWD}" ${INPUT_DUB_FLAGS} -- ${INPUT_FLAGS} | reviewdog -efm="%f(%l:%c)[%tarn]: %m" -efm="%f(%l:%c)[%trror]: %m" -name="dscanner" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" diff --git a/testdata/dscanner.ini b/testdata/dscanner.ini new file mode 100644 index 0000000..2f973b9 --- /dev/null +++ b/testdata/dscanner.ini @@ -0,0 +1,204 @@ +; Configure which static analysis checks are enabled +[analysis.config.StaticAnalysisConfig] +; Check variable, class, struct, interface, union, and function names against t +; he Phobos style guide +style_check="enabled" +; Check for array literals that cause unnecessary allocation +enum_array_literal_check="enabled" +; Check for poor exception handling practices +exception_check="enabled" +; Check for use of the deprecated 'delete' keyword +delete_check="enabled" +; Check for use of the deprecated floating point operators +float_operator_check="enabled" +; Check number literals for readability +number_style_check="enabled" +; Checks that opEquals, opCmp, toHash, and toString are either const, immutable +; , or inout. +object_const_check="enabled" +; Checks for .. expressions where the left side is larger than the right. +backwards_range_check="enabled" +; Checks for if statements whose 'then' block is the same as the 'else' block +if_else_same_check="enabled" +; Checks for some problems with constructors +constructor_check="enabled" +; Checks for unused variables +unused_variable_check="enabled" +; Checks for unused labels +unused_label_check="enabled" +; Checks for unused function parameters +unused_parameter_check="enabled" +; Checks for duplicate attributes +duplicate_attribute="enabled" +; Checks that opEquals and toHash are both defined or neither are defined +opequals_tohash_check="enabled" +; Checks for subtraction from .length properties +length_subtraction_check="enabled" +; Checks for methods or properties whose names conflict with built-in propertie +; s +builtin_property_names_check="enabled" +; Checks for confusing code in inline asm statements +asm_style_check="enabled" +; Checks for confusing logical operator precedence +logical_precedence_check="enabled" +; Checks for undocumented public declarations +undocumented_declaration_check="enabled" +; Checks for poor placement of function attributes +function_attribute_check="enabled" +; Checks for use of the comma operator +comma_expression_check="enabled" +; Checks for local imports that are too broad +local_import_check="enabled" +; Checks for variables that could be declared immutable +could_be_immutable_check="enabled" +; Checks for redundant expressions in if statements +redundant_if_check="enabled" +; Checks for redundant parenthesis +redundant_parens_check="enabled" +; Checks for mismatched argument and parameter names +mismatched_args_check="enabled" +; Checks for labels with the same name as variables +label_var_same_name_check="enabled" +; Checks for lines longer than 120 characters +long_line_check="enabled" +; Checks for assignment to auto-ref function parameters +auto_ref_assignment_check="enabled" +; Checks for incorrect infinite range definitions +incorrect_infinite_range_check="enabled" +; Checks for asserts that are always true +useless_assert_check="enabled" +; Check for uses of the old-style alias syntax +alias_syntax_check="enabled" +; Checks for else if that should be else static if +static_if_else_check="enabled" +; Check for unclear lambda syntax +lambda_return_check="enabled" +; Check for auto function without return statement +auto_function_check="enabled" +; Check for sortedness of imports +imports_sortedness="disabled" +; Check for explicitly annotated unittests +explicitly_annotated_unittests="disabled" +; Check for properly documented public functions (Returns, Params) +properly_documented_public_functions="disabled" +; Check for useless usage of the final attribute +final_attribute_check="enabled" +; Check for virtual calls in the class constructors +vcall_in_ctor="enabled" +; Check for useless user defined initializers +useless_initializer="disabled" +; Check allman brace style +allman_braces_check="disabled" +; Check for redundant attributes +redundant_attributes_check="enabled" +; Check public declarations without a documented unittest +has_public_example="disabled" +; Check for asserts without an explanatory message +assert_without_msg="disabled" +; Check indent of if constraints +if_constraints_indent="disabled" +; Check for @trusted applied to a bigger scope than a single function +trust_too_much="enabled" +; Check for redundant storage classes on variable declarations +redundant_storage_classes="enabled" +; ModuleFilters for selectively enabling (+std) and disabling (-std.internal) i +; ndividual checks +[analysis.config.ModuleFilters] +; Exclude/Import modules +style_check="" +; Exclude/Import modules +enum_array_literal_check="" +; Exclude/Import modules +exception_check="" +; Exclude/Import modules +delete_check="" +; Exclude/Import modules +float_operator_check="" +; Exclude/Import modules +number_style_check="" +; Exclude/Import modules +object_const_check="" +; Exclude/Import modules +backwards_range_check="" +; Exclude/Import modules +if_else_same_check="" +; Exclude/Import modules +constructor_check="" +; Exclude/Import modules +unused_variable_check="" +; Exclude/Import modules +unused_label_check="" +; Exclude/Import modules +unused_parameter_check="" +; Exclude/Import modules +duplicate_attribute="" +; Exclude/Import modules +opequals_tohash_check="" +; Exclude/Import modules +length_subtraction_check="" +; Exclude/Import modules +builtin_property_names_check="" +; Exclude/Import modules +asm_style_check="" +; Exclude/Import modules +logical_precedence_check="" +; Exclude/Import modules +undocumented_declaration_check="" +; Exclude/Import modules +function_attribute_check="" +; Exclude/Import modules +comma_expression_check="" +; Exclude/Import modules +local_import_check="" +; Exclude/Import modules +could_be_immutable_check="" +; Exclude/Import modules +redundant_if_check="" +; Exclude/Import modules +redundant_parens_check="" +; Exclude/Import modules +mismatched_args_check="" +; Exclude/Import modules +label_var_same_name_check="" +; Exclude/Import modules +long_line_check="" +; Exclude/Import modules +auto_ref_assignment_check="" +; Exclude/Import modules +incorrect_infinite_range_check="" +; Exclude/Import modules +useless_assert_check="" +; Exclude/Import modules +alias_syntax_check="" +; Exclude/Import modules +static_if_else_check="" +; Exclude/Import modules +lambda_return_check="" +; Exclude/Import modules +auto_function_check="" +; Exclude/Import modules +imports_sortedness="" +; Exclude/Import modules +explicitly_annotated_unittests="" +; Exclude/Import modules +properly_documented_public_functions="" +; Exclude/Import modules +final_attribute_check="" +; Exclude/Import modules +vcall_in_ctor="" +; Exclude/Import modules +useless_initializer="" +; Exclude/Import modules +allman_braces_check="" +; Exclude/Import modules +redundant_attributes_check="" +; Exclude/Import modules +has_public_example="" +; Exclude/Import modules +assert_without_msg="" +; Exclude/Import modules +if_constraints_indent="" +; Exclude/Import modules +trust_too_much="" +; Exclude/Import modules +redundant_storage_classes="" From 09b7ede2a2fdd1238d58ec2b98b7162349fa704a Mon Sep 17 00:00:00 2001 From: Samuel El-Borai Date: Fri, 1 May 2020 20:15:16 +0200 Subject: [PATCH 2/5] Fix issues reported by linters --- README.md | 4 ++-- action.yml | 4 ++-- entrypoint.sh | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d196671..95ecc38 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,12 @@ inputs: flags: description: | List of arguments to pass to D-Scanner. - Exemple: '--config path/to/dscanner.ini' + Example: '--config path/to/dscanner.ini' default: '' dub_flags: description: | List of arguments to pass to dub. - Exemple: '--config path/to/dub.json' + Example: '--config path/to/dub.json' default: '' ``` diff --git a/action.yml b/action.yml index 7f23b95..96c4c54 100644 --- a/action.yml +++ b/action.yml @@ -21,12 +21,12 @@ inputs: flags: description: | List of arguments to pass to D-Scanner. - Exemple: '--config path/to/dscanner.ini' + Example: '--config path/to/dscanner.ini' default: '' dub_flags: description: | List of arguments to pass to dub. - Exemple: '--config path/to/dub.json' + Example: '--config path/to/dub.json' default: '' runs: diff --git a/entrypoint.sh b/entrypoint.sh index 7f3e904..45eb8f4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,4 +7,5 @@ fi export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +# shellcheck disable=SC2086 dub lint --root="${INPUT_PATH:-PWD}" ${INPUT_DUB_FLAGS} -- ${INPUT_FLAGS} | reviewdog -efm="%f(%l:%c)[%tarn]: %m" -efm="%f(%l:%c)[%trror]: %m" -name="dscanner" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" From b9b49851f1bbd3bad3d1f535bc3ade576a3970a9 Mon Sep 17 00:00:00 2001 From: Samuel El-Borai Date: Fri, 1 May 2020 20:39:42 +0200 Subject: [PATCH 3/5] Should fail if error found --- entrypoint.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 45eb8f4..5824e37 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e if [ -n "${GITHUB_WORKSPACE}" ]; then @@ -7,5 +7,11 @@ fi export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +# 1. First check for warnings, should not exit with fail code when warnings found # shellcheck disable=SC2086 -dub lint --root="${INPUT_PATH:-PWD}" ${INPUT_DUB_FLAGS} -- ${INPUT_FLAGS} | reviewdog -efm="%f(%l:%c)[%tarn]: %m" -efm="%f(%l:%c)[%trror]: %m" -name="dscanner" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" +dub lint ${INPUT_DUB_FLAGS} --root="${INPUT_PATH:-PWD}" -- ${INPUT_FLAGS} | reviewdog -efm="%f(%l:%c)[%tarn]: %m" -name="dscanner" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" + +# 2. Then check for errors, if an error is found we should exit in error +set -euox pipefail # i.e: enable strict mode +# shellcheck disable=SC2086 +dub lint ${INPUT_DUB_FLAGS} --root="${INPUT_PATH:-PWD}" -- ${INPUT_FLAGS} | reviewdog -efm="%f(%l:%c)[%trror]: %m" -name="dscanner" -reporter="${INPUT_REPORTER}" -level="${INPUT_LEVEL}" From 57002088c73c2db8de7bc0e0d545568ea9d53f6d Mon Sep 17 00:00:00 2001 From: Samuel El-Borai Date: Fri, 1 May 2020 20:43:31 +0200 Subject: [PATCH 4/5] Test syntax error --- testdata/source/app.d | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/testdata/source/app.d b/testdata/source/app.d index fd5a501..6a559f0 100644 --- a/testdata/source/app.d +++ b/testdata/source/app.d @@ -1,9 +1,9 @@ import std.stdio; -// Issue: Prefer the new "'alias' identifier '=' type ';'" syntax to the old "'alias' type identifier ';'" syntax. +// Warning: Prefer the new "'alias' identifier '=' type ';'" syntax to the old "'alias' type identifier ';'" syntax. alias string myString; -// Issue: Empty declaration +// Warning: Empty declaration ; void main(string[] args) @@ -12,8 +12,11 @@ void main(string[] args) { writeln("Hello World"); } - // Issue: Catching Error or Throwable is almost always a bad idea. + // Warning: Catching Error or Throwable is almost always a bad idea. catch (Throwable) { } + + // Error: Expected `)` instead of `;` + writeln("hmm, you should have close that one"; } From ebc7aa481c0fd7d8f48c9eeeeda3d9881fec2cdc Mon Sep 17 00:00:00 2001 From: Samuel El-Borai Date: Fri, 1 May 2020 22:41:30 +0200 Subject: [PATCH 5/5] Fix use of --config flag --- .github/workflows/test.yml | 12 ++++++------ README.md | 4 ++-- action.yml | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c556973..a72afbc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,8 +16,8 @@ jobs: reporter: github-check level: info path: ./testdata - flags: '--config ./testdata/dscanner.ini' - dub_flags: '--config ./testdata/dub.sdl' + flags: '--config=./testdata/dscanner.ini' + dub_flags: '--config=./testdata/dub.sdl' test-pr-check: if: github.event_name == 'pull_request' @@ -31,8 +31,8 @@ jobs: reporter: github-pr-check level: error path: ./testdata - flags: '--config ./testdata/dscanner.ini' - dub_flags: '--config ./testdata/dub.sdl' + flags: '--config=./testdata/dscanner.ini' + dub_flags: '--config=./testdata/dub.sdl' test-pr-review: if: github.event_name == 'pull_request' @@ -46,5 +46,5 @@ jobs: reporter: github-pr-review level: error path: ./testdata - flags: '--config ./testdata/dscanner.ini' - dub_flags: '--config ./testdata/dub.sdl' + flags: '--config=./testdata/dscanner.ini' + dub_flags: '--config=./testdata/dub.sdl' diff --git a/README.md b/README.md index 95ecc38..d27eab9 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,12 @@ inputs: flags: description: | List of arguments to pass to D-Scanner. - Example: '--config path/to/dscanner.ini' + Example: '--config=path/to/dscanner.ini' default: '' dub_flags: description: | List of arguments to pass to dub. - Example: '--config path/to/dub.json' + Example: '--config=path/to/dub.json' default: '' ``` diff --git a/action.yml b/action.yml index 96c4c54..07816b6 100644 --- a/action.yml +++ b/action.yml @@ -21,12 +21,12 @@ inputs: flags: description: | List of arguments to pass to D-Scanner. - Example: '--config path/to/dscanner.ini' + Example: '--config=path/to/dscanner.ini' default: '' dub_flags: description: | List of arguments to pass to dub. - Example: '--config path/to/dub.json' + Example: '--config=path/to/dub.json' default: '' runs: