3

I'm trying to gently introduce scalafmt to a large existing codebase and I want it to make virtually no changes except for a handful of noncontroversial settings the whole team can agree on.

With some settings like maxColumn I can override the default of 80 to something absurd like 5000 to have no changes. But with other settings I have to make choices that will modify the existing code like with continuationIndent.callSite. The setting requires a number which would aggressively introduce changes on the first run on our codebase.

Is there anything I can do in my scalafmt config to preserve all my code except for a few specific settings?

EDIT: I will also accept suggestions of other tools that solve the same issue.

codenoodle
  • 982
  • 6
  • 19

1 Answers1

2

Consider project.includeFilters:

Configure which source files should be formatted in this project.

# manually include files to format. 
project.includeFilters = [
 regex1   
 regex2 
] 

For example, say we have project structure with foo, bar, baz, etc. packages like so

someProject/src/main/scala/com/example/foo/*.scala
someProject/src/main/scala/com/example/bar/*.scala
someProject/src/main/scala/com/example/baz/qux/*.scala
...

Then the following .scalafmt.conf

project.includeFilters = [
  "foo/.*"
]
continuationIndent.callSite = 2
...

will format only files in foo package. Now we can proceed to gradually introduce formatting to the codebase package-by-package

project.includeFilters = [
  "foo/.*"
  "bar/.*"
]
continuationIndent.callSite = 2
...

or even file-by-file

project.includeFilters = [
  "foo/FooA\.scala"
  "foo/FooB\.scala"
]
continuationIndent.callSite = 2
...
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • This is cool and I didn't know you could do that. But I'm really looking for a way to just enforce one or two of the scalafmt settings on all the files. – codenoodle Sep 04 '19 at 21:16