reviewdog

package module
v0.10.1-0...-928943b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2020 License: MIT Imports: 15 Imported by: 0

README ΒΆ

reviewdog - A code review dog who keeps your codebase healthy.


reviewdog provides a way to post review comments to code hosting service, such as GitHub, automatically by integrating with any linter tools with ease. It uses an output of lint tools and posts them as a comment if findings are in diff of patches to review.

reviewdog also supports run in the local environment to filter an output of lint tools by diff.

design doc

Table of Contents

github-pr-check sample comment in pull-request commit status sample-comment.png reviewdog-local-demo.gif

Installation

# Install the latest version. (Install it into ./bin/ by default).
$ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s

# Specify installation directory ($(go env GOPATH)/bin/) and version.
$ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $(go env GOPATH)/bin [vX.Y.Z]

# In alpine linux (as it does not come with curl by default)
$ wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s [vX.Y.Z]

Nightly releases

You can also use nightly reviewdog release to try the latest reviewdog improvements every day!

$ curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $(go env GOPATH)/bin

Build from HEAD with go get

$ go get -u github.com/reviewdog/reviewdog/cmd/reviewdog

homebrew / linuxbrew

You can also install reviewdog using brew:

$ brew install reviewdog/tap/reviewdog
$ brew upgrade reviewdog/tap/reviewdog

Input Format

'errorformat'

reviewdog accepts any compiler or linter result from stdin and parses it with scan-f like 'errorformat', which is the port of Vim's errorformat feature.

For example, if the result format is {file}:{line number}:{column number}: {message}, errorformat should be %f:%l:%c: %m and you can pass it as -efm arguments.

$ golint ./...
comment_iowriter.go:11:6: exported type CommentWriter should have comment or be unexported
$ golint ./... | reviewdog -efm="%f:%l:%c: %m" -diff="git diff master"
name description
%f file name
%l line number
%c column number
%m error message
%% the single '%' character
... ...

Please see reviewdog/errorformat and :h errorformat if you want to deal with a more complex output. 'errorformat' can handle more complex output like a multi-line error message.

You can also try errorformat on the Playground!

By this 'errorformat' feature, reviewdog can support any tools output with ease.

Available pre-defined 'errorformat'

But, you don't have to write 'errorformat' in many cases. reviewdog supports pre-defined errorformat for major tools.

You can find available errorformat name by reviewdog -list and you can use it with -f={name}.

$ reviewdog -list
golint          linter for Go source code                                       - https://github.com/golang/lint
govet           Vet examines Go source code and reports suspicious problems     - https://golang.org/cmd/vet/
sbt             the interactive build tool                                      - http://www.scala-sbt.org/
...
$ golint ./... | reviewdog -f=golint -diff="git diff master"

You can add supported pre-defined 'errorformat' by contributing to reviewdog/errorformat

checkstyle format

reviewdog also accepts checkstyle XML format as well. If the linter supports checkstyle format as a report format, you can use -f=checkstyle instead of using 'errorformat'.

# Local
$ eslint -f checkstyle . | reviewdog -f=checkstyle -diff="git diff"

# CI (overwrite tool name which is shown in review comment by -name arg)
$ eslint -f checkstyle . | reviewdog -f=checkstyle -name="eslint" -reporter=github-pr-check

Also, if you want to pass other Json/XML/etc... format to reviewdog, you can write a converter.

$ <linter> | <convert-to-checkstyle> | reviewdog -f=checkstyle -name="<linter>" -reporter=github-pr-check

reviewdog config file

reviewdog can also be controlled via the .reviewdog.yml configuration file instead of "-f" or "-efm" arguments.

With .reviewdog.yml, you can run the same commands both CI service and local environment including editor integration with ease.

.reviewdog.yml
runner:
  <tool-name>:
    cmd: <command> # (required)
    errorformat: # (optional if there is supported format for <tool-name>. see reviewdog -list)
      - <list of errorformat>
    name: <tool-name> # (optional. you can overwrite <tool-name> defined by runner key)
    level: <level> # (optional. same as -level flag. [info,warning,error])

  # examples
  golint:
    cmd: golint ./...
    errorformat:
      - "%f:%l:%c: %m"
    level: warning
  govet:
    cmd: go vet -all .
