fluff

package module
v0.0.0-...-5da21bf Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Gofluff is a fork of Golint, adding command line flags for selecting the specific rules that you want to check.

Build Status

Installation

Gofluff requires Go 1.6 or later.

go get -u github.com/btubbs/gofluff/gofluff

Usage

Invoke gofluff with one or more filenames, directories, or packages named by its import path. Gofluff uses the same import path syntax as the go command and therefore also supports relative import paths like ./.... Additionally the ... wildcard can be used as suffix on relative and absolute file paths to recurse into them.

The output of this tool is a list of suggestions in Vim quickfix format, which is accepted by lots of different editors.

Ignoring and Specifying Rules

To ignore a specific rule, use the -ignore flag and give it the same code shown in parentheses when the error is printed out. If you see an error like this:

testdata/4.go:27:5: (comments.exportedval) exported var W should have comment or be unexported

You can ignore it like this:

gofluff -ignore comments.exportedval testdata/4.go

You can ignore a whole class of rules by providing just the parent category:

gofluff -ignore comments testdata/4.go

You can pass multiple things to ignore by joining them with a comma:

gofluff -ignore naming.leadingk,naming.allcaps testdata/names.go

If you only want to check for a specific rule or category of rules, you can use the -rules flag (a whitelist) instead of the -ignore flag (a blacklist).

gofluff -rules naming,comments testdata/4.go

If you provide both a -rules whitelist and a -ignore blacklist, the blacklist will take precedence. You can use this to specify whole categories to check, and then exclude specific rules within them:

gofluff -rules comments -ignore comments.exportedval testdata/4.go

Purpose

Gofluff differs from golint. Golint has a hard-coded set of warnings matching Google's internal style rules, whereas gofluff allows teams to define their own subset of these rules.

Gofluff differs from gofmt. Gofmt reformats Go source code, whereas gofluff prints out style mistakes.

Gofluff differs from govet. Govet is concerned with correctness, whereas gofluff is concerned with coding style.

If you find an established style that is frequently violated, and which you think gofluff could statically check, file an issue or even better, submit a pull request.

Vim

Add this to your ~/.vimrc:

set rtp+=$GOPATH/src/github.com/btubbs/gofluff/misc/vim

If you have multiple entries in your GOPATH, replace $GOPATH with the right value.

Running :Lint will run gofluff on the current file and populate the quickfix list.

Optionally, add this to your ~/.vimrc to automatically run gofluff on :w

autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow

Emacs

Add this to your .emacs file:

(add-to-list 'load-path (concat (getenv "GOPATH")  "/src/github.com/btubbs/gofluff/misc/emacs"))
(require 'golint)

If you have multiple entries in your GOPATH, replace $GOPATH with the right value.

Running M-x gofluff will run gofluff on the current file.

For more usage, see Compilation-Mode.

Documentation

Overview

Package fluff contains a linter for Go source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Linter

type Linter struct {
}

A Linter lints Go source code.

func (*Linter) Lint

func (l *Linter) Lint(filename string, src []byte) ([]Problem, error)

Lint lints src.

func (*Linter) LintFiles

func (l *Linter) LintFiles(files map[string][]byte) ([]Problem, error)

LintFiles lints a set of files of a single package. The argument is a map of filename to source.

type Problem

type Problem struct {
	Position   token.Position // position in source file
	Text       string         // the prose that describes the problem
	Link       string         // (optional) the link to the style guide for the problem
	Confidence float64        // a value in (0,1] estimating the confidence in this problem's correctness
	LineText   string         // the source line
	Category   string         // a short name for the general category of the problem

	// If the problem has a suggested fix (the minority case),
	// ReplacementLine is a full replacement for the relevant line of the source file.
	ReplacementLine string
}

Problem represents a problem in some source code.

func (*Problem) String

func (p *Problem) String() string

Directories

Path Synopsis
gofluff lints the Go source files named on its command line.
gofluff lints the Go source files named on its command line.

Jump to

Keyboard shortcuts

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