Skip to main content

avoid-dot-shorthands

effort: 2m
pro+

Warns against using dot shorthands.

Use this rule only if you would like to not use dot shorthands in your codebase and keep it consistent.

info

This rule is incompatible with rules that suggest using dot shorthands in various cases.

Example

❌ Bad:

void fn(SomeClass? e) {
switch (e) {
// LINT: Avoid dot shorthands as they reduce readability. Try adding explicit types.
case .first:
print(e);
}

final v = switch (e) {
// LINT: Avoid dot shorthands as they reduce readability. Try adding explicit types.
.first => 1,
_ => 2,
};

// LINT: Avoid dot shorthands as they reduce readability. Try adding explicit types.
final SomeClass another = .first;

// LINT: Avoid dot shorthands as they reduce readability. Try adding explicit types.
if (e == .first) {}
}

✅ Good:

void fn(SomeClass? e) {
switch (e) {
case SomeClass.first:
print(e);
}

final v = switch (e) {
SomeClass.first => 1,
_ => 2,
};

final another = SomeClass.first;

if (e == SomeClass.first) {}
}