Skip to content

Commit 348e175

Browse files
authored
Merge pull request #913 from olafurpg/docs
Update docs based on Gitter feedback
2 parents efea302 + 4a006b7 commit 348e175

File tree

3 files changed

+127
-24
lines changed

3 files changed

+127
-24
lines changed

docs/developers/symbol-information.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,28 @@ import scala.meta._
3535
```scala mdoc:passthrough
3636
import scalafix.docs.PatchDocs
3737
import scalafix.docs.PatchDocs._
38-
implicit var doc: Symtab = scalafixSymtab
38+
implicit var doc: SemanticDocument = null
39+
```
40+
41+
### Get symbol of a tree
42+
43+
Use `Tree.symbol` to get the symbol of a tree. Consider the following code.
44+
45+
```scala mdoc:passthrough
46+
doc = PatchDocs.fromStatement("""
47+
println(42)
48+
println()
49+
""")
50+
```
51+
52+
To get the `println` symbol we match against the `Term.Name("println")` tree
53+
node.
54+
55+
```scala mdoc
56+
doc.tree.collect {
57+
case apply @ Term.Apply(println @ Term.Name("println"), _) =>
58+
(apply.syntax, println.symbol)
59+
}
3960
```
4061

4162
### Lookup method return type

docs/developers/tutorial.md

Lines changed: 105 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ Next we update the rule to have an instance of the configuration
478478

479479
> It's important to keep an empty constructor `def this() = ...` so that
480480
> Scalafix can load the rule. If we forget the empty constructor we get an error
481-
> like this: "Provider fix.NoLiteralArguments could not be instantiated"
481+
> like this: "java.lang.NoSuchMethodException: Provider fix.NoLiteralArguments
482+
> could not be instantiated"
482483
483484
Next, we create a companion object with decoders to read `.scalafix.conf`
484485
configuration into `NoLiteralArgumentsConfig`.
@@ -640,16 +641,77 @@ The expansion rules for `github:org/repo` are the following:
640641

641642
## Publish the rule to Maven Central
642643

