Merged
Conversation
7491c3f to
2ccf9c7
Compare
6
approved these changes
Mar 24, 2026
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/MessageExpectationcorpus conformance.Details
RSpec/MessageExpectationResult
Changes
Agent conversation excerpt
Now I understand the FP. The source context shows:
Here
expect { ... }is called with a block, not an argument. In RuboCop's Parser AST,expect { ... }.to receive(:stop)has ablocknode as the receiver of.to, so RuboCop's pattern$(send nil? {:expect :allow} ...)does NOT match — it requires asendnode. But in Prism's AST,expect { ... }is aCallNodewith a block attached, so nitrocop'sreceiver.as_call_node()succeeds and incorrectly flags it.Fix: skip when the receiver call has a block attached.
Let me verify with RuboCop first, then add the test and fix.
RuboCop does NOT flag
expect { ... }.to receive(:stop). Confirmed FP.Now let me add the test case and fix:
Now verify the test fails before the fix:
Test fails as expected. Now fix the cop — skip when the receiver call has a block attached:
Now verify tests pass:
All 4 tests pass. Now update the doc comment on the struct and run
cargo fmt:Now commit:
I`
Done. Here's a summary of the fix:
Root cause:
expect { ... }.to receive(:stop)was falsely flagged. In Prism's AST,expect { ... }is aCallNodewith ablockfield set, soreceiver.as_call_node()succeeded and the cop flagged it. In RuboCop's Parser AST,expect { ... }becomes ablocknode (not asendnode), so the pattern$(send nil? {:expect :allow} ...)never matches.Fix: Added an early return when
recv_call.block().is_some()— i.e., whenexpect/allowis called with a block rather than an argument.Task prompt (4360 tokens)
Fix RSpec/MessageExpectation — 1 FP, 0 FN
Cross-Corpus Risk
Risk class: extended-only edge case against a standard-perfect baseline.
Treat the extended examples as a narrow edge case, not proof that the broad pattern is safe.
Any carve-out that reduces the extended FP/FN count but regresses the standard corpus is a bad fix.
Prefer the smallest context-specific change you can justify from RuboCop behavior and the vendor spec.
This is concentrated in only a few repos, which increases the risk of overfitting to one local shape.
Instructions
You are fixing ONE cop in nitrocop, a Rust Ruby linter that uses Prism for parsing.
Current state: 77,088 matches, 1 false positives, 0 false negatives.
Focus on: FP (nitrocop flags code RuboCop does not).
Workflow
behavior on BOTH the specific FP case AND the general pattern:
tests/fixtures/cops/rspec/message_expectation/offense.rbwith^annotationtests/fixtures/cops/rspec/message_expectation/no_offense.rbcargo test --lib -- cop::rspec::message_expectationsrc/cop/rspec/message_expectation.rscargo test --lib -- cop::rspec::message_expectation///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/MessageExpectation: <message text>.IMPORTANT: This is a config/context issue, NOT a detection bug
Pre-diagnostic shows nitrocop already detects all FP/FN patterns correctly in isolation.
The corpus mismatches are caused by configuration differences in target repos.
Do NOT loop trying to fix detection logic — the detection code is correct.
Instead:
repo's config context. Common causes:
.rubocop.yml# rubocop:disablecomments in the source filesrc/config/for how config affects this cop///comment on the cop struct and commit what you have.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/message_expectation.rsandtests/fixtures/cops/rspec/message_expectation/cargo test --lib -- cop::rspec::message_expectationto verify your fix (do NOT run the full test suite)git stashStart Here
Use the existing corpus data to focus on the most concentrated regressions first.
Helpful local commands:
python3 scripts/investigate-cop.py RSpec/MessageExpectation --repos-onlypython3 scripts/investigate-cop.py RSpec/MessageExpectation --contextpython3 scripts/verify-cop-locations.py RSpec/MessageExpectationTop FP repos:
nats-io__nats-pure.rb__b484a05(1 FP) — examplespec/service_spec.rb:146Representative FP examples:
nats-io__nats-pure.rb__b484a05: spec/service_spec.rb:146— Preferallowfor setting message expectations.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.
FP #1:
nats-io__nats-pure.rb__b484a05: spec/service_spec.rb:146NOT REPRODUCED in isolation — CONTEXT-DEPENDENT
nitrocop does not flag this in isolation. The FP is triggered
by surrounding code context or file-level state.
Investigate what full-file context causes the false detection.
Source context:
Message:
Preferallowfor setting message expectations.Current Rust Implementation
src/cop/rspec/message_expectation.rsRuboCop Ruby Implementation (ground truth)
vendor/rubocop-rspec/lib/rubocop/cop/rspec/message_expectation.rbRuboCop Test Excerpts
vendor/rubocop-rspec/spec/rubocop/cop/rspec/message_expectation_spec.rbCurrent Fixture: offense.rb
tests/fixtures/cops/rspec/message_expectation/offense.rbCurrent Fixture: no_offense.rb
tests/fixtures/cops/rspec/message_expectation/no_offense.rb