Giter VIP home page Giter VIP logo

scala-pre-commit-hooks's Introduction

Pre-commit/Pre-push hooks for Scala

What for?

To make your code go smoother while still maintaining high code quality.

Why?

Scala has a quite rich build ecosystem, and a myriad of tools to help you writ good code. However, the build system(s) are relatively slow, so any helpers executed via those build system run the risk of interrupting the flow of a developer.

Moreover, some of the code quality tools/features (like unused import checks) are actively in opposition to a "run-often" coding approach.

Moving relevant checks to the pre-commit/pre-push phases partially alleviates those two issues.

How?

This is a set of hooks defined in the excellent pre-commit library.

Currently, they include the following:

  • sbt-fatal-warnings - turns on -Xfatal-warnings, runs a clean compilation on the given scope.

  • sbt-unused-imports - as above, but also adds the "unused imports" warning.

  • sbt-scalafmt - runs scalafmtCheckAll.

  • sbt-wartremover - runs the wartremover plugin.

To add one or more of the hooks into your repo:

  1. Have everyone on your team install pre-commit.

  2. Add a .pre-commit-config.yaml file to your repository, with the following syntax:

    .pre-commit-config.yaml
    repos:
    -   repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v0.3.0
        default_phase: push #change to commit if desired
        hooks: #mix and match any of the following:
        -   id: sbt-fatal-warnings #arguments optional
            args: [--scope=test:compile]
        -   id: sbt-unused-imports #includes fatal warnings, arguments optional
            args: [--scope=test:compile]
        -   id: sbt-scalafmt
        -   id: sbt-wartremover #arguments are optional
            args: [--warts=Warts.unsafe, --scope=test:compile]
  3. Run pre-commit install to apply your hooks to the repo.

Note

All hooks except for sbt-scalafmt have the optional scope argument, which allows to define what source scopes are relevant for the hook’s check. The default is test:compile.

Important

Steps 1-2 are only really required for the person setting up the pre-commit library integration. pre-commit library plugins, once installed, are normal Git hooks and are thus "visible" to everyone using the repo.

How to control hook run time

By default, the hooks defined here run on both pre-commit and pre-push. They do, however, require some time to get running on large codebases, especially since each hook’s execution is essentially a clean build.

To limit hook runs to e.g. pre-push, you need to add a stages argument with the relevant value:

.pre-commit-config.yaml
repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v0.3.0
    hooks:
    -   id: sbt-fatal-warnings
        stages: [push] #or [commit, push] etc.

I want more hooks/found a problem!

Thanks for noticing that! Please create an issue.

I want to add a hook!

Excellent, please create a PR. See the contribution guide for more details.

scala-pre-commit-hooks's People

Contributors

mikolak-net avatar

Watchers

 avatar

Forkers

ffdhorkin

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.