Repository navigation
Conversation
Flags data-test-selector passed to a ViewComponent through data: instead of the test_selector: system argument, which Primer only renders outside production. Autocorrects by moving the key out of data:. Limited to component constructors, slot calls and configured forwarding helpers. Skips Primer form controls, which render the argument as a literal attribute.
There was a problem hiding this comment.
🟡 Changes recommended
Autocorrection can alter evaluation order or create duplicate keywords, while broad with_* matching causes false positives.
3 open findings
What changed in this PR
Adds a RuboCop cop that moves ViewComponent test selectors into Primer’s environment-aware system argument.
Changes:
- Implements detection and autocorrection for component, slot, and forwarding-helper calls.
- Adds configuration, exclusions, tests, registration, and release notes.
- Covers nested arguments and multiple selector syntaxes.
| File | Description |
|---|---|
lib/rubocop/cop/open_project/test_selector_system_argument.rb |
Implements the cop and autocorrection. |
spec/rubocop/cop/open_project/test_selector_system_argument_spec.rb |
Tests detection, correction, and exclusions. |
lib/rubocop/cop/open_project_cops.rb |
Registers the cop. |
config/default.yml |
Enables and configures the cop. |
.changeset/test-selector-system-argument.md |
Documents the new feature. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+97
to
+116
| def check_arguments(arguments) | ||
| arguments.pairs.each do |pair| | ||
| name = key_name(pair) | ||
|
|
||
| if name == "data" && pair.value.hash_type? | ||
| selector = pair.value.pairs.find { |data_pair| DATA_KEYS.include?(key_name(data_pair)) } | ||
| register(arguments, pair, selector) if selector | ||
| elsif FLAT_KEYS.include?(name) | ||
| register(arguments, nil, pair) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def register(arguments, data_pair, selector) | ||
| add_offense(selector) do |corrector| | ||
| next if arguments.pairs.any? { |pair| key_name(pair) == "test_selector" } | ||
|
|
||
| move_selector(corrector, data_pair, selector) | ||
| end | ||
| end |
| corrector.replace(data_pair || selector, replacement) | ||
| else | ||
| corrector.remove(range_with_separator(data_pair.value, selector)) | ||
| corrector.insert_before(data_pair, "#{replacement},#{separator_before(data_pair)}") |
Comment on lines
+70
to
+71
| elsif name.start_with?(SLOT_PREFIX) | ||
| !config_list("IgnoredSlots").include?(name) |
1 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Ticket
https://community.openproject.org/wp/DREAM-906
What are you trying to accomplish?
Flags
data-test-selectorpassed to a ViewComponent throughdata:instead of thetest_selector:system argument, which Primer only renders outside production. Autocorrects by moving the key out of data:. Limited to component constructors, slot calls and configured forwarding helpers. Skips Primer form controls, which render the argument as a literal attribute.Screenshots
What approach did you choose and why?
AI involvement
Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.
Merge checklist