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

Fix #373: addLeft's implementation doesn't match its specification #378

Merged
merged 1 commit into from
Sep 29, 2017
Merged

Conversation

abeln
Copy link
Contributor

@abeln abeln commented Sep 27, 2017

Return headOption instead of lastOption in addLeft's implementation.
Additionally, add a unit test, and refactor the syntax tests.

TESTED=unit tests pass

@gabro gabro requested a review from olafurpg September 27, 2017 17:40
@abeln
Copy link
Contributor Author

abeln commented Sep 27, 2017

The binary compatibility test ("mima"?) fails (because I renamed the test suite). Is that a blocker?

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution @abeln ! We recently enabled MiMa in an attempt to stabilize the public API.

A few minor comments, otherwise looks great. Nice job refactoring the test suite to make it easier to validate this fix.

@@ -8,16 +8,20 @@ import scalafix.syntax._

import org.scalatest.FunSuiteLike

class SyntacticRuleSuite(rule: Rule) extends FunSuiteLike with DiffAssertions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration manager (mima) is complaining because of this change, scalafix-testkit is a published artifact to help scalafix users develop custom rules in repositories outside of scalacenter/scalafix.

I think we can make this change without breaking compatibility by changing this parameter to defaultRule: Rule = Rule.empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -8,16 +8,20 @@ import scalafix.syntax._

import org.scalatest.FunSuiteLike

class SyntacticRuleSuite(rule: Rule) extends FunSuiteLike with DiffAssertions {
def check(name: String, original: String, expected: String): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forward this to new check overload with defaultRule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

test(name) {
import scala.meta._
val obtained = rule.apply(Input.String(original))
assertNoDiff(obtained, expected)
}
}

def checkDiff(original: Input, expected: String): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forward this to new checkDiff overload with defaultRule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

test("on parse error") {
intercept[ParseException] {
ProcedureSyntax.apply(Input.String("object A {"))
}
}
}
class PatchSuite
extends SyntacticRuleSuite(Rule.syntactic("PatchSuite")(ctx =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice cleanup, removing the rule definition in the constructor 👍

ctx.addRight(ctx.tree.tokens.find(_.is[Ident]).get, "bba")
}

val addLeftRule: Rule = Rule.syntactic("addLeft") { (ctx) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this definition right next to the next where it's used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Return `headOption` instead of `lastOption` in addLeft's implementation.
Additionally, add a unit test, and refactor the syntax tests.

TESTED=unit tests pass
@abeln
Copy link
Contributor Author

abeln commented Sep 28, 2017

Thanks for the review. PTAL.

@abeln
Copy link
Contributor Author

abeln commented Sep 28, 2017

The binary compatibility test now passes.

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thank you @abeln ! I will immediately be using the new PatchSuite to test a fix for #372

FYI, I will rename defaultRule to rule in a followup PR, I just realized although this change is binary compatible it does break clients that use a named argument. I am a total beginner at keeping compatibility between releases, but I'm trying to learn 😅

@olafurpg olafurpg merged commit 621fa77 into scalacenter:master Sep 29, 2017
@olafurpg olafurpg added this to the v0.5.3 milestone Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants