Conversation
d1c464f to
c696956
Compare
Auto-repair Started
Task prompt (4636 tokens)PR Repair Task: PR #186Before making changes, read Repair the existing PR branch in place. Do not create a new branch or PR. Context
Required OutcomeFix the currently failing checks shown below. Required Local VerificationThe workflow will rerun these commands before pushing. Your changes should make them pass: python3 scripts/dispatch_cops.py changed --base origin/main --head HEAD > "$REPAIR_CHANGED_COPS_FILE"
failed=0
while IFS= read -r cop; do
[ -z "$cop" ] && continue
echo "=============================="
echo "Checking: $cop (re-running against corpus)"
echo "=============================="
if ! python3 scripts/check_cop.py "$cop" --verbose --rerun --quick --clone; then
echo "FAIL: $cop regression detected"
failed=$((failed + 1))
fi
done < "$REPAIR_CHANGED_COPS_FILE"
test "$failed" -eq 0
Current PR Diff StatCurrent PR Diff Excerptdiff --git a/src/cop/rails/blank.rs b/src/cop/rails/blank.rs
index b4f07dcd5..2b641eade 100644
--- a/src/cop/rails/blank.rs
+++ b/src/cop/rails/blank.rs
@@ -90,6 +90,18 @@ use ruby_prism::Visit;
/// but `pkey_cols&.blank?` would return `nil` (falsy). So the replacement changes semantics.
///
/// Fix: Added `call_operator_loc() == &.` check in `check_not_present` to skip safe navigation.
+///
+/// ## Investigation (2026-03-24)
+///
+/// **FN root cause (14 FN):** The `or` keyword in `foo.nil? or foo.empty?` was detected correctly
+/// (Prism parses both `||` and `or` as `OrNode`), but the diagnostic message hardcoded `||` as the
+/// separator between left and right operands. RuboCop uses `node.source` which preserves the actual
+/// operator (`or` or `||`). The message mismatch caused corpus FN counts because the expected
+/// message used `or` but nitrocop produced `||`.
+///
+/// Fix: Changed `check_nil_or_empty` to use `or_node.location().as_slice()` (the full OrNode
+/// source text) in the message instead of concatenating `left || right`. This preserves the actual
+/// operator in the diagnostic message, matching RuboCop's behavior.
pub struct Blank;
/// Extract the receiver source text from a CallNode, returning None if absent.
@@ -198,7 +210,7 @@ impl<'pr> BlankVisitor<'_, '_> {
let left = or_node.left();
let right = or_node.right();
- if let Some((nil_recv, left_src)) = nil_check_receiver(&left) {
+ if let Some((nil_recv, _left_src)) = nil_check_receiver(&left) {
// Right side must be `<same>.empty?` — NOT safe navigation (`&.empty?`)
// RuboCop's NodePattern `(send $_ :empty?)` only matches send, not csend.
if let Some(right_call) = right.as_call_node() {
@@ -211,18 +223,15 @@ impl<'pr> BlankVisitor<'_, '_> {
if nil_recv == empty_recv {
let loc = or_node.location();
let (line, column) = self.source.offset_to_line_col(loc.start_offset());
- let left_str = std::str::from_utf8(left_src).unwrap_or("nil?");
- let right_str =
- std::str::from_utf8(right.location().as_slice()).unwrap_or("empty?");
+ let or_src =
+ std::str::from_utf8(or_node.location().as_slice()).unwrap_or("...");
let message = match nil_recv {
Some(recv_bytes) => {
let recv_str = std::str::from_utf8(recv_bytes).unwrap_or("object");
- format!(
- "Use `{recv_str}.blank?` instead of `{left_str} || {right_str}`."
- )
+ format!("Use `{recv_str}.blank?` instead of `{or_src}`.")
}
None => {
- format!("Use `blank?` instead of `{left_str} || {right_str}`.")
+ format!("Use `blank?` instead of `{or_src}`.")
}
};
self.diagnostics.push(self.cop.diagnostic(
diff --git a/tests/fixtures/cops/rails/blank/offense.rb b/tests/fixtures/cops/rails/blank/offense.rb
index bf8858b14..04bd0e9f5 100644
--- a/tests/fixtures/cops/rails/blank/offense.rb
+++ b/tests/fixtures/cops/rails/blank/offense.rb
@@ -40,3 +40,21 @@
^^^^^^^^^^^^^^ Rails/Blank: Use `blank?` instead of `nil? || empty?`.
return [] if nil? || empty?
^^^^^^^^^^^^^^ Rails/Blank: Use `blank?` instead of `nil? || empty?`.
+
+elements.nil? or elements.empty?
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `elements.blank?` instead of `elements.nil? or elements.empty?`.
+
+return if name.nil? or name.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `name.blank?` instead of `name.nil? or name.empty?`.
+
+words.shift if words[0].nil? or words[0].empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `words[0].blank?` instead of `words[0].nil? or words[0].empty?`.
+
+foo unless bar.nil? || bar.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `bar.blank?` instead of `bar.nil? || bar.empty?`.
+
+break if line.nil? or line.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `line.blank?` instead of `line.nil? or line.empty?`.
+
+break if rnext.nil? or rnext.empty? or rline.nil? or rline.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `rnext.blank?` instead of `rnext.nil? or rnext.empty?`.Local Corpus ContextThese corpus oracle artifacts are already downloaded locally by the workflow.
Use these files directly with the repo scripts when you need corpus context. python3 scripts/investigate_cop.py Department/CopName --input /home/runner/work/_temp/agent-pr-repair/repair/corpus.json --context
python3 scripts/check_cop.py Department/CopName --input /home/runner/work/_temp/agent-pr-repair/repair/corpus.json --verbose --rerun --quick --cloneFailed Checks Packetcop-check
Constraints
Available Local Helper ScriptsThese helper scripts are available in this CI checkout. Prefer the stable top-level CLI paths shown below over ad hoc commands when they directly help with diagnosis or validation.
Typical usage when present: python3 scripts/check_cop.py Department/CopName --verbose --rerun --quick --clone
python3 scripts/dispatch_cops.py changed --base origin/main --head HEAD
python3 scripts/investigate_cop.py Department/CopName --context
python3 scripts/verify_cop_locations.py Department/CopName
python3 scripts/corpus_smoke_test.py --binary target/release/nitrocopLocal Cop-Check DiagnosisThe workflow already reran the changed-cop corpus check locally before agent execution. Changed cops:
Rails/BlankStart here:
Oracle context from CI corpus artifact:
Representative oracle FN examples:
587: private
588: def __do_split_word(word, size) #:nodoc:
589: [word[0 .. (size - 1)], word[size .. -1]]
590: end
591:
592: def __format(to_wrap) #:nodoc:
593: words = to_wrap.split(/\s+/).compact
>>> 594: words.shift if words[0].nil? or words[0].empty?
595: to_wrap = []
596:
597: abbrev = false
598: width = @columns - @first_indent - @left_margin - @right_margin
599: indent_str = ' ' * @first_indent
600: first_line = true
601: line = words.shift
>>> 602: abbrev = __is_abbrev(line) unless line.nil? || line.empty?
623: line = w
624: end
625:
626: abbrev = __is_abbrev(w) unless w.nil?
627: end
628:
629: loop do
>>> 630: break if line.nil? or line.empty?/usr/bin/python3 scripts/check_cop.py Rails/Blank --verbose --rerun --quick --cloneExit status: |
Auto-repair Started
Task prompt (2960 tokens)PR Repair Task: PR #186Before making changes, read Repair the existing PR branch in place. Do not create a new branch or PR. Context
Required OutcomeFix the currently failing checks shown below. Required Local VerificationThe workflow will rerun these commands before pushing. Your changes should make them pass: Current PR Diff StatCurrent PR Diff Excerptdiff --git a/src/cop/rails/blank.rs b/src/cop/rails/blank.rs
index b4f07dcd5..2b641eade 100644
--- a/src/cop/rails/blank.rs
+++ b/src/cop/rails/blank.rs
@@ -90,6 +90,18 @@ use ruby_prism::Visit;
/// but `pkey_cols&.blank?` would return `nil` (falsy). So the replacement changes semantics.
///
/// Fix: Added `call_operator_loc() == &.` check in `check_not_present` to skip safe navigation.
+///
+/// ## Investigation (2026-03-24)
+///
+/// **FN root cause (14 FN):** The `or` keyword in `foo.nil? or foo.empty?` was detected correctly
+/// (Prism parses both `||` and `or` as `OrNode`), but the diagnostic message hardcoded `||` as the
+/// separator between left and right operands. RuboCop uses `node.source` which preserves the actual
+/// operator (`or` or `||`). The message mismatch caused corpus FN counts because the expected
+/// message used `or` but nitrocop produced `||`.
+///
+/// Fix: Changed `check_nil_or_empty` to use `or_node.location().as_slice()` (the full OrNode
+/// source text) in the message instead of concatenating `left || right`. This preserves the actual
+/// operator in the diagnostic message, matching RuboCop's behavior.
pub struct Blank;
/// Extract the receiver source text from a CallNode, returning None if absent.
@@ -198,7 +210,7 @@ impl<'pr> BlankVisitor<'_, '_> {
let left = or_node.left();
let right = or_node.right();
- if let Some((nil_recv, left_src)) = nil_check_receiver(&left) {
+ if let Some((nil_recv, _left_src)) = nil_check_receiver(&left) {
// Right side must be `<same>.empty?` — NOT safe navigation (`&.empty?`)
// RuboCop's NodePattern `(send $_ :empty?)` only matches send, not csend.
if let Some(right_call) = right.as_call_node() {
@@ -211,18 +223,15 @@ impl<'pr> BlankVisitor<'_, '_> {
if nil_recv == empty_recv {
let loc = or_node.location();
let (line, column) = self.source.offset_to_line_col(loc.start_offset());
- let left_str = std::str::from_utf8(left_src).unwrap_or("nil?");
- let right_str =
- std::str::from_utf8(right.location().as_slice()).unwrap_or("empty?");
+ let or_src =
+ std::str::from_utf8(or_node.location().as_slice()).unwrap_or("...");
let message = match nil_recv {
Some(recv_bytes) => {
let recv_str = std::str::from_utf8(recv_bytes).unwrap_or("object");
- format!(
- "Use `{recv_str}.blank?` instead of `{left_str} || {right_str}`."
- )
+ format!("Use `{recv_str}.blank?` instead of `{or_src}`.")
}
None => {
- format!("Use `blank?` instead of `{left_str} || {right_str}`.")
+ format!("Use `blank?` instead of `{or_src}`.")
}
};
self.diagnostics.push(self.cop.diagnostic(
diff --git a/tests/fixtures/cops/rails/blank/offense.rb b/tests/fixtures/cops/rails/blank/offense.rb
index bf8858b14..04bd0e9f5 100644
--- a/tests/fixtures/cops/rails/blank/offense.rb
+++ b/tests/fixtures/cops/rails/blank/offense.rb
@@ -40,3 +40,21 @@
^^^^^^^^^^^^^^ Rails/Blank: Use `blank?` instead of `nil? || empty?`.
return [] if nil? || empty?
^^^^^^^^^^^^^^ Rails/Blank: Use `blank?` instead of `nil? || empty?`.
+
+elements.nil? or elements.empty?
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `elements.blank?` instead of `elements.nil? or elements.empty?`.
+
+return if name.nil? or name.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `name.blank?` instead of `name.nil? or name.empty?`.
+
+words.shift if words[0].nil? or words[0].empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `words[0].blank?` instead of `words[0].nil? or words[0].empty?`.
+
+foo unless bar.nil? || bar.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `bar.blank?` instead of `bar.nil? || bar.empty?`.
+
+break if line.nil? or line.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `line.blank?` instead of `line.nil? or line.empty?`.
+
+break if rnext.nil? or rnext.empty? or rline.nil? or rline.empty?
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^ Rails/Blank: Use `rnext.blank?` instead of `rnext.nil? or rnext.empty?`.Local Corpus ContextThese corpus oracle artifacts are already downloaded locally by the workflow.
Use these files directly with the repo scripts when you need corpus context. python3 scripts/investigate_cop.py Department/CopName --input /home/runner/work/_temp/agent-pr-repair/repair/corpus.json --context
python3 scripts/check_cop.py Department/CopName --input /home/runner/work/_temp/agent-pr-repair/repair/corpus.json --verbose --rerun --quick --cloneFailed Checks Packetcop-check (5)
cop-check-gate
Constraints
Available Local Helper ScriptsThese helper scripts are available in this CI checkout. Prefer the stable top-level CLI paths shown below over ad hoc commands when they directly help with diagnosis or validation.
Typical usage when present: python3 scripts/check_cop.py Department/CopName --verbose --rerun --quick --clone
python3 scripts/dispatch_cops.py changed --base origin/main --head HEAD
python3 scripts/investigate_cop.py Department/CopName --context
python3 scripts/verify_cop_locations.py Department/CopName
python3 scripts/corpus_smoke_test.py --binary target/release/nitrocop |
Auto-repair Succeeded
Auto-repair succeeded with backend Validated locally before push using |
61c2e85 to
dddbda9
Compare
Automated fix fix for
Rails/Blankcorpus conformance.Refs #160
Details
Rails/BlankResult
Changes
Agent conversation excerpt
Let me run the existing tests to see the current state of failures.
The test reveals the detection works but two things are wrong:
||instead of using the actual operator (orvs||)^positions are at column 0 instead of the OrNode's actual columnLet me fix both issues.
Now I need to remove the unused
left_srcfromnil_check_receiver's return type — wait, actuallyleft_srcis still returned fromnil_check_receiverbut no longer used in the message. Let me check if it's used elsewhere.Now fix the fixture annotations. I need to calculate correct
^positions for each new test case. Let me also simplify by removing duplicate test cases and ensuring clean Ruby syntax.Both tests pass. Now let me add the doc comment and verify the fixture looks correct.
Now let me add the doc comment on the cop struct documenting this fix.
Tests pass. Let me run clippy and fmt on the changed file.
All clean — no clippy warnings, no format changes needed. Now let me commit.
The NilOrEmpty check ha`
Done. The fix was straightforward:
Root cause: The
check_nil_or_emptymethod hardcoded||in the diagnostic message (left_str || right_str). Ruby'sorkeyword also produces anOrNodein Prism, so detection worked fine, but the message said||instead ofor. The corpus comparison flagged these as FN because the expected message (from RuboCop usingnode.source) usedor.Fix:
or_node.location().as_slice()(the full OrNode source text) instead of concatenating left/right with hardcoded||orexpression, modifierifwithor, indexed receiver withor, modifierunlesswith||,break ifwithor, and chainedorexpressionsTask prompt (10435 tokens)
Fix Rails/Blank — 0 FP, 14 FN
Instructions
You are fixing ONE cop in nitrocop, a Rust Ruby linter that uses Prism for parsing.
Current state: 6,472 matches, 0 false positives, 14 false negatives.
Focus on: FN (RuboCop flags code nitrocop misses).
Workflow
behavior on BOTH the specific FP case AND the general pattern:
tests/fixtures/cops/rails/blank/offense.rbwith^annotationtests/fixtures/cops/rails/blank/no_offense.rbcargo test --lib -- cop::rails::blanksrc/cop/rails/blank.rscargo test --lib -- cop::rails::blank///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 isRails/Blank: <message text>.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/rails/blank.rsandtests/fixtures/cops/rails/blank/cargo test --lib -- cop::rails::blankto 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 Rails/Blank --repos-onlypython3 scripts/investigate_cop.py Rails/Blank --contextpython3 scripts/verify_cop_locations.py Rails/BlankTop FN repos:
databasically__lowdown__d593927(5 FN) — examplevendor/rails/actionmailer/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb:594cjstewart88__Tubalr__f6956c8(4 FN) — exampleheroku/ruby/1.9.1/gems/rdoc-3.8/lib/rdoc/parser/c.rb:784pitluga__supply_drop__d64c50c(4 FN) — exampleexamples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/adsi.rb:161Representative FN examples:
cjstewart88__Tubalr__f6956c8: heroku/ruby/1.9.1/gems/rdoc-3.8/lib/rdoc/parser/c.rb:784— Useelements.blank?instead ofelements.nil? or elements.empty?.cjstewart88__Tubalr__f6956c8: heroku/ruby/1.9.1/gems/rdoc-3.8/lib/rdoc/ri/driver.rb:865— Usename.blank?instead ofname.nil? or name.empty?.cjstewart88__Tubalr__f6956c8: heroku/ruby/1.9.1/gems/rdoc-3.9.4/lib/rdoc/parser/c.rb:782— Useelements.blank?instead ofelements.nil? or elements.empty?.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:
cjstewart88__Tubalr__f6956c8: heroku/ruby/1.9.1/gems/rdoc-3.8/lib/rdoc/parser/c.rb:784NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Enclosing structure: if branch (line:
if type.downcase == 'const' then)The offense is inside this structure — the cop may need
to handle this context to detect the pattern.
Message:
Useelements.blank?instead ofelements.nil? or elements.empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
FN #2:
cjstewart88__Tubalr__f6956c8: heroku/ruby/1.9.1/gems/rdoc-3.8/lib/rdoc/ri/driver.rb:865NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Message:
Usename.blank?instead ofname.nil? or name.empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
FN #3:
cjstewart88__Tubalr__f6956c8: heroku/ruby/1.9.1/gems/rdoc-3.9.4/lib/rdoc/parser/c.rb:782NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Enclosing structure: if branch (line:
if type.downcase == 'const' then)The offense is inside this structure — the cop may need
to handle this context to detect the pattern.
Message:
Useelements.blank?instead ofelements.nil? or elements.empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
FN #4:
cjstewart88__Tubalr__f6956c8: heroku/ruby/1.9.1/gems/rdoc-3.9.4/lib/rdoc/ri/driver.rb:878NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Message:
Usename.blank?instead ofname.nil? or name.empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
FN #5:
databasically__lowdown__d593927: vendor/rails/actionmailer/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb:594NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Enclosing structure: method body (line:
def __format(to_wrap) #:nodoc:)The offense is inside this structure — the cop may need
to handle this context to detect the pattern.
Message:
Usewords[0].blank?instead ofwords[0].nil? or words[0].empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
FN #6:
databasically__lowdown__d593927: vendor/rails/actionmailer/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb:602NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Message:
Useline.blank?instead ofline.nil? || line.empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
FN #7:
databasically__lowdown__d593927: vendor/rails/actionmailer/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb:630NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Enclosing structure: block (do..end) (line:
loop do)The offense is inside this structure — the cop may need
to handle this context to detect the pattern.
Message:
Useline.blank?instead ofline.nil? or line.empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
FN #8:
databasically__lowdown__d593927: vendor/rails/actionmailer/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb:790NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Enclosing structure: enclosing line:
elseThe offense is inside this structure — the cop may need
to handle this context to detect the pattern.
Message:
Usernext.blank?instead ofrnext.nil? or rnext.empty?.Ready-made test snippet (add to offense.rb, adjust
^count):Full source context:
Omitted 6 additional diagnosed FN example(s) for brevity.
Current Rust Implementation
src/cop/rails/blank.rsRuboCop Ruby Implementation (ground truth)
vendor/rubocop-rails/lib/rubocop/cop/rails/blank.rbRuboCop Test Excerpts
vendor/rubocop-rails/spec/rubocop/cop/rails/blank_spec.rbCurrent Fixture: offense.rb
tests/fixtures/cops/rails/blank/offense.rbCurrent Fixture: no_offense.rb
tests/fixtures/cops/rails/blank/no_offense.rb