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 named parameters in constructors #28

Open guenth39 opened 2 years ago

guenth39 commented 2 years ago

I would like to see the plugin also sort the named parameters in a constructor, so it would fit nicely with the already sorted variables.
Perfect would be if there would also be the option to place required parameters first.

Example

// before
ExampleWidget({
  Key? key,
  required this.onPressed,
  this.visualDensity,
  this.closeKeyboard = false,
  this.icon,
  required this.text,
  this.scheme,
})

// after
// with required first
ExampleWidget({
  required this.text,
  required this.onPressed,
  this.closeKeyboard = false,
  Key? key,
  this.icon,
  this.scheme,
  this.visualDensity,
})

// after
// without required first
ExampleWidget({
  this.closeKeyboard = false,
  Key? key,
  this.icon,
  required this.onPressed,
  this.scheme,
  required this.text,
  this.visualDensity,
})
gmlewis commented 2 years ago

Hi @guenth39 - thank you for the request. I have a couple questions for you.

Perfect would be if there would also be the option to place required parameters first.

In addition to placing them first, would you also want them to be sorted? In your "after with required first" example, I'm thinking you might want this.onPressed to appear before this.text, correct? (Or do you want that to be yet a third option? If so, I'm starting to get concerned about the sheer number of options this thing is accumulating.)

I would like to see the plugin also sort the named parameters in a constructor, so it would fit nicely with the already sorted variables.

One concern I have is that someone may choose to break lines at arbitrary locations (within the named parameters section) and if this stylizer is going to remain self-consistent, I would think it must always break lines such that there is exactly one named parameter per line (as in your examples above).

Also, I'm wondering if the very next request I get will be to sort named parameters in ALL methods, not just the constructors, and I would like to anticipate that request.

So here's one proposal, let's call it "Option A" in case other options are discussed:

Option A:

These would operate on all methods for consistency.

Thoughts? Other proposed options?

guenth39 commented 1 year ago

Hey @gmlewis thanks for the feedback and sorry for not replying earlier, it kind of got lost in the day-to-day work. Today we were just talking about it and so I stumbled across the ticket again. In fact this is a mistake of course the parameters should be sorted alphabetically within the groups. Your suggestion to make it the same for all functions is of course great! I would therefore vote for option A and would be happy if these flags find their way into the plugin. We appreciate the plugin and your effort very much.

Kind regards Micha

gmlewis commented 1 year ago

Thank you, Micha! I will take a look at this issue again in December when I get back from traveling.