• Stars
    star
    149
  • Rank 240,923 (Top 5 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Scalafmt SBT plugin

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+.

More Repositories

1

relate

Performant database access in Scala
Scala
160
star
2

xtract

A library to make it easy to deserialize XML to user types in scala
Scala
59
star
3

apt-boto-s3

The fast and simple S3 transport for apt.
Python
56
star
4

piezo

Piezo is a set of tools for operating a quartz scheduling cluster.
Scala
53
star
5

ebs-monitor

53
star
6

sbt-cross

A better solution for building multiple Scala versions (cross compiling) in SBT
Scala
50
star
7

closure-typescript-example

An example of using the Google Closure Compiler with TypeScript, Tsickle, and Clutz.
JavaScript
40
star
8

cumulus

Cloudformation alternative
Ruby
28
star
9

nodegun

Nailgun for Node.js
TypeScript
26
star
10

auto-renewing-subscription-demo

Demo of how to implement in-app purchases
Objective-C
21
star
11

nark

Nark is an alerting and dashboard frontend for graphite.
JavaScript
18
star
12

javascriptcore-demo

JavaScript
11
star
13

rules_play_routes

Bazel rules for compiling Play Framework routes files
Starlark
11
star
14

statsd-ha-receiver

Simple daemon that uses the StatsD protocol to accept stats from a load balancer and distribute them among a known set of StatsD servers. This helps in creating a highly available StatsD / Graphite architecture.
JavaScript
10
star
15

xtract-example

Example project using xtract
Scala
9
star
16

lucid-programming-competition-2020

TypeScript
8
star
17

java-thread-context

Track thread local things
Java
7
star
18

opentracing-playframework

OpenTracing for the Play Framework
Scala
7
star
19

cashy

Lucid's static asset manager.
JavaScript
7
star
20

sample-lucid-extensions

Example Lucid (lucid.app) Editor Extensions
TypeScript
6
star
21

lucid-programming-competition-2019

Exercises and solutions for the 2019 LPC
TypeScript
6
star
22

aws-sdk-cpp-deb

[unmaintained] AWS C++ SDK Debian packages
Makefile
5
star
23

terraform-audit

Tool to find resources that aren't managed by terraform (but should be)
Ruby
5
star
24

statsd-smart-repeater

A backend for statsd that aggregates and sends metrics out to another statsd server.
JavaScript
5
star
25

Lucideyes

Easily compare images for visual equality without pixel perfection
Java
4
star
26

lucid-programming-competition-2017

Python
4
star
27

lucid-android

A small collection of useful classes and helpers for using Scala on Android.
Scala
4
star
28

pekko-thread-context

Thread context propogation for Akka
Scala
4
star
29

zipkin-opentracing

OpenTracing for Zipkin
Java
3
star
30

rules_twirl

Bazel rules for compiling Twirl templates
Starlark
3
star
31

opentracing-thread-context

Opentracing with thread-context
Java
2
star
32

lucid-programming-competition-2018

Python
2
star
33

phase_zinc

Scala
1
star
34

byu-coding-challenge-2015f

Problems and solutions for the Fall 2015 BYU ACM Invitational Coding Challenge
HTML
1
star
35

rules_hocon

Bazel rules for verifying and merging HOCON config files
Starlark
1
star
36

closure-examples

Examples of Google Closure Compiler and Closure Library.
JavaScript
1
star
37

thread-flow

libraries for tracking execution flow through asynchronous or distributed systems on the JVM
Scala
1
star
38

lucid-programming-competition-2022

Lucid Programming Competition 2022
Python
1
star
39

opentracing-httpcomponents

OpenTracing for HttpComponents
Java
1
star
40

ctf2019

Capture the flag challenges and answers for Lucid's 2019 CTF
PHP
1
star
41

lucid-programming-competition-2021

Python
1
star
42

sample-lucid-rest-applications

Example REST API apps for Lucid (lucid.app)
Python
1
star