-
-
Notifications
You must be signed in to change notification settings - Fork 8
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 new Capybara/ClickLinkOrButtonStyle
cop
#61
Conversation
e355e90
to
e60c0bb
Compare
I'm not sure why it's supposed to be bad to use Put another way, the issue #58 says "There is no information which style is preferred.", but I don't think this is a matter of style at all! |
Can someone explain the rationale behind why using |
I thought strict was better when I first created this cop, but I reconsidered that you are right that |
…LinkOrButtonStyle` cop Fix: #61 (comment) Fix: #61 (comment)
…LinkOrButtonStyle` cop Fix: #61 (comment) Fix: #61 (comment)
@ydah To be honest my preference would be that this rule is disabled by default, but I appreciate that many other people would find it helpful |
@iainbeeston Thank you for your feedback, we appreciate it. We will consider whether to enable or disable this cop by default at the time of the next major version update. |
For the reasons mentioned above, I too have always preferred |
@mvz @iainbeeston @ydah Let me open another round. 🤓 Here's why I will definitely stay with the strict mode (if my team agrees ^^): buttons and links are very different in terms of semantics. No matter whether they look the same to the user, they should not be used interchangably. I really like that writing good Capybara tests often forces me to solve problems that also solve problems for e.g. sight-impaired users (e.g. somehow creating a unique accessible label to avoid using IDs or other technical details as selectors). With the loose default, this cop would work against that. |
For my use case 'strict' mode just means more work when the UI changes. On the other hand, I don't want to be forced to change everywhere there is For me, the one thing that would be useful is enforcing a choice of either I see that a PR was merged changing to |
@franzliedke I'm not sure I follow your reasoning. How does link-button agnosticism encourage more accessible markup? I too am a strong advocate for using Capybara tests as a prompt for improving HTML accessibility, but I normally find myself reaching for I also agree that links and buttons should not be used interchangeably; they have different use cases. However, to the user, they provide indistinguishable UX. They are semantically different to an engineer but semantically indistinguishable to the end user. |
@mvz I often find this argument confusing. When behavior changes (and that is the case when changing from button to link, or vice versa), I would expect having to make changes in tests. I am not proposing to break your use case (you can still configure Rubocop to your preference,
I am confused. According to the examples in #76, the new default
@samrjenkins I meant to express the opposite: Encouraging devs to ignore the difference between button and link has the potential to hurt accessibility. Thus, the new "loose" (non-strict) default has the potential to hurt accessibility.
I disagree. Keyboard interaction, mouseover, ctrl+click are all different, that's also user-visible behavior. |
@franzliedke apologies. I mistyped. I should have asked: How does link-button agnosticism DIScourage more accessible markup? |
Ah, thanks for clarifying. 🙈 Agnosticism enforces the notion that there's no difference between links and buttons; that is factually wrong and hurts accessibility. |
I agree, but this should only be the case in tests where the change in behavior is relevant to thing being tested. If it is relevant, I would definitely use |
That's great. 👍🏼 Aren't linters supposed to provide the safe path forward, and point out potential problems. (There's always some human judgement necessary, especially when it comes to the amount and level of suggestions that Rubocop makes.) I argue for the default to be that safe path, and for anyone who wants to say "I know what I'm doing", there's |
Yes, I'm not against having to configure this cop to do what I want, and I can also see that requiring a specific action would be a good default. What I am against is the idea that this is a matter of 'style'. |
My apologies. I reminded myself that this cop is certainly not something that should be unified one way or the other, and that it is important to use it appropriately. How about we remove this cop for the next major version update? |
I definitely like having it available, even if I don't prefer the default. 😉 |
I'm late to the party here since this only showed up in a release now, but the answer to this question is that assistive software for people with disabilities uses the distinction between links and buttons to better help explain what will happen when one is followed or pressed. If your site is audited for WCAG 2.1 compliance using e.g. links for in-page actions will definitely get flagged and your site won't be compliant. So knowing when to use a button or a link is important even when visible there is not going to be a difference. I really hope that this default can be reverted so that the default will be to be explicit about using links or buttons and thus create more accessible websites. |
now false positive if finding link by click_link(href: seo_link)
# Capybara/ClickLinkOrButtonStyle: Use click_link_or_button or click_on instead of click_link.
|
Similar to @ermolaev's comment above, I'm seeing the same error from Capybara when following this cop's advice: # Test passes
# Capybara/ClickLinkOrButtonStyle complains
click_button title: "Delete" # Test fails
# Capybara/ClickLinkOrButtonStyle happy
click_on title: "Delete" The exception (same as @ermolaev's):
From that, it's not entirely clear to me if this is an issue with this cop's guidance or in Capybara itself. The various methods appear equivalent and I'm having trouble tracing the source of the # Lines 25–28
def click_link_or_button(locator = nil, **options)
find(:link_or_button, locator, **options).click
end
alias_method :click_on, :click_link_or_button
# Lines 41–43
def click_link(locator = nil, **options)
find(:link, locator, **options).click
end
# Lines 57–59
def click_button(locator = nil, **options)
find(:button, locator, **options).click
end |
I think proceeding in the direction of deleting |
This rule's default enforce style, `link_or_button` [1], introduced a number of problems [2]. Specifically, I noticed issues switching to `click_on` from `click_button` [3]. The hack solution is to ignore or disable the rule in some places but not in others. Not great. As a result, the rule is slated for removal [4] and replacement [5] by a new rule. In the interim, configuring this rule to enforce a strict use of `click_button` and `click_link` is preferential (and, honestly, more communicative). In this author's opinion, user interface specs should be explicit about the markup under test. [1] https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaraclicklinkorbuttonstyle [2] rubocop/rubocop-capybara#61 [3] rubocop/rubocop-capybara#61 (comment) [4] rubocop/rubocop-capybara#81 [5] rubocop/rubocop-capybara#99
## Description This rule's default enforce style, `link_or_button` [1], introduced a number of problems [2]. Specifically, I noticed issues switching to `click_on` from `click_button` [3]. The hack solution is to ignore or disable the rule in some places but not in others. Not great. As a result, the rule is slated for removal [4] and replacement [5] by a new rule. In the interim, configuring this rule to enforce a strict use of `click_button` and `click_link` is preferential (and, honestly, more communicative). In this author's opinion, user interface specs should be explicit about the markup under test. [1] https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaraclicklinkorbuttonstyle [2] rubocop/rubocop-capybara#61 [3] rubocop/rubocop-capybara#61 (comment) [4] rubocop/rubocop-capybara#81 [5] rubocop/rubocop-capybara#99 ## Commits - Configure `Capybara/ClickLinkOrButtonStyle` - Bump version to v1.1.0
Fix: #58
Before submitting the PR make sure the following are checked:
main
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.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
.Enabled: pending
inconfig/default.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.