wsl

package module
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: MIT Imports: 7 Imported by: 0

README

WSL - Whitespace Linter

forthebadge forthebadge

Build Status Coverage Status

WSL is a linter that enforces a very non scientific vision of how to make code more readable by enforcing empty lines at the right places.

I think too much code out there is to cuddly and a bit too warm for it's own good, making it harder for other people to read and understand. The linter will warn about newlines in and around blocks, in the beginning of files and other places in the code.

I know this linter is aggressive and a lot of projects I've tested it on have failed miserably. For this linter to be useful at all I want to be open to new ideas, configurations and discussions! Also note that some of the warnings might be bugs or unintentional false positives so I would love an issue to fix, discuss, change or make something configurable!

Installation

By go get (local installation)

You can do that by using:

go get -u github.com/bombsimon/wsl/cmd/...
By golangci-lint (CI automation)

wsl is already integrated with golangci-lint. Please refer to the instructions there.

Usage

How to use depends on how you install wsl.

With local binary

The general command format for wsl is:

$ wsl [flags] <file1> [files...]
$ wsl [flags] </path/to/package/...>

# Examples

$ wsl ./main.go
$ wsl --no-test ./main.go
$ wsl --allow-cuddle-declarations ./main.go
$ wsl --no-test --allow-cuddle-declaration ./main.go
$ wsl --no-test --allow-trailing-comment ./myProject/...

The "..." wildcard is not used like other go commands but instead can only be to a relative or absolute path.

By default, the linter will run on ./... which means all go files in the current path and all subsequent paths, including test files. To disable linting test files, use -n or --no-test.

By golangci-lint (CI automation)

The recommended command is:

golangci-lint --disable-all --enable wsl

For more information, please refer to golangci-lint's documentation.

Issues and configuration

The linter suppers a few ways to configure it to satisfy more than one kind of code style. These settings could be set either with flags or with YAML configuration if used via golangci-lint.

The supported configuration can be found in the documentation.

Below are the available checklist for any hit from wsl. If you do not see any, feel free to raise an issue.

Note: this linter doesn't take in consideration the issues that will be fixed with go fmt -s so ensure that the code is properly formatted before use.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration added in v1.1.0

type Configuration struct {
	// StrictAppend will do strict checking when assigning from append (x =
	// append(x, y)). If this is set to true the append call must append either
	// a variable assigned, called or used on the line above. Example on not
	// allowed when this is true:
	//
	//  x := []string{}
	//  y := "not going in X"
	//  x = append(x, "not y") // This is not allowed with StrictAppend
	//  z := "going in X"
	//
	//  x = append(x, z) // This is allowed with StrictAppend
	//
	//  m := transform(z)
	//  x = append(x, z) // So is this because Z is used above.
	StrictAppend bool

	// AllowAssignAndCallCuddle allows assignments to be cuddled with variables
	// used in calls on line above and calls to be cuddled with assignments of
	// variables used in call on line above.
	// Example supported with this set to true:
	//
	//  x.Call()
	//  x = Assign()
	//  x.AnotherCall()
	//  x = AnotherAssign()
	AllowAssignAndCallCuddle bool

	// AllowMultiLineAssignCuddle allows cuddling to assignments even if they
	// span over multiple lines. This defaults to true which allows the
	// following example:
	//
	//  err := function(
	//  	"multiple", "lines",
	//  )
	//  if err != nil {
	//  	// ...
	//  }
	AllowMultiLineAssignCuddle bool

	// If the number of lines in a case block is equal to or lager than this
	// number, the case *must* end white a newline.
	CaseForceTrailingWhitespaceLimit int

	// AllowTrailingComment will allow blocks to end with comments.
	AllowTrailingComment bool

	// AllowCuddleDeclaration will allow multiple var/declaration statements to
	// be cuddled. This defaults to false but setting it to true will enable the
	// following example:
	//  var foo bool
	//  var err error
	AllowCuddleDeclaration bool

	// AllowCuddleWithCalls is a list of call idents that everything can be
	// cuddled with. Defaults to calls looking like locks to support a flow like
	// this:
	//
	//  mu.Lock()
	//  allow := thisAssignment
	AllowCuddleWithCalls []string

	// AllowCuddleWithRHS is a list of right hand side variables that is allowed
	// to be cuddled with anything. Defaults to assignments or calls looking
	// like unlocks to support a flow like this:
	//
	//  allow := thisAssignment()
	//  mu.Unlock()
	AllowCuddleWithRHS []string

	// Backwards compatible filed due to failed release versioning of WSL. This
	// is a no-op field. See https://github.com/bombsimon/wsl/issues/60
	AllowCaseTrailingWhitespace bool
}

func DefaultConfig added in v1.2.0

func DefaultConfig() Configuration

DefaultConfig returns default configuration

type Processor added in v1.1.0

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

func NewProcessor

func NewProcessor() *Processor

NewProcessor will create a Processor.

func NewProcessorWithConfig added in v1.1.0

func NewProcessorWithConfig(cfg Configuration) *Processor

NewProcessor will create a Processor.

func (*Processor) ProcessFiles added in v1.1.0

func (p *Processor) ProcessFiles(filenames []string) ([]Result, []string)

ProcessFiles takes a string slice with file names (full paths) and lints them. nolint: gocritic

type Result added in v1.1.0

type Result struct {
	FileName   string
	LineNumber int
	Position   token.Position
	Reason     string
}

Result represents the result of one error.

func (*Result) String added in v1.1.0

func (r *Result) String() string

String returns the filename, line number and reason of a Result.

Directories

Path Synopsis
cmd
wsl

Jump to

Keyboard shortcuts

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