Skip to content

Fix false positive in if_switch_linter() for empty strings#3018

Merged
MichaelChirico merged 8 commits intomainfrom
fix/issue-2835-empty-string-switch
Mar 2, 2026
Merged

Fix false positive in if_switch_linter() for empty strings#3018
MichaelChirico merged 8 commits intomainfrom
fix/issue-2835-empty-string-switch

Conversation

@emmanuel-ferdman
Copy link
Collaborator

PR Summay

if_switch_linter() was flagging if-else chains that compare against empty strings ("" or ''), but we can't actually use empty strings as switch() case names as R throws an error. This PR skips those cases so the linter only suggests switch() when it's actually valid.

Fixes #2835

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@emmanuel-ferdman emmanuel-ferdman force-pushed the fix/issue-2835-empty-string-switch branch from c3a9da2 to ac74b25 Compare February 27, 2026 20:26
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.23%. Comparing base (f185cf1) to head (f0f8e57).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3018   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files         128      128           
  Lines        7293     7317   +24     
=======================================
+ Hits         7237     7261   +24     
  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.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Copy link
Collaborator

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

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

Looking great! I found the original test suite a bit lacking so added a few more tests too as better assurance against backsliding elsewhere from the refactor.

Explaining my tweaks to the helper names:

  • I think it's good to emphasize this is specifically an if_else chain
  • Hadley influenced me to dislike get_ in function names. I tend to agree it's usually redundant.
  • var doesn't precisely match the case like if (foo(x) == 'a') else if (foo(x) == 'b'), I think expr is better

@MichaelChirico MichaelChirico merged commit ccad66a into main Mar 2, 2026
19 checks passed
@MichaelChirico MichaelChirico deleted the fix/issue-2835-empty-string-switch branch March 2, 2026 19:36
@emmanuel-ferdman
Copy link
Collaborator Author

@MichaelChirico thanks on all the the guidance on this!

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.

if_switch_linter false positive when testing == ""

2 participants