-
-
Notifications
You must be signed in to change notification settings - Fork 15
Add scalafix rules for 0.13.0 release
#330
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| resolvers += Resolver.sonatypeRepo("releases") | ||
| addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.2") | ||
| addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.6") | ||
| addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.11.0") |
3 changes: 2 additions & 1 deletion
3
scalafix/rules/src/main/resources/META-INF/services/scalafix.v1.Rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| fix.RenameAssertToExpect | ||
| fix.RewriteExpect | ||
| fix.AddClueToExpect | ||
| fix.v0_11_0 | ||
| fix.v0_11_0 | ||
| fix.v0_13_0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package fix | ||
|
|
||
| import scalafix.v1._ | ||
| import scala.meta._ | ||
|
|
||
| class v0_13_0 extends SemanticRule("v0_13_0") { | ||
|
|
||
| override def fix(implicit doc: SemanticDocument): Patch = | ||
| renameMutableSuites + renameSuiteName | ||
|
|
||
| def renameMutableSuites(implicit doc: SemanticDocument): Patch = { | ||
| val suiteNames = Map( | ||
| "MutableIOSuite" -> "IOSuite", | ||
| "MutableFSuite" -> "FSuite", | ||
| "SimpleMutableIOSuite" -> "SimpleIOSuite", | ||
| "FunSuiteIO" -> "FunSuite" | ||
| ) | ||
| suiteNames.map { case (prevSuiteName, nextSuiteName) => | ||
| val suiteSymbol = SymbolMatcher.normalized(s"weaver/$prevSuiteName") | ||
| doc.tree.collect { | ||
| case suiteSymbol(tree) => | ||
| tree match { | ||
| case Type.Name(`prevSuiteName`) => | ||
| Patch.replaceTree(tree, nextSuiteName) | ||
| case Importee.Name(_) => | ||
| Patch.replaceTree(tree, nextSuiteName) | ||
| case Importee.Rename(fromTree, _) => | ||
| Patch.replaceTree(fromTree, nextSuiteName) | ||
| case _ => | ||
| Patch.empty | ||
| } | ||
| }.asPatch | ||
| }.asPatch | ||
| } | ||
|
|
||
| def renameSuiteName(implicit doc: SemanticDocument): Patch = { | ||
| val symbol = SymbolMatcher.normalized(s"weaver/EffectSuite#name().") | ||
| doc.tree.collect { | ||
| case symbol(tree) => | ||
| tree match { | ||
| case Term.Name("name") => | ||
| Patch.replaceTree(tree, "suiteName") | ||
| case _ => Patch.empty | ||
| } | ||
| }.asPatch | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
scalafix/v0_13_0/input/src/main/scala/fix/RenameFunSuiteIOTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| rule = v0_13_0 | ||
| */ | ||
| package fix | ||
|
|
||
| import weaver.FunSuiteIO | ||
| import cats.effect._ | ||
|
|
||
| object BasicFunSuiteIO extends FunSuiteIO { | ||
| def basicFunction(suite: FunSuiteIO): FunSuiteIO = suite | ||
| } | ||
|
|
||
| import weaver.{ FunSuiteIO => FunSuiteIOAlias } | ||
|
|
||
| object AnotherFunSuiteIO extends FunSuiteIOAlias |
26 changes: 26 additions & 0 deletions
26
scalafix/v0_13_0/input/src/main/scala/fix/RenameMutableIOSuiteTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| rule = v0_13_0 | ||
| */ | ||
| package fix | ||
|
|
||
| import weaver.MutableIOSuite | ||
| import cats.effect._ | ||
|
|
||
| object BasicMutableIOSuite extends MutableIOSuite { | ||
|
|
||
| type Res = Unit | ||
| def sharedResource: Resource[IO, Res] = Resource.unit | ||
|
|
||
| def basicFunction(suite: MutableIOSuite): MutableIOSuite = suite | ||
| } | ||
|
|
||
| import weaver.{ MutableIOSuite => MutableIOSuiteAlias } | ||
|
|
||
| object AnotherMutableIOSuite extends MutableIOSuiteAlias { | ||
| type Res = Unit | ||
| def sharedResource: Resource[IO, Res] = Resource.unit | ||
| } | ||
|
|
||
| import weaver.MutableFSuite | ||
|
|
||
| trait BasicMutableFSuite extends MutableFSuite[IO] |
21 changes: 21 additions & 0 deletions
21
scalafix/v0_13_0/input/src/main/scala/fix/RenameNameToSuiteNameTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| rule = v0_13_0 | ||
| */ | ||
| package fix | ||
| import weaver._ | ||
|
|
||
| object RenameNameToSuiteName extends SimpleIOSuite { | ||
|
|
||
| pureTest("basic") { | ||
| expect.same(name, "basic") | ||
| } | ||
|
|
||
| pureTest("other name") { | ||
| val name = "basic" | ||
| expect.same(name, "basic") | ||
| } | ||
|
|
||
| def getName(suite: SimpleIOSuite): String = { | ||
| suite.name | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
scalafix/v0_13_0/input/src/main/scala/fix/RenameSimpleMutableIOSuiteTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| rule = v0_13_0 | ||
| */ | ||
| package fix | ||
|
|
||
| import weaver.SimpleMutableIOSuite | ||
| import cats.effect._ | ||
|
|
||
| object BasicSimpleMutableIOSuite extends SimpleMutableIOSuite { | ||
| def basicFunction(suite: SimpleMutableIOSuite): SimpleMutableIOSuite = suite | ||
| } | ||
|
|
||
| import weaver.{ SimpleMutableIOSuite => SimpleMutableIOSuiteAlias } | ||
|
|
||
| object AnotherSimpleMutableIOSuite extends SimpleMutableIOSuiteAlias |
12 changes: 12 additions & 0 deletions
12
scalafix/v0_13_0/output/src/main/scala/fix/RenameFunSuiteIOTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package fix | ||
|
|
||
| import weaver.FunSuite | ||
| import cats.effect._ | ||
|
|
||
| object BasicFunSuiteIO extends FunSuite { | ||
| def basicFunction(suite: FunSuite): FunSuite = suite | ||
| } | ||
|
|
||
| import weaver.{ FunSuite => FunSuiteIOAlias } | ||
|
|
||
| object AnotherFunSuiteIO extends FunSuiteIOAlias | ||
23 changes: 23 additions & 0 deletions
23
scalafix/v0_13_0/output/src/main/scala/fix/RenameMutableIOSuiteTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package fix | ||
|
|
||
| import weaver.IOSuite | ||
| import cats.effect._ | ||
|
|
||
| object BasicMutableIOSuite extends IOSuite { | ||
|
|
||
| type Res = Unit | ||
| def sharedResource: Resource[IO, Res] = Resource.unit | ||
|
|
||
| def basicFunction(suite: IOSuite): IOSuite = suite | ||
| } | ||
|
|
||
| import weaver.{ IOSuite => MutableIOSuiteAlias } | ||
|
|
||
| object AnotherMutableIOSuite extends MutableIOSuiteAlias { | ||
| type Res = Unit | ||
| def sharedResource: Resource[IO, Res] = Resource.unit | ||
| } | ||
|
|
||
| import weaver.FSuite | ||
|
|
||
| trait BasicMutableFSuite extends FSuite[IO] |
18 changes: 18 additions & 0 deletions
18
scalafix/v0_13_0/output/src/main/scala/fix/RenameNameToSuiteNameTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package fix | ||
| import weaver._ | ||
|
|
||
| object RenameNameToSuiteName extends SimpleIOSuite { | ||
|
|
||
| pureTest("basic") { | ||
| expect.same(suiteName, "basic") | ||
| } | ||
|
|
||
| pureTest("other name") { | ||
| val name = "basic" | ||
| expect.same(name, "basic") | ||
| } | ||
|
|
||
| def getName(suite: SimpleIOSuite): String = { | ||
| suite.suiteName | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
scalafix/v0_13_0/output/src/main/scala/fix/RenameSimpleMutableIOSuiteTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package fix | ||
|
|
||
| import weaver.SimpleIOSuite | ||
| import cats.effect._ | ||
|
|
||
| object BasicSimpleMutableIOSuite extends SimpleIOSuite { | ||
| def basicFunction(suite: SimpleIOSuite): SimpleIOSuite = suite | ||
| } | ||
|
|
||
| import weaver.{ SimpleIOSuite => SimpleMutableIOSuiteAlias } | ||
|
|
||
| object AnotherSimpleMutableIOSuite extends SimpleMutableIOSuiteAlias |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package fix | ||
|
|
||
| import scalafix.testkit._ | ||
| import org.scalatest.funsuite.AnyFunSuiteLike | ||
|
|
||
| class RuleSuite extends AbstractSemanticRuleSuite with AnyFunSuiteLike { | ||
| runAllTests() | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: how about removing
IOfrom the alias?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to leave it untouched. We can't guarantee what the alias name is, nor whether it will conflict with anything else in the user code.