eclint

package module
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2020 License: MIT Imports: 13 Imported by: 0

README

eclint - EditorConfig linter ★

An alternative to the JavaScript eclint written in Go.

Work in progress

Usage

$ go install gitlab.com/greut/eclint

$ eclint -version

Excluding some files using the EditorConfig matcher

$ eclint -exclude "testdata/**/*"

Features

  • charset
  • end_of_line
  • indent_size
  • indent_style
  • insert_final_newline
  • max_line_length (when using tabs, specify the tab_width or indent_size)
    • by default, UTF-8 charset is assumed and multi-byte characters should be counted as one. However, combining characters won't.
  • trim_trailing_whitespace
  • domain-specific properties
    • line_comment
    • block_comment_start, block_comment, block_comment_end
  • miminal magic bytes detection (currently for PDF)
More
  • when not path is given, it searches for files via git ls-files
  • -exclude to filter out some files
  • unset / alter properties via the eclint_ prefix
  • Docker images
  • colored output à la ripgrep (use -no_colors to disable, or -force_colors to skip detection)
  • -summary mode showing only the number of errors per file
  • only the X first errors are shown (use -show_all_errors to disable)
  • binary file detection (however quite basic)

Missing features

  • basic //nolint suffix
  • max_line_length counting UTF-16 and UTF-32 characters
  • more tests
  • ability to fix
  • etc.

Benchmarks

NB benchmarks matter at feature parity (which is also hard to measure).

The contenders are the following.

The methodology is to run the linter against some big repositories time eclint -show_all_errors.

Repository editorconfig-checker jedmao/eclint greut/eclint
Roslyn 37s 1m5s 4s
SaltStack 7s 1m9s <1s
Profiling

Two options: -cpuprofile <file> and -memprofile <file>, will produce the appropriate pprof files. At the time being a good chunk of time is spent into the editorconfig-core-go library as it has no sense of definition caching.

Libraries and tools

Documentation

Overview

Package eclint is a set of linters to for the EditorConfig rules

Index

Constants

View Source
const (
	// UnsetValue is the value equivalent to an empty / unset one.
	UnsetValue = "unset"
	// TabValue is the value representing tab indentation (the ugly one)
	TabValue = "tab"
	// SpaceValue is the value representing space indentation (the good one)
	SpaceValue = "space"
	// Utf8 is the ubiquitous character set
	Utf8 = "utf-8"
)
View Source
const DefaultTabWidth = 8

DefaultTabWidth sets the width of a tab used when counting the line length

Variables

This section is empty.

Functions

func GitLsFiles added in v0.0.5

func GitLsFiles(log logr.Logger, path string) ([]string, error)

GitLsFiles returns the list of file based on what is in the git index.

-z is mandatory as some repositories non-ASCII file names which creates quoted and escaped file names. This method also returns directories for any submodule there is. Submodule will be skipped afterwards and thus not checked.

func Lint added in v0.0.5

func Lint(filename string, log logr.Logger) []error

Lint does the hard work of validating the given file.

func LintWithDefinition added in v0.0.18

func LintWithDefinition(def *editorconfig.Definition, filename string, log logr.Logger) []error

LintWithDefinition does the hard work of validating the given file.

func ListFiles added in v0.0.5

func ListFiles(log logr.Logger, args ...string) ([]string, error)

ListFiles returns the list of files based on the input.

When its empty, it relies on `git ls-files` first, which whould fail if `git` is not present or the current working directory is not managed by it. In that case, it work the current working directory.

When args are given, it recursively walks into them.

func MaxLineLength added in v0.0.5

func MaxLineLength(maxLength int, tabWidth int, data []byte) error

MaxLineLength checks the length of a given line.

It assumes UTF-8 and will count as one runes. The first byte has no prefix 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx, 111110xx, etc. and the following byte the 10xxxxxx prefix which are skipped.

func PrintErrors added in v0.0.5

func PrintErrors(opt Option, filename string, errors []error) error

PrintErrors is the rich output of the program.

func ProbeCharsetOrBinary added in v0.0.16

func ProbeCharsetOrBinary(r *bufio.Reader, charset string, log logr.Logger) (string, bool, error)

ProbeCharsetOrBinary does all the probes to detect the encoding or whether it is a binary file.

func ReadLines added in v0.0.5

func ReadLines(r io.Reader, fn LineFunc) []error

ReadLines consumes the reader and emit each line via the LineFunc

Line numbering starts at 0. Scanner is pretty smart an will reuse its memory structure. This is somehing we explicitly avoid by copying the content to a new slice.

func SplitLines added in v0.0.5

func SplitLines(data []byte, atEOF bool) (int, []byte, error)

SplitLines works like bufio.ScanLines while keeping the line endings.

func Walk added in v0.0.5

func Walk(log logr.Logger, paths ...string) ([]string, error)

Walk iterates on each path item recursively.

Types

type LineFunc added in v0.0.5

type LineFunc func(int, []byte) error

LineFunc is the callback for a line.

It returns the line number starting from zero.

type Option added in v0.0.5

type Option struct {
	IsTerminal        bool
	NoColors          bool
	ShowAllErrors     bool
	Summary           bool
	ShowErrorQuantity int
	Exclude           string
	Log               logr.Logger
	Stdout            io.Writer
}

Option contains the environment of the program.

When ShowErrorQuantity is 0, it will show all the errors. Use ShowAllErrors false to disable this.

type ValidationError added in v0.0.6

type ValidationError struct {
	Message  string
	Filename string
	Line     []byte
	Index    int
	Position int
}

ValidationError is a rich type containing information about the error

func (ValidationError) Error added in v0.0.6

func (e ValidationError) Error() string

Error builds the error string.

func (ValidationError) String added in v0.0.6

func (e ValidationError) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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