Skip to content

Enforce consistent order of class members #58283

Open
@jibiel

Description

@jibiel

Consistently structured class declarations are often regarded as not important but they sure improve code readability and a definite must-have for teams.

The most comprehensive guide on this topic is probably Style guide for Flutter repo. The suggested default order is quite detailed and potentially could be implemented as a conventional Flutter Style rule.

However not everyone may find such a structure appropriate for their project. For example, I find it odd that private methods used in build should be listed before it. I'm new to Dart and honestly don't know if the Linter supports configurable rules, but in the ideal world it could look something like this:

 # Uses flutter repo style by default

- class_members_ordering

# Custom order that potentially could be specified separately for different paths,
# e.g. `lib/models`, `lib/widgets` etc.

class_members_ordering:
  - constructors
  - factories
  - instance_variables
  # etc.

The rule is not specific to any Dart framework.

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-requesttype-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