├── mix.lock ├── .gitignore ├── .github ├── renovate.json └── workflows │ ├── dockerimage.yml │ └── reviewdog.yml ├── test └── test.ex ├── mix.exs ├── entrypoint.sh ├── Dockerfile ├── action.yml ├── README.md └── .credo.exs /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | } 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | deps 2 | _build 3 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /test/test.ex: -------------------------------------------------------------------------------- 1 | defmodule Foo do 2 | def foo do 3 | bar(:atom) 4 | |> baz() 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule ReviewdogCredo.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :reviewdog_credo, 7 | version: "0.0.1", 8 | deps: [] 9 | ] 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /.github/workflows/dockerimage.yml: -------------------------------------------------------------------------------- 1 | name: Docker Image CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | 7 | build: 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Build the Docker image 14 | run: docker build . --file Dockerfile --tag reviewdog-credo:$(date +%s) 15 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd "$GITHUB_WORKSPACE" 4 | 5 | git config --global --add safe.directory $GITHUB_WORKSPACE || exit 1 6 | 7 | export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" 8 | 9 | mix credo suggest --strict --format=flycheck \ 10 | | reviewdog -efm="%f:%l:%c: %t: %m" -efm="%f:%l: %t: %m" -name="credo" -reporter="${INPUT_REPORTER:-'github-pr-check'}" -level="${INPUT_LEVEL}" 11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM elixir:1.16-alpine 2 | 3 | RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b /usr/local/bin/ v0.17.4 4 | RUN apk --update add git && \ 5 | rm -rf /var/lib/apt/lists/* && \ 6 | rm /var/cache/apk/* 7 | 8 | ENV MIX_HOME /var/mix 9 | 10 | RUN mix local.hex --force && \ 11 | mix archive.install --force github rrrene/bunt && \ 12 | mix archive.install --force github rrrene/credo 13 | 14 | COPY entrypoint.sh /entrypoint.sh 15 | 16 | ENTRYPOINT ["/entrypoint.sh"] 17 | -------------------------------------------------------------------------------- /.github/workflows/reviewdog.yml: -------------------------------------------------------------------------------- 1 | name: reviewdog 2 | on: [pull_request] 3 | jobs: 4 | credo: 5 | name: runner / credo 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Check out code. 9 | uses: actions/checkout@v2 10 | - uses: erlef/setup-beam@v1 11 | with: 12 | otp-version: 26.2.5 13 | elixir-version: 1.16-otp-26 14 | - name: Install Dependencies 15 | run: | 16 | mix local.rebar --force 17 | mix local.hex --force 18 | mix deps.get 19 | - name: credo 20 | uses: ./ 21 | with: 22 | github_token: ${{ secrets.github_token }} 23 | - name: credo-pr-review 24 | uses: ./ 25 | with: 26 | github_token: ${{ secrets.github_token }} 27 | reporter: github-pr-review 28 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Run credo with reviewdog' 2 | description: '🐶 Run credo with reviewdog on pull requests to improve code review experience.' 3 | author: 'Hauleth' 4 | inputs: 5 | github_token: 6 | description: 'GITHUB_TOKEN.' 7 | required: true 8 | level: 9 | description: 'Report level for reviewdog [info,warning,error]' 10 | default: 'error' 11 | reporter: 12 | description: | 13 | Reporter of reviewdog command [github-pr-check,github-pr-review]. 14 | Default is github-pr-check. 15 | github-pr-review can use Markdown and add a link to rule page in reviewdog reports. 16 | default: 'github-pr-check' 17 | runs: 18 | using: 'docker' 19 | image: 'Dockerfile' 20 | args: 21 | - ${{ inputs.github_token }} 22 | - ${{ inputs.level }} 23 | - ${{ inputs.reporter }} 24 | branding: 25 | icon: 'chevron-down' 26 | color: 'green' 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Action: Run credo with reviewdog 2 | 3 | [![Docker Image CI](https://github.com/red-shirts/reviewdog-action-credo/workflows/Docker%20Image%20CI/badge.svg)](https://github.com/red-shirts/reviewdog-action-credo/actions) 4 | [![Release](https://img.shields.io/github/release/red-shirts/reviewdog-action-credo.svg?maxAge=43200)](https://github.com/red-shirts/reviewdog-action-credo/releases) 5 | 6 | This action runs [credo](https://github.com/rrrene/credo) with 7 | [reviewdog](https://github.com/reviewdog/reviewdog) on pull requests to improve 8 | code review experience. 9 | 10 | ## Inputs 11 | 12 | ### `github_token` 13 | 14 | **Required**. Must be in form of `github_token: ${{ secrets.github_token }}`'. 15 | 16 | ### `level` 17 | 18 | Optional. Report level for reviewdog [info,warning,error]. 19 | It's same as `-level` flag of reviewdog. 20 | 21 | ### `reporter` 22 | 23 | Reporter of reviewdog command [github-pr-check,github-pr-review]. 24 | Default is github-pr-check. 25 | github-pr-review can use Markdown and add a link to rule page in reviewdog reports. 26 | 27 | ## Example usage 28 | 29 | ### [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml) 30 | 31 | ```yml 32 | name: reviewdog 33 | on: [pull_request] 34 | jobs: 35 | credo: 36 | name: runner / credo 37 | runs-on: ubuntu-latest 38 | container: 39 | image: elixir:1.16-slim 40 | steps: 41 | - uses: actions/checkout@v2 42 | - name: Install Dependencies 43 | run: | 44 | mix local.rebar --force 45 | mix local.hex --force 46 | mix deps.get 47 | - name: credo 48 | uses: red-shirts/reviewdog-action-credo@v1 49 | with: 50 | github_token: ${{ secrets.github_token }} 51 | reporter: github-pr-review # Change reporter. 52 | ``` 53 | -------------------------------------------------------------------------------- /.credo.exs: -------------------------------------------------------------------------------- 1 | # This file contains the configuration for Credo and you are probably reading 2 | # this after creating it with `mix credo.gen.config`. 3 | # 4 | # If you find anything wrong or unclear in this file, please report an 5 | # issue on GitHub: https://github.com/rrrene/credo/issues 6 | # 7 | %{ 8 | # 9 | # You can have as many configs as you like in the `configs:` field. 10 | configs: [ 11 | %{ 12 | # 13 | # Run any exec using `mix credo -C `. If no exec name is given 14 | # "default" is used. 15 | # 16 | name: "default", 17 | # 18 | # These are the files included in the analysis: 19 | files: %{ 20 | # 21 | # You can give explicit globs or simply directories. 22 | # In the latter case `**/*.{ex,exs}` will be used. 23 | # 24 | included: ["test/"], 25 | excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"] 26 | }, 27 | # 28 | # Load and configure plugins here: 29 | # 30 | plugins: [], 31 | # 32 | # If you create your own checks, you must specify the source files for 33 | # them here, so they can be loaded by Credo before running the analysis. 34 | # 35 | requires: [], 36 | # 37 | # If you want to enforce a style guide and need a more traditional linting 38 | # experience, you can change `strict` to `true` below: 39 | # 40 | strict: false, 41 | # 42 | # If you want to use uncolored output by default, you can change `color` 43 | # to `false` below: 44 | # 45 | color: true, 46 | # 47 | # You can customize the parameters of any check by adding a second element 48 | # to the tuple. 49 | # 50 | # To disable a check put `false` as second element: 51 | # 52 | # {Credo.Check.Design.DuplicatedCode, false} 53 | # 54 | checks: [ 55 | # 56 | ## Consistency Checks 57 | # 58 | {Credo.Check.Consistency.ExceptionNames, []}, 59 | {Credo.Check.Consistency.LineEndings, []}, 60 | {Credo.Check.Consistency.ParameterPatternMatching, []}, 61 | {Credo.Check.Consistency.SpaceAroundOperators, []}, 62 | {Credo.Check.Consistency.SpaceInParentheses, []}, 63 | {Credo.Check.Consistency.TabsOrSpaces, []}, 64 | 65 | # 66 | ## Design Checks 67 | # 68 | # You can customize the priority of any check 69 | # Priority values are: `low, normal, high, higher` 70 | # 71 | {Credo.Check.Design.AliasUsage, 72 | [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]}, 73 | # You can also customize the exit_status of each check. 74 | # If you don't want TODO comments to cause `mix credo` to fail, just 75 | # set this value to 0 (zero). 76 | # 77 | {Credo.Check.Design.TagTODO, [exit_status: 2]}, 78 | {Credo.Check.Design.TagFIXME, []}, 79 | 80 | # 81 | ## Readability Checks 82 | # 83 | {Credo.Check.Readability.AliasOrder, []}, 84 | {Credo.Check.Readability.FunctionNames, []}, 85 | {Credo.Check.Readability.LargeNumbers, []}, 86 | {Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]}, 87 | {Credo.Check.Readability.ModuleAttributeNames, []}, 88 | {Credo.Check.Readability.ModuleDoc, []}, 89 | {Credo.Check.Readability.ModuleNames, []}, 90 | {Credo.Check.Readability.ParenthesesInCondition, []}, 91 | {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []}, 92 | {Credo.Check.Readability.PredicateFunctionNames, []}, 93 | {Credo.Check.Readability.PreferImplicitTry, []}, 94 | {Credo.Check.Readability.RedundantBlankLines, []}, 95 | {Credo.Check.Readability.Semicolons, []}, 96 | {Credo.Check.Readability.SpaceAfterCommas, []}, 97 | {Credo.Check.Readability.StringSigils, []}, 98 | {Credo.Check.Readability.TrailingBlankLine, []}, 99 | {Credo.Check.Readability.TrailingWhiteSpace, []}, 100 | # TODO: enable by default in Credo 1.1 101 | {Credo.Check.Readability.UnnecessaryAliasExpansion, false}, 102 | {Credo.Check.Readability.VariableNames, []}, 103 | 104 | # 105 | ## Refactoring Opportunities 106 | # 107 | {Credo.Check.Refactor.CondStatements, []}, 108 | {Credo.Check.Refactor.CyclomaticComplexity, []}, 109 | {Credo.Check.Refactor.FunctionArity, []}, 110 | {Credo.Check.Refactor.LongQuoteBlocks, []}, 111 | {Credo.Check.Refactor.MapInto, false}, 112 | {Credo.Check.Refactor.MatchInCondition, []}, 113 | {Credo.Check.Refactor.NegatedConditionsInUnless, []}, 114 | {Credo.Check.Refactor.NegatedConditionsWithElse, []}, 115 | {Credo.Check.Refactor.Nesting, []}, 116 | {Credo.Check.Refactor.UnlessWithElse, []}, 117 | {Credo.Check.Refactor.WithClauses, []}, 118 | 119 | # 120 | ## Warnings 121 | # 122 | {Credo.Check.Warning.BoolOperationOnSameValues, []}, 123 | {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, 124 | {Credo.Check.Warning.IExPry, []}, 125 | {Credo.Check.Warning.IoInspect, []}, 126 | {Credo.Check.Warning.LazyLogging, false}, 127 | {Credo.Check.Warning.OperationOnSameValues, []}, 128 | {Credo.Check.Warning.OperationWithConstantResult, []}, 129 | {Credo.Check.Warning.RaiseInsideRescue, []}, 130 | {Credo.Check.Warning.UnusedEnumOperation, []}, 131 | {Credo.Check.Warning.UnusedFileOperation, []}, 132 | {Credo.Check.Warning.UnusedKeywordOperation, []}, 133 | {Credo.Check.Warning.UnusedListOperation, []}, 134 | {Credo.Check.Warning.UnusedPathOperation, []}, 135 | {Credo.Check.Warning.UnusedRegexOperation, []}, 136 | {Credo.Check.Warning.UnusedStringOperation, []}, 137 | {Credo.Check.Warning.UnusedTupleOperation, []}, 138 | 139 | # 140 | # Controversial and experimental checks (opt-in, just replace `false` with `[]`) 141 | # 142 | {Credo.Check.Consistency.MultiAliasImportRequireUse, false}, 143 | {Credo.Check.Consistency.UnusedVariableNames, false}, 144 | {Credo.Check.Design.DuplicatedCode, false}, 145 | {Credo.Check.Readability.AliasAs, false}, 146 | {Credo.Check.Readability.MultiAlias, false}, 147 | {Credo.Check.Readability.Specs, false}, 148 | {Credo.Check.Readability.SinglePipe, false}, 149 | {Credo.Check.Refactor.ABCSize, false}, 150 | {Credo.Check.Refactor.AppendSingleItem, false}, 151 | {Credo.Check.Refactor.DoubleBooleanNegation, false}, 152 | {Credo.Check.Refactor.ModuleDependencies, false}, 153 | {Credo.Check.Refactor.PipeChainStart, false}, 154 | {Credo.Check.Refactor.VariableRebinding, false}, 155 | {Credo.Check.Warning.MapGetUnsafePass, false}, 156 | {Credo.Check.Warning.UnsafeToAtom, false} 157 | 158 | # 159 | # Custom checks can be created using `mix credo.gen.check`. 160 | # 161 | ] 162 | } 163 | ] 164 | } 165 | --------------------------------------------------------------------------------