eclint

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 18 Imported by: 0

README

eclint - EditorConfig linter ★

A faster alternative to the JavaScript eclint written in Go.

Tarballs are signed (.minisig) using the following public key:

RWRP3/Z4+t+iZk1QU6zufn6vSDlvd76FLWhGCkt5kE7YqW3mOtSh7FvE

Which can be verified using minisig or signify.

Installation

Usage

$ go install gitlab.com/greut/eclint/cmd/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
  • minimal magic bytes detection (currently for PDF)
More
  • when no 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 (also on Quay.io, GitHub and GitLab registries)
  • colored output (use -color: never to disable and always to skip detection)
  • -summary mode showing only the number of errors per file
  • only the first X errors are shown (use -show_all_errors to disable)
  • binary file detection (however quite basic)
  • -fix to modify files in place rather than showing the errors currently:
    • only basic unix2dos, dos2unix
    • space to tab and tab to space conversion
    • trailing whitespaces

Missing features

  • max_line_length counting UTF-32 characters
  • more tests
  • etc.

Thanks for their contributions

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.

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"
	// Latin1 is the legacy 7-bits character set.
	Latin1 = "latin1"
)
View Source
const DefaultTabWidth = 8

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

Variables

View Source
var ErrConfiguration = errors.New("configuration error")

ErrConfiguration represents an error in the editorconfig value.

View Source
var ErrNotImplemented = errors.New("not implemented yet, PRs are welcome")

ErrNotImplemented represents a missing feature.

Functions

func FixWithDefinition added in v0.1.12

func FixWithDefinition(ctx context.Context, d *editorconfig.Definition, filename string) error

FixWithDefinition does the hard work of validating the given file.

func GitLsFilesContext added in v0.1.2

func GitLsFilesContext(ctx context.Context, path string) (<-chan string, <-chan error)

GitLsFilesContext returns the list of file base on what is in the git index (asynchronously).

-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(ctx context.Context, filename string) []error

Lint does the hard work of validating the given file.

func LintWithDefinition added in v0.0.18

func LintWithDefinition(ctx context.Context, d *editorconfig.Definition, filename string) []error

LintWithDefinition does the hard work of validating the given file.

func ListFilesContext added in v0.1.2

func ListFilesContext(ctx context.Context, args ...string) (<-chan string, <-chan error)

ListFilesContext lists the files in an asynchronous fashion

When its empty, it relies on `git ls-files` first, which would 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 OverrideDefinitionUsingPrefix added in v0.0.21

func OverrideDefinitionUsingPrefix(def *editorconfig.Definition, prefix string) error

OverrideDefinitionUsingPrefix is an helper that takes the prefixed values.

It replaces those values into the nominal ones. That way a tool could a different set of definition than the real editor would.

func PrintErrors added in v0.0.5

func PrintErrors(ctx context.Context, opt *Option, filename string, errs []error) error

PrintErrors is the rich output of the program.

func ProbeCharsetOrBinary added in v0.0.16

func ProbeCharsetOrBinary(ctx context.Context, r *bufio.Reader, charset string) (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, fileSize int64, 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 something 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 WalkContext added in v0.1.2

func WalkContext(ctx context.Context, paths ...string) (<-chan string, <-chan error)

WalkContext iterates on each path item recursively (asynchronously).

Future work: use godirwalk.

Types

type LineFunc added in v0.0.5

type LineFunc func(int, []byte, bool) 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
	FixAllErrors      bool
	ShowErrorQuantity int
	Exclude           string
	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