$ reviewdog -diff="git diff master"
project/run_test.go:61:28: [golint] error strings should not end with punctuation
project/run.go:57:18: [errcheck]        defer os.Setenv(name, os.Getenv(name))
project/run.go:58:12: [errcheck]        os.Setenv(name, "")
# You can use -runners to run only specified runners.
$ reviewdog -diff="git diff master" -runners=golint,govet
project/run_test.go:61:28: [golint] error strings should not end with punctuation
# You can use -conf to specify config file path.
$ reviewdog -conf=./.reviewdog.yml -reporter=github-pr-check

Output format for project config based run is one of the following formats.

  • <file>: [<tool name>] <message>
  • <file>:<lnum>: [<tool name>] <message>
  • <file>:<lnum>:<col>: [<tool name>] <message>

Reporters

reviewdog can report results both in local environment and review services as continuous integration.

Reporter: Local (-reporter=local) [default]

reviewdog can find newly introduced findings by filtering linter results using diff. You can pass diff command as -diff arg.

$ golint ./... | reviewdog -f=golint -diff="git diff master"

Reporter: GitHub Checks (-reporter=github-pr-check)

github-pr-check sample annotation with option 1 github-pr-check sample

github-pr-check reporter reports results to GitHub Checks.

You can change report level for this reporter by level field in config file or -level flag. You can control GitHub status check result with this feature. (default: error)

Level GitHub Status
info neutral
warning neutral
error failure

There are two options to use this reporter.

Option 1) Run reviewdog from GitHub Actions w/ secrets.GITHUB_TOKEN

Example: .github/workflows/reviewdog.yml

- name: Run reviewdog
  env:
    REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    golint ./... | reviewdog -f=golint -reporter=github-pr-check

See GitHub Actions section too. You can also use public reviewdog GitHub Actions.

Option 2) Install reviewdog GitHub Apps

reviewdog CLI send a request to reviewdog GitHub App server and the server post results as GitHub Checks, because Check API only supported for GitHub App and GitHub Actions.

  1. Install reviewdog Apps. https://github.com/apps/reviewdog
  2. Set REVIEWDOG_TOKEN or run reviewdog CLI in trusted CI providers.
  • Get token from https://reviewdog.app/gh/{owner}/{repo-name}.
$ export REVIEWDOG_TOKEN="<token>"
$ reviewdog -reporter=github-pr-check

Note: Token is not required if you run reviewdog in Travis or AppVeyor.

Caution

As described above, github-pr-check reporter with Option 2 depends on reviewdog GitHub App server. The server is running with haya14busa's pocket money for now and I may break things, so I cannot ensure that the server is running 24h and 365 days.

UPDATE: Started getting support by opencollective and GitHub sponsor. See Supporting reviewdog

github-pr-check reporter is better than github-pr-review reporter in general because it provides more rich feature and has less scope, but please bear in mind the above caution and please use it on your own risk.

You can use github-pr-review reporter if you don't want to depend on reviewdog server.

Reporter: GitHub Checks (-reporter=github-check)

It's basically same as -reporter=github-pr-check except it works not only for Pull Request but also for commit and it reports results outside Pull Request diff too.

sample comment outside diff

You can create reviewdog badge for this reporter.

Reporter: GitHub PullRequest review comment (-reporter=github-pr-review)

sample-comment.png

github-pr-review reporter reports results to GitHub PullRequest review comments using GitHub Personal API Access Token. GitHub Enterprise is supported too.

$ export REVIEWDOG_GITHUB_API_TOKEN="<token>"
$ reviewdog -reporter=github-pr-review

For GitHub Enterprise, set API endpoint by environment variable.

$ export GITHUB_API="https://example.githubenterprise.com/api/v3/"
$ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL

See GitHub Actions section too if you can use GitHub Actions. You can also use public reviewdog GitHub Actions.

Reporter: GitLab MergeRequest discussions (-reporter=gitlab-mr-discussion)

gitlab-mr-discussion sample

Required GitLab version: >= v10.8.0

