solid-software / solid_lints

🟧 Lints for Dart and Flutter based on software industry standards and best practices.
Other
36 stars 17 forks source link

Add rule to sort class methods by their modifiers and usage in other methods #16

Open solid-danylosafonov opened 1 year ago

solid-danylosafonov commented 1 year ago

There are already rules that enforce following order:

  1. attributes
  2. getters/setters
  3. constructor
  4. methods

I propose to make it stricter and enforce order of methods:

* - can go above in order if they go just after method they are used in

BAD:

_privateMethod() {
  ...
}

publicMethod() {
  ...
}

@override
overwritenMethod() {
  ...
}

GOOD:

@override
overwritenMethod() {
  ...
}

publicMethod() {
  ...
}

_privateMethod() {
  ...
}

GOOD:

@override
overwritenMethod() {
  ...
  _privateMethod();
  ...
}

_privateMethod() {
  ...
}

publicMethod() {
  ...
}
illia-romanenko commented 1 year ago

That would require a custom rule, correct?

ruslan-rudenko-solid commented 1 year ago

There is an updated dcm functionality that I believe allows doing this

illia-romanenko commented 1 year ago

It probably doesn't cover this case:

    • can go above in order if they go just after method they are used in
danylo-safonov-solid commented 1 year ago

It probably doesn't cover this case:

can go above in order if they go just after method they are used in

Yes, it doesn't seem to, but it allows to enforce privates/overrides, but I guess it's too strict without allowing the mixed order depending on usage?

That would require a custom rule, correct?

More like a variant of existing one, but yes