Skip to content

Fix parsing usage warnings from codetools without location info - #1993

Merged
AshesITR merged 7 commits into
mainfrom
fix/1986-codetools-location
Jul 2, 2023
Merged

AshesITR merged 7 commits into
mainfrom
fix/1986-codetools-location

Conversation

@AshesITR

@AshesITR AshesITR commented Jul 1, 2023 •

Copy link
Copy Markdown
Collaborator

Fixes #1986, Fixes #1917

Comment thread NEWS.md Resolved
@AshesITR

AshesITR commented Jul 1, 2023 •

Copy link
Copy Markdown
Collaborator Author

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

codecov-commenter commented Jul 1, 2023 •

Copy link
Copy Markdown

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%> (ø)

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

nice! lazy matching... my Achilles heel!

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

@AshesITR

AshesITR commented Jul 1, 2023 •

Copy link
Copy Markdown
Collaborator Author

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

AshesITR commented Jul 1, 2023

Copy link
Copy Markdown
Collaborator Author

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

AshesITR commented Jul 1, 2023

Copy link
Copy Markdown
Collaborator Author

also fixes #1917

@AshesITR AshesITR linked an issue Jul 1, 2023 that may be closed by this pull request
@AshesITR
AshesITR requested a review from MichaelChirico July 1, 2023 18:28
Comment thread NEWS.md 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