hint

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

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

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

README

Gohint is an alternative linter for Go source code. It is based on golint and inspired by jshint. That is, basically gohint is the same golint plus configuration (plus some extra checks, plus report generators, plus... :) )

To install, run go get github.com/elgris/hint/gohint

Any other documentation you can check at golint's README. At the moment there is not so much difference, but I'm not sure what will happen in future :)

Why you may need it? As golint says:

The suggestions made by golint are exactly that: suggestions.
Golint is not perfect, and has both false positives and false negatives.

But sometimes you want those suggestions to work, so you start to use the tool in your continuous integration. And after that you begin to realize that many of those suggestions do not fit your project and just add noise to health report.

That's why you can try gohint - you can configure it, so it will scream only in case of problems that really hurt your project. Don't try to filter the noise, define your rules and do not produce such noise! :)

Also it can produce reports in various formats, so integration to your CI cycle becomes even easier. At the moment it supports only 2 formats: plain text and Checkstyle XML.

Running gohint

gohint supports 2 options that can be passed:

opt description
config path to JSON file with configuration. See above how to prepare config file
reporter name of reporter to use for output. Supported ones: plain and checkstyle. plain outputs report in plain text (like golint) and is used by default. checkstyle outputs Checkstyle XML

Example:

gohint -config="/path/to/config.json" -reporter=plain

Configuration options

JSON config can contain following options:

TBD...

opt type description
package bool analyze package comments, definitions, etc
imports bool check imports for .
names bool check names of functions, variables, etc
exported bool check exported types and vars for correct comments and other
var-decls bool analyze variable declaration for correctness
elses bool check if..else statements for redundant else
make-slice bool check making slices for using short syntax
error-return bool check list of function's return values for position of error, it should be last
ignored-return bool check if there any function call which returned result is ignored
min-confidence float minimal confidence value to reduce output, [0..1]

Documentation

Overview

Package lint contains a linter for Go source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCheckstyleReporter

func NewCheckstyleReporter(indent bool) *checkstyleReporter

NewCheckstyleReporter creates initialized Checkstyle report generator

Types

type Config

type Config struct {
	Package            bool `json:"package"`
	Imports            bool `json:"imports"`
	Names              bool `json:"names"`
	Exported           bool `json:"exported"`
	VarDecls           bool `json:"var-decls"`
	Elses              bool `json:"elses"`
	MakeSlice          bool `json:"make-slice"`
	ErrorReturn        bool `json:"error-return"`
	IgnoredReturn      bool `json:"ignored-return"`
	PackageUnderscore  bool `json:"package-underscore"`
	NamedReturn        bool `json:"named-return"`
	PackagePrefixNames bool `json:"package-prefix-names"`

	MinConfidence float64 `json:"min-confidence"`

	IgnoreFiles []string `json:"ignore-files"`

	IgnorePackages []string `json:"ignore-packages"`

	IgnoreTypes []string `json:"ignore-types"`

	Initialisms      map[string]bool `json:"initialisms"`
	BadReceiverNames map[string]bool `json:"bad-receivers"`
	// contains filtered or unexported fields
}

Config defines configuration options for linter

func NewConfig

func NewConfig(file string) (*Config, error)

NewConfig reads config from given file. If filename is empty, default config will be returned

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates linter config with predefined options

type Linter

type Linter struct {
}

A Linter lints Go source code.

func (*Linter) Lint

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

Lint lints src.

type PlainReporter

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

PlainReporter defines reporter that output problems as plain text

func (*PlainReporter) Collect

func (r *PlainReporter) Collect(ps []Problem)

Collect receives problems for further report generation

func (*PlainReporter) Flush

func (r *PlainReporter) Flush() (report string, err error)

Flush outputs collected problems one by one in plain text Expect no errors here

type Problem

type Problem struct {
	File       string         // name of the sourcefile
	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
}

Problem represents a problem in some source code.

func (*Problem) String

func (p *Problem) String() string

type Reporter

type Reporter interface {
	Collect(problems []Problem)
	Flush() (string, error)
}

Reporter defines interface that should be implemented to generate a report.

Directories

Path Synopsis
cmd
gohint
golint lints the Go source files named on its command line.
golint 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