mill icon indicating copy to clipboard operation
mill copied to clipboard

Support a way to run Scalafmt on the build files

Open lolgab opened this issue 2 years ago • 2 comments

Is there a way to lint the build files? In my projects I usually define a target like:

def buildSources = T.sources(os.pwd / "build.sc")

And then I run Scalafmt with:

mill mill.scalalib.scalafmt.ScalafmtModule/reformatAll buildSources

It would be nice if there was a way to access the build sources without having to define them manually.

lolgab avatar Feb 23 '22 14:02 lolgab

Currently there is no such target, but I think it is a good idea to have it. It should probably also contain all included files, which we need also in other places like e.g. IDE/BSP support.

lefou avatar Feb 23 '22 22:02 lefou

I opened a RFC which might affect this issue.

  • https://github.com/com-lihaoyi/mill/discussions/1857

lefou avatar May 04 '22 09:05 lefou

I opened two PR to support running targets on meta-builds (#2719) and to look up the .scalafmt.conf in the current working directory (#2720). After merging both, the following should work to format the build.sc and it's included files:

$ mill --meta-level 1 mill.scalalib.scalafmt.ScalafmtModule/reformatAll sources
Formatting 3 Scala sources
parsed config (v3.7.10): /home/lefou/work/opensource/mill/.scalafmt.conf

lefou avatar Aug 31 '23 11:08 lefou

Thank you very much for this @lefou! 👏👏👏👏

lolgab avatar Sep 01 '23 15:09 lolgab