gmlewis / flutter-stylizer

Flutter Stylizer is a VSCode extension that organizes your Flutter classes and mixins in an opinionated and consistent manner.
https://marketplace.visualstudio.com/items?itemName=gmlewis-vscode.flutter-stylizer
Apache License 2.0
23 stars 3 forks source link

Sort "other methods" alphabetically? #18

Closed longtimedeveloper closed 3 years ago

longtimedeveloper commented 3 years ago

Hi,

Is it possible to enable sorting each block alphabetically?

Version: v0.0.17

You can see the below before and after. The after-class groups are not sorted. Any way to do this?

Before

class Global {
   double _aBalance;

  Global(this._balance, this._aBalance) {}

  double get aBalance => _aBalance;

  double _balance;

  void utility() {}

  double get balance => _balance;

  bool isValid() {
    return true;
  }

  void printer() {}

  bool isNotValid() {
    return false;
  }
}

After

class Global {

  Global(this._balance, this._aBalance) {}

  double _aBalance;
  double _balance;

  double get aBalance => _aBalance;

  void utility() {}

  double get balance => _balance;

  bool isValid() {
    return true;
  }

  void printer() {}

  bool isNotValid() {
    return false;
  }
}

Desired

class Global {

  Global(this._balance, this._aBalance) {}

  double _aBalance;
  double _balance;

  double get aBalance => _aBalance;
  double get balance => _balance;

  bool isNotValid() {
    return false;
  }

  bool isValid() {
    return true;
  }

  void printer() {}

  void utility() {}
}

Having getters group together I think is very important.

Within each group, sort alphabetically as above.

I totally understand some developers pushing back on alphabetical sorting because of the hubbub that would be created by changing the file from a git comparison or merge perspective.

To honor that concern, recommend adding an additional method that does sort alphabetically.

Thank you very much for your time and consideration,

Karl

gmlewis commented 3 years ago

Hi @longtimedeveloper - ~I'm trying to understand what you are asking for... Do you want isNotValid to appear before isValid?~ ~(If I'm wrong, maybe you could provide a "Would Like It To Be Like This:" section.)~ EDIT: Oh, I think I get it... you want all the "other" methods to be sorted... OK, my comments below still apply, I think.

Note that the original design (in the README) states this:

I worked on a very large Flutter project and we decided that the stylizer should not mess around with the ordering of all the "other" methods that don't fall into another category.

I'll leave this topic open in case there is demand for it, but I'm thinking that this might be much more challenging and bug-ridden to implement, so I'm leaning toward not implementing this.

longtimedeveloper commented 3 years ago

@gmlewis I updated the original question and handled the concern about sorting alphabetically with mature code.

There is an additional ask to group getters together.

Make sense? Thank you!

gmlewis commented 3 years ago

OK, gotcha. Thank you for the "Desired" section, @longtimedeveloper - that helps a lot.

So if we made this an option (by default it would be disabled), then would could consider this an "experimental" feature and see if I can get it to work. :-)

... and an additional option to group getters together.

longtimedeveloper commented 3 years ago

@gmlewis thank you so very much.

I did check the code and read the below. From a quick look, it appears already have a sort function and it sorts by name. Is this not working or possibly turned off?

 case 'public-static-variables': {
        dc.staticVariables.sort(sortFunc)
        addEntities(dc.staticVariables, false)
        break
      }
gmlewis commented 3 years ago

Is this not working or possibly turned off?

That's specifically for static variables. Note that each section (except for "other methods") should already be getting sorted... so this issue (I believe) is specifically for what this plugin calls "other methods".

longtimedeveloper commented 3 years ago

@gmlewis Ah... Yes, that is the only group not sorted. I hope this will be easy, thank you again!!!

gmlewis commented 3 years ago

Hi @longtimedeveloper - this issue has been addressed in release: https://github.com/gmlewis/flutter-stylizer/releases/tag/v0.0.19

Please read either the CHANGELOG.md or the README.md to discover the two new configuration flags needed to enable the new features, and let me know if you find any bugs. Thanks!

longtimedeveloper commented 3 years ago

@gmlewis OUTSTANDING, thank you very much. Great readme.md too!!