Skip to content
This repository has been archived by the owner on Dec 4, 2022. It is now read-only.

Sort named parameters in constructors #28

Open
guenth39 opened this issue Mar 8, 2022 · 3 comments
Open

Sort named parameters in constructors #28

guenth39 opened this issue Mar 8, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@guenth39
Copy link

guenth39 commented Mar 8, 2022

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
Copy link
Owner

gmlewis commented Mar 8, 2022

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:

  • add a new config variable: "sortNamedParameters: true"
  • add a new config variable: "groupAndSortRequiredParameters: true"

These would operate on all methods for consistency.

Thoughts? Other proposed options?

@guenth39
Copy link
Author

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
Copy link
Owner

gmlewis commented Nov 14, 2022

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

@gmlewis gmlewis added enhancement New feature or request and removed waiting for reply labels Dec 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants