Open
Conversation
bf1a8f7 to
527aeda
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
RSpec/LeakyLocalVariablecorpus conformance.Refs #569
Details
RSpec/LeakyLocalVariableResult
Changes
Agent conversation excerpt
Reading
docs/agent-ci.mdfirst, then the current Rust cop and RuboCop ground-truth files to isolate the missed FN pattern before I touch fixtures.Reading
docs/agent-ci.mdfirst, then the current Rust cop and RuboCop ground-truth files to isolate the missed FN pattern before I touch fixtures.I’ve got the workflow and the current cop history. Next I’m reading the rest of the Rust implementation and then I’ll reproduce the reported FN with a fixture-first test so the failure is concrete.
I’ve got the workflow and the current cop history. Next I’m reading the rest of the Rust implementation and then I’ll reproduce the reported FN with a fixture-first test so the failure is concrete.
The missing corpus patterns are already present in the offense fixture. I’m checking whether they’re correctly annotated and whether the current unit test actually misses them, which will tell us if this is a real detection bug or a fixture/config mismatch.
The missing corpus patterns are already present in the offense fixture. I’m checking whether they’re correctly annotated and whether the current unit test actually misses them, which will tell us if this is a real detection bug or a fixture/config mismatch.
The fixture already contains the reported FN snippets, which means the next question is whether the existing test currently fails. If it already passes, this is not a cop-logic bug and I’ll switch to confirming why corpus/context diverged.
The fixture already contains the reported FN snippets, which means the next question is whether the existing test currently fails. If it already passes, this is not a cop-logic bug and I’ll switch to confirming why corpus/context diverged.
Compilation is still running. While that finishes, I’m tracing the current implementation around file-level and nested-scope assignment handling, because the reported missed examples cluster around top-level assignments, nested
contexts, anddef/block wrappers.Compilation is still running. While that finishes, I’m tracing the current implementation around file-level and nested-scope assignment handling, because the reported missed examples cluster around top-level assignments, nested
contexts, anddef/block wrappers.The unit test already fails exactly where expected, so this is a real detection gap. The missing offenses are the appended corpus patterns at the end of
offense.rb; I’m mapping those line numbers to the AST traversal that currently drops them.The unit test already fails exactly where expected, so this is a real detection gap. The missing offenses are the appended corpus patterns at the end of
offense.rb; I’m mapping those line numbers to the AST traversal that currently drops them.I found why the fixture is red: the tail of
offense.rbonly has bare assignment lines, so those expectations can never pass. I’m turning those placeholders into real minimal reproductions from the corpus examples, then I’ll use that failing fixture to drive the implementation fix.I found why the fixture is red: the tail of
offense.rbonly has bare assignment lines, so those expectations can never pass. I’m turning those placeholders into real minimal reproductions from the corpus examples, then I’ll use that failing fixture to drive the implementation fix.Plan:
offense.rbwith minimal real repros for the diagnosed FN cases from the prompt.cargo test --lib -- cop::rspec::leaky_local_variableto see which patterns still fail after the fixture is valid.src/cop/rspec/leaky_local_variable.rs, patch the narrow traversal/dataflow gap, and add a short///note documenting the fix.python3 scripts/check_cop.py RSpec/LeakyLocalVariable --rerun --clone --sample 15, and commit only the cop files if the corpus check is clean.Plan:
offense.rbwith minimal real repros for the diagnosed FN cases from the prompt.cargo test --lib -- cop::rspec::leaky_local_variableto see which patterns still fail after the fixture is valid.src/cop/rspec/leaky_local_variable.rs, patch the narrow traversal/dataflow gap, and add a short///note documenting the fix.python3 scripts/check_cop.py RSpec/LeakyLocalVariable --rerun --clone --sample 15, and commit only the cop files if the corpus check is clean.I’m updating
offense.rbnow: removing the impossible placeholder annotations at the end and replacing them with actual minimal reproductions for the diagnosed FN cases from the prompt.I’m updating
offense.rbnow: removing the impossible placeholder annotations at the end and replacing them with actual minimal reproductions for the diagnosed FN cases from the prompt.The fixture now contains real repros instead of disconnected assignments. I’m rerunning the focused test to see which of these patterns the cop still misses before touching Rust.
The fixture now contains real repros instead of disconnected assignments. I’m rerunning the focused test to see which of these patterns the cop still misses before touching Rust.
While the rebuild finishes, I’m checking the likely gap: the cop’s assignment collectors only recurse through a hand-picked set of structural nodes. Any assignment embedded in a general expression subtree can still disappear, which would explain the high-FN repos like
cenitand some of these new repros.Task prompt (16359 tokens)
Fix RSpec/LeakyLocalVariable — 11 FP, 99 FN
Instructions
You are fixing ONE cop in nitrocop, a Rust Ruby linter that uses Prism for parsing.
Current state: 5,422 matches, 11 false positives, 99 false negatives.
Focus on: FN (RuboCop flags code nitrocop misses).
⚠ 5,422 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/rspec/leaky_local_variable/offense.rbwith^annotationtests/fixtures/cops/rspec/leaky_local_variable/no_offense.rbcargo test --lib -- cop::rspec::leaky_local_variablesrc/cop/rspec/leaky_local_variable.rscargo test --lib -- cop::rspec::leaky_local_variable///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 isRSpec/LeakyLocalVariable: <message text>.See the Current Fixture sections below for real examples from this cop.
Mixed issues: some code bugs, some config issues
Pre-diagnostic shows SOME patterns are correctly detected in isolation (config issues)
and SOME are genuinely missed (code bugs). See the per-example diagnosis below.
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/rspec/leaky_local_variable.rsandtests/fixtures/cops/rspec/leaky_local_variable/cargo test --lib -- cop::rspec::leaky_local_variableto verify your fix (do NOT run the full test suite)python3 scripts/check_cop.py RSpec/LeakyLocalVariable --rerun --clone --sample 15before committing to catch regressionsgit stashPrism Notes
{}) and KeywordHashNode (keyword argsfoo(a: 1)). If you handle one, check if you need the other.begin..endis BeginNode, implicit method body is StatementsNode. Check which one(s) your cop needs.Current Fixture: offense.rb
tests/fixtures/cops/rspec/leaky_local_variable/offense.rbCurrent Fixture: no_offense.rb
tests/fixtures/cops/rspec/leaky_local_variable/no_offense.rbKey Source Files
src/cop/rspec/leaky_local_variable.rsvendor/rubocop-rspec/lib/rubocop/cop/rspec/leaky_local_variable.rbvendor/rubocop-rspec/spec/rubocop/cop/rspec/leaky_local_variable_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 RSpec/LeakyLocalVariable --repos-onlypython3 scripts/investigate_cop.py RSpec/LeakyLocalVariable --contextpython3 scripts/verify_cop_locations.py RSpec/LeakyLocalVariableTop FP repos:
bdewey__org-ruby__e4a6e7d(4 FP) — examplespec/parser_spec.rb:132puppetlabs__puppetlabs-docker__04382c9(2 FP) — examplespec/acceptance/docker_full_spec.rb:43robotdana__leftovers__1f40b1a(2 FP) — examplespec/config_built_in_spec.rb:21Top FN repos:
cenit-io__cenit__0106da3(18 FN) — examplespec/integration/mongoff/validator_spec.rb:44saml-idp__saml_idp__4dde1a3(7 FN) — examplespec/lib/saml_idp/incoming_metadata_spec.rb:5tobymao__18xx__8f5e103(7 FN) — examplespec/lib/engine/game/fixtures_auto_actions_spec.rb:22Representative FP examples:
bdewey__org-ruby__e4a6e7d: spec/parser_spec.rb:132— Do not use local variables defined outside of examples inside of them.bdewey__org-ruby__e4a6e7d: spec/parser_spec.rb:154— Do not use local variables defined outside of examples inside of them.bdewey__org-ruby__e4a6e7d: spec/parser_spec.rb:214— Do not use local variables defined outside of examples inside of them.Representative FN examples:
DivanteLtd__anonymizer__694eb35: spec/unit/model/database/multiple_spec.rb:15— Do not use local variables defined outside of examples inside of them.DivanteLtd__anonymizer__694eb35: spec/unit/model/database/multiple_spec.rb:16— Do not use local variables defined outside of examples inside of them.DivanteLtd__anonymizer__694eb35: spec/unit/model/database/multiple_spec.rb:62— Do not use local variables defined outside of examples inside of them.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:
DivanteLtd__anonymizer__694eb35: spec/unit/model/database/multiple_spec.rb:15NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 13:
context '#Work with proper query' do) > block (do..end) (line 8:RSpec.describe Database::Multiple, '#multiple' do)Message:
Do not use local variables defined outside of examples inside of them.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #2:
DivanteLtd__anonymizer__694eb35: spec/unit/model/database/multiple_spec.rb:16NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 13:
context '#Work with proper query' do) > block (do..end) (line 8:RSpec.describe Database::Multiple, '#multiple' do)Message:
Do not use local variables defined outside of examples inside of them.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #3:
DivanteLtd__anonymizer__694eb35: spec/unit/model/database/multiple_spec.rb:62NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 60:
context '#Work with linked tables' do) > block (do..end) (line 8:RSpec.describe Database::Multiple, '#multiple' do)Message:
Do not use local variables defined outside of examples inside of them.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #4:
DivanteLtd__anonymizer__694eb35: spec/unit/model/database/multiple_spec.rb:63NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 60:
context '#Work with linked tables' do) > block (do..end) (line 8:RSpec.describe Database::Multiple, '#multiple' do)Message:
Do not use local variables defined outside of examples inside of them.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #5:
MissionCriticalCloud__vagrant-cloudstack__e09bfb4: functional-tests/vmlifecycle/vmlifecycle_spec.rb:11NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Message:
Do not use local variables defined outside of examples inside of them.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #6:
OpenVoxProject__openvox__2665666: spec/unit/pops/types/ruby_generator_spec.rb:421NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 420:
context 'when generating static code' do) > block (do..end) (line 210:context 'when generating from Object types' do) > block (do..end) (line 12:describe 'Puppet Ruby Generator' do)Prism AST at offense line:
StatementsNode > LocalVariableWriteNode > NilNodeMessage:
Do not use local variables defined outside of examples inside of them.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #7:
OpenVoxProject__openvox__2665666: spec/unit/pops/types/ruby_generator_spec.rb:733NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 732:
context 'when generating static code' do) > block (do..end) (line 532:context 'when generating from TypeSets' do) > block (do..end) (line 12:describe 'Puppet Ruby Generator' do)Prism AST at offense line:
StatementsNode > LocalVariableWriteNode > NilNodeMessage:
Do not use local variables defined outside of examples inside of them.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #8:
SUSE__machinery__e41b642: spec/integration/support/inspect_unmanaged_files_examples.rb:40NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 19:
describe "--scope=unmanaged-files" do) > block (do..end) (line 18:shared_examples "inspect unmanaged files" do |base, skip_remote_mounts_test|)Message:
Do not use local variables defined outside of examples inside of them.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.
FP #1:
bdewey__org-ruby__e4a6e7d: spec/parser_spec.rb:132NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not use local variables defined outside of examples inside of them.Full file context (30 lines before offense):
FP #2:
bdewey__org-ruby__e4a6e7d: spec/parser_spec.rb:154NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not use local variables defined outside of examples inside of them.Full file context (30 lines before offense):
FP #3:
bdewey__org-ruby__e4a6e7d: spec/parser_spec.rb:214NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not use local variables defined outside of examples inside of them.Full file context (30 lines before offense):
FP #4:
bdewey__org-ruby__e4a6e7d: spec/parser_spec.rb:242NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not use local variables defined outside of examples inside of them.Full file context (30 lines before offense):
FP #5:
department-of-veterans-affairs__vets-api__038d1df: modules/appeals_api/spec/docs/notice_of_disagreements/v0_spec.rb:423NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not use local variables defined outside of examples inside of them.Full file context (30 lines before offense):
FP #6:
iftheshoefritz__solargraph-rails__2c284b9: spec/solargraph-rails/rails_spec.rb:4NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not use local variables defined outside of examples inside of them.Full file context (30 lines before offense):