Skip to content

Latest commit

 

History

History
333 lines (239 loc) · 6.12 KB

configuration.md

File metadata and controls

333 lines (239 loc) · 6.12 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)

Supported 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"

This option allows whitespace after each comment group that begins a block.

Default value: false

For example,

func example() string {
  // comment

  return fmt.Sprintf("x")
}

and

func example() string {
  // comment

  // comment
  return fmt.Sprintf("x")
}

become legal, as the whitespace after (or between) each comment block doesn't count against whitespace before the first actual statement.

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("newline")
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 blocks can end with comments. This is not encouraged sine it's not clear what node the comment belongs to. To be allowed there must be no whitespace between the comment and the last statement or the comment and the closing bracket.

Example functions used for testing is excluded from this rule.

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 force-err-cuddling option above, among others.