Skip to content

Latest commit

 

History

History
336 lines (243 loc) · 6.11 KB

configuration.md

File metadata and controls

336 lines (243 loc) · 6.11 KB

Configuration

The configuration should always have the same name for the flag in wsl as the key name in the golangci-lint documentation. For example if you run local installation you should be able to use --allow-cuddle-declarations and if you're using golangci-lint the golangci.yaml configuration should look like this:

linters-settings:
  wsl:
    allow-cuddle-declarations: true

Available settings

The following configuration is available. Click each header to jump to the rule description.

Controls if the checks for slice append should be "strict" in the sense that it will only allow these assignments to be cuddled with variables being appended.

Default value: true

Required when true:

x := []string{}
y := "not going in x")

x = append(x, "not y")
x = append(x, y)

Supproted when false:

x := []string{}
y := "not going in x")
x = append(x, "not y")
z := "string"
x = append(x, "i don't care")

Controls if you may cuddle assignments and calls without needing an empty line between them.

Default value: true

Supported when true:

x := GetX()
x.Call()
x = AssignAgain()
x.CallAgain()

Required when false:

x := GetX()
x.Call()

x = AssignAgain()
x.CallAgain()

Controls if you may cuddle assignments and anything without needing an empty line between them.

Default value: false

Supported when true:

if x == 1 {
    x = 0
}
z := x + 2

fmt.Println("x")
y := "x"

Required when false:

if x == 1 {
    x = 0
}

z := x + 2

fmt.Println("x")

y := "x"

Controls if you may cuddle assignments even if they span over multiple lines.

Default value: true

Supported when true:

assignment := fmt.Sprintf(
    "%s%s",
    "I span over", "multiple lines"
)
assignmentTwo := "and yet I may be cuddled"
assignmentThree := "this is fine"

Required when false:

assignment := fmt.Sprintf(
    "%s%s",
    "I span over", "multiple lines"
)

assignmentTwo := "so I cannot be cuddled"
assignmentThree := "this is fine"

Can be set to force trailing newlines at the end of case blocks to improve readability. If the number of lines (including comments) in a case block exceeds this number a linter error will be yielded if the case does not end with a newline.

Default value: 0 (never force)

Supported when set to 0:

switch n {
case 1:
    fmt.Println("newline")

case 2:
    fmt.Println("no newline")
case 3:
    fmt.Println("Many")
    fmt.Println("lines")
    fmt.Println("without")
    fmt.Println("newlinew")
case 4:
    fmt.Println("done")
}

Required when set to 2:

switch n {
case 1:
    fmt.Println("must have")
    fmt.Println("empty whitespace")

case 2:
    fmt.Println("might have empty whitespace")

case 3:
    fmt.Println("might skip empty whitespace")
case 4:
    fmt.Println("done"9)
}

Controls if you're allowed to cuddle multiple declarations. This is false by default to encourage you to group them in one var block. One major benefit with this is that if the variables are assigned the assignments will be tabulated.

Default value: false

Supported when true:

var foo = 1
var fooBar = 2

Required when false:

var (
    foo    = 1
    fooBar = 2
)

Controls if you may end case statements with a whitespace. This option is independent of other blocks and was introduced to improve readability for complex blocks.

Default value: false

Supported when true:

switch {
case 1:
    fmt.Println("x")

case 2:
    fmt.Println("x")

case 3:
    fmt.Pritnln("x")
}

Required when false:

switch {
case 1:
    fmt.Println("x")
case 2:
    fmt.Println("x")
case 3:
    fmt.Pritnln("x")
}

Controls if blocks can end with comments. This is not encouraged sine it's usually code smell but might be useful do improve understanding or learning purposes. To be allowed there must be no whitespace between the comment and the last statement or the comment and the closing brace.

Default value: false

Supported when true

if true {
    fmt.Println("x")
    // See ya later!
}

if false {
    fmt.Println("x")
    //
    // Multiline OK
}

if 1 == 1 {
    fmt.Println("x")
    /*
        This is also fine!
        So just comment awaaay!
    */
}

Enforces that an if statement checking an error variable is cuddled with the line that assigned that error variable.

Default value: false

Supported when false:

err := ErrorProducingFunc()

if err != nil {
    return err
}

Required when true:

err := ErrorProducingFunc()
if err != nil {
    return err
}

Enforces that an assignment which is actually a short declaration (using :=) is only allowed to cuddle with other short declarations, and not plain assignments, blocks, etc. This rule helps make declarations stand out by themselves, much the same as grouping var statements.

Default value: false

Supported when false:

a := 1
a = 2

err := ErrorProducingFunc()
if err != nil {
    return err
}

Required when true:

a := 1

a = 2

err := ErrorProducingFunc()

if err != nil {
    return err
}

Note: this means the option overrides the enforce-err-cuddling option above, among others.