slang icon indicating copy to clipboard operation
slang copied to clipboard

Use source_gen

Open ncuillery opened this issue 1 year ago • 2 comments

In the Dart package ecosystem, most of the packages are using source_gen which formats the output code. This process has 2 main benefits:

  • The generator can just produce valid code and not care about indentation, carriage returns, etc. since the output is formatted at the end anyway
  • The developer can run dart format . and there is no change in the generated code since it has already been formatted that way.

I have started using slang and everytime I run dart run slang, I have to run dart format . and commit the changes otherwise my CI build is broken.

There is no way to exclude file in Dart formatter (yet) https://github.com/dart-lang/dart_style/issues/864 so having generated code properly formatted like code gen packages do would be great.

To repro:

  • Clone the slang repo
  • Run cd slang/example
  • Run flutter pub get
  • Run dart format .
  • Run git diff 👉 There are some changes that shouldn't be here.

ncuillery avatar Sep 22 '23 20:09 ncuillery

A temporary workaround is to remove the generated file inside the CI before running dart format .. This essentially ignores the file as it doesn't exist anymore.

Integrating source_gen requires a lot of effort so it is unlikely in the near future.

Tienisto avatar Sep 22 '23 21:09 Tienisto

Having the same problem. Would wish this feature to be implemented.

ngoc-quoc-huynh avatar Feb 11 '24 13:02 ngoc-quoc-huynh