require_trailing_commas_custom 1.0.4 copy "require_trailing_commas_custom: ^1.0.4" to clipboard
require_trailing_commas_custom: ^1.0.4 copied to clipboard

A modified version of the require_trailing_commas lint rule that behaves like ESLint’s comma-dangle with the always-multiline option.

require_trailing_commas_custom #

A lint rule for custom_lint

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 #

Just add this package to your dependencies. custom_lint package is required to use this lint rule.

dart pub add dev:require_trailing_commas_custom dev:custom_lint
# or
flutter pub add dev:require_trailing_commas_custom dev:custom_lint

If you're using an IDE like VSCode, edit your analysis_options.yaml like this:

# ...
analyzer:
  plugins:
    - custom_lint
# ...

Running the linter with command line:

dart run custom_lint
1
likes
130
points
226
downloads

Publisher

verified publisherchikach.net

Weekly Downloads

A modified version of the require_trailing_commas lint rule that 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

analyzer, analyzer_plugin, custom_lint_builder

More

Packages that depend on require_trailing_commas_custom