From e85659367e3f87cf3429e852bcc866637ab8c19f Mon Sep 17 00:00:00 2001 From: Bor Kae Hwang Date: Mon, 27 Jan 2020 13:33:33 -0700 Subject: [PATCH] Move doc to separate md --- README.md | 38 ++----------------------------------- docs/phase_scalafmt.md | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 docs/phase_scalafmt.md diff --git a/README.md b/README.md index e408c0529..87af5fd10 100644 --- a/README.md +++ b/README.md @@ -201,42 +201,8 @@ Phases provide 3 major benefits: See [Customizable Phase](docs/customizable_phase.md) for more info. -## Scala Format -A phase extension `phase_scalafmt` can format Scala source code via [Scalafmt](https://scalameta.org/scalafmt/). - -Add this snippet to `WORKSPACE` -``` -load("//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories") -scalafmt_default_config() -scalafmt_repositories() -``` - -To add this phase to the rules, you have to pass the extension to rule macros. Take `scala_binary` for example, -``` -load("//scala:advanced_usage/scala.bzl", "make_scala_binary") -load("//scala/scalafmt:phase_scalafmt_ext.bzl", "ext_scalafmt") - -scalafmt_scala_binary = make_scala_binary(ext_scalafmt) -``` -Then use `scalafmt_scala_binary` as normal. - -The extension adds 2 additional attributes to the rule - - `format`: enable formatting - - `config`: the Scalafmt configuration file - -When `format` is set to `true`, you can do -``` -bazel run .format -``` -to format the source code, and do -``` -bazel run .format-test -``` -to check the format (without modifying source code). - -The extension provides default configuration, but there are 2 ways to use custom configuration. - - Put `.scalafmt.conf` at root of your workspace - - Pass `.scalafmt.conf` in via `config` attribute +### Phase extensions + - [Scala Format](docs/phase_scalafmt.md) ## Building from source Test & Build: diff --git a/docs/phase_scalafmt.md b/docs/phase_scalafmt.md new file mode 100644 index 000000000..f018e1c7c --- /dev/null +++ b/docs/phase_scalafmt.md @@ -0,0 +1,43 @@ +# Phase Scalafmt + +## Contents +* [Overview](#overview) +* [How to set up](#how-to-set-up) + +## Overview +A phase extension `phase_scalafmt` can format Scala source code via [Scalafmt](https://scalameta.org/scalafmt/). + +## How to set up +Add this snippet to `WORKSPACE` +``` +load("//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories") +scalafmt_default_config() +scalafmt_repositories() +``` + +To add this phase to the rules, you have to pass the extension to rule macros. Take `scala_binary` for example, +``` +load("//scala:advanced_usage/scala.bzl", "make_scala_binary") +load("//scala/scalafmt:phase_scalafmt_ext.bzl", "ext_scalafmt") + +scalafmt_scala_binary = make_scala_binary(ext_scalafmt) +``` +Then use `scalafmt_scala_binary` as normal. + +The extension adds 2 additional attributes to the rule + - `format`: enable formatting + - `config`: the Scalafmt configuration file + +When `format` is set to `true`, you can do +``` +bazel run .format +``` +to format the source code, and do +``` +bazel run .format-test +``` +to check the format (without modifying source code). + +The extension provides default configuration, but there are 2 ways to use custom configuration. + - Put `.scalafmt.conf` at root of your workspace + - Pass `.scalafmt.conf` in via `config` attribute