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

Add Disable linter to disallow usage of a set of symbols #353

Merged
merged 6 commits into from
Sep 18, 2017

Conversation

barambani
Copy link
Contributor

Ported from Wartremover, completed as part of the Scala Center Dublin spree

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 @barambani ! This looks great, only a minor comment on name of the rule and configurability.

import scalafix.lint.LintCategory
import scalafix.syntax._

case class AsInstanceOfDisabled(index: SemanticdbIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about renaming this rewrite to Disable and make the disabled symbols configurable as is done with NoInfer in #355 ? Each rule does a full traversal on the tree so we should avoid a custom rule per disabled symbol.

Copy link

Choose a reason for hiding this comment

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

Hehe, I remember that @barambani wanted to do it this way, and then I convinced him to make it specific to asInstanceOf and if there's interest we can generalize it afterwards. 👍 I agree that if general, better!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks to both for the great feedback. Please, give it a look and let me know your thoughts.

)

override def check(ctx: RuleCtx): Seq[LintMessage] =
ctx.tree.collect {
Copy link
Contributor

Choose a reason for hiding this comment

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

ctx.index.names.collect { ... } will do the same with the benefit of avoiding the tricky Term.Apply... match. SymbolMatcher.normalized can also be used as a replacement of s.symbol.contains with the benefit of being able to support multiple symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed, thanks for the help.

@jvican jvican added the spree label Sep 17, 2017
gabro
gabro previously requested changes Sep 17, 2017
Copy link
Collaborator

@gabro gabro left a comment

Choose a reason for hiding this comment

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

Overall it looks 👍 I left some nitpick comments about names and default config


case object Disable {
lazy val disabledSymbol: List[Symbol] =
Symbol("_root_.scala.Any#asInstanceOf()Ljava/lang/Object;.") :: Nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would probably use the normalized symbol here, and change the SymbolMatcher accordingly. It's a little nicer to read and more consistent with other usages of Symbol across rules

Copy link
Collaborator

Choose a reason for hiding this comment

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

On a second thought though, now that you made the rule more general it's kind of strange that asInstanceOf is the default. It feels arbitrary. Maybe this rule could be noop if not configured?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I removed the default from the rule and added a config entry in the test. Thanks.

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 @barambani ! I will follow up with a PR to rename the rule to DisableSymbol following a discussion with @gabro

@olafurpg
Copy link
Contributor

Nice work btw! I suspect this will become a popular rul!

@olafurpg olafurpg dismissed gabro’s stale review September 18, 2017 13:57

Review was addressed.

@olafurpg olafurpg merged commit d2d63a4 into scalacenter:master Sep 18, 2017
@olafurpg olafurpg changed the title Added semantic rule to disable asInstanceOf Add Disable linter to disallow usage of a set of symbols Sep 18, 2017
@barambani barambani deleted the asInstanceOf-disabled branch October 27, 2017 13:32
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.

4 participants