scalafmt-api

Bridge for scalafmt API

License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.lucidchart
ArtifactId

ArtifactId

scalafmt-api
Last Version

Last Version

1.16
Release Date

Release Date

Type

Type

jar
Description

Description

scalafmt-api
Bridge for scalafmt API
Project URL

Project URL

https://github.com/lucidsoftware/neo-sbt-scalafmt
Project Organization

Project Organization

com.lucidchart
Source Code Management

Source Code Management

https://github.com/lucidsoftware/neo-sbt-scalafmt

Download scalafmt-api

How to add to project

<!-- https://jarcasting.com/artifacts/com.lucidchart/scalafmt-api/ -->
<dependency>
    <groupId>com.lucidchart</groupId>
    <artifactId>scalafmt-api</artifactId>
    <version>1.16</version>
</dependency>
// https://jarcasting.com/artifacts/com.lucidchart/scalafmt-api/
implementation 'com.lucidchart:scalafmt-api:1.16'
// https://jarcasting.com/artifacts/com.lucidchart/scalafmt-api/
implementation ("com.lucidchart:scalafmt-api:1.16")
'com.lucidchart:scalafmt-api:jar:1.16'
<dependency org="com.lucidchart" name="scalafmt-api" rev="1.16">
  <artifact name="scalafmt-api" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.lucidchart', module='scalafmt-api', version='1.16')
)
libraryDependencies += "com.lucidchart" % "scalafmt-api" % "1.16"
[com.lucidchart/scalafmt-api "1.16"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

neo-sbt-scalafmt

Build Status Maven Version

An sbt plugin for Scalafmt that

  • formats .sbt and .scala files
  • supports sbt 0.13 and 1.0.0-RC3
  • supports Scalafmt 0.6 and 1.0
  • runs in-process
  • uses sbt's ivy2 for dependency resolution

Usage

In project/plugins.sbt,

// see the Maven badge at the top of this README for the latest version

addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "<version>")
// if you use coursier, you must use sbt-scalafmt-coursier
// addSbtPlugin("com.lucidchart" % "sbt-scalafmt-coursier" % "<version>")

then

> scalafmt       # format compile sources
> test:scalafmt  # format test sources
> sbt:scalafmt   # format .sbt source

To ensure everything is formatted, and fail if it is not (e.g. as a CI step),

> scalafmt::test      # check compile sources
> test:scalafmt::test # check test sources
> sbt:scalafmt::test  # check .sbt sources

Scalafmt configuration

By default, .scalafmt.conf in the root project is used for Scalafmt configuration. If the file does not exist, the Scalafmt defaults are used. To choose another config file,

scalafmtConfig in ThisBuild := file("other.scalafmt.conf") // all projects
scalafmtConfig := file("other.scalafmt.conf")              // current project
scalafmtConfig in Compile := file("other.scalafmt.conf")   // current project, specific configuration

To change the Scalafmt version,

scalafmtVersion in ThisBuild := "1.0.0-RC2" // all projects
scalafmtVersion := "1.0.0-RC2"              // current project

Task configuration

To run scalafmt automatically before compiling (or before loading, in the case of sbt).

scalafmtOnCompile in ThisBuild := true // all projects
scalafmtOnCompile := true              // current project
scalafmtOnCompile in Compile := true   // current project, specific configuration

To run scalafmt::test automatically before compiling (or before loading, in the case of sbt).

scalafmtTestOnCompile in ThisBuild := true // all projects
scalafmtTestOnCompile := true              // current project
scalafmtTestOnCompile in Compile := true   // current project, specific configuration

By default, scalafmt::test fails if sources are unformatted. If you'd prefer warnings instead:

scalafmtFailTest in ThisBuild := false // all projects
scalafmtFailTest := false              // current project
scalafmtFailTest in Compile := false   // current project, specific configuration

At the time of writing, Scalafmt fails on some valid inputs. By default, errors in Scalafmt itself do not fail the scalafmt task. To fail instead,

ignoreErrors in (ThisBuild, scalafmt) := false // all projects
ignoreErrors in scalafmt := false              // current project
ignoreErrors in (Compile, scalafmt) := false   // current project, specific configuration

By default, scalafmt just lists the files that have differences. You can configure it to show the actual diff like this:

scalafmtShowDiff in (ThisBuild, scalafmt) := true // all projects
scalafmtShowDiff in scalafmt := true              // current project
scalafmtShowDiff in (Compile, scalafmt) := true   // current project, specific configuration

Additional configuration

The scalafmt task is defined by default for the compile and test configurations. To define it for additional configurations, e.g. Integration,

inConfig(Integration)(scalafmtSettings)

To disable this plugin for a project

disablePlugins(ScalafmtCorePlugin)

Formatting build files

If you wish to format project/*.scala files, configure the meta-build by adding sbt-scalafmt to project/project/plugins.sbt, and configuring it in project/plugins.sbt. See sbt documentation on meta-builds.

Implementation details

Scalafmt artifacts are downloaded with a scalafmt Ivy configuration added to each project. Scalafmt classes are loaded in a separate classloader, allowing them work regardless of the Scala version of sbt.

  • ScalafmtCorePlugin adds the Ivy configuration and scalafmt dependency.
  • ScalafmtCoursierPlugin replaces the sbt ivy configuration with coursier.
  • ScalafmtSbtPlugin create scalafmt tasks for .sbt sources.
  • ScalafmtPlugin creates the scalafmt task for compile and test configurations.

Scalafmt requires Java 8+.

com.lucidchart

Lucid Software, Inc

Versions

Version
1.16
1.15
1.14
1.13
1.12
1.11
1.10
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0
0.4
0.3
0.2
0.1
0.0