Open
Conversation
7bd5f6a to
c5ebb0a
Compare
Contributor
|
✅ Cop-check results (8 shards)
All shards passed — ready to merge. |
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.
Automated fix fix for
Style/Attrcorpus conformance.Refs #323
Details
Style/AttrResult
Changes
Agent conversation excerpt
Reading the CI instructions and the existing Style/Attr implementation first, then I’ll add a failing fixture that matches the corpus FN pattern before touching the cop logic.
Reading the CI instructions and the existing Style/Attr implementation first, then I’ll add a failing fixture that matches the corpus FN pattern before touching the cop logic.
The current cop has an explicit
opening_locguard that skips all parenthesizedattr(...)calls. I’m checking RuboCop on those patterns now because the existing local fixture saysattr(:name)is allowed, which looks inconsistent with the corpus FN examples.The current cop has an explicit
opening_locguard that skips all parenthesizedattr(...)calls. I’m checking RuboCop on those patterns now because the existing local fixture saysattr(:name)is allowed, which looks inconsistent with the corpus FN examples.The workspace already has an uncommitted edit in the Style/Attr offense fixture. I’m inspecting that diff before I touch anything so I can avoid trampling a prior attempt and make the next change set consistent.
The workspace already has an uncommitted edit in the Style/Attr offense fixture. I’m inspecting that diff before I touch anything so I can avoid trampling a prior attempt and make the next change set consistent.
The pre-added fixture cases are real: RuboCop flags
attr(:name)in a class body, while it still acceptsattr(1)when a localdef attrexists. I’m letting the targeted test run finish next so I can confirm the current failure shape before editing the cop.The pre-added fixture cases are real: RuboCop flags
attr(:name)in a class body, while it still acceptsattr(1)when a localdef attrexists. I’m letting the targeted test run finish next so I can confirm the current failure shape before editing the cop.I have the targeted failure now: the existing cop still only catches the original 4 fixtures and misses every newly added parenthesized/dynamic-call case. Next I’m drilling into Prism node shapes for those missed examples so the fix can stay narrow and preserve the 686 existing matches.
I have the targeted failure now: the existing cop still only catches the original 4 fixtures and misses every newly added parenthesized/dynamic-call case. Next I’m drilling into Prism node shapes for those missed examples so the fix can stay narrow and preserve the 686 existing matches.
The likely bug is narrower than the current guard suggests: RuboCop treats receiverless
attr(...)as an offense even with parentheses, so the blanketopening_loc()early return is wrong. I’m confirming the AST shape and then I’ll patch the cop plus the staleno_offensefixture that still expectsattr(:name)to be allowed.The likely bug is narrower than the current guard suggests: RuboCop treats receiverless
attr(...)as an offense even with parentheses, so the blanketopening_loc()early return is wrong. I’m confirming the AST shape and then I’ll patch the cop plus the staleno_offensefixture that still expectsattr(:name)to be allowed.Plan after the initial read-through:
completedReaddocs/agent-ci.md, the current Style/Attr cop, RuboCop’s source/spec, and the existing fixture state.in_progressPatch the stale fixture set so it matches RuboCop: keep the FN cases inoffense.rb, updatecorrected.rb, and replace the invalidattr(:name)no-offense with a real allowed parenthesized custom-attrcase.pendingRemove the broad parenthesized-call skip insrc/cop/style/attr.rs, add a///doc comment describing the FN root cause, and keep the custom-def attrscope guard intact.pendingRuncargo test --lib -- cop::style::attr, thenpython3 scripts/check_cop.py Style/Attr --rerun --clone --sample 15, and only then commit the cop files.Plan after the initial read-through:
completedReaddocs/agent-ci.md, the current Style/Attr cop, RuboCop’s source/spec, and the existing fixture state.in_progressPatch the stale fixture set so it matches RuboCop: keep the FN cases inoffense.rb, updatecorrected.rb, and replace the invalidattr(:name)no-offense with a real allowed parenthesized custom-attrcase.pendingRemove the broad parenthesized-call skip insrc/cop/style/attr.rs, add a///doc comment describing the FN root cause, and keep the custom-def attrscope guard intact.pendingRuncargo test --lib -- cop::style::attr, thenpython3 scripts/check_cop.py Style/Attr --rerun --clone --sample 15, and only then commit the cop files.I’m about to edit the fixture set first. Before that, I’m checking RuboCop’s actual autocorrections for the parenthesized reader/accessor cases so
corrected.rbmatches ground truth instead of just matching whatever the current Rust code happens to emit.I’m about to edit the fixture set first. Before that, I’m checking RuboCop’s actual autocorrections for the parenthesized reader/accessor cases so
corrected.rbmatches ground truth instead of just matching whatever the current Rust code happens to emit.There’s a second issue beyond parentheses: the current Rust cop decides
attr_accessorvsattr_readerfrom the second argument, but RuboCop uses the last argument for the message and only uses the second argument when deciding whether it can safely delete the boolean tail during autocorrect. I’m verifying the multi-call/column details before patching the fixtures so the test file matches RuboCop exactly.There’s a second issue beyond parentheses: the current Rust cop decides
attr_accessorvsattr_readerfrom the second argument, but RuboCop uses the last argument for the message and only uses the second argument when deciding whether it can safely delete the boolean tail during autocorrect. I’m verifying the multi-call/column details before patching the fixtures so the test file matches RuboCop exactly.Task prompt (5690 tokens)
Fix Style/Attr — 0 FP, 25 FN
Instructions
You are fixing ONE cop in nitrocop, a Rust Ruby linter that uses Prism for parsing.
Current state: 686 matches, 0 false positives, 25 false negatives.
Focus on: FN (RuboCop flags code nitrocop misses).
⚠ 686 existing matches must not regress. Validate with
check_cop.pybefore committing.Workflow
behavior on BOTH the specific FP case AND the general pattern:
tests/fixtures/cops/style/attr/offense.rbwith^annotationtests/fixtures/cops/style/attr/no_offense.rbcargo test --lib -- cop::style::attrsrc/cop/style/attr.rscargo test --lib -- cop::style::attr///doc comment on the cop struct documenting what you found and fixedFixture Format
Mark offenses with
^markers on the line AFTER the offending source line.The
^characters must align with the offending columns. The message format isStyle/Attr: <message text>.See the Current Fixture sections below for real examples from this cop.
If your test passes immediately
If you add a test case and it passes without code changes, the corpus mismatch is
caused by config/context differences, not a detection bug.
Do NOT loop trying to make the test fail. Instead:
src/config/or the cop's config handling, not detection logica
///comment on the cop struct and commitCRITICAL: Avoid regressions in the opposite direction
When fixing FPs, your change MUST NOT suppress legitimate detections. When fixing FNs,
your change MUST NOT flag code that RuboCop accepts. A fix that eliminates a few issues
in one direction but introduces hundreds in the other is a catastrophic regression.
Before exempting a category of patterns, verify with RuboCop that the general case
is still an offense:
If RuboCop flags the general pattern but not your specific case, the difference is in
a narrow context (e.g., enclosing structure, receiver type, argument count) — your fix
must target that specific context, not the broad category.
Rule of thumb: if your fix adds an early
returnorcontinuethat skips a wholenode type, operator class, or naming pattern, it's probably too broad. Prefer adding a
condition that matches the SPECIFIC differentiating context.
Rules
src/cop/style/attr.rsandtests/fixtures/cops/style/attr/cargo test --lib -- cop::style::attrto verify your fix (do NOT run the full test suite)python3 scripts/check_cop.py Style/Attr --rerun --clone --sample 15before committing to catch regressionsgit stashCurrent Fixture: offense.rb
tests/fixtures/cops/style/attr/offense.rbCurrent Fixture: no_offense.rb
tests/fixtures/cops/style/attr/no_offense.rbKey Source Files
src/cop/style/attr.rsvendor/rubocop/lib/rubocop/cop/style/attr.rbvendor/rubocop/spec/rubocop/cop/style/attr_spec.rbRead these files before making changes.
Start Here
Use the existing corpus data to focus on the most concentrated regressions first.
Helpful local commands:
python3 scripts/investigate_cop.py Style/Attr --repos-onlypython3 scripts/investigate_cop.py Style/Attr --contextpython3 scripts/verify_cop_locations.py Style/AttrTop FN repos:
aws__aws-record-ruby__7ef7a2e(13 FN) — examplelib/aws-record/record/attributes.rb:158asciidoctor__asciidoctor-diagram__11462a8(3 FN) — examplelib/asciidoctor-diagram/diagram_source.rb:34tombenner__nikkou__3159aff(3 FN) — examplelib/nikkou/nokogiri/xml/node.rb:80Representative FN examples:
FortySource__forty_facets__98a4f77: lib/forty_facets/filter_definition.rb:5— Do not useattr. Useattr_readerinstead.FortySource__forty_facets__98a4f77: lib/forty_facets/order_definition.rb:4— Do not useattr. Useattr_readerinstead.SketchUp__sketchup-stl__0b83322: src/sketchup-stl/SKUI/control_manager.rb:7— Do not useattr. Useattr_readerinstead.Pre-diagnostic Results
Diagnosis Summary
Each example was tested by running nitrocop on the extracted source in isolation
with
--force-default-configto determine if the issue is a code bug or config issue.Note: source context is truncated and may not parse perfectly. If a diagnosis
seems wrong (e.g., your test passes immediately for a 'CODE BUG'), treat it as
a config/context issue instead.
FN #1:
FortySource__forty_facets__98a4f77: lib/forty_facets/filter_definition.rb:5NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: class body (line 3:
class FilterDefinition) > module body (line 1:module FortyFacets)Message:
Do not useattr. Useattr_readerinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #2:
FortySource__forty_facets__98a4f77: lib/forty_facets/order_definition.rb:4NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: class body (line 3:
class OrderDefinition) > module body (line 1:module FortyFacets)Message:
Do not useattr. Useattr_readerinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #3:
SketchUp__sketchup-stl__0b83322: src/sketchup-stl/SKUI/control_manager.rb:7NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: module body (line 4:
module ControlManager) > module body (line 1:module SKUI)Message:
Do not useattr. Useattr_readerinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #4:
asciidoctor__asciidoctor-diagram__11462a8: lib/asciidoctor-diagram/diagram_source.rb:34NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: method body (line 33:
def global_attr(name, default_value = nil)) > module body (line 8:module DiagramSource) > module body (line 5:module Diagram) > module body (line 4:module Asciidoctor)Message:
Do not useattr. Useattr_readerinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #5:
asciidoctor__asciidoctor-diagram__11462a8: lib/asciidoctor-diagram/diagram_source.rb:38NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: method body (line 37:
def opt(opt)) > module body (line 8:module DiagramSource) > module body (line 5:module Diagram) > module body (line 4:module Asciidoctor)Message:
Do not useattr. Useattr_readerinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #6:
asciidoctor__asciidoctor-diagram__11462a8: lib/asciidoctor-diagram/diagram_source.rb:61NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: method body (line 60:
def base_dir) > module body (line 8:module DiagramSource) > module body (line 5:module Diagram) > module body (line 4:module Asciidoctor)Message:
Do not useattr. Useattr_accessorinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #7:
aws__aws-record-ruby__7ef7a2e: lib/aws-record/record/attributes.rb:158NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: method body (line 156:
def string_attr(name, opts = {})) > module body (line 102:module ClassMethods) > module body (line 5:module Attributes) > module body (line 4:module Record) > module body (line 3:module Aws)Message:
Do not useattr. Useattr_readerinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #8:
aws__aws-record-ruby__7ef7a2e: lib/aws-record/record/attributes.rb:180NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: method body (line 178:
def boolean_attr(name, opts = {})) > module body (line 102:module ClassMethods) > module body (line 5:module Attributes) > module body (line 4:module Record) > module body (line 3:module Aws)Message:
Do not useattr. Useattr_readerinstead.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
Omitted 7 additional diagnosed FN example(s) for brevity.