Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation to cross publish rules #1237

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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