github.com/alexey-mercari/reviewdog@v0.10.1-0.20200514053941-928943b10766/README.md (about)

     1  <div align="center">
     2    <a href="https://github.com/reviewdog/reviewdog">
     3      <img alt="reviewdog" src="https://raw.githubusercontent.com/haya14busa/i/d598ed7dc49fefb0018e422e4c43e5ab8f207a6b/reviewdog/reviewdog.logo.png">
     4    </a>
     5  </div>
     6  
     7  <h2 align="center">
     8    reviewdog - A code review dog who keeps your codebase healthy.
     9  </h2>
    10  
    11  <div align="center">
    12    <a href="./LICENSE">
    13      <img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-blue.svg?maxAge=43200">
    14    </a>
    15    <a href="https://godoc.org/github.com/reviewdog/reviewdog">
    16      <img alt="GoDoc" src="https://img.shields.io/badge/godoc-reference-4F73B3.svg?label=godoc.org&maxAge=43200&logo=go">
    17    </a>
    18    <a href="./CHANGELOG.md">
    19      <img alt="releases" src="https://img.shields.io/github/release/reviewdog/reviewdog.svg?logo=github">
    20    </a>
    21    <a href="https://github.com/reviewdog/nightly">
    22      <img alt="nightly releases" src="https://img.shields.io/github/v/release/reviewdog/nightly.svg?logo=github">
    23    </a>
    24  </div>
    25  
    26  <div align="center">
    27    <a href="https://github.com/reviewdog/reviewdog/actions?query=workflow%3AGo+event%3Apush+branch%3Amaster">
    28      <img alt="GitHub Actions" src="https://github.com/reviewdog/reviewdog/workflows/Go/badge.svg">
    29    </a>
    30    <a href="https://github.com/reviewdog/reviewdog/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amaster">
    31      <img alt="reviewdog" src="https://github.com/reviewdog/reviewdog/workflows/reviewdog/badge.svg?branch=master&event=push">
    32    </a>
    33    <a href="https://github.com/reviewdog/reviewdog/actions?query=workflow%3Arelease">
    34      <img alt="release" src="https://github.com/reviewdog/reviewdog/workflows/release/badge.svg">
    35    </a>
    36    <a href="https://travis-ci.org/reviewdog/reviewdog"><img alt="Travis Status" src="https://img.shields.io/travis/reviewdog/reviewdog/master.svg?label=Travis&logo=travis"></a>
    37    <a href="https://circleci.com/gh/reviewdog/reviewdog"><img alt="CircleCI Status" src="http://img.shields.io/circleci/build/github/reviewdog/reviewdog/master.svg?label=CircleCI&logo=circleci"></a>
    38    <a href="https://codecov.io/github/reviewdog/reviewdog"><img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/reviewdog/reviewdog/master.svg?logo=codecov"></a>
    39  </div>
    40  
    41  <div align="center">
    42    <a href="https://gitlab.com/reviewdog/reviewdog/pipelines">
    43      <img alt="GitLab Supported" src="https://img.shields.io/badge/GitLab%20-Supported-fc6d26?logo=gitlab">
    44    </a>
    45    <a href="https://github.com/haya14busa/action-bumpr">
    46      <img alt="action-bumpr supported" src="https://img.shields.io/badge/bumpr-supported-ff69b4?logo=github&link=https://github.com/haya14busa/action-bumpr">
    47    </a>
    48    <a href="./CODE_OF_CONDUCT.md">
    49      <img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg">
    50    </a>
    51    <a href="https://somsubhra.com/github-release-stats/?username=reviewdog&repository=reviewdog">
    52      <img alt="Github Releases Stats" src="https://img.shields.io/github/downloads/reviewdog/reviewdog/total.svg?logo=github">
    53    </a>
    54    <a href="https://starcharts.herokuapp.com/reviewdog/reviewdog"><img alt="Stars" src="https://img.shields.io/github/stars/reviewdog/reviewdog.svg?style=social"></a>
    55  </div>
    56  <br />
    57  
    58  reviewdog provides a way to post review comments to code hosting service,
    59  such as GitHub, automatically by integrating with any linter tools with ease.
    60  It uses an output of lint tools and posts them as a comment if findings are in
    61  diff of patches to review.
    62  
    63  reviewdog also supports run in the local environment to filter an output of lint tools
    64  by diff.
    65  
    66  [design doc](https://docs.google.com/document/d/1mGOX19SSqRowWGbXieBfGPtLnM0BdTkIc9JelTiu6wA/edit?usp=sharing)
    67  
    68  ## Table of Contents
    69  
    70  - [Installation](#installation)
    71  - [Input Format](#input-format)
    72    * ['errorformat'](#errorformat)
    73    * [Available pre-defined 'errorformat'](#available-pre-defined-errorformat)
    74    * [checkstyle format](#checkstyle-format)
    75  - [reviewdog config file](#reviewdog-config-file)
    76  - [Reporters](#reporters)
    77    * [Reporter: Local (-reporter=local) [default]](#reporter-local--reporterlocal-default)
    78    * [Reporter: GitHub Checks (-reporter=github-pr-check)](#reporter-github-checks--reportergithub-pr-check)
    79    * [Reporter: GitHub Checks (-reporter=github-check)](#reporter-github-checks--reportergithub-check)
    80    * [Reporter: GitHub PullRequest review comment (-reporter=github-pr-review)](#reporter-github-pullrequest-review-comment--reportergithub-pr-review)
    81    * [Reporter: GitLab MergeRequest discussions (-reporter=gitlab-mr-discussion)](#reporter-gitlab-mergerequest-discussions--reportergitlab-mr-discussion)
    82    * [Reporter: GitLab MergeRequest commit (-reporter=gitlab-mr-commit)](#reporter-gitlab-mergerequest-commit--reportergitlab-mr-commit)
    83  - [Supported CI services](#supported-ci-services)
    84    * [GitHub Actions](#github-actions)
    85    * [Travis CI](#travis-ci)
    86    * [Circle CI](#circle-ci)
    87    * [GitLab CI](#gitlab-ci)
    88    * [Common (Jenkins, local, etc...)](#common-jenkins-local-etc)
    89      + [Jenkins with Github pull request builder plugin](#jenkins-with-github-pull-request-builder-plugin)
    90  - [Exit codes](#exit-codes)
    91  - [Filter mode](#filter-mode)
    92  - [Articles](#articles)
    93  
    94  [![github-pr-check sample](https://user-images.githubusercontent.com/3797062/40884858-6efd82a0-6756-11e8-9f1a-c6af4f920fb0.png)](https://github.com/reviewdog/reviewdog/pull/131/checks)
    95  ![comment in pull-request](https://user-images.githubusercontent.com/3797062/40941822-1d775064-6887-11e8-98e9-4775d37d47f8.png)
    96  ![commit status](https://user-images.githubusercontent.com/3797062/40941738-d62acb0a-6886-11e8-858d-7b97aded2a42.png)
    97  [![sample-comment.png](https://raw.githubusercontent.com/haya14busa/i/dc0ccb1e110515ea407c146d99b749018db05c45/reviewdog/sample-comment.png)](https://github.com/reviewdog/reviewdog/pull/24#discussion_r84599728)
    98  ![reviewdog-local-demo.gif](https://raw.githubusercontent.com/haya14busa/i/dc0ccb1e110515ea407c146d99b749018db05c45/reviewdog/reviewdog-local-demo.gif)
    99  
   100  ## Installation
   101  
   102  ```shell
   103  # Install the latest version. (Install it into ./bin/ by default).
   104  $ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s
   105  
   106  # Specify installation directory ($(go env GOPATH)/bin/) and version.
   107  $ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $(go env GOPATH)/bin [vX.Y.Z]
   108  
   109  # In alpine linux (as it does not come with curl by default)
   110  $ wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s [vX.Y.Z]
   111  ```
   112  
   113  ### Nightly releases
   114  
   115  You can also use [nightly reviewdog release](https://github.com/reviewdog/nightly)
   116  to try the latest reviewdog improvements every day!
   117  
   118  ```
   119  $ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $(go env GOPATH)/bin
   120  ```
   121  
   122  ### Build from HEAD with go get
   123  
   124  ```shell
   125  $ go get -u github.com/reviewdog/reviewdog/cmd/reviewdog
   126  ```
   127  
   128  ### homebrew / linuxbrew
   129  You can also install reviewdog using brew:
   130  
   131  ```shell
   132  $ brew install reviewdog/tap/reviewdog
   133  $ brew upgrade reviewdog/tap/reviewdog
   134  ```
   135  
   136  ## Input Format
   137  
   138  ### 'errorformat'
   139  
   140  reviewdog accepts any compiler or linter result from stdin and parses it with
   141  scan-f like [**'errorformat'**](https://github.com/reviewdog/errorformat),
   142  which is the port of Vim's [errorformat](https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format)
   143  feature.
   144  
   145  For example, if the result format is `{file}:{line number}:{column number}: {message}`,
   146  errorformat should be `%f:%l:%c: %m` and you can pass it as `-efm` arguments.
   147  
   148  ```shell
   149  $ golint ./...
   150  comment_iowriter.go:11:6: exported type CommentWriter should have comment or be unexported
   151  $ golint ./... | reviewdog -efm="%f:%l:%c: %m" -diff="git diff master"
   152  ```
   153  
   154  | name | description |
   155  | ---- | ----------- |
   156  | %f | file name |
   157  | %l | line number |
   158  | %c | column number |
   159  | %m | error message |
   160  | %% | the single '%' character |
   161  | ... | ... |
   162  
   163  Please see [reviewdog/errorformat](https://github.com/reviewdog/errorformat)
   164  and [:h errorformat](https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format)
   165  if you want to deal with a more complex output. 'errorformat' can handle more
   166  complex output like a multi-line error message.
   167  
   168  You can also try errorformat on [the Playground](https://reviewdog.github.io/errorformat-playground/)!
   169  
   170  By this 'errorformat' feature, reviewdog can support any tools output with ease.
   171  
   172  ### Available pre-defined 'errorformat'
   173  
   174  But, you don't have to write 'errorformat' in many cases. reviewdog supports
   175  pre-defined errorformat for major tools.
   176  
   177  You can find available errorformat name by `reviewdog -list` and you can use it
   178  with `-f={name}`.
   179  
   180  ```shell
   181  $ reviewdog -list
   182  golint          linter for Go source code                                       - https://github.com/golang/lint
   183  govet           Vet examines Go source code and reports suspicious problems     - https://golang.org/cmd/vet/
   184  sbt             the interactive build tool                                      - http://www.scala-sbt.org/
   185  ...
   186  ```
   187  
   188  ```shell
   189  $ golint ./... | reviewdog -f=golint -diff="git diff master"
   190  ```
   191  
   192  You can add supported pre-defined 'errorformat' by contributing to [reviewdog/errorformat](https://github.com/reviewdog/errorformat)
   193  
   194  ### checkstyle format
   195  
   196  reviewdog also accepts [checkstyle XML format](http://checkstyle.sourceforge.net/) as well.
   197  If the linter supports checkstyle format as a report format, you can use
   198  -f=checkstyle instead of using 'errorformat'.
   199  
   200  ```shell
   201  # Local
   202  $ eslint -f checkstyle . | reviewdog -f=checkstyle -diff="git diff"
   203  
   204  # CI (overwrite tool name which is shown in review comment by -name arg)
   205  $ eslint -f checkstyle . | reviewdog -f=checkstyle -name="eslint" -reporter=github-pr-check
   206  ```
   207  
   208  Also, if you want to pass other Json/XML/etc... format to reviewdog, you can write a converter.
   209  
   210  ```shell
   211  $ <linter> | <convert-to-checkstyle> | reviewdog -f=checkstyle -name="<linter>" -reporter=github-pr-check
   212  ```
   213  
   214  ## reviewdog config file
   215  
   216  reviewdog can also be controlled via the .reviewdog.yml configuration file instead of "-f" or "-efm" arguments.
   217  
   218  With .reviewdog.yml, you can run the same commands both CI service and local
   219  environment including editor integration with ease.
   220  
   221  #### .reviewdog.yml
   222  
   223  ```yaml
   224  runner:
   225    <tool-name>:
   226      cmd: <command> # (required)
   227      errorformat: # (optional if there is supported format for <tool-name>. see reviewdog -list)
   228        - <list of errorformat>
   229      name: <tool-name> # (optional. you can overwrite <tool-name> defined by runner key)
   230      level: <level> # (optional. same as -level flag. [info,warning,error])
   231  
   232    # examples
   233    golint:
   234      cmd: golint ./...
   235      errorformat:
   236        - "%f:%l:%c: %m"
   237      level: warning
   238    govet:
   239      cmd: go vet -all .
   240  ```
   241  
   242  ```shell
   243  $ reviewdog -diff="git diff master"
   244  project/run_test.go:61:28: [golint] error strings should not end with punctuation
   245  project/run.go:57:18: [errcheck]        defer os.Setenv(name, os.Getenv(name))
   246  project/run.go:58:12: [errcheck]        os.Setenv(name, "")
   247  # You can use -runners to run only specified runners.
   248  $ reviewdog -diff="git diff master" -runners=golint,govet
   249  project/run_test.go:61:28: [golint] error strings should not end with punctuation
   250  # You can use -conf to specify config file path.
   251  $ reviewdog -conf=./.reviewdog.yml -reporter=github-pr-check
   252  ```
   253  
   254  Output format for project config based run is one of the following formats.
   255  
   256  - `<file>: [<tool name>] <message>`
   257  - `<file>:<lnum>: [<tool name>] <message>`
   258  - `<file>:<lnum>:<col>: [<tool name>] <message>`
   259  
   260  ## Reporters
   261  
   262  reviewdog can report results both in local environment and review services as
   263  continuous integration.
   264  
   265  ### Reporter: Local (-reporter=local) [default]
   266  
   267  reviewdog can find newly introduced findings by filtering linter results
   268  using diff. You can pass diff command as `-diff` arg.
   269  
   270  ```shell
   271  $ golint ./... | reviewdog -f=golint -diff="git diff master"
   272  ```
   273  
   274  ### Reporter: GitHub Checks (-reporter=github-pr-check)
   275  
   276  [![github-pr-check sample annotation with option 1](https://user-images.githubusercontent.com/3797062/64875597-65016f80-d688-11e9-843f-4679fb666f0d.png)](https://github.com/reviewdog/reviewdog/pull/275/files#annotation_6177941961779419)
   277  [![github-pr-check sample](https://user-images.githubusercontent.com/3797062/40884858-6efd82a0-6756-11e8-9f1a-c6af4f920fb0.png)](https://github.com/reviewdog/reviewdog/pull/131/checks)
   278  
   279  github-pr-check reporter reports results to [GitHub Checks](https://help.github.com/articles/about-status-checks/).
   280  
   281  You can change report level for this reporter by `level` field in [config
   282  file](#reviewdog-config-file) or `-level` flag. You can control GitHub status
   283  check result with this feature. (default: error)
   284  
   285  | Level     | GitHub Status |
   286  | --------- | ------------- |
   287  | `info`    | neutral       |
   288  | `warning` | neutral       |
   289  | `error`   | failure       |
   290  
   291  There are two options to use this reporter.
   292  
   293  #### Option 1) Run reviewdog from GitHub Actions w/ secrets.GITHUB_TOKEN
   294  
   295  Example: [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml)
   296  
   297  ```yaml
   298  - name: Run reviewdog
   299    env:
   300      REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   301    run: |
   302      golint ./... | reviewdog -f=golint -reporter=github-pr-check
   303  ```
   304  
   305  See [GitHub Actions](#github-actions) section too. You can also use public
   306  reviewdog GitHub Actions.
   307  
   308  #### Option 2) Install reviewdog GitHub Apps
   309  reviewdog CLI send a request to reviewdog GitHub App server and the server post
   310  results as GitHub Checks, because Check API only supported for GitHub App and
   311  GitHub Actions.
   312  
   313  1. Install reviewdog Apps. https://github.com/apps/reviewdog
   314  2. Set `REVIEWDOG_TOKEN` or run reviewdog CLI in trusted CI providers.
   315    - Get token from `https://reviewdog.app/gh/{owner}/{repo-name}`.
   316  
   317  ```shell
   318  $ export REVIEWDOG_TOKEN="<token>"
   319  $ reviewdog -reporter=github-pr-check
   320  ```
   321  
   322  Note: Token is not required if you run reviewdog in Travis or AppVeyor.
   323  
   324  *Caution*
   325  
   326  As described above, github-pr-check reporter with Option 2 depends on
   327  reviewdog GitHub App server.
   328  The server is running with haya14busa's pocket money for now and I may break
   329  things, so I cannot ensure that the server is running 24h and 365 days.
   330  
   331  **UPDATE:** Started getting support by [opencollective](https://opencollective.com/reviewdog)
   332  and GitHub sponsor.
   333  See [Supporting reviewdog](#supporting-reviewdog)
   334  
   335  github-pr-check reporter is better than github-pr-review reporter in general
   336  because it provides more rich feature and has less scope, but please bear in
   337  mind the above caution and please use it on your own risk.
   338  
   339  You can use github-pr-review reporter if you don't want to depend on reviewdog
   340  server.
   341  
   342  ### Reporter: GitHub Checks (-reporter=github-check)
   343  
   344  It's basically same as `-reporter=github-pr-check` except it works not only for
   345  Pull Request but also for commit and it reports results outside Pull Request
   346  diff too.
   347  
   348  [![sample comment outside diff](https://user-images.githubusercontent.com/3797062/69917921-e0680580-14ae-11ea-9a56-de9e3cbac005.png)](https://github.com/reviewdog/reviewdog/pull/364/files)
   349  
   350  You can create [reviewdog badge](#reviewdog-badge-) for this reporter.
   351  
   352  ### Reporter: GitHub PullRequest review comment (-reporter=github-pr-review)
   353  
   354  [![sample-comment.png](https://raw.githubusercontent.com/haya14busa/i/dc0ccb1e110515ea407c146d99b749018db05c45/reviewdog/sample-comment.png)](https://github.com/reviewdog/reviewdog/pull/24#discussion_r84599728)
   355  
   356  github-pr-review reporter reports results to GitHub PullRequest review comments
   357  using GitHub Personal API Access Token.
   358  [GitHub Enterprise](https://enterprise.github.com/home) is supported too.
   359  
   360  - Go to https://github.com/settings/tokens and generate new API token.
   361  - Check `repo` for private repositories or `public_repo` for public repositories.
   362  
   363  ```shell
   364  $ export REVIEWDOG_GITHUB_API_TOKEN="<token>"
   365  $ reviewdog -reporter=github-pr-review
   366  ```
   367  
   368  For GitHub Enterprise, set API endpoint by environment variable.
   369  
   370  ```shell
   371  $ export GITHUB_API="https://example.githubenterprise.com/api/v3/"
   372  $ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL
   373  ```
   374  
   375  See [GitHub Actions](#github-actions) section too if you can use GitHub
   376  Actions. You can also use public reviewdog GitHub Actions.
   377  
   378  ### Reporter: GitLab MergeRequest discussions (-reporter=gitlab-mr-discussion)
   379  
   380  [![gitlab-mr-discussion sample](https://user-images.githubusercontent.com/3797062/41810718-f91bc540-773d-11e8-8598-fbc09ce9b1c7.png)](https://gitlab.com/haya14busa/reviewdog/merge_requests/113#note_83411103)
   381  
   382  Required GitLab version: >= v10.8.0
   383  
   384  gitlab-mr-discussion reporter reports results to GitLab MergeRequest discussions using
   385  GitLab Personal API Access token.
   386  Get the token with `api` scope from https://gitlab.com/profile/personal_access_tokens.
   387  
   388  ```shell
   389  $ export REVIEWDOG_GITLAB_API_TOKEN="<token>"
   390  $ reviewdog -reporter=gitlab-mr-discussion
   391  ```
   392  
   393  The `CI_API_V4_URL` environment variable, defined automatically by Gitlab CI (v11.7 onwards), will be used to find out the Gitlab API URL.
   394  
   395  Alternatively, `GITLAB_API` can also be defined, in which case it will take precedence over `CI_API_V4_URL`.
   396  
   397  ```shell
   398  $ export GITLAB_API="https://example.gitlab.com/api/v4"
   399  $ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL
   400  ```
   401  
   402  ### Reporter: GitLab MergeRequest commit (-reporter=gitlab-mr-commit)
   403  
   404  gitlab-mr-commit is similar to [gitlab-mr-discussion](#reporter-gitlab-mergerequest-discussions--reportergitlab-mr-discussion) reporter but reports results to each commit in GitLab MergeRequest.
   405  
   406  gitlab-mr-discussion is recommended, but you can use gitlab-mr-commit reporter
   407  if your GitLab version is under v10.8.0.
   408  
   409  ```shell
   410  $ export REVIEWDOG_GITLAB_API_TOKEN="<token>"
   411  $ reviewdog -reporter=gitlab-mr-commit
   412  ```
   413  
   414  ### Reporter: Gerrit Change review (-reporter=gerrit-change-review)
   415  
   416  gerrit-change-review reporter reports result to Gerrit Change using Gerrit Rest APIs.
   417  
   418  The reporter supports Basic Authentication and Git-cookie based authentication for reporting results.
   419  
   420  Set `GERRIT_USERNAME` and `GERRIT_PASSWORD` environment variables for basic authentication, and put `GIT_GITCOOKIE_PATH` for git cookie based authentication.
   421  
   422  ```shell
   423  $ export GERRIT_CHANGE_ID=changeID
   424  $ export GERRIT_REVISION_ID=revisionID
   425  $ export GERRIT_BRANCH=master
   426  $ export GERRIT_ADDRESS=http://<gerrit-host>:<gerrit-port>
   427  $ reviewdog -reporter=gerrit-change-review
   428  ```
   429  
   430  ## Supported CI services
   431  
   432  ### [GitHub Actions](https://github.com/features/actions)
   433  
   434  Example: [.github/workflows/reviewdog.yml](.github/workflows/reviewdog.yml)
   435  
   436  ```yaml
   437  name: reviewdog
   438  on: [pull_request]
   439  jobs:
   440    reviewdog:
   441      name: reviewdog
   442      runs-on: ubuntu-latest
   443      steps:
   444        # ...
   445        - name: Setup reviewdog
   446          run: |
   447            mkdir -p $HOME/bin && curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $HOME/bin
   448            echo ::add-path::$HOME/bin
   449            echo ::add-path::$(go env GOPATH)/bin # for Go projects
   450        - name: Run reviewdog
   451          env:
   452            REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   453          run: |
   454            reviewdog -reporter=github-pr-check -runners=golint,govet
   455            # or
   456            reviewdog -reporter=github-pr-review -runners=golint,govet
   457  ```
   458  
   459  <details>
   460  <summary><strong>Example (github-check reporter):</strong></summary>
   461  
   462  [.github/workflows/reviewdog](.github/workflows/reviewdog.yml)
   463  
   464  Only `github-check` reporter can run on push event too.
   465  
   466  ```yaml
   467  name: reviewdog (github-check)
   468  on:
   469    push:
   470      branches:
   471        - master
   472    pull_request:
   473  
   474  jobs:
   475    reviewdog:
   476      name: reviewdog
   477      runs-on: ubuntu-latest
   478      steps:
   479        # ...
   480        - name: Run reviewdog
   481          env:
   482            REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   483          run: |
   484            reviewdog -reporter=github-check -runners=golint,govet
   485  ```
   486  
   487  </details>
   488  
   489  #### Public Reviewdog GitHub Actions
   490  You can use public GitHub Actions to start using reviewdog with ease! :tada: :arrow_forward: :tada:
   491  
   492  - Common
   493    - [reviewdog/action-misspell](https://github.com/reviewdog/action-misspell) - Run [misspell](https://github.com/client9/misspell).
   494    - [tsuyoshicho/action-textlint](https://github.com/tsuyoshicho/action-textlint) - Run [textlint](https://github.com/textlint/textlint)
   495    - [tsuyoshicho/action-redpen](https://github.com/tsuyoshicho/action-redpen) - Run [redpen](https://github.com/redpen-cc/redpen)
   496    - [reviewdog/action-languagetool](https://github.com/reviewdog/action-languagetool) - Run [languagetool](https://github.com/languagetool-org/languagetool).
   497  - Docker
   498    - [reviewdog/action-hadolint](https://github.com/reviewdog/action-hadolint) - Run [hadolint](https://github.com/hadolint/hadolint) to lint `Dockerfile`.
   499  - Env
   500    - [mgrachev/action-dotenv-linter](https://github.com/mgrachev/action-dotenv-linter) - Run [dotenv-linter](https://github.com/mgrachev/dotenv-linter) to lint `.env` files.
   501  - Shell script
   502    - [reviewdog/action-shellcheck](https://github.com/reviewdog/action-shellcheck) - Run [shellcheck](https://github.com/koalaman/shellcheck).
   503  - Go
   504    - [reviewdog/action-staticcheck](https://github.com/reviewdog/action-staticcheck) - Run [staticcheck](https://staticcheck.io/).
   505    - [reviewdog/action-golangci-lint](https://github.com/reviewdog/action-golangci-lint) - Run [golangci-lint](https://github.com/golangci/golangci-lint) and supported linters individually by golangci-lint.
   506  - JavaScript
   507    - [reviewdog/action-eslint](https://github.com/reviewdog/action-eslint) - Run [eslint](https://github.com/eslint/eslint).
   508  - CSS
   509    - [reviewdog/action-stylelint](https://github.com/reviewdog/action-stylelint) - Run [stylelint](https://github.com/stylelint/stylelint).
   510  - Vim script
   511    - [reviewdog/action-vint](https://github.com/reviewdog/action-vint) - Run [vint](https://github.com/Kuniwak/vint).
   512    - [tsuyoshicho/action-vimlint](https://github.com/tsuyoshicho/action-vimlint) - Run [vim-vimlint](https://github.com/syngan/vim-vimlint)
   513  - Terraform
   514    - [reviewdog/action-tflint](https://github.com/reviewdog/action-tflint) - Run [tflint](https://github.com/wata727/tflint).
   515  - YAML
   516    - [reviewdog/action-yamllint](https://github.com/reviewdog/action-yamllint) - Run [yamllint](https://github.com/adrienverge/yamllint).
   517  - Ruby
   518    - [reviewdog/action-brakeman](https://github.com/reviewdog/action-brakeman) - Run [brakeman](https://github.com/presidentbeef/brakeman).
   519    - [reviewdog/action-reek](https://github.com/reviewdog/action-reek) - Run [reek](https://github.com/troessner/reek).
   520    - [reviewdog/action-rubocop](https://github.com/reviewdog/action-rubocop) - Run [rubocop](https://github.com/rubocop-hq/rubocop).
   521    - [vk26/action-fasterer](https://github.com/vk26/action-fasterer) - Run [fasterer](https://github.com/DamirSvrtan/fasterer).
   522    - [SennaLabs/action-standardrb](https://github.com/SennaLabs/action-standardrb) - Run [standardrb](https://github.com/testdouble/standard).
   523  
   524  - Python
   525    - [wemake-python-styleguide](https://github.com/wemake-services/wemake-python-styleguide) - Run wemake-python-styleguide
   526  - Kotlin
   527    - [ScaCap/action-ktlint](https://github.com/ScaCap/action-ktlint) - Run [ktlint](https://ktlint.github.io/).
   528    
   529  ... and more on [GitHub Marketplace](https://github.com/marketplace?utf8=✓&type=actions&query=reviewdog).
   530  
   531  Missing actions? Check out [reviewdog/action-template](https://github.com/reviewdog/action-template) and create a new reviewdog action!
   532  
   533  Please open a Pull Request to add your created reviewdog actions here :sparkles:.
   534  I can also put your repositories under reviewdog org and co-maintain the actions.
   535  Example: [action-tflint](https://github.com/reviewdog/reviewdog/issues/322).
   536  
   537  #### Graceful Degradation for Pull Requests from forked repositories
   538  
   539  ![Graceful Degradation example](https://user-images.githubusercontent.com/3797062/71781334-e2266b00-3010-11ea-8a38-dee6e30c8162.png)
   540  
   541  `GITHUB_TOKEN` for Pull Requests from forked repository doesn't have write
   542  access to Check API nor Review API due to [GitHub Actions
   543  restriction](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret).
   544  
   545  Instead, reviewdog uses [Logging commands of GitHub
   546  Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-error-message-error)
   547  to post results as
   548  [annotations](https://developer.github.com/v3/checks/runs/#annotations-object)
   549  similar to `github-pr-check` reporter.
   550  
   551  Note that there is a limitation for annotations created by logging commands,
   552  such as [max # of annotations per run](https://github.com/reviewdog/reviewdog/issues/411#issuecomment-570893427).
   553  You can check GitHub Actions log to see full results in such cases.
   554  
   555  #### reviewdog badge [![reviewdog](https://github.com/reviewdog/reviewdog/workflows/reviewdog/badge.svg?branch=master&event=push)](https://github.com/reviewdog/reviewdog/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amaster)
   556  
   557  As [`github-check` reporter](#reporter-github-checks--reportergithub-pr-check) support running on commit, we can create reviewdog
   558  [GitHub Action badge](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow#adding-a-workflow-status-badge-to-your-repository)
   559  to check the result against master commit for example. :tada:
   560  
   561  Example:
   562  ```
   563  <!-- Replace <OWNER> and <REPOSITORY>. It assumes workflow name is "reviewdog" -->
   564  [![reviewdog](https://github.com/<OWNER>/<REPOSITORY>/workflows/reviewdog/badge.svg?branch=master&event=push)](https://github.com/<OWNER>/<REPOSITORY>/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amaster)
   565  ```
   566  
   567  ### Travis CI
   568  
   569  #### Travis CI (-reporter=github-pr-check)
   570  
   571  If you use -reporter=github-pr-check in Travis CI, you don't need to set `REVIEWDOG_TOKEN`.
   572  
   573  Example:
   574  
   575  ```yaml
   576  install:
   577    - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH"
   578    - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin
   579  
   580  script:
   581    - reviewdog -conf=.reviewdog.yml -reporter=github-pr-check
   582  ```
   583  
   584  #### Travis CI (-reporter=github-pr-review)
   585  
   586  Store GitHub API token by [travis encryption keys](https://docs.travis-ci.com/user/encryption-keys/).
   587  
   588  ```shell
   589  $ gem install travis
   590  $ travis encrypt REVIEWDOG_GITHUB_API_TOKEN=<token> --add env.global
   591  ```
   592  Example:
   593  
   594  ```yaml
   595  env:
   596    global:
   597      - secure: <token>
   598  
   599  install:
   600    - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH"
   601    - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin
   602  
   603  script:
   604    - >-
   605      golint ./... | reviewdog -f=golint -reporter=github-pr-review
   606  ```
   607  
   608  Examples
   609  - https://github.com/azu/textlint-reviewdog-example
   610  
   611  ### Circle CI
   612  
   613  Store `REVIEWDOG_GITHUB_API_TOKEN` (or `REVIEWDOG_TOKEN` for github-pr-check) in
   614  [Environment variables - CircleCI](https://circleci.com/docs/environment-variables/#setting-environment-variables-for-all-commands-without-adding-them-to-git)
   615  
   616  #### .circleci/config.yml sample
   617  
   618  ```yaml
   619  version: 2
   620  jobs:
   621    build:
   622      docker:
   623        - image: golang:latest
   624      steps:
   625        - checkout
   626        - run: curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ./bin
   627        - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-review
   628  
   629        # Deprecated: prefer GitHub Actions to use github-pr-check reporter.
   630        - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-check
   631  ```
   632  
   633  ### GitLab CI
   634  
   635  Store `REVIEWDOG_GITLAB_API_TOKEN` in [GitLab CI variable](https://docs.gitlab.com/ee/ci/variables/#variables).
   636  
   637  #### .gitlab-ci.yml sample
   638  
   639  ```yaml
   640  reviewdog:
   641    script:
   642      - reviewdog -reporter=gitlab-mr-discussion
   643      # Or
   644      - reviewdog -reporter=gitlab-mr-commit
   645  ```
   646  
   647  ### Common (Jenkins, local, etc...)
   648  
   649  You can use reviewdog to post review comments from anywhere with following
   650  environment variables.
   651  
   652  | name | description |
   653  | ---- | ----------- |
   654  | `CI_PULL_REQUEST` | Pull Request number (e.g. 14) |
   655  | `CI_COMMIT`       | SHA1 for the current build |
   656  | `CI_REPO_OWNER`   | repository owner (e.g. "haya14busa" for https://github.com/haya14busa/reviewdog) |
   657  | `CI_REPO_NAME`    | repository name (e.g. "reviewdog" for https://github.com/haya14busa/reviewdog) |
   658  | `CI_BRANCH`       | [optional] branch of the commit |
   659  
   660  ```shell
   661  $ export CI_PULL_REQUEST=14
   662  $ export CI_REPO_OWNER=haya14busa
   663  $ export CI_REPO_NAME=reviewdog
   664  $ export CI_COMMIT=$(git rev-parse HEAD)
   665  ```
   666  and set a token if required.
   667  
   668  ```shell
   669  $ REVIEWDOG_TOKEN="<token>"
   670  $ REVIEWDOG_GITHUB_API_TOKEN="<token>"
   671  $ REVIEWDOG_GITLAB_API_TOKEN="<token>"
   672  ```
   673  
   674  If a CI service doesn't provide information such as Pull Request ID - reviewdog can guess it by branch name and commit SHA.
   675  Just pass the flag `guess`:
   676  
   677  ```shell
   678  $ reviewdog -conf=.reviewdog.yml -reporter=github-pr-check -guess
   679  ```
   680  
   681  #### Jenkins with Github pull request builder plugin
   682  - [GitHub pull request builder plugin - Jenkins - Jenkins Wiki](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin)
   683  
   684  ```shell
   685  $ export CI_PULL_REQUEST=${ghprbPullId}
   686  $ export CI_REPO_OWNER=haya14busa
   687  $ export CI_REPO_NAME=reviewdog
   688  $ export CI_COMMIT=${ghprbActualCommit}
   689  $ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need
   690  $ REVIEWDOG_TOKEN="<token>" reviewdog -reporter=github-pr-check
   691  # Or
   692  $ REVIEWDOG_GITHUB_API_TOKEN="<token>" reviewdog -reporter=github-pr-review
   693  ```
   694  
   695  ## Exit codes
   696  By default reviewdog will return `0` as exit code even if it finds errors.
   697  If `-fail-on-error` flag is passed, reviewdog exits with `1` when at least one error was found/reported.
   698  This can be helpful when you are using it as a step in your CI pipeline and want to mark the step failed if any error found by linter.
   699  
   700  See also `-level` flag for [github-pr-check/github-check](#reporter-github-checks--reportergithub-pr-check) reporters.
   701  reviewdog will exit with `1` if reported check status is `failure` as well if `-fail-on-error=true`.
   702  
   703  ## Filter mode
   704  reviewdog filter results by diff and you can control how reviewdog filter results by `-filter-mode` flag.
   705  Available filter modes are as below.
   706  
   707  ### `added` (default)
   708  Filter results by added/modified lines.
   709  ### `diff_context`
   710  Filter results by diff context. i.e. changed lines +-N lines (N=3 for example).
   711  ### `file`
   712  Filter results by added/modified file. i.e. reviewdog will report results as long as they are in added/modified file even if the results are not in actual diff.
   713  ### `nofilter`
   714  Do not filter any results. Useful for posting results as comments as much as possible and check other results in console at the same time.
   715  
   716  `-fail-on-error` also works with any filter-mode and can catch all results from any linters with `nofilter` mode.
   717  
   718  Example:
   719  ```shell
   720  $ reviewdog -reporter=github-pr-review -filter-mode=nofilter -fail-on-error
   721  ```
   722  
   723  ### Filter Mode Support Table
   724  Note that not all reporters provide full suppport of filter mode due to API limitation.
   725  e.g. `github-pr-review` reporter uses [GitHub Review
   726  API](https://developer.github.com/v3/pulls/reviews/) but it doesn't support posting comment outside diff (`diff_context`),
   727  so reviewdog will use [Check annotation](https://developer.github.com/v3/checks/runs/) as fallback to post those comments [1]. 
   728  
   729  | `-reporter` \ `-filter-mode` | `added` | `diff_context` | `file`                  | `nofilter` |
   730  | ---------------------------- | ------- | -------------- | ----------------------- | ---------- |
   731  | **`local`**                  | OK      | OK             | OK                      | OK |
   732  | **`github-check`**           | OK      | OK             | OK                      | OK |
   733  | **`github-pr-check`**        | OK      | OK             | OK                      | OK |
   734  | **`github-pr-review`**       | OK      | OK             | Partially Supported [1] | Partially Supported [1] |
   735  | **`gitlab-mr-discussion`**   | OK      | OK             | OK                      | Partially Supported [2] |
   736  | **`gitlab-mr-commit`**       | OK      | Partially Supported [2] | Partially Supported [2] | Partially Supported [2] |
   737  | **`gerrit-change-review`**   | OK      | OK? [3]        | OK? [3]                 | Partially Supported? [2][3] |
   738  
   739  - [1] Report results which is outside diff context with Check annotation as fallback if it's running in GitHub actions instead of Review API (comments). All results will be reported to console as well.
   740  - [2] Report results which is outside diff file to console.
   741  - [3] It should work, but not verified yet.
   742  
   743  ## Articles
   744  - [reviewdog — A code review dog who keeps your codebase healthy ](https://medium.com/@haya14busa/reviewdog-a-code-review-dog-who-keeps-your-codebase-healthy-d957c471938b)
   745  - [reviewdog ♡ GitHub Check — improved automated review experience](https://medium.com/@haya14busa/reviewdog-github-check-improved-automated-review-experience-58f89e0c95f3)
   746  - [Automated Code Review on GitHub Actions with reviewdog for any languages/tools](https://medium.com/@haya14busa/automated-code-review-on-github-actions-with-reviewdog-for-any-languages-tools-20285e04448e)
   747  
   748  ## :bird: Author
   749  haya14busa [![GitHub followers](https://img.shields.io/github/followers/haya14busa.svg?style=social&label=Follow)](https://github.com/haya14busa)
   750  
   751  ## Contributors
   752  
   753  [![Contributors](https://opencollective.com/reviewdog/contributors.svg?width=890)](https://github.com/reviewdog/reviewdog/graphs/contributors)
   754  
   755  ### Supporting reviewdog
   756  
   757  Become GitHub Sponsor for [each contributor](https://github.com/reviewdog/reviewdog/graphs/contributors)
   758  or become a backer or sponsor from [opencollective](https://opencollective.com/reviewdog).
   759  
   760  [![Become a backer](https://opencollective.com/reviewdog/tiers/backer.svg?avatarHeight=64)](https://opencollective.com/reviewdog#backers)