Skip to content

Commit

Permalink
Add documentation to cross publish rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mlachkar committed Sep 17, 2020
1 parent 6ee88ea commit 7ed5b4f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
41 changes: 41 additions & 0 deletions docs/developers/cross-publish-custom-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
id: cross-publish-custom-rules
title: Cross publish custom rules
---
## Already existing custom rules
If your rule is meant only for one scala version, for example, a rule that
automates a migration from one scala version to another, you don't need
to cross publish your rule. In fact, your rule should only be run for
this specific scala version, and should only be published in this
scala version.

Otherwise, if your rule is not specific to a scala version, and in order
to make the migration to scalafix v1 smooth for users, we need the rules
authors to cross-publish their rules for the scala versions they support.
For most rules, this change requires only modifying the build settings as follows:

```diff
// build.sbt
scalaVersion := V.scala212,
+crossScalaVersions := List(V.scala213, V.scala212, V.scala211),
```
The second step is to update your CI to run tests on the different
scala versions your rule is being cross-published to. For that, you only
need prefix the test action with `+`. For example:
```
sbt +test
```

## New rules
The scalafix template has already been updated to automatically
cross publish rules (see [pull request](https://github.com/scalacenter/scalafix/issues/1202)).
Therefore, no change is required if you are writing a new rule.



## Projects that already cross-publish
[Edit](https://github.com/scalacenter/scalafix/edit/master/docs/developers/cross-publish-custom-rules.md) this page to submit a pull request that adds more project that cross-publish their rule.
This is a non-exhaustive list of pull request that have cross-published their rules:
- [liancheng/**scalafix-organize-imports**](https://github.com/liancheng/scalafix-organize-imports/pull/69)
- [scala/**scala-rewrites**](https://github.com/scala/scala-rewrites/pull/33)
- [NeQuissimus/**sort-imports**](https://github.com/NeQuissimus/sort-imports/pull/66)
3 changes: 2 additions & 1 deletion docs/developers/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ The expansion rules for `github:org/repo` are the following:

> If your rule only targets a single codebase and is not meant to be
> distributed, you might want to develop it [as part of your existing
> build](local-rules.md) instead.
> build](local-rules.md) instead. You may also read [how to cross publish you rules](cross-publish-custom-rules.md)
> once you have set up the necessary configuration to publish to Maven Central.
Run the following sbt command to publish a rule locally.

Expand Down
3 changes: 2 additions & 1 deletion website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"developers/setup",
"developers/before-you-begin",
"developers/tutorial",
"developers/local-rules"
"developers/local-rules",
"developers/cross-publish-custom-rules"
],
"API Reference": [
"developers/api",
Expand Down

0 comments on commit 7ed5b4f

Please sign in to comment.