643-
The most robust way to share a custom rule is to publish it as a library to
644-
Maven Central. The
645-
[`build.sbt`](https://github.com/olafurpg/named-literal-arguments/blob/master/scalafix/build.sbt)
646-
shows the necessary changes to build.sbt to populate publishing information. The
647-
[sbt-ci-release](https://github.com/olafurpg/sbt-ci-release) readme documents
648-
the further steps to configure gpg and Sonatype.
644+
Run the following sbt command to publish a rule locally.
649645

650-
Once you have your rule, users can depend on it in the sbt plugin by updating
651-
`scalafixDependencies`
652-
(`scalafix.sbt.ScalafixPlugin.autoImport.scalafixDependencies`)
646+
```sh
647+
> rules/publishLocal
648+
```
649+
650+
To publish a rule online you need additional steps. First, add the settings
651+
below to your `build.sbt` (replacing `ch.epfl.scala`, `scalacenter/scalafix` and
652+
`olafurpg` with your own organization and project name)
653+
654+
```scala
655+
// build.sbt
656+
inThisBuild(List(
657+
organization := "ch.epfl.scala",
658+
homepage := Some(url("https://github.com/scalacenter/scalafix")),
659+
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
660+
developers := List(
661+
Developer(
662+
"olafurpg",
663+
"Ólafur Páll Geirsson",
664+
665+
url("https://geirsson.com")
666+
)
667+
)
668+
))
669+
```
670+
671+
Next, add the `sbt-ci-release` plugin to `project/plugins.sbt`
672+
673+
```scala
674+
// project/plugins.sbt
675+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.2.2")
676+
```
677+
678+
If you have not setup GPG on your machine, run the following command
679+
680+
```sh
681+
gpg --gen-key
682+
```
683+
684+
Finally, create a Sonatype account if you have never published to Sonatype
685+
before. Follow the instructions
686+
[here](https://central.sonatype.org/pages/ossrh-guide.html). If you don't have a
687+
domain name, you can use `com.github.@username`. Here is a template you can use
688+
to write the Sonatype issue:
689+
690+
```text
691+
Title:
692+
Publish rights for com.github.olafurpg
693+
Description:
694+
Hi, I would like to publish under the groupId: com.github.olafurpg.
695+
It's my GitHub account https://github.com/olafurpg/
696+
```
697+
698+
Once Sonatype and GPG are setup, run the following command to publish the rule
699+
online.
700+
701+
```sh
702+
> rules/publishSigned
703+
> sonatypeRelease
704+
```
705+
706+
Once published, users can run your rule with the following sbt command.
707+
708+
```sh
709+
// sbt shell
710+
> scalafix dependency:[email protected]:named-literal-arguments:VERSION
711+
```
712+
713+
To permanently install the rule for a build, users can add the dependency to
714+
`build.sbt` by updating `scalafixDependencies in ThisBuild`.
653715

654716
```scala
655717
// build.sbt
@@ -659,6 +721,12 @@ scalafixDependencies in ThisBuild +=
659721
> scalafix NamedLiteralArguments
660722
```
661723

724+
For builds using `project/*.scala` files, add the following auto import
725+
726+
```scala
727+
import scalafix.sbt.ScalafixPlugin.autoImport._
728+
```
729+
662730
Users of the Scalafix command-line interface can use the `--tool-classpath` flag
663731

664732
```
@@ -672,11 +740,31 @@ scalafix \
672740
Note that for syntactic rules like `NoLiteralArguments`, the `--classpath`
673741
argument is not required.
674742

675-
Don't be intimidated by publishing to Maven Central, it gets easier once you've
676-
done it the first time. A guide on how to publish libraries can be found
677-
[here](https://github.com/olafurpg/sbt-ci-release). The benefits of publishing a
678-
rule to Maven Central are many.
743+
### Adding custom resolver
744+
745+
Update the `scalafixResolvers` setting to resolve rules that are published to a
746+
custom repository like Bintray or a private Nexus.
679747

680-
- Dependencies, you can use custom library dependency to implement your rule
681-
- Fast to run, no need to re-compile the rule on every Scalafix invocation
682-
- Tab completion in sbt, users can tab-complete your rule when using sbt plugin
748+
```scala
749+
// build.sbt
750+
import com.geirsson.coursiersmall.{Repository => R}
751+
scalafixResolvers.in(ThisBuild) ++= List(
752+
R.SonatypeSnapshots,
753+
R.bintrayRepo("scalacenter", "releases"),
754+
R.bintrayIvyRepo("sbt", "sbt-plugin-releases"),
755+
new R.Maven("https://oss.sonatype.org/content/repositories/snapshots/"),
756+
new R.Ivy(s"https://dl.bintray.com/sbt/sbt-plugin-releases/")
757+
)
758+
```
759+
760+
### Conclusion
761+
762+
Don't be intimidated by publishing to Maven Central, it gets easier once you've
763+
done it the first time. A more detailed guide on how to publish libraries can be
764+
found [here](https://github.com/olafurpg/sbt-ci-release). The benefits of
765+
publishing a rule to Maven Central are many.
766+
767+
- Bring your own dependencies, you can use custom library dependency to
768+
implement a published rule.
769+
- Fast to run, no need to re-compile the rule on every Scalafix invocation.
770+
- Tab completion in sbt, users can tab-complete your rule when using sbt plugin.

website/i18n/en.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
"developers/patch": {
2020
"title": "Patch"
2121
},
22-
"developers/scala-type": {
23-
"title": "ScalaType"
24-
},
2522
"developers/semantic-tree": {
2623
"title": "SemanticTree"
2724
},
@@ -40,9 +37,6 @@
4037
"developers/symbol-matcher": {
4138
"title": "SymbolMatcher"
4239
},
43-
"developers/synthetic-tree": {
44-
"title": "SyntheticTree"
45-
},
4640
"developers/tutorial": {
4741
"title": "Tutorial"
4842
},

0 commit comments

Comments
 (0)