Skip to content

Update sprintf_linter() to lint constant strings - #2894

Merged
MichaelChirico merged 21 commits into
mainfrom
constant-strings
Jul 28, 2025
Merged

MichaelChirico merged 21 commits into
mainfrom
constant-strings

Conversation

@Bisaloo

@Bisaloo Bisaloo commented Jul 26, 2025 •

Copy link
Copy Markdown
Collaborator

Covers some cases from #2183.

As opposed to what seemed implied in some of the comments, I went with treating the constant strings case before checking if the call is invalid to make the maximum possible as static analysis before evaluating calls.

Comment thread R/sprintf_linter.R Outdated
constant_fmt_lint <- xml_nodes_to_lints(
sprintf_calls[constant_fmt],
source_expression = source_expression,
lint_message = "A constant string is used and the sprintf call can be removed",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This message should be improved to use the actual function, which can be gettextf, rather than sprintf.

@Bisaloo
Bisaloo force-pushed the constant-strings branch from 3a5ab38 to 9e18825 Compare July 26, 2025 18:16
@Bisaloo
Bisaloo force-pushed the constant-strings branch from 9e18825 to 85ce180 Compare July 26, 2025 18:17
Comment thread tests/testthat/test-sprintf_linter.R Resolved
@codecov

codecov Bot commented Jul 27, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@38db1ac). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2894   +/-   ##
=======================================
  Coverage        ?   99.27%           
=======================================
  Files           ?      128           
  Lines           ?     7222           
  Branches        ?        0           
=======================================
  Hits            ?     7170           
  Misses          ?       52           
  Partials        ?        0           

☔ 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.

Comment thread R/sprintf_linter.R Resolved
Comment thread R/sprintf_linter.R Resolved

@MichaelChirico MichaelChirico left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it's ready to go, just another round of small tweaks requested. Thanks!

Comment thread R/sprintf_linter.R Resolved

@MichaelChirico MichaelChirico left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great, thanks!

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.

2 participants