Skip to content

Commit

Permalink
feat: add Scalafix rule for organizing imports (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
hseeberger authored Jan 18, 2022
1 parent 01628a1 commit 3b603d9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
OrganizeImports {
blankLines = Manual
coalesceToWildcardImportThreshold = null
expandRelative = false
groupExplicitlyImportedImplicitsSeparately = false
groupedImports = AggressiveMerge
groups = [ "*" ]
importSelectorsOrder = Ascii
importsOrder = Ascii
preset = DEFAULT
removeUnused = true
}
3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ maxColumn = 100
indentOperator.preset = "spray"
unindentTopLevelOperators = true
spaces.inImportCurlyBraces = true
rewrite.rules = ["AsciiSortImports", "RedundantBraces", "RedundantParens"]
rewrite.rules = ["Imports", "RedundantBraces", "RedundantParens"]
rewrite.imports.sort = "ascii"
docstrings.blankFirstLine = true
trailingCommas = "preserve"
newlines.beforeCurlyLambdaParams = "multilineWithCaseOnly"
5 changes: 4 additions & 1 deletion src/main/scala/de/heikoseeberger/sbtfresh/Fresh.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ private final class Fresh(
def writeReadme(): Path =
write("README.md", Template.readme(name, license))

def writeScalafmt(): Path =
def writeScalafixConf(): Path =
write(".scalafix.conf", Template.scalafixConf)

def writeScalafmtConf(): Path =
write(".scalafmt.conf", Template.scalafmtConf)

private def write(path: String, content: String) =
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/de/heikoseeberger/sbtfresh/FreshPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ object FreshPlugin extends AutoPlugin {
fresh.writeNotice()
fresh.writePlugins()
fresh.writeReadme()
fresh.writeScalafmt()
fresh.writeScalafixConf()
fresh.writeScalafmtConf()
if (setUpGit) fresh.initialCommit()

state.reboot(true)
Expand Down
17 changes: 16 additions & 1 deletion src/main/scala/de/heikoseeberger/sbtfresh/Template.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ private object Template {
|""".stripMargin
}

def scalafixConf: String =
"""|OrganizeImports {
| blankLines = Manual
| coalesceToWildcardImportThreshold = null
| expandRelative = false
| groupExplicitlyImportedImplicitsSeparately = false
| groupedImports = AggressiveMerge
| groups = [ "*" ]
| importSelectorsOrder = Ascii
| importsOrder = Ascii
| preset = DEFAULT
| removeUnused = true
|}""".stripMargin

def scalafmtConf: String =
"""|version = "3.3.1"
|
Expand All @@ -212,7 +226,8 @@ private object Template {
|indentOperator.preset = "spray"
|unindentTopLevelOperators = true
|spaces.inImportCurlyBraces = true
|rewrite.rules = ["AsciiSortImports", "RedundantBraces", "RedundantParens"]
|rewrite.rules = ["Imports", "RedundantBraces", "RedundantParens"]
|rewrite.imports.sort = "ascii"
|docstrings.blankFirstLine = true
|trailingCommas = "preserve"
|newlines.beforeCurlyLambdaParams = "multilineWithCaseOnly"
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/sbt-fresh/default/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
> fresh organization=org name=acme setUpGit=true
$ exists .gitignore
$ exists .scalafix.conf
$ exists .scalafmt.conf
$ exists build.sbt
$ exists LICENSE
Expand Down

0 comments on commit 3b603d9

Please sign in to comment.