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 cop that checks for valid sigil #5

Merged
merged 5 commits into from
Jul 16, 2019
Merged

Conversation

peterzhu2118
Copy link
Member

Adds a new cop ValidSorbetSigil that checks that every Ruby file contains a valid Sorbet sigil. Has autocorrect features that adds typed: false to all files that do not have a sigil. I've tested this on core and it works as expected and causes no typecheck errors.

I've talked to @clarkdave and has given me permission to adapt from this gist: https://gist.github.com/clarkdave/85aca4e16f33fd52aceb6a0a29936e52.

@peterzhu2118 peterzhu2118 requested a review from a team July 16, 2019 14:52
lib/rubocop/cop/sorbet/valid_sorbet_sigil.rb Show resolved Hide resolved
lib/rubocop/cop/sorbet/valid_sorbet_sigil.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@Morriar Morriar left a comment

Choose a reason for hiding this comment

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

Thanks for indulging me!

@XrXr
Copy link

XrXr commented Jul 16, 2019

Instead of searching twice, why not search the first block of comment tokens?

something like: processed_source.tokens.take_while {|token| token.type == :tCOMMENT}.find { |token| /^ # typed: (\w+)/.match(token.text){|m| sigil = m[1] }; !!sigil }

This way you wouldn't have to search twice to find the location of the token when you want to report the error.

Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Not sure what the rule for matching the comment is, but I think we can be a bit more flexible with it.

lib/rubocop/cop/sorbet/valid_sorbet_sigil.rb Show resolved Hide resolved
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Awesome!

@peterzhu2118 peterzhu2118 merged commit 6db161c into master Jul 16, 2019
@peterzhu2118 peterzhu2118 deleted the sorbet-sigil-cop branch July 16, 2019 18:43
@peterzhu2118 peterzhu2118 temporarily deployed to production July 16, 2019 18:50 Inactive
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