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

enh: order classes?? #8

Closed
gslender opened this issue Jun 22, 2022 · 27 comments · Fixed by #9 or gmlewis/flutter-stylizer#34
Closed

enh: order classes?? #8

gslender opened this issue Jun 22, 2022 · 27 comments · Fixed by #9 or gmlewis/flutter-stylizer#34

Comments

@gslender
Copy link

Wondering if you can add the option of ordering/sorting class objects in files - I have got into the (bad) habit of placing several related classes inside a single dart file, but it would now be nice to see them ordered as part of the stylizing ??

@gmlewis
Copy link
Owner

gmlewis commented Jun 22, 2022

Ah, that's a bit trickier, but I'll see what I can come up with.

@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

@gslender - please try out the latest release when you have a chance:
https://github.com/gmlewis/go-flutter-stylizer/releases/tag/v0.1.12

by adding the new sortClassesWithinFile: true option to your yaml config file, and let me know if you find any problems with it.

Thank you!

@gslender
Copy link
Author

Having issues trying to figure out where it looks for the default location of the flutter-stylizer.yaml file. I've placed it in the root folder of where I'm running the command, in the user home folder but it still complains with...

flutterStylizer.memberOrdering must have 10 or 11 values, but found 0. Ignoring and using default

So I'm guessing it isn't reading my yaml file... of which the contents are...

groupAndSortGetterMethods: false
groupAndSortVariableTypes: false
memberOrdering:
  public-constructor
  named-constructors
  public-static-variables
  public-instance-variables
  public-override-variables
  private-static-variables
  private-instance-variables
  public-override-methods
  public-other-methods
  private-other-methods
  build-method
sortClassesWithinFile: false
sortOtherMethods: false
sortClassesWithinFile: true

@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

The default location is: $HOME/.flutter-stylizer.yaml but this can be overriden with --config.

@gslender
Copy link
Author

Where is $HOME ?? if that's not defined?

@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

What platform are you running on?

@gslender
Copy link
Author

MacOS

I tried with --config and got this as the output...

$ ../flutter-stylizer --config ~/flutter-stylizer.yaml -w ./lib/...
Using config file: /Users/gslender/flutter-stylizer.yaml
2022/06/23 13:31:22 Stylizing 68 files...
panic: runtime error: slice bounds out of range [:24191] with length 10460

goroutine 1 [running]:
github.com/gmlewis/go-flutter-stylizer/dart.(*Client).rewriteClasses(0xc00010fad0?, {0xc0001c8a80?, 0x6300?}, {0xc000279520, 0x3, 0xc0001679c0?})
	/home/glenn/go/src/github.com/gmlewis/go-flutter-stylizer/dart/rewrite.go:244 +0x110
github.com/gmlewis/go-flutter-stylizer/dart.(*Client).StylizeFile(0xc00010fad0, {0xc00014e2b8, 0x18})
	/home/glenn/go/src/github.com/gmlewis/go-flutter-stylizer/dart/dart.go:125 +0x37f
github.com/gmlewis/go-flutter-stylizer/cli.rootRunE(0x153f440?, {0xc000126640, 0x1, 0x4?})
	/home/glenn/go/src/github.com/gmlewis/go-flutter-stylizer/cli/cli.go:156 +0xb10
github.com/spf13/cobra.(*Command).execute(0x153f440, {0xc000100060, 0x4, 0x4})
	/home/glenn/go/pkg/mod/github.com/spf13/[email protected]/command.go:842 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0x153f440)
	/home/glenn/go/pkg/mod/github.com/spf13/[email protected]/command.go:950 +0x39c
github.com/spf13/cobra.(*Command).Execute(...)
	/home/glenn/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
github.com/gmlewis/go-flutter-stylizer/cli.Execute()
	/home/glenn/go/src/github.com/gmlewis/go-flutter-stylizer/cli/cli.go:177 +0x25
main.main()
	/home/glenn/go/src/github.com/gmlewis/go-flutter-stylizer/cmd/flutter-stylizer/main.go:22 +0x17

@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

