-
Notifications
You must be signed in to change notification settings - Fork 184
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
Second steps towards scalafix.v1 #809
Conversation
Now that scala.meta.Symbol no longer exists this rename is safe
I don't think rules should be both rewrites and linters.
Codecov Report
@@ Coverage Diff @@
## master #809 +/- ##
==========================================
- Coverage 72.55% 67.37% -5.18%
==========================================
Files 158 166 +8
Lines 3869 4067 +198
Branches 331 332 +1
==========================================
- Hits 2807 2740 -67
- Misses 1062 1327 +265
Continue to review full report at Codecov.
|
def owner: Symbol = Symbol(info.symbol).owner | ||
def name: String = info.name | ||
def kind: SymbolKind = new SymbolKind(info) | ||
def props: SymbolProperties = new SymbolProperties(info.properties) |
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.
How about inlining kind.isXXX
and props.isXXX
into SymbolInfo
, so that it's info.isFinal
and info.isMethod
instead of info.props.isFinal
and info.kind.isMethod
?
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.
case _ => scala.None | ||
} | ||
def isPublic: Boolean = a.isInstanceOf[s.PublicAccess] | ||
def isNone: Boolean = a == s.NoAccess |
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.
An alternative approach to this API would be to replace privateWithin
and protectedWithin
with isPrivateWithin
, isProtectedWithin
and within
. I think I like that better than the current API.
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.
if (isVal) buf += "val" | ||
if (isVar) buf += "var" | ||
buf.mkString("SymbolProperties(", " ", ")") | ||
} |
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 wonder if we can use metap for that.
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.
We can, but it requires making metap more flexible: scalameta/scalameta#1751
// def constant(c: s.Constant): Constant = c match { | ||
// case s.NoConstant => throw new IllegalArgumentException(c.toString) | ||
// case s.NoConstant => throw new IllegalArgumentException(c.toString) | ||
// } |
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.
Is this used anywhere?
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.
It's not, removed.
@@ -9,7 +9,7 @@ final class Symbol private (val value: String) { | |||
def isGlobal: Boolean = value.isGlobal | |||
def isLocal: Boolean = value.isLocal | |||
def owner: Symbol = Symbol(value.owner) | |||
def info(doc: SemanticDoc): SymbolInfo = doc.info(this) | |||
def info(doc: SemanticDoc): Option[SymbolInfo] = doc.info(this) |
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.
Looks like there are two ways of doing the same thing: doc.info
and symbol.info
. How about we keep only the former?
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 agree having two ways to do the same thing is a smell, I will go for Symbol.info
with an implicit SemanticDoc
instead. SemanticDoc
is already implicit so that it can be passed to unapply
methods.
We should update to latest scalafmt to automatically fix this with `trailingCommas=never`
This makes it possible to experiement with different kinds of symbol matchers: - prefix trees for instant lookups - combined symbol matchers
This commit refactors Doc.tree to be computed on demand. This makes it possible to implement rules that don't even parse the source file, which could save a lot of redundant work when running on large codebases for example when only targeting files that reference a single symbol.
This required exposing messages in the API
This aligns the scalafix API with semanticdb/lsp terminology. It was always weird to write `messsage.message` to get the string message from a `LintMessage`. The `LintMessage` name remains accessible via forwarders for v0.
- LintMessage and LintCategory belong in the v0 package. Refactor v1 rules to use Diagnostic directly instead. - Diagnostic.apply is a simple constructor for simple use-cases - LintDiagnostic doesn't need to be a trait, fewer extension points is better. - remove dead code
Will merge before this grows any bigger. All rules except
|
These were originally copy-pasted before M10 was released.
This required introducing a new trait scalafix.v1.Symtab since - we need access to the symtab in order to pretty-print symbols - if we use SemanticDoc then we'd need to construct bogus Tree instances in order to construct a basic SymbolInfo. We should not let `SemanticDoc` creep in everywhere as a dependency to even the most trivial functionality.
Gonna merge to unblock a PR from @MasseGuillaume on the website, happy to iterate further on this. I believe it will be more interesting to discuss the new v1 API once the docs are in, which is next on my queue :) |
This PR makes progress towards migrating the codebase to use scalafix.v1 instead of scalafix.v0
scala.meta.Symbol
is goneScope
is replaced withList[SymbolInfo]
which is possible thanks to having a symbol table around. Most of the pain was writingequals
andhashCode
by hand since I thinkType
andSignature
should be "data classes" with reasonable equalityTODO: