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 Capybara/VisibilityMatcher cop #886
Conversation
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.
Flawless headstart! 👏
I believe I have this PR in an acceptable working state except for the node matchers that are not as strict as they could be. But I don't know how to properly write the possible signatures. |
Looks great, I have nothing to add! Can you please resolve the conflict? @bquorning @Darhazer do you have any objections on onboarding this new cop? |
04411f5
to
369e500
Compare
Rebased, squashed and resolved. |
it 'registers an offense when using a using multiple options`' do | ||
expect_offense(<<-RUBY) | ||
expect(page).to have_selector('.my_element', count: 1, visible: false, normalize_ws: true) | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`. |
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.
Good stuff! Thanks for contributing.
One comment though. Instead of
expect(page).to have_selector('.my_element', count: 1, visible: false, normalize_ws: true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
I would prefer
expect(page).to have_selector('.my_element', count: 1, visible: false, normalize_ws: true)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
That is, highlighting only the offending part of the hash argument.
You can do this by having the node matchers return that part of the node by using $
, e.g.
(send nil? :have_selector ... (hash <$(pair (sym :visible) true) ...>))
and then using the return value (which is also yielded, if you call the node matcher with a block) – e.g.
visible_true?(node) do |arg|
add_offense(arg, message: MSG_TRUE)
end
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.
Good point, I didn't know how to do that, thanks for the pointers. I've added these changes and am now waiting for CI. I will squash if you approve the changes.
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.
Go ahead, looks perfect.
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.
Done.
23307c7
to
7aa3340
Compare
Thank you for your contribution! |
🙏 Thank you @aried3r |
Thank you for all the help! |
Fixes #885.
This is a work in progress still, since it's my first cop.
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.