Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing usage warnings from codetools without location info #1993

Merged
merged 7 commits into from
Jul 2, 2023

Conversation

AshesITR
Copy link
Collaborator

@AshesITR AshesITR commented Jul 1, 2023

Fixes #1986, Fixes #1917

NEWS.md Show resolved Hide resolved
@AshesITR
Copy link
Collaborator Author

AshesITR commented Jul 1, 2023

There is still one ugly edge case, but I fear it will be very hard to properly fix:

codetools::checkUsage({
  foo <- function() a <-
    bar()
})
# This one will fail to find col1 because the symbol is on line 2:
# <anonymous>: no visible global function definition for ‘bar’
# This one is fixed by the PR:
# <anonymous>: local variable ‘a’ assigned but may not be used
lint(text = "foo <- function() a <-\n  bar()", linters = object_usage_linter())
#> <text>:1:19: warning: [object_usage_linter] no visible global function definition for 'bar'
#> foo <- function() a <-
#>                   ^
#> <text>:1:19: warning: [object_usage_linter] local variable 'a' assigned but may not be used
#> foo <- function() a <-
#>                   ^

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2023

Codecov Report

Merging #1993 (57f10de) into main (4f75e7a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 57f10de differs from pull request most recent head 500d137. Consider uploading reports for the commit 500d137 to get more accurate results

@@           Coverage Diff           @@
##             main    #1993   +/-   ##
=======================================
  Coverage   98.55%   98.55%           
=======================================
  Files         113      113           
  Lines        4993     4999    +6     
=======================================
+ Hits         4921     4927    +6     
  Misses         72       72           
Impacted Files Coverage Δ
R/object_usage_linter.R 99.42% <100.00%> (+0.02%) ⬆️
R/quotes_linter.R 100.00% <100.00%> (ø)

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.

nice! lazy matching... my Achilles heel!

it looks like this may have popped new lints in quotes_linter()?

@AshesITR
Copy link
Collaborator Author

AshesITR commented Jul 1, 2023

Interesting.
codetools messes up the deeply nested with() block.
Our new fallback lints the first expr on the first line, i.e. c('"', "'").
Not an ideal fallback...

On current main, we see a warning as expected:

lintr::lint("R/quotes_linter.R", linters = object_usage_linter())
#> Warning in parse_check_usage(fun, known_used_symbols = known_used_symbols,  :
#>   Possible bug in lintr: Couldn't parse usage message ‘<anonymous> : <anonymous> : <anonymous>: local variable 'col2' assigned but may not be used

Also seeing a warning in lint-changed-files:

Linter consecutive_stopifnot_linter was deprecated in lintr version 3.1.0. Use consecutive_assertion_linter instead.

@AshesITR
Copy link
Collaborator Author

AshesITR commented Jul 1, 2023

Thinking about the lint in R/quotes_linter.R actually helped me find a solution for the multi-line edge case I presented above 🥳

@AshesITR
Copy link
Collaborator Author

AshesITR commented Jul 1, 2023

also fixes #1917

@AshesITR AshesITR linked an issue Jul 1, 2023 that may be closed by this pull request
NEWS.md Show resolved Hide resolved
@AshesITR AshesITR merged commit f9eb181 into main Jul 2, 2023
@AshesITR AshesITR deleted the fix/1986-codetools-location branch July 2, 2023 06:46
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.

New warning in 'designer' from object_usage_linter object_usage_linter fails to parse inline function output
3 participants