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

Refactor scalafix migration rewrite #1

Merged
merged 2 commits into from
Sep 11, 2017

Conversation

olafurpg
Copy link

  • ctx.replaceSymbols also renames
  • ctx.replaceSymbols also removes imports
  • Tree.is[Comma] instead of .syntax == ","
  • Tree.collectFirst/exists from contrib module.
  • tokenList.leading().takeWhile to strip leading whitespace

- ctx.replaceSymbols also renames
- ctx.replaceSymbols also removes imports
- Tree.is[Comma] instead of `.syntax == ","`
- Tree.collectFirst/exists from contrib module.
- tokenList.leading().takeWhile to strip leading whitespace
}
}
for {
head <- t.tokens.headOption
Copy link
Owner

Choose a reason for hiding this comment

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

are there concrete cases in which head is not safe?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it's quite common unfortunately :/

@ "trait A".parse[Source].get.collect {
    case t @ Name(_) => t.tokens.head.syntax
  }
java.util.NoSuchElementException: next on empty iterator

Copy link
Owner

Choose a reason for hiding this comment

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

wut, why isn't A the head of those tokens?

Copy link
Author

Choose a reason for hiding this comment

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

There's a Name.Anonymous() inside the Template.self

@ template"{}"
res3: Template = Template(List(), List(), Self(_, None), List())

Symbol("_root_.cats.Foldable.sequenceU_.") -> "sequence_",
Symbol("_root_.cats.data.Func.appFuncU.") -> "appFunc",
Symbol("_root_.cats.free.FreeT.liftTU.") -> "liftT"
override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols(
Copy link
Owner

Choose a reason for hiding this comment

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

best diff <3

val leadingSpaces = ctx.tokenList.slice(leadingComma, t.tokens.head)
ctx.removeToken(leadingComma) +
leadingSpaces.map(ctx.removeToken).asPatch +
val leadingSpaces = ctx.tokenList.slice(leadingComma, t.tokens.last)
Copy link
Owner

Choose a reason for hiding this comment

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

are you sure about this change? The leading spaces are the once from the leading comma to the first token non-space token, what am I missing?

Copy link
Author

Choose a reason for hiding this comment

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

whoops, that was a relic of a failed refactoring attempt.

)

private[this] def importeeName(importee: Importee): Option[Name] =
Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

nice!

@gabro gabro merged commit 4d9d333 into gabro:master Sep 11, 2017
@gabro
Copy link
Owner

gabro commented Sep 11, 2017

Amazing PR, thank you @olafurpg!

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