gitlab-mr-discussion reporter reports results to GitLab MergeRequest discussions using GitLab Personal API Access token. Get the token with api scope from https://gitlab.com/profile/personal_access_tokens.

$ export REVIEWDOG_GITLAB_API_TOKEN="<token>"
$ reviewdog -reporter=gitlab-mr-discussion

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.

Alternatively, GITLAB_API can also be defined, in which case it will take precedence over CI_API_V4_URL.

$ export GITLAB_API="https://example.gitlab.com/api/v4"
$ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need to skip verifying SSL

Reporter: GitLab MergeRequest commit (-reporter=gitlab-mr-commit)

gitlab-mr-commit is similar to gitlab-mr-discussion reporter but reports results to each commit in GitLab MergeRequest.

gitlab-mr-discussion is recommended, but you can use gitlab-mr-commit reporter if your GitLab version is under v10.8.0.

$ export REVIEWDOG_GITLAB_API_TOKEN="<token>"
$ reviewdog -reporter=gitlab-mr-commit

Reporter: Gerrit Change review (-reporter=gerrit-change-review)

gerrit-change-review reporter reports result to Gerrit Change using Gerrit Rest APIs.

The reporter supports Basic Authentication and Git-cookie based authentication for reporting results.

Set GERRIT_USERNAME and GERRIT_PASSWORD environment variables for basic authentication, and put GIT_GITCOOKIE_PATH for git cookie based authentication.

$ export GERRIT_CHANGE_ID=changeID
$ export GERRIT_REVISION_ID=revisionID
$ export GERRIT_BRANCH=master
$ export GERRIT_ADDRESS=http://<gerrit-host>:<gerrit-port>
$ reviewdog -reporter=gerrit-change-review

Supported CI services

GitHub Actions

Example: .github/workflows/reviewdog.yml

name: reviewdog
on: [pull_request]
jobs:
  reviewdog:
    name: reviewdog
    runs-on: ubuntu-latest
    steps:
      # ...
      - name: Setup reviewdog
        run: |
          mkdir -p $HOME/bin && curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $HOME/bin
          echo ::add-path::$HOME/bin
          echo ::add-path::$(go env GOPATH)/bin # for Go projects
      - name: Run reviewdog
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          reviewdog -reporter=github-pr-check -runners=golint,govet
          # or
          reviewdog -reporter=github-pr-review -runners=golint,govet
Example (github-check reporter):

.github/workflows/reviewdog

Only github-check reporter can run on push event too.

name: reviewdog (github-check)
on:
  push:
    branches:
      - master
  pull_request:

jobs:
  reviewdog:
    name: reviewdog
    runs-on: ubuntu-latest
    steps:
      # ...
      - name: Run reviewdog
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          reviewdog -reporter=github-check -runners=golint,govet
Public Reviewdog GitHub Actions

You can use public GitHub Actions to start using reviewdog with ease! πŸŽ‰ β–Ά πŸŽ‰

... and more on GitHub Marketplace.

Missing actions? Check out reviewdog/action-template and create a new reviewdog action!

Please open a Pull Request to add your created reviewdog actions here ✨. I can also put your repositories under reviewdog org and co-maintain the actions. Example: action-tflint.

Graceful Degradation for Pull Requests from forked repositories

Graceful Degradation example

GITHUB_TOKEN for Pull Requests from forked repository doesn't have write access to Check API nor Review API due to GitHub Actions restriction.

Instead, reviewdog uses Logging commands of GitHub Actions to post results as annotations similar to github-pr-check reporter.

Note that there is a limitation for annotations created by logging commands, such as max # of annotations per run. You can check GitHub Actions log to see full results in such cases.

reviewdog badge reviewdog

As github-check reporter support running on commit, we can create reviewdog GitHub Action badge to check the result against master commit for example. πŸŽ‰

Example:

