linter

package
v0.0.0-...-7907a5d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsText

func IsText(s []byte) bool

IsText reports whether a significant prefix of s looks like correct UTF-8; that is, if it is likely that s is human-readable text.

see godoc: https://github.com/golang/tools/blob/gopls/v0.3.3/godoc/util/util.go#L38-L56

func MustCompileIgnoreLines

func MustCompileIgnoreLines(lines ...string) *gitignore.GitIgnore

MustCompileIgnoreLines compiles the ignore lines and throws a panic if it fails

Types

type Config

type Config struct {
	// AutoFix sets if the linter should try to fix the error
	AutoFix bool `yaml:"autofix"`
	Verbose bool `yaml:"verbose"`

	// Ignore uses the gitignore syntax the select which files or folders to ignore
	Ignore []string `yaml:"ignore"`

	// Rules contains configuration specific for each rule
	Rules RulesConfig `yaml:"rules"`
}

Config represents a Rule configuration

func NewConfigFromFile

func NewConfigFromFile(path string) Config

NewConfigFromFile returns a new Config

func NewDefaultConfig

func NewDefaultConfig() Config

type EndOfFileConfig

type EndOfFileConfig struct {
	Enable bool `yaml:"enable"`

	DisableAutofix bool `yaml:"disable-autofix"`

	// Ignore uses the gitignore syntax the select which files or folders to ignore
	Ignore []string `yaml:"ignore"`

	SingleNewLine bool `yaml:"single-new-line"`
}

EndOfFileConfig config for the End of File rule

type EndOfFileRule

type EndOfFileRule struct {
	Rule

	// If SingleNewLine is true, the EndOfFileRule expects that files end strictly in a
	// single newline character.
	SingleNewLine bool
}

EndOfFileRule checks if the file ends in a newline character, or `\n`. It can be configured to check if it ends strictly in a single newline or in any number of newline characters.

func (EndOfFileRule) Lint

func (rule EndOfFileRule) Lint(b []byte) (valid bool, fix []byte)

Lint implements the Lint interface

type Linter

type Linter interface {
	GetName() string

	// Lint performs the lint operation.
	//
	//  valid: 	if true, the file is valid, the linting check has passed
	//  fix:	if true, the linter will return a "fixed" copy of the file
	Lint([]byte) (valid bool, fix []byte)
	ShouldIgnore(path string) bool
}

Linter exposes the lint method

func NewEndOfFileRule

func NewEndOfFileRule(config Config) Linter

NewEndOfFileRule returns a new EndOfFileRule

type Rule

type Rule struct {
	Config

	Name        string
	Description string

	// AutoFix sets if the linter should try to fix the error; if false, this Rule should
	// only return if the text is valid or not when the lint method is called; otherwise
	// the lint method should return a fixed copy of the data, to pass the linting rule
	AutoFix bool

	// ignore uses the gitignore syntax the select which files or folders to ignore
	Ignore *gitignore.GitIgnore
}

Rule represents a linting rule

func (Rule) GetName

func (r Rule) GetName() string

GetName returns the rule name

func (Rule) ShouldIgnore

func (r Rule) ShouldIgnore(path string) bool

ShouldIgnore decides if the file should be ignored based on the Ignore configuration

type RulesConfig

type RulesConfig struct {
	EndOfFile EndOfFileConfig `yaml:"end-of-file"`
}

RulesConfig is the map of configs which includes all rules

Jump to

Keyboard shortcuts

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