Yikes! Back to the drawing board. :-(

If you feel like making a tiny test case for me that reproduces the problem, that would be great... otherwise I'll keep poking at it.
Sorry about that.

Oh, and $HOME should be set to /Users/gslender on your Mac with a terminal like iTerm2 or equivalent bash/zsh terminal.

@gmlewis gmlewis reopened this Jun 23, 2022
@gslender
Copy link
Author

Yes, $HOME is set to the same path as ~/ but it doesn't work. So there is a bug/issue with the default way it derives the path for $HOME - maybe write the "path" it is trying to use when you think it is working to show that the correct config is being used... and then maybe that might tell you what is wrong at my end. Because my $HOME is correctly set, and the config file is there, but the command isn't picking it up... at least not without me using --config

@gslender
Copy link
Author

I re-ran the command with verbose on, and it barfs on a dart file with 3 enums and 3 classes defined. Does that help give you a clue to the issue? Otherwise nothing else odd about that file. I'll see if I can declassify the contents of the dart file to share, but in the meantime, see if you can confirm that a mix of enum and classes will work.

@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

Yes, $HOME is set to the same path as ~/ but it doesn't work. So there is a bug/issue with the default way it derives the path for $HOME - maybe write the "path" it is trying to use when you think it is working to show that the correct config is being used... and then maybe that might tell you what is wrong at my end. Because my $HOME is correctly set, and the config file is there, but the command isn't picking it up... at least not without me using --config

Please note the leading dot in $HOME/.flutter-stylizer.yaml - not $HOME/flutter-stylizer.yaml.

I re-ran the command with verbose on, and it barfs on a dart file with 3 enums and 3 classes defined. Does that help give you a clue to the issue? Otherwise nothing else odd about that file. I'll see if I can declassify the contents of the dart file to share, but in the meantime, see if you can confirm that a mix of enum and classes will work.

OK, thanks... I'll investigate.

@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

Whups, I didn't mean to close this one yet.

@gmlewis gmlewis reopened this Jun 23, 2022
@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

I believe I found the problem. I'm working on a fix.

@gmlewis
Copy link
Owner

gmlewis commented Jun 23, 2022

Hi @gslender - please try out v0.1.13 and see if that fixes the problem with sorting classes within the file.
https://github.com/gmlewis/go-flutter-stylizer/releases/tag/v0.1.13

@gslender
Copy link
Author

gslender commented Jun 23, 2022

Close but no cigar! It works and orders the classes in the dart files, but it also incorrectly (in my opinion) orders classes that start with an underscore ie _MyClassState lower than all other classes... so it separates the widget class from the state class associated with that widget class. The solution would be, for correct "Flutter" class ordering, to ignore the _ as a character (ie remove it in the ordering method) and allow the order to be just based on name, and the associated class files would be kept together and with the state class being lower/after the widget class. Fix that and I think you're sorted !!

@gmlewis
Copy link
Owner

gmlewis commented Jun 24, 2022

OK, gotcha. I'll work on the next version. Thanks for the feedback! I appreciate it.

@gmlewis
Copy link
Owner

gmlewis commented Jun 24, 2022

Hi @gslender - please try out v0.1.14 when you get a chance and see if that is what you described:
https://github.com/gmlewis/go-flutter-stylizer/releases/tag/v0.1.14

@gslender
Copy link
Author

It works well. I would suggest you consider enums as well, but happy for you to close this enh request off as done ! Awesome tool by the way :-)

@gmlewis
Copy link
Owner

gmlewis commented Jun 24, 2022

I would suggest you consider enums as well

I would be happy to look into this. If you could please send me an example input along with expected output, that would make things much easier on my end. Thanks!

Awesome tool by the way :-)

Thank you! I'm glad you like it.

@gslender
Copy link
Author

handling enums as you do classes... right now enums seem to be ignored and not ordered like the classes... so either sort them with classes (together) or optionally (my preference) would be to sort them like this, all enums sorted above all classes sorted. Does it really doesn't need an example to explain it..?? just sort the enums as opposed to ignoring (or make it an option) etc. Not a big deal, but it was what I then noticed after seeing the classes all nicely sorted.

@gmlewis
Copy link
Owner

gmlewis commented Jun 25, 2022

OK, so maybe groupAndSortEnumsBeforeClasses: true ?

@gmlewis
Copy link
Owner

gmlewis commented Jun 25, 2022

Do you also want the internals of the enums to be processed in addition to the classes with the same ordering as the classes?

@gmlewis
Copy link
Owner

gmlewis commented Jun 25, 2022

Maybe processEnumsLikeClasses: true would just be simpler all-around and use all the exact same settings.

@gslender
Copy link
Author

Sounds good !! 👍

@gslender
Copy link
Author

Do you also want the internals of the enums to be processed in addition to the classes with the same ordering as the classes?

That would definitely be good if possible!

@gmlewis
Copy link
Owner

gmlewis commented Jun 27, 2022

Hi @gslender - when you get a chance, please try out the new release:
https://github.com/gmlewis/go-flutter-stylizer/releases/tag/v0.1.15
and the new processEnumsLikeClasses flag and see if it works like you expect it to.

Thank you!

@gslender
Copy link
Author

Works perfectly !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants