Documentation ¶
Overview ¶
Package revgrep filter static analysis tools to only lines changed based on a commit reference.
Index ¶
- func GitPatch(ctx context.Context, revisionFrom, revisionTo string) (io.Reader, []string, error)
- type Checker
- func (c *Checker) Check(ctx context.Context, reader io.Reader, writer io.Writer) (issues []Issue, err error)
- func (c *Checker) IsNew(filePath string, line int) (hunkPos int, isNew bool)
- func (c *Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool)
- func (c *Checker) Prepare(ctx context.Context) error
- type InputIssue
- type Issue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GitPatch ¶
GitPatch returns a patch from a git repository. If no git repository 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 // WholeFiles indicates that the user wishes to see all issues that comes up anywhere in any file that has been changed in this revision or patch. WholeFiles bool // 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 // contains filtered or unexported fields }
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(ctx context.Context, 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 the 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.
func (*Checker) IsNew ¶ added in v0.7.0
IsNew checks whether issue found by linter is new: it was found in changed lines.
WARNING: it requires to call Checker.Prepare before call this method to load the changes from patch.
func (*Checker) IsNewIssue ¶
func (c *Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool)
IsNewIssue checks whether issue found by linter is new: it was found in changed lines.
WARNING: it requires to call Checker.Prepare before call this method to load the changes from patch.
func (*Checker) Prepare ¶
Prepare extracts a patch and changed lines.
WARNING: it should only be used before an explicit call to Checker.IsNewIssue/Checker.IsNew.
WARNING: only [Checker.Patch], [Checker.RevisionFrom], [Checker.RevisionTo], [Checker.WholeFiles] options are used, the other options ([Checker.Regexp], [Checker.AbsPath]) are only used by Checker.Check.
type InputIssue ¶
InputIssue represents issue found by some linter.
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.