Skip to content

[pkg:linter] proposal: test_block_last #59417

@kevmoo

Description

@kevmoo

Description

When providing optional arguments to package:test functions that take functions (like test and group) supply the named arguments before the function block.

Details

When the test/group "body" is large, it's easy to "lose" the named arguments (like skip, onPlatform, etc) below the anonymous function.

Kind

Enforces (un-formalized) style advice that might be generally applicable, but especially with pkg:test functions that take blocks and (optional) named args.

Bad Examples

test(
  'bob',
  () {
    // code
  },
  skip: 'Reason',
);

Good Examples

test(
  'bob',
  skip: 'Reason',
  () {
    // code
  },
);

Discussion

See also https://dart.dev/tools/linter-rules/sort_child_properties_last

One could argue this should be in Effective Dart or Flutter Style Guide, but it's a bit weird since it references an API defined in a package.

Example of a PR that implements this change:

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposallinter-set-flutterlinter-status-pendingtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions