revgrep

package module
v0.0.0-...-c04006d Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2017 License: Apache-2.0 Imports: 11 Imported by: 2

README

Overview

Build Status Coverage Status GoDoc

revgrep is a CLI tool used to filter static analysis tools to only lines changed based on a commit reference.

Install

go get -u github.com/bradleyfalzon/revgrep/...

Usage

In the scenario below, a change was made causing a warning in go vet on line 5, but go vet will show all warnings. Using revgrep, you can show only warnings for lines of code that have been changed (in this case, hiding line 6).

[user@host dir (master)]$ go vet
main.go:5: missing argument for Sprintf("%s"): format reads arg 1, have only 0 args
main.go:6: missing argument for Sprintf("%s"): format reads arg 1, have only 0 args
[user@host dir (master)]$ go vet |& revgrep
main.go:5: missing argument for Sprintf("%s"): format reads arg 1, have only 0 args

|& is shown above as many static analysis programs write to stderr, not stdout, |& combines both stderr and stdout. It could also be achieved with go vet 2>&1 | revgrep.

revgrep CLI tool will return an exit status of 1 if any issues match, else it will return 0. Consider using ${PIPESTATUS[0]} for the exit status of the go vet command in the above example.

Usage: revgrep [options] [from-rev] [to-rev]

from-rev filters issues to lines changed since (and including) this revision
  to-rev filters issues to lines changed since (and including) this revision, requires <from-rev>

  If no revisions are given, and there are unstaged changes or untracked files, only those changes are shown
  If no revisions are given, and there are no unstaged changes or untracked files, only changes in HEAD~ are shown
  If from-rev is given and to-rev is not, only changes between from-rev and HEAD are shown.

    -d    Show debug output
      -regexp string
              Regexp to match path, line number, optional column number, and message

Other Examples

Issues between branches:

[user@host dir (feature/branch)]$ go vet |& revgrep master

Issues since last push:

[user@host dir (master)]$ go vet |& revgrep origin/master

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitPatch

func GitPatch(revisionFrom, revisionTo string) (io.Reader, []string, error)

GitPatch returns a patch from a git repository, if no git repository was was found and no errors occurred, nil is returned, else an error is returned revisionFrom and revisionTo defines the git diff parameters, if left blank and there are unstaged changes or untracked files, only those will be returned else only check changes since HEAD~. If revisionFrom is set but revisionTo is not, untracked files will be included, to exclude untracked files set revisionTo to HEAD~. It's incorrect to specify revisionTo without a revisionFrom.

Types

type Checker

type Checker struct {
	// Patch file (unified) to read to detect lines being changed, if nil revgrep
	// will attempt to detect the VCS and generate an appropriate patch. Auto
	// detection will search for uncommitted changes first, if none found, will
	// generate a patch from last committed change. File paths within patches
	// must be relative to current working directory.
	Patch io.Reader
	// NewFiles is a list of file names (with absolute paths) where the entire
	// contents of the file is new.
	NewFiles []string
	// Debug sets the debug writer for additional output.
	Debug io.Writer
	// RevisionFrom check revision starting at, leave blank for auto detection
	// ignored if patch is set.
	RevisionFrom string
	// RevisionTo checks revision finishing at, leave blank for auto detection
	// ignored if patch is set.
	RevisionTo string
	// Regexp to match path, line number, optional column number, and message.
	Regexp string
	// AbsPath is used to make an absolute path of an issue's filename to be
	// relative in order to match patch file. If not set, current working
	// directory is used.
	AbsPath string
}

Checker provides APIs to filter static analysis tools to specific commits, such as showing only issues since last commit.

func (Checker) Check

func (c Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err error)

Check scans reader and writes any lines to writer that have been added in Checker.Patch.

Returns issues written to writer when no error occurs.

If no VCS could be found or other VCS errors occur, all issues are written to writer and an error is returned.

File paths in reader must be relative to current working directory or absolute.

type Issue

type Issue struct {
	// File is the name of the file as it appeared from the patch.
	File string
	// LineNo is the line number of the file.
	LineNo int
	// ColNo is the column number or 0 if none could be parsed.
	ColNo int
	// HunkPos is position from file's first @@, for new files this will be the
	// line number.
	//
	// See also: https://developer.github.com/v3/pulls/comments/#create-a-comment
	HunkPos int
	// Issue text as it appeared from the tool.
	Issue string
	// Message is the issue without file name, line number and column number.
	Message string
}

Issue contains metadata about an issue found.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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