<!-- Replace <OWNER> and <REPOSITORY>. It assumes workflow name is "reviewdog" -->
[![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)

Travis CI

Travis CI (-reporter=github-pr-check)

If you use -reporter=github-pr-check in Travis CI, you don't need to set REVIEWDOG_TOKEN.

Example:

install:
  - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH"
  - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin

script:
  - reviewdog -conf=.reviewdog.yml -reporter=github-pr-check
Travis CI (-reporter=github-pr-review)

Store GitHub API token by travis encryption keys.

$ gem install travis
$ travis encrypt REVIEWDOG_GITHUB_API_TOKEN=<token> --add env.global

Example:

env:
  global:
    - secure: <token>

install:
  - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH"
  - curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ~/bin

script:
  - >-
    golint ./... | reviewdog -f=golint -reporter=github-pr-review

Examples

Circle CI

Store REVIEWDOG_GITHUB_API_TOKEN (or REVIEWDOG_TOKEN for github-pr-check) in Environment variables - CircleCI

.circleci/config.yml sample
version: 2
jobs:
  build:
    docker:
      - image: golang:latest
    steps:
      - checkout
      - run: curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b ./bin
      - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-review

      # Deprecated: prefer GitHub Actions to use github-pr-check reporter.
      - run: go vet ./... 2>&1 | ./bin/reviewdog -f=govet -reporter=github-pr-check

GitLab CI

Store REVIEWDOG_GITLAB_API_TOKEN in GitLab CI variable.

.gitlab-ci.yml sample
reviewdog:
  script:
    - reviewdog -reporter=gitlab-mr-discussion
    # Or
    - reviewdog -reporter=gitlab-mr-commit

Common (Jenkins, local, etc...)

You can use reviewdog to post review comments from anywhere with following environment variables.

name description
CI_PULL_REQUEST Pull Request number (e.g. 14)
CI_COMMIT SHA1 for the current build
CI_REPO_OWNER repository owner (e.g. "haya14busa" for https://github.com/haya14busa/reviewdog)
CI_REPO_NAME repository name (e.g. "reviewdog" for https://github.com/haya14busa/reviewdog)
CI_BRANCH [optional] branch of the commit
$ export CI_PULL_REQUEST=14
$ export CI_REPO_OWNER=haya14busa
$ export CI_REPO_NAME=reviewdog
$ export CI_COMMIT=$(git rev-parse HEAD)

and set a token if required.

$ REVIEWDOG_TOKEN="<token>"
$ REVIEWDOG_GITHUB_API_TOKEN="<token>"
$ REVIEWDOG_GITLAB_API_TOKEN="<token>"

If a CI service doesn't provide information such as Pull Request ID - reviewdog can guess it by branch name and commit SHA. Just pass the flag guess:

$ reviewdog -conf=.reviewdog.yml -reporter=github-pr-check -guess
Jenkins with Github pull request builder plugin
$ export CI_PULL_REQUEST=${ghprbPullId}
$ export CI_REPO_OWNER=haya14busa
$ export CI_REPO_NAME=reviewdog
$ export CI_COMMIT=${ghprbActualCommit}
$ export REVIEWDOG_INSECURE_SKIP_VERIFY=true # set this as you need
$ REVIEWDOG_TOKEN="<token>" reviewdog -reporter=github-pr-check
# Or
$ REVIEWDOG_GITHUB_API_TOKEN="<token>" reviewdog -reporter=github-pr-review

Exit codes

By default reviewdog will return 0 as exit code even if it finds errors. If -fail-on-error flag is passed, reviewdog exits with 1 when at least one error was found/reported. 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.

See also -level flag for github-pr-check/github-check reporters. reviewdog will exit with 1 if reported check status is failure as well if -fail-on-error=true.

Filter mode

reviewdog filter results by diff and you can control how reviewdog filter results by -filter-mode flag. Available filter modes are as below.

added (default)

Filter results by added/modified lines.

diff_context

Filter results by diff context. i.e. changed lines +-N lines (N=3 for example).

file

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.

nofilter

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.

-fail-on-error also works with any filter-mode and can catch all results from any linters with nofilter mode.

Example:

$ reviewdog -reporter=github-pr-review -filter-mode=nofilter -fail-on-error

Filter Mode Support Table

Note that not all reporters provide full suppport of filter mode due to API limitation. e.g. github-pr-review reporter uses GitHub Review API but it doesn't support posting comment outside diff (diff_context), so reviewdog will use Check annotation as fallback to post those comments [1].

-reporter \ -filter-mode added diff_context file nofilter
local OK OK OK OK
github-check OK OK OK OK
github-pr-check OK OK OK OK
github-pr-review OK OK Partially Supported [1] Partially Supported [1]
gitlab-mr-discussion OK OK OK Partially Supported [2]
gitlab-mr-commit OK Partially Supported [2] Partially Supported [2] Partially Supported [2]
gerrit-change-review OK OK? [3] OK? [3] Partially Supported? [2][3]
  • [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.
  • [2] Report results which is outside diff file to console.
  • [3] It should work, but not verified yet.

Articles

🐦 Author

haya14busa GitHub followers

Contributors

Contributors

Supporting reviewdog

Become GitHub Sponsor for each contributor or become a backer or sponsor from opencollective.

Become a backer

Documentation ΒΆ

Index ΒΆ

Examples ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func CleanPath ΒΆ

func CleanPath(path, workdir string) string

CleanPath clean up given path. If workdir is not empty, it returns relative path to the given workdir.

func RunFromResult ΒΆ

func RunFromResult(ctx context.Context, c CommentService, results []*CheckResult,
	filediffs []*diff.FileDiff, strip int, toolname string, filterMode difffilter.Mode, failOnError bool) error

RunFromResult creates a new Reviewdog and runs it with check results.

Types ΒΆ

type BulkCommentService ΒΆ

type BulkCommentService interface {
	CommentService
	Flush(context.Context) error
}

BulkCommentService posts comments all at once when Flush() is called. Flush() will be called at the end of reviewdog run.

type CheckResult ΒΆ

type CheckResult struct {
	Path    string   // relative file path
	Lnum    int      // line number
	Col     int      // column number (1 <tab> == 1 character column)
	Message string   // error message
	Lines   []string // Original error lines (often one line)
}

CheckResult represents a checked result of static analysis tools. :h error-file-format

type CheckStyleError ΒΆ

type CheckStyleError struct {
	Column   int    `xml:"column,attr,omitempty"`
	Line     int    `xml:"line,attr"`
	Message  string `xml:"message,attr"`
	Severity string `xml:"severity,attr,omitempty"`
	Source   string `xml:"source,attr,omitempty"`
}

CheckStyleError represents <error line="1" column="10" severity="error" message="msg" source="src" />

type CheckStyleFile ΒΆ

type CheckStyleFile struct {
	Name   string             `xml:"name,attr"`
	Errors []*CheckStyleError `xml:"error"`
}

CheckStyleFile represents <file name="fname"><error ... />...</file>

type CheckStyleParser ΒΆ

type CheckStyleParser struct{}

CheckStyleParser is checkstyle parser.

func (*CheckStyleParser) Parse ΒΆ

func (p *CheckStyleParser) Parse(r io.Reader) ([]*CheckResult, error)

type CheckStyleResult ΒΆ

type CheckStyleResult struct {
	XMLName xml.Name          `xml:"checkstyle"`
	Version string            `xml:"version,attr"`
	Files   []*CheckStyleFile `xml:"file,omitempty"`
}

CheckStyleResult represents checkstyle XML result. <?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"><file ...></file>...</checkstyle>

References:

type Comment ΒΆ

type Comment struct {
	Result   *FilteredCheck
	ToolName string
	Body     string
}

Comment represents a reported result as a comment.

type CommentService ΒΆ

type CommentService interface {
	Post(context.Context, *Comment) error
}

CommentService is an interface which posts Comment.

func MultiCommentService ΒΆ

func MultiCommentService(services ...CommentService) CommentService

MultiCommentService creates a comment service that duplicates its post to all the provided comment services.

type DiffCmd ΒΆ

type DiffCmd struct {
	// contains filtered or unexported fields
}

func NewDiffCmd ΒΆ

func NewDiffCmd(cmd *exec.Cmd, strip int) *DiffCmd

func (*DiffCmd) Diff ΒΆ

func (d *DiffCmd) Diff(_ context.Context) ([]byte, error)

Diff returns diff. It caches the result and can be used more than once.

func (*DiffCmd) Strip ΒΆ

func (d *DiffCmd) Strip() int

type DiffService ΒΆ

type DiffService interface {
	Diff(context.Context) ([]byte, error)
	Strip() int
}

DiffService is an interface which get diff.

func NewDiffString ΒΆ

func NewDiffString(diff string, strip int) DiffService

type DiffString ΒΆ

type DiffString struct {
	// contains filtered or unexported fields
}

func (*DiffString) Diff ΒΆ

func (d *DiffString) Diff(_ context.Context) ([]byte, error)

func (*DiffString) Strip ΒΆ

func (d *DiffString) Strip() int

type EmptyDiff ΒΆ

type EmptyDiff struct{}

EmptyDiff service return empty diff.

func (*EmptyDiff) Diff ΒΆ

func (*EmptyDiff) Diff(context.Context) ([]byte, error)

func (*EmptyDiff) Strip ΒΆ

func (*EmptyDiff) Strip() int

type ErrorformatParser ΒΆ

type ErrorformatParser struct {
	// contains filtered or unexported fields
}

ErrorformatParser is errorformat parser.

func NewErrorformatParser ΒΆ

func NewErrorformatParser(efm *errorformat.Errorformat) *ErrorformatParser

NewErrorformatParser returns a new ErrorformatParser.

func NewErrorformatParserString ΒΆ

func NewErrorformatParserString(efms []string) (*ErrorformatParser, error)

NewErrorformatParserString returns a new ErrorformatParser from errorformat in string representation.

func (*ErrorformatParser) Parse ΒΆ

func (p *ErrorformatParser) Parse(r io.Reader) ([]*CheckResult, error)

type FilteredCheck ΒΆ

type FilteredCheck struct {
	*CheckResult
	ShouldReport bool
	LnumDiff     int  // 0 if the result is outside diff.
	InDiffFile   bool // false if the result is outside diff files.
	OldPath      string
	OldLine      int
}

FilteredCheck represents CheckResult with filtering info.

func FilterCheck ΒΆ

func FilterCheck(results []*CheckResult, diff []*diff.FileDiff, strip int,
	cwd string, mode difffilter.Mode) []*FilteredCheck

FilterCheck filters check results by diff. It doesn't drop check which is not in diff but set FilteredCheck.ShouldReport field false.

type FilteredResult ΒΆ

type FilteredResult struct {
	Level         string
	FilteredCheck []*FilteredCheck
}

type FilteredResultMap ΒΆ

type FilteredResultMap struct {
	// contains filtered or unexported fields
}

FilteredResultMap represents a concurrent-safe map to store CheckResults generated by concurrent jobs.

func (*FilteredResultMap) Len ΒΆ

func (rm *FilteredResultMap) Len() int

Len returns the length of FilteredResultMap count. Len() is not yet officially not supported by Go. (ref: https://github.com/golang/go/issues/20680)

func (*FilteredResultMap) Load ΒΆ

func (rm *FilteredResultMap) Load(key string) (*FilteredResult, error)

Load fetches FilteredResult from FilteredResultMap

func (*FilteredResultMap) Range ΒΆ

func (rm *FilteredResultMap) Range(f func(key string, val *FilteredResult))

Range retrieves `key` and `values` from FilteredResultMap iteratively.

func (*FilteredResultMap) Store ΒΆ

func (rm *FilteredResultMap) Store(key string, r *FilteredResult)

Store saves a new []*FilteredCheckFilteredResult into FilteredResultMap.

type Parser ΒΆ

type Parser interface {
	Parse(r io.Reader) ([]*CheckResult, error)
}

Parser is an interface which parses compilers, linters, or any tools results.

func NewCheckStyleParser ΒΆ

func NewCheckStyleParser() Parser

NewCheckStyleParser returns a new CheckStyleParser.

func NewParser ΒΆ

func NewParser(opt *ParserOpt) (Parser, error)

NewParser returns Parser based on ParserOpt.

type ParserOpt ΒΆ

type ParserOpt struct {
	FormatName  string
	Errorformat []string
}

ParserOpt represents option to create Parser. Either FormatName or Errorformat should be specified.

type RawCommentWriter ΒΆ

type RawCommentWriter struct {
	// contains filtered or unexported fields
}

RawCommentWriter is comment writer which writes results to given writer without any formatting.

func NewRawCommentWriter ΒΆ

func NewRawCommentWriter(w io.Writer) *RawCommentWriter

func (*RawCommentWriter) Post ΒΆ

func (s *RawCommentWriter) Post(_ context.Context, c *Comment) error

type Result ΒΆ

type Result struct {
	Level        string
	CheckResults []*CheckResult

	// Optional. Report an error of the command execution.
	CmdErr error
}

type ResultMap ΒΆ

type ResultMap struct {
	// contains filtered or unexported fields
}

ResultMap represents a concurrent-safe map to store CheckResults generated by concurrent jobs.

func (*ResultMap) Len ΒΆ

func (rm *ResultMap) Len() int

Len returns the length of ResultMap count. Len() is not yet officially not supported by Go. (ref: https://github.com/golang/go/issues/20680)

func (*ResultMap) Load ΒΆ

func (rm *ResultMap) Load(key string) (*Result, error)

Load fetches *Result from ResultMap

func (*ResultMap) Range ΒΆ

func (rm *ResultMap) Range(f func(key string, val *Result))

Range retrieves `key` and `values` from ResultMap iteratively.

func (*ResultMap) Store ΒΆ

func (rm *ResultMap) Store(key string, r *Result)

Store saves a new *Result into ResultMap.

type Reviewdog ΒΆ

type Reviewdog struct {
	// contains filtered or unexported fields
}

Reviewdog represents review dog application which parses result of compiler or linter, get diff and filter the results by diff, and report filtered results.

Example ΒΆ
difftext := `diff --git a/golint.old.go b/golint.new.go
index 34cacb9..a727dd3 100644
--- a/golint.old.go
+++ b/golint.new.go
@@ -2,6 +2,12 @@ package test
 
 var V int
 
+var NewError1 int
+
 // invalid func comment
 func F() {
 }
+
+// invalid func comment2
+func F2() {
+}
`
lintresult := `golint.new.go:3:5: exported var V should have comment or be unexported
golint.new.go:5:5: exported var NewError1 should have comment or be unexported
golint.new.go:7:1: comment on exported function F should be of the form "F ..."
golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..."
`
efm, _ := errorformat.NewErrorformat([]string{`%f:%l:%c: %m`})
p := NewErrorformatParser(efm)
c := NewRawCommentWriter(os.Stdout)
d := NewDiffString(difftext, 1)
app := NewReviewdog("tool name", p, c, d, difffilter.ModeAdded, false)
app.Run(context.Background(), strings.NewReader(lintresult))
Output:

golint.new.go:5:5: exported var NewError1 should have comment or be unexported
golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..."

func NewReviewdog ΒΆ

func NewReviewdog(toolname string, p Parser, c CommentService, d DiffService, filterMode difffilter.Mode, failOnError bool) *Reviewdog

NewReviewdog returns a new Reviewdog.

func (*Reviewdog) Run ΒΆ

func (w *Reviewdog) Run(ctx context.Context, r io.Reader) error

Run runs Reviewdog application.

type UnifiedCommentWriter ΒΆ

type UnifiedCommentWriter struct {
	// contains filtered or unexported fields
}

UnifiedCommentWriter is comment writer which writes results to given writer in one of following unified formats.

Format:

  • <file>: [<tool name>] <message>
  • <file>:<lnum>: [<tool name>] <message>
  • <file>:<lnum>:<col>: [<tool name>] <message>

where <message> can be multiple lines.

func NewUnifiedCommentWriter ΒΆ

func NewUnifiedCommentWriter(w io.Writer) *UnifiedCommentWriter

func (*UnifiedCommentWriter) Post ΒΆ

Directories ΒΆ

Path Synopsis
Package cienv provides utility for environment variable in CI services.
Package cienv provides utility for environment variable in CI services.
cmd
Package diff provides a utility to parse unified diff.
Package diff provides a utility to parse unified diff.
appengine/statik
Package statik contains static assets.
Package statik contains static assets.
Package project provides utility for reviewdog execution based on project config.
Package project provides utility for reviewdog execution based on project config.
service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL