wsl (whitespace linter) is a linter that wants you to use empty
lines to separate grouping of different types to increase readability. There are
also a few places where it encourages you to remove whitespaces which is at
the start and the end of blocks or between assigning and error checking.
Each check can be disabled or enabled individually to the point where no checks can be run. The idea with this is to attract more users. Some checks have configuration that affect how they work but most of them can only be turned on or off.
This is an exhaustive list of all the checks that can be enabled or disabled and their default value. The names are the same as the Go AST type name for built-ins.
The base rule is that statements that has a block (e.g. for, range,
switch, if etc) should only be cuddled with variables that are used in the
block. By default only a single cuddled statement is allowed, but this can be
changed with cuddle-max-statements.
For more details and examples, see CHECKS.
✅ = enabled by default, ❌ = disabled by default
break, continue, fallthrough, goto)
should only be cuddled if the block is less than n lines where n is the
value of branch-max-linesdefer, after error
checking or with a single variable used on the line abovego or a single variable
used on the line above++/--) has the same rules as assignn
lines where n is the value of branch-max-lineswsl casesvar, const,
type) statementsdefer statementsgo statementsappend if the value being
appended exist on the line aboveOther than enabling or disabling specific checks some checks can be configured in more details. See CHECKS.md for details and examples.
return, break, continue) need to be separated by
a whitespace (default 2)case blocks needs to
end with a whitespace if exceeding this number (default 0, 0 = off, 1 =
always)go, defer and send. Every cuddled statement must have
at least one variable used in the block. Respects allow-first-in-block and
allow-whole-block. With 0 no cuddling is allowed at all — every
cuddle-checked trigger requires a blank line above it (default 1)# Latest release
go install github.com/bombsimon/wsl/v5/cmd/wsl@latest
# Main branch
go install github.com/bombsimon/wsl/v5/cmd/wsl@main
Note: This linter provides a fixer that can fix most issues with the
--fixflag.
wsl uses the analysis package meaning it will operate on package level with
the default analysis flags and way of working.
wsl --help
wsl [flags] </path/to/package/...>
wsl --default none --enable branch,return --fix ./...
wsl is also integrated in golangci-lint but since v5 which
had a bunch of breaking changes it's renamed to wsl_v5. The previous version
of wsl is deprecated and will be removed from golangci-lint eventually.
golangci-lint run --no-config --enable-only wsl_v5 --fix
This is an exhaustive, default, configuration for wsl_v5 in golangci-lint.
linters:
default: none
enable:
- wsl_v5
settings:
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
case-max-lines: 0
cuddle-max-statements: 1
default: ~ # Can be `all`, `none`, `default` or empty
enable:
- append
- assign
- branch
- decl
- defer
- err
- expr
- for
- go
- if
- inc-dec
- label
- range
- return
- select
- send
- switch
- type-switch
- leading-whitespace
- trailing-whitespace
disable:
- after-block
- after-decl
- after-defer
- after-expr
- after-go
- assign-exclusive
- assign-expr
- cuddle-group
newline-after-block - Require newline after blocks
nlreturn - Use empty lines before return
whitespace - Don't use a blank newline at the start or end of
a block.
gofumpt - Stricter formatter than gofmt.
Go
100.0%
wsl (whitespace linter) is a linter that wants you to use empty
lines to separate grouping of different types to increase readability. There are
also a few places where it encourages you to remove whitespaces which is at
the start and the end of blocks or between assigning and error checking.
Each check can be disabled or enabled individually to the point where no checks can be run. The idea with this is to attract more users. Some checks have configuration that affect how they work but most of them can only be turned on or off.
This is an exhaustive list of all the checks that can be enabled or disabled and their default value. The names are the same as the Go AST type name for built-ins.
The base rule is that statements that has a block (e.g. for, range,
switch, if etc) should only be cuddled with variables that are used in the
block. By default only a single cuddled statement is allowed, but this can be
changed with cuddle-max-statements.
For more details and examples, see CHECKS.
✅ = enabled by default, ❌ = disabled by default
break, continue, fallthrough, goto)
should only be cuddled if the block is less than n lines where n is the
value of branch-max-linesdefer, after error
checking or with a single variable used on the line abovego or a single variable
used on the line above++/--) has the same rules as assignn
lines where n is the value of branch-max-lineswsl casesvar, const,
type) statementsdefer statementsgo statementsappend if the value being
appended exist on the line aboveOther than enabling or disabling specific checks some checks can be configured in more details. See CHECKS.md for details and examples.
return, break, continue) need to be separated by
a whitespace (default 2)case blocks needs to
end with a whitespace if exceeding this number (default 0, 0 = off, 1 =
always)go, defer and send. Every cuddled statement must have
at least one variable used in the block. Respects allow-first-in-block and
allow-whole-block. With 0 no cuddling is allowed at all — every
cuddle-checked trigger requires a blank line above it (default 1)# Latest release
go install github.com/bombsimon/wsl/v5/cmd/wsl@latest
# Main branch
go install github.com/bombsimon/wsl/v5/cmd/wsl@main
Note: This linter provides a fixer that can fix most issues with the
--fixflag.
wsl uses the analysis package meaning it will operate on package level with
the default analysis flags and way of working.
wsl --help
wsl [flags] </path/to/package/...>
wsl --default none --enable branch,return --fix ./...
wsl is also integrated in golangci-lint but since v5 which
had a bunch of breaking changes it's renamed to wsl_v5. The previous version
of wsl is deprecated and will be removed from golangci-lint eventually.
golangci-lint run --no-config --enable-only wsl_v5 --fix
This is an exhaustive, default, configuration for wsl_v5 in golangci-lint.
linters:
default: none
enable:
- wsl_v5
settings:
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
case-max-lines: 0
cuddle-max-statements: 1
default: ~ # Can be `all`, `none`, `default` or empty
enable:
- append
- assign
- branch
- decl
- defer
- err
- expr
- for
- go
- if
- inc-dec
- label
- range
- return
- select
- send
- switch
- type-switch
- leading-whitespace
- trailing-whitespace
disable:
- after-block
- after-decl
- after-defer
- after-expr
- after-go
- assign-exclusive
- assign-expr
- cuddle-group
newline-after-block - Require newline after blocks
nlreturn - Use empty lines before return
whitespace - Don't use a blank newline at the start or end of
a block.
gofumpt - Stricter formatter than gofmt.
Go
100.0%