Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@emmanuel-ferdman
Copy link
Contributor

PR Summary

Using && or || inside an anonymous function passed to vapply(), sapply(), or similar within filter()/subset() is correct because each iteration processes a single element. The linter was incorrectly flagging these as needing &/|. This adds an XPath exclusion for FUNCTION and OP-LAMBDA ancestors, matching the pattern already used in library_call_linter.

Closes #2935

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.23%. Comparing base (e1859e5) to head (27b2a0a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3004   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files         128      128           
  Lines        7281     7282    +1     
=======================================
+ Hits         7225     7226    +1     
  Misses         56       56           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

and not(preceding-sibling::expr[last()]/SYMBOL_FUNCTION_CALL[not(text() = 'subset' or text() = 'filter')])
and not(preceding-sibling::OP-LEFT-BRACKET)
and not(preceding-sibling::*[not(self::COMMENT)][2][self::SYMBOL_SUB and text() = 'circular'])
and not(ancestor::expr[FUNCTION or OP-LAMBDA])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may not be complicated enough:

subset(x,
  sapply(col, function(x) {
  if (A | B) {
    do_ab(x)
  } else {
    do_other(x)
  })
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I added [not(descendant-or-self::expr[FUNCTION or OP-LAMBDA])] to the exclusion so that if (A | B) inside a function definition still gets linted, while things like if (any(x | y)) stay excluded. Added tests for your exact example and a few variations (lambda syntax, while loops, nested aggregators). Let me know if you spot anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vector_logic_linter() false positive with && in mapping/apply

2 participants