1# WSL - Whitespace Linter 2 3[![forthebadge](https://forthebadge.com/images/badges/made-with-go.svg)](https://forthebadge.com) 4[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com) 5 6[![Build Status](https://travis-ci.org/bombsimon/wsl.svg?branch=master)](https://travis-ci.org/bombsimon/wsl) 7[![Coverage Status](https://coveralls.io/repos/github/bombsimon/wsl/badge.svg?branch=master)](https://coveralls.io/github/bombsimon/wsl?branch=master) 8 9WSL is a linter that enforces a very **non scientific** vision of how to make 10code more readable by enforcing empty lines at the right places. 11 12I think too much code out there is to cuddly and a bit too warm for it's own 13good, making it harder for other people to read and understand. The linter will 14warn about newlines in and around blocks, in the beginning of files and other 15places in the code. 16 17**I know this linter is aggressive** and a lot of projects I've tested it on 18have failed miserably. For this linter to be useful at all I want to be open to 19new ideas, configurations and discussions! Also note that some of the warnings 20might be bugs or unintentional false positives so I would love an 21[issue](https://github.com/bombsimon/wsl/issues/new) to fix, discuss, change or 22make something configurable! 23 24## Installation 25 26### By `go get` (local installation) 27 28You can do that by using: 29 30```sh 31go get -u github.com/bombsimon/wsl/cmd/... 32``` 33 34### By golangci-lint (CI automation) 35 36`wsl` is already integrated with 37[golangci-lint](https://github.com/golangci/golangci-lint). Please refer to the 38instructions there. 39 40## Usage 41 42How to use depends on how you install `wsl`. 43 44### With local binary 45 46The general command format for `wsl` is: 47 48```sh 49$ wsl [flags] <file1> [files...] 50$ wsl [flags] </path/to/package/...> 51 52# Examples 53 54$ wsl ./main.go 55$ wsl --no-test ./main.go 56$ wsl --allow-cuddle-declarations ./main.go 57$ wsl --no-test --allow-cuddle-declaration ./main.go 58$ wsl --no-test --allow-trailing-comment ./myProject/... 59``` 60 61The "..." wildcard is not used like other `go` commands but instead can only 62be to a relative or absolute path. 63 64By default, the linter will run on `./...` which means all go files in the 65current path and all subsequent paths, including test files. To disable linting 66test files, use `-n` or `--no-test`. 67 68### By `golangci-lint` (CI automation) 69 70The recommended command is: 71 72```sh 73golangci-lint run --disable-all --enable wsl 74``` 75 76For more information, please refer to 77[golangci-lint](https://github.com/golangci/golangci-lint)'s documentation. 78 79## Issues and configuration 80 81The linter suppers a few ways to configure it to satisfy more than one kind of 82code style. These settings could be set either with flags or with YAML 83configuration if used via `golangci-lint`. 84 85The supported configuration can be found [in the documentation](doc/configuration.md). 86 87Below are the available checklist for any hit from `wsl`. If you do not see any, 88feel free to raise an [issue](https://github.com/bombsimon/wsl/issues/new). 89 90> **Note**: this linter doesn't take in consideration the issues that will be 91> fixed with `go fmt -s` so ensure that the code is properly formatted before 92> use. 93 94* [Anonymous switch statements should never be cuddled](doc/rules.md#anonymous-switch-statements-should-never-be-cuddled) 95* [Append only allowed to cuddle with appended value](doc/rules.md#append-only-allowed-to-cuddle-with-appended-value) 96* [Assignments should only be cuddled with other assignments](doc/rules.md#assignments-should-only-be-cuddled-with-other-assignments) 97* [Block should not end with a whitespace (or comment)](doc/rules.md#block-should-not-end-with-a-whitespace-or-comment) 98* [Block should not start with a whitespace](doc/rules.md#block-should-not-start-with-a-whitespace) 99* [Case block should end with newline at this size](doc/rules.md#case-block-should-end-with-newline-at-this-size) 100* [Branch statements should not be cuddled if block has more than two lines](doc/rules.md#branch-statements-should-not-be-cuddled-if-block-has-more-than-two-lines) 101* [Declarations should never be cuddled](doc/rules.md#declarations-should-never-be-cuddled) 102* [Defer statements should only be cuddled with expressions on same variable](doc/rules.md#defer-statements-should-only-be-cuddled-with-expressions-on-same-variable) 103* [Expressions should not be cuddled with blocks](doc/rules.md#expressions-should-not-be-cuddled-with-blocks) 104* [Expressions should not be cuddled with declarations or returns](doc/rules.md#expressions-should-not-be-cuddled-with-declarations-or-returns) 105* [For statement without condition should never be cuddled](doc/rules.md#for-statement-without-condition-should-never-be-cuddled) 106* [For statements should only be cuddled with assignments used in the iteration](doc/rules.md#for-statements-should-only-be-cuddled-with-assignments-used-in-the-iteration) 107* [Go statements can only invoke functions assigned on line above](doc/rules.md#go-statements-can-only-invoke-functions-assigned-on-line-above) 108* [If statements should only be cuddled with assignments](doc/rules.md#if-statements-should-only-be-cuddled-with-assignments) 109* [If statements should only be cuddled with assignments used in the if 110 statement 111 itself](doc/rules.md#if-statements-should-only-be-cuddled-with-assignments-used-in-the-if-statement-itself) 112* [If statements that check an error must be cuddled with the statement that assigned the error](doc/rules.md#if-statements-that-check-an-error-must-be-cuddled-with-the-statement-that-assigned-the-error) 113* [Only cuddled expressions if assigning variable or using from line 114 above](doc/rules.md#only-cuddled-expressions-if-assigning-variable-or-using-from-line-above) 115* [Only one cuddle assignment allowed before defer statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-defer-statement) 116* [Only one cuddle assginment allowed before for statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-for-statement) 117* [Only one cuddle assignment allowed before go statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-go-statement) 118* [Only one cuddle assignment allowed before if statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-if-statement) 119* [Only one cuddle assignment allowed before range statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-range-statement) 120* [Only one cuddle assignment allowed before switch statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-switch-statement) 121* [Only one cuddle assignment allowed before type switch statement](doc/rules.md#only-one-cuddle-assignment-allowed-before-type-switch-statement) 122* [Ranges should only be cuddled with assignments used in the iteration](doc/rules.md#ranges-should-only-be-cuddled-with-assignments-used-in-the-iteration) 123* [Return statements should not be cuddled if block has more than two lines](doc/rules.md#return-statements-should-not-be-cuddled-if-block-has-more-than-two-lines) 124* [Short declarations should cuddle only with other short declarations](doc/rules.md#short-declaration-should-cuddle-only-with-other-short-declarations) 125* [Switch statements should only be cuddled with variables switched](doc/rules.md#switch-statements-should-only-be-cuddled-with-variables-switched) 126* [Type switch statements should only be cuddled with variables switched](doc/rules.md#type-switch-statements-should-only-be-cuddled-with-variables-switched) 127