Acton
Linting rules

E001: field-init-can-be-folded

Checks for struct initialization where the field name and the variable used to initialize it are the same.

Metadata

  • Code: E001
  • Rule: field-init-can-be-folded
  • Status: Stable since v0.0.1
  • Quick fix: always available

What it does

Checks for struct initialization where the field name and the variable used to initialize it are the same.

Why is this bad?

It's redundant and can be simplified using the shorthand syntax.

Example

struct Foo { bar: int }

fun main() {
    val bar = 1;
    val foo = Foo { bar: bar };
E001: field initialization can be folded
}

Use instead:

struct Foo { bar: int }

fun main() {
    val bar = 1;
    val foo = Foo { bar };
}
Source code

Last updated on

On this page