Giter Club home page Giter Club logo

pre-commit-scalafmt's Introduction

Scalafmt hook for pre-commit

Overview

This is pre-commit hook that runs scalafmt on changed .scala and .sbt files each time you commit them.

Getting Started

You need to have pre-commit (for installation guidelines please see its site) and bash installed first.

Next, you should place the hook inside the .pre-commit-hooks.yaml. Minimal version can looks like this:

- repo: [email protected]:coyainsurance/pre-commit-scalafmt.git
  sha: master # you probably do not want to use latest version, but rather pin it to specific commit and update manually
  hooks:
  - id: scalafmt
    args: [ -p9090, -t ] # run in server mode on port 9090 and pass `--test` to scalafmt; alternatively you can place here other supported cmdline arguments

After that, you should run

pre-commit install -f --install-hooks

or equivalent to install and/or update your hooks file.

Then you should be ready to enjoy automatic checks if your Scala files are formatted accordingly.

Details

Script has several options than can be passed using args array for the pre-commit hook configuration.

  • -c $scalafmtConfig sets the scalafmt config (default=.scalafmt.conf).

  • -d $bootstrapDirectory sets the bootstrap directory (default=$HOME/.scalafmt).

    It is used to place coursier and scalafmt binaries for the first time this hook is run.

  • -p $port - binds nailgun to the specified port. Implies the -s option.

  • -s - starts scalafmt in background using nailgun.

    That should significantly speedup checking your files, as scalafmt is then already running in background and JVM processes can take quite significant time to initialize. The tradeoff is that you may sometimes need to commit again, as hook may fail due to connection problems (apparently happens with long-enough running nailgun service).

    You should also make sure to have recent enough nailgun version (0.9.1 should do). In case of older version you may simply get no response back.

    Default port is specified by $NAILGUN_PORT environment variable if it exists. If not, 2113 is taken. Alternatively one can use -p option to override the port.

  • -t - passes --test to scalafmt, that implies no mis-formatted file will be changed instead of returning 1 exit code on any.

  • -v $version - forces to use specific (default=1.4.0) scalafmt version.

  • -o $organisation - forces to use specific (default=com.geirsson) scalafmt organisation.

It was successfully tested both on Linux distributions and MacOS.

pre-commit-scalafmt's People

Contributors

kjanosz avatar rb3ckers avatar note avatar smur89 avatar fvlankvelt avatar

Watchers

James Cloos avatar  avatar

Forkers

fvlankvelt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.