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

[Fix #1288] Let LinkToBlank find violations in link_to_if and link_to_unless #1289

Merged

Conversation

fwolfst
Copy link
Contributor

@fwolfst fwolfst commented May 30, 2024

Fix #1288 (but not adding link_to_unless_current) by adding respective methods to the RESTRICT_ON_SEND list, hoping that this is the right approach.

I sketched an approach for the specs, but it would mean executing very similar specs three times - see relevant commit for a very brief discussion: 70db8e4 . What do you think?


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@fwolfst fwolfst changed the title 1288 let link to blank find link to if and unless Let LinkToBlank find link_to_if and link_to_unless (#1288) May 30, 2024
@fwolfst fwolfst changed the title Let LinkToBlank find link_to_if and link_to_unless (#1288) [Fix #1288] Let LinkToBlank find link_to_if and link_to_unless May 30, 2024
@fwolfst fwolfst changed the title [Fix #1288] Let LinkToBlank find link_to_if and link_to_unless [Fix #1288] Let LinkToBlank find violations in link_to_if and link_to_unless May 30, 2024
@@ -1,6 +1,18 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Rails::LinkToBlank, :config do
['link_to', 'link_to_if condition?, ', 'link_to_unless condition?, '].each do |link_helper_method|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Examplary. All other specs in here could be wrapped like this (70db8e4)

Copy link
Member

Choose a reason for hiding this comment

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

Can you divide this into three separate tests instead of using each loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, it will be three basically identically long blocks of tests then, but I understand if you prefer the explicitness.

Copy link
Member

Choose a reason for hiding this comment

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

For example, redundant commas like in with 'link_to_unless condition?, ' will be included in the text of context. To avoid this, it is acceptable to write three similar tests that only differ in the method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, did that in the last commit for all the specs. If acceptable, I will squash the commits/drop the old one.

@fwolfst fwolfst force-pushed the 1288-let_link_to_blank_find_link_to_if_and_unless branch 2 times, most recently from fe22f72 to a3138ef Compare June 4, 2024 06:04
@fwolfst fwolfst requested a review from koic June 10, 2024 07:34
@koic
Copy link
Member

koic commented Jun 17, 2024

@fwolfst Looks good to me. Can you squash your commits into one?

of the LinkToBlank cop.

Add changelog entry and add specs within three contexts for the three
different methods

Co-authored-by: Koichi ITO <koic.ito@gmail.com>
@fwolfst fwolfst force-pushed the 1288-let_link_to_blank_find_link_to_if_and_unless branch from a3138ef to e8d60f3 Compare June 17, 2024 05:59
@fwolfst
Copy link
Contributor Author

fwolfst commented Jun 17, 2024

@fwolfst Looks good to me. Can you squash your commits into one?

done.

@koic koic merged commit d99bbe1 into rubocop:master Jun 19, 2024
14 checks passed
@koic
Copy link
Member

koic commented Jun 19, 2024

Thanks!

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.

Let Rails/LinkToBlank also catch cases where link_to_if++ is used
2 participants