Skip to content

Commit 75743f6

Browse files
committed
Address feedback
1 parent 211a076 commit 75743f6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

blog/_posts/2017-02-25-scalafix-v0.3.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A symbol is a unique identifier of a single definition.
3030
For example, `println` from the standard library has the symbol `_root_.scala.Predef.println(Ljava/lang/Object;)V.`.
3131
The compiler is responsible for resolving names to symbols.
3232

33-
Scalahost is a compiler plugin in the scala.meta project that extracts symbols from the compiler and maps them to scala.meta syntax trees.
33+
[Scalahost][] is a compiler plugin in the scala.meta project that extracts symbols from the compiler and maps them to scala.meta syntax trees.
3434
Scalahost emits the extracted symbols into a "semantic database".
3535
The semantic database can be persisted to files on disk and loaded for later analysis.
3636
Semantic databases from different compilation units, potentially produced by different
@@ -39,16 +39,18 @@ This opens possibilities for large-scale code analysis.
3939

4040
The introduction of the scala.meta semantic API is a game changer for scalafix.
4141
The ability to resolve names to symbols opens possibilities for many scalafix rewrites.
42+
Before we cover a few example rewrites, let's look closer at what exactly "rewrite" means.
4243

4344
## Rewrite: meta.Tree => Seq[Patch]
44-
45+
In a nutshell, a scalafix `Rewrite` is a `scala.meta.Tree => Seq[Patch]` function.
46+
The tree is backed by the scala.meta semantic API, so the rewrite is able to query for compiler information such as symbols.
4547
A scalafix `Patch` is a small operation that can produce a diff on a Scala source file.
4648
A patch can either be a "token patch" or a "tree patch".
4749

4850
Token patches are low-level but give full control over how every detail in a source file is handled, for example formatting and comments.
4951
Example token patches are `Remove(token)` and `AddLeft(token, toAdd: String)`, which removes or prepends a string to `token`, respectively.
5052

51-
Tree patches are high-level and allow rewrite author to declaratively explain what operation to perform.
53+
Tree patches are high-level and allow the rewrite author to declaratively explain what operation to perform.
5254
An example tree patch is `AddGlobalImport(importer)`, which adds a new import to the top of a file if it does not exist.
5355
Observe that `AddGlobalImport` does not worry about token-level details such as whether the user groups imports by prefix (`import a.{b, c}`) or not (`import a.b; import a.c`).
5456

@@ -60,8 +62,6 @@ It can be harder to resolve conflicts on the token level since the original inte
6062
Unsolvable conflicts abort the refactoring.
6163
In the future, we hope to support more advanced conflict resolution strategies.
6264

63-
In a nutshell, a scalafix `Rewrite` is a `scala.meta.Tree => Seq[Patch]` function.
64-
The tree is backed by the scala.meta semantic API, so the rewrite is able to query for compiler information such as symbols.
6565
To demonstrate how rewrites are implemented with scalafix v0.3, let's step through an example use-case.
6666

6767
## Example: Xor to Either
@@ -138,6 +138,7 @@ the early days of scalafix development and come up with several brilliant ideas
138138
for scalafix use-cases.
139139

140140

141+
[Scalahost]: https://github.com/scalameta/sbt-semantic-example
141142
[@ShaneDelmore]: https://twitter.com/ShaneDelmore
142143
[@olafurpg]: https://twitter.com/olafurpg
143144
[@xeno_by]: https://twitter.com/xeno_by

0 commit comments

Comments
 (0)