Add a cop to check for usage of `within` instead of `within_element`
The following discussion from gitlab-ee!14360 should be addressed:
-
@splattael commented on a discussion:
So, if
within_element
is preferred overwithin
I wonder we'd need a👮 rule for this specifically for theqa/
folder to guide other folks.Currently, there are plenty of places where
within
is used:
page.within(selector) { yield } if block_given?
page.within(element_selector_css(name), text: text) do
page.within all_elements(name)[index] do
page.within('.flash-notice') do
page.within('.qa-groups-dropdown-sidebar') do
page.within('.qa-projects-dropdown-sidebar') do
page.within('.qa-navbar') do
page.within('.dropdown-menu') do
page.within(element_selector_css(:assignee_block)) do
page.within(element_selector_css(:labels_block)) do
page.within('.sidebar-top-level-items') do
page.within('.issuable-show-labels') do
page.within('.block.milestone') do
within first_token_row_for_name(token_name) do
page.within('.clone-options-dropdown') do
within('.sidebar-top-level-items') do
within('.fly-out-list') do
within(project_import_row) do
within(".js-branch-#{branch_name}") do
within(".js-branch-#{branch_name} .badge") do
within('.ci-variable-row-body', text: key) do
within('.ci-header-container') do
within('.pipeline-graph') do
within('.ci-job-component', text: name) do
within(".js-cluster-application-row-#{application_name}") do
within(".js-cluster-application-row-#{application_name}") do
within find_element(:template_option_row, text: project_name) do
page.within('form.filter-form') do
Funnily, some of them already use
.qa-
selectors so them we can adjust easily.
There are many similar cops that we could implement for all the other ways capybara page methods could be used instead of *_element
methods, or possibly a more general cop, but we can start with this specific cop.