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

Use Cop::Base API for Lint department #8395

Merged

Conversation

koic
Copy link
Member

@koic koic commented Jul 24, 2020

Follow #7868.

This PR uses Cop::Base API for Lint department's cops.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@@ -21,21 +21,20 @@ module Lint
#
# # With parentheses, there's no ambiguity.
# do_something(/pattern/i)
class AmbiguousRegexpLiteral < Cop
class AmbiguousRegexpLiteral < Base
include ParserDiagnostic
Copy link
Contributor

@marcandre marcandre Jul 24, 2020

Choose a reason for hiding this comment

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

My 2 cents is that this module doesn't do enough to justify its existence and makes things more complicated than if it didn't exist. If you think it should exist, than maybe it could define on_new_investigation and call on_diagnostic, but that's it. There is nothing else it does that is of any use.

@marcandre
Copy link
Contributor

Wow, impressive PR 💪 🙇‍♂️
I'd love to review more but won't be able till next monday.

@koic koic force-pushed the use_cop_base_api_for_lint_department branch from b66d27a to 40c21b0 Compare July 24, 2020 18:59
Copy link
Contributor

@marcandre marcandre left a comment

Choose a reason for hiding this comment

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

Lots of work in there 💪!

I found just one extra thing in addition to my comment about ParserDiagnostic

end
end

private

def autcocorrect(comment)
Copy link
Contributor

@marcandre marcandre Aug 3, 2020

Choose a reason for hiding this comment

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

Oh! Interesting! 😅
This is a problem, because now the block is called even if autocorrection won't happen...
So this would always do the chmod.
I had not considered this case 😆, and there's no test for that either I think.
If you add if autocorrect_requested? you should be pretty much ok.
(Also, there's a typo)

Copy link
Member Author

Choose a reason for hiding this comment

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

(Also, there's a typo)

Oops! I missed this typo 💦

This is a problem, because now the block is called even if autocorrection won't happen...

I did print debugging. The block execution seems to be running only when offensed. Is if autocorrect_requested? required?

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a spec in #8441
I think that if you rebase now, you will get a failure. Sorry, the expect_offense method need improvement...

Copy link
Member Author

Choose a reason for hiding this comment

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

The build failed as expected with #8441. I added if autocorrect_requested? and the build has been passed. Thank you for adding the reproduction test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks

end
end

private
def autocorrect(corrector, node)
if (captured_values = uri_regexp_with_argument?(node))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised we don't have a cop to change this to

captured_values = uri_regexp_with_argument?(node) ||
                  uri_regexp_without_argument?(node)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I've also improved other redundant logic in uri_regexp.rb. Thank you for your review ❤️

@koic koic force-pushed the use_cop_base_api_for_lint_department branch from 40c21b0 to 8624579 Compare August 3, 2020 03:35
@koic
Copy link
Member Author

koic commented Aug 3, 2020

I found just one extra thing in addition to my comment about ParserDiagnostic

Yeah, I would like to refactor it in another PR due to this update changes the module structure.

marcandre added a commit to marcandre/rubocop that referenced this pull request Aug 3, 2020
marcandre added a commit that referenced this pull request Aug 3, 2020
Follow rubocop#7868.

This PR uses `Cop::Base` API for `Lint` department's cops.
@koic koic force-pushed the use_cop_base_api_for_lint_department branch from 8624579 to 71c9653 Compare August 3, 2020 04:40
@marcandre marcandre merged commit ecdf9c5 into rubocop:master Aug 3, 2020
@marcandre
Copy link
Contributor

Cool!

Great work 💪

I found just one extra thing in addition to my comment about ParserDiagnostic

Yeah, I would like to refactor it in another PR due to this update changes the module structure.

Looking forward to it, thanks!

@koic koic deleted the use_cop_base_api_for_lint_department branch August 3, 2020 05:19
koic added a commit to koic/rubocop that referenced this pull request Aug 3, 2020
Follow rubocop#8395 (comment).

This PR does a refactoring to inline `ParserDiagnostic` module.
It seems that it is simpler and easier to maintain if it is implemented
by each cop rather than mix-in the module.

I don't think `ParserDiagnostic` module is used outside of RuboCop core,
at least not in the RuboCop HQ products.
On the other hand, I added it to the changelog just in case for 3rd party gems.
@koic koic mentioned this pull request Aug 3, 2020
8 tasks
@koic
Copy link
Member Author

koic commented Aug 3, 2020

I've opened #8442 :-)

marcandre pushed a commit that referenced this pull request Aug 3, 2020
Follow #8395 (comment).

This PR does a refactoring to inline `ParserDiagnostic` module.
It seems that it is simpler and easier to maintain if it is implemented
by each cop rather than mix-in the module.

I don't think `ParserDiagnostic` module is used outside of RuboCop core,
at least not in the RuboCop HQ products.
On the other hand, I added it to the changelog just in case for 3rd party gems.
koic added a commit to koic/rubocop that referenced this pull request Aug 28, 2020
Follow rubocop#7868, rubocop#8377, and rubocop#8395

This PR uses `Cop::Base` API for `Lint/TopLevelReturnWithArgument`.
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.

None yet

2 participants