better_require_trailing_commas 2.0.5 copy "better_require_trailing_commas: ^2.0.5" to clipboard
better_require_trailing_commas: ^2.0.5 copied to clipboard

A lint rule that enforces trailing commas behaves like ESLint’s comma-dangle with the always-multiline option.

better_require_trailing_commas #

Dart linter plugin to enforce trailing commas (enhanced version of linter built-in require_trailing_commas)

The rule is simple. If you opened parentheses intending to write multiline contents, it requires trailing commas. It's like always-multilinesetting of comma-dangle rule in ESLint.

✅ Good #

Foo(
  a: 1,
  b: 2,
);

Foo(Bar(
  a: 1,
  b: 2,
));

useEffect(() {
  // ...
}, []);

❌️ Bad #

Foo(
  a: 1,
  b: 2 // <-
);

Foo(Bar(
  a: 1,
  b: 2 // <-
));

useEffect(
  () {
    // ...
  },
  [] // <-
);

Records are supported

final (String, String) foo = (
  "bar",
  "baz" // <-
);

Switch expressions are supported

final foo = switch (state) {
  State.success => 0,
  State.failure => 1 // <-
}

Enums are supported

enum FooState {
  bar,
  baz // <-
}

enum BarState {
  taro("taro"),
  hanako("hanako") // <-
  ;
  
  const BarState(this.name);

  final String name;
}

Of course, also have quick fixes.

Installation #

Dart 3.10 or later (Flutter 3.38 or later) is required to use this plugin.

Edit your analysis_options.yaml like below. You don't need to add this to your dependencies (for more information, see here).

# ...
# Note: `plugins` property is TOP LEVEL.
plugins:
  # Note: Do not put `riverpod_lint` after this plugin.
  #       This may cause unexpected behavior.
  # riverpod_lint: ^3.1.0 # Put this BEFORE better_require_trailing_commas
  better_require_trailing_commas: ^2.0.0
# ...

Running the linter with command line:

dart analyze
0
likes
150
points
277
downloads

Publisher

verified publisherchikach.net

Weekly Downloads

A lint rule that enforces trailing commas behaves like ESLint’s comma-dangle with the always-multiline option.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

analysis_server_plugin, analyzer, analyzer_plugin, meta

More

Packages that depend on better_require_trailing_commas