Comments (1)
Crude POC using Global / onLoad
with sbt 1.3.x - done in my own project as an autoplugin. Has "double pass" behavior if changes are detected:
import sbt.{ Def, _ }
import Keys._
import org.scalafmt.sbt.ScalafmtPlugin
// https://www.scala-sbt.org/1.x/docs/Howto-Startup.html
object ScalafmtOnLoad extends AutoPlugin {
override def requires = ScalafmtPlugin
override def trigger = AllRequirements
// This prepends the String you would type into the shell
lazy val startupTransition: State => State = { s: State =>
"scalafmtSbt" :: s
}
override def globalSettings: Seq[Def.Setting[_]] = Seq(
// onLoad is scoped to Global because there's only one.
Global / onLoad := {
val old = (Global / onLoad).value
// compose the new transition on top of the existing one
// in case your plugins are using this hook.
startupTransition.compose(old)
}
)
}
Note that I excluded ScalafmtOnLoad.scala
using project.excludeFilters
out of fear of infinite loop π
- sbt detects changes, reloads
onLoad
firesscalafmtSbt
, build files are formatted (i intentionally added a changes that would get reformatted)- sbt detects changes, reloads a second time
- this time, no changes detected, loop exits, life goes on, itβs all cool
sbt:foo>
[info] build source files have changed
[info] modified files:
[info] /Users/rtoomey/workspace/foo/build.sbt
[info] /Users/rtoomey/workspace/foo/project/ScalafmtOnLoad.scala
[info] Reloading sbt...
[info] Loading global plugins from /Users/rtoomey/.sbt/1.0/plugins
[info] Loading settings for project foo-build from plugins.sbt,build.sbt ...
[info] Loading project definition from /Users/rtoomey/workspace/foo/project
[info] Compiling 1 Scala source to /Users/rtoomey/workspace/foo/project/target/scala-2.12/sbt-1.0/classes ...
[info] Loading settings for project root from build.sbt ...
[info] Resolving key references (36593 settings) ...
[info] Set current project to foo (in build file:/Users/rtoomey/workspace/foo/)
[success] Total time: 3 s, completed Dec 6, 2019 12:24:11 PM
[info] build source files have changed
[info] modified files:
[info] /Users/rtoomey/workspace/foo/build.sbt
[info] Reloading sbt...
[info] Loading global plugins from /Users/rtoomey/.sbt/1.0/plugins
[info] Loading settings for project foo-build from plugins.sbt,build.sbt ...
[info] Loading project definition from /Users/rtoomey/workspace/foo/project
[info] Loading settings for project root from build.sbt ...
[info] Resolving key references (36593 settings) ...
[info] Set current project to foo (in build file:/Users/rtoomey/workspace/foo/)
[success] Total time: 3 s, completed Dec 6, 2019 12:24:17 PM
Further manual reload
command is silent about formatting build files:
sbt:foo> reload
[info] Loading global plugins from /Users/rtoomey/.sbt/1.0/plugins
[info] Loading settings for project foo-build from plugins.sbt,build.sbt ...
[info] Loading project definition from /Users/rtoomey/workspace/foo/project
[info] Loading settings for project root from build.sbt ...
[info] Resolving key references (36593 settings) ...
[info] Set current project to foo (in build file:/Users/rtoomey/workspace/foo/)
[success] Total time: 3 s, completed Dec 6, 2019 12:27:53 PM
Seems to work! π€
from sbt-scalafmt.
Related Issues (20)
- Diff mode doesn't work with remote branch HOT 2
- Bumping from 2.4.4 to 2.4.5, scalafmtCheckAll ignores badly formatted files if git is not setup and config says otherwise HOT 5
- `shared/` sources for cross-platform projects ignored in 2.4.5 HOT 5
- [Security] Workflow release.yml is using vulnerable action actions/checkout HOT 1
- "fatal: bad revision 'main'" in Jenkins after updating from 2.4.5 to 2.4.6 with scalafmtFilter diff-ref HOT 5
- Error when no version specified in config HOT 1
- Trouble using SNAPSHOT of Scalafmt HOT 1
- Formatting breaks the code with combination of interpolated string and escaped quotations mark HOT 3
- Does this work with ammonite scripts? HOT 1
- Fail to format a single file HOT 3
- Plugin doesn't check/format a sources for scripted tests HOT 7
- Ignore not existing FileCredentials instead of failing
- Scala 3.3 ScalafmtSbtError for type with match HOT 1
- `NoSuchElementException` while formatting a file HOT 2
- Build crashes with a "corrupted class path" error after upgrading to Scalafmt 3.7.16 HOT 1
- Possibility to make new version with fix of #290 available as binary HOT 2
- Plugin doesn't format a separate integration tests module HOT 6
- 3.8.0 fails to parse numeric literal separators
- Please document how to apply configuration settings on the web site HOT 3
- apply more stringent scalafmt formatting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sbt-scalafmt.