-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
- 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 |
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.
are there concrete cases in which head
is not safe?
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.
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
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.
wut, why isn't A
the head of those tokens?
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.
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( |
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.
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) |
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.
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?
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.
whoops, that was a relic of a failed refactoring attempt.
) | ||
|
||
private[this] def importeeName(importee: Importee): Option[Name] = |
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.
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.
nice!
Amazing PR, thank you @olafurpg! |
.syntax == ","