vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

Spurious lintr message ?

Open gowerc opened this issue 4 years ago • 11 comments

Apologies in advance if this is the wrong place to raise this. I am making the assumption the issue is from how this extension is using lintr rather than with lintr itself.

Describe the bug

When developing a package the lintr warns of "no visible bindings" if a function is defined in another file

To Reproduce

  1. create an R package
  2. define a function in 1 file
  3. use that function in another file
  4. lintr complains that there is "no visible binding" for that function

Do you want to fix by self? (We hope your help!)

No (Well yes but it is likely to be multiple months before I get around to it sorry ! 😢 )

Settings

All settings are left as defaults as of v2.1.0

Expected behavior

Not to raise the warning

Screenshots image

Environment (please complete the following information):

  • OS: macOS Catalina
  • VSCode Version: 1.58.2
  • R Version: 4.1.0
  • vscode-R version: 2.1.0

gowerc avatar Jul 22 '21 13:07 gowerc

object_usage_linter does not well via lintr::lint() for package functions and multi-file cases. Please disable it in your project or global .lintr at the moment according to https://github.com/jimhester/lintr#lintr-file-example.

renkun-ken avatar Jul 22 '21 13:07 renkun-ken

Arr ok so you guys are running it per file. I guess there is no solution to this then. I'd rather avoid disabling object_usage_linter as it can help identfy areas where functions truely haven't been defined. Hmmm I can't think of anyway of resolving this :( feel free to close I guess !

gowerc avatar Jul 22 '21 16:07 gowerc

Are you using the latest dev of lintr? I'm running the latest lintr and object_usage_linter seems to work correctly.

renkun-ken avatar Jul 23 '21 05:07 renkun-ken

I'm using "2.0.1" apparently which is the most recent CRAN version

gowerc avatar Jul 23 '21 08:07 gowerc

Please try the latest development version via remotes::install_github("jimhester/lintr").

The current CRAN release is too old. A lot has been improved and fixed.

renkun-ken avatar Jul 23 '21 08:07 renkun-ken

Installed the github version and restarted VScode, still am getting the same warning messages :( Are there any other meaningful diagnostics I could provide ?

gowerc avatar Jul 23 '21 09:07 gowerc

Had the same issue (ton of "no visible binding" messages) - e.g. when using tags$div(...) from htmltools

Installing the most current dev-version devtools::install_github("r-lib/lintr") solved the issue for me (thank´s for the hint @renkun-ken 👏)

Seems version 3.0.0 is currently worked on and will hopefully be released soon 😀

markschat avatar Apr 22 '22 16:04 markschat

Weird things happen: Today I opened my shiny-project (with shiny modules) and get a flood of warnings like:

no visible global function definition for ‘%>%’ object_usage_linter

I have the current lintr dev version 2.0.1.9000 and I´m pretty shure those warnings where not there before. Maybe this is somehow related to this issue.

markschat avatar May 06 '22 09:05 markschat

I have this too with lintr 3.0.0 in VS Code. ~Calling lintr::lint_package() works just fine~, and the LSP finds the object definitions in my R/ folder. However, lintr still throws object_usage_linter warnings for "no visible global function" and "no visible binding" for function calls and symbols, respectively. lintr doesn't seem to honor "NAMESPACE" either as imported names are not resolved.

sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.4

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
 [1] ps_1.7.0        crayon_1.5.1    withr_2.5.0    
 [4] rprojroot_2.0.3 R6_2.5.1        jsonlite_1.8.0 
 [7] rlang_1.0.3     cli_3.3.0       lazyeval_0.2.2 
[10] remotes_2.4.2   callr_3.7.0     rex_1.2.1      
[13] xml2_1.3.3      cyclocomp_1.1.0 desc_1.4.1     
[16] tools_4.2.0     lintr_3.0.0     compiler_4.2.0 
[19] processx_3.6.0 
Relevant settings.json configuration
{
  "[r]": {
        "editor.defaultFormatter": "REditorSupport.r"
    },
    "r.alwaysUseActiveTerminal": true,
    "r.bracketedPaste": true,
    "r.rmarkdown.enableCodeLens": true,
    "r.rterm.mac": "/usr/local/bin/radian",
    "r.sessionWatcher": true,
    "r.workspaceViewer.removeHiddenItems": true,
    "r.lsp.args": [ "--no-save", "--no-restore" ],
    "r.rpath.mac": "/usr/local/bin/R",
    "r.rterm.option": [
      "--no-save",
      "--no-restore",
      "--r-binary=/usr/local/bin/R"
    ]
}

Using reditorsupport.r version 2.5.2 with Visual Studio Code 1.70.2.


Edit: calling lintr::lint_package() actually is not okay. This might be a lintr problem?

psanker avatar Aug 17 '22 19:08 psanker

@gowerc @psanker Would you like to try https://github.com/REditorSupport/languageserver/pull/568 and see if it works for you?

renkun-ken avatar Aug 18 '22 10:08 renkun-ken

Works for me!

psanker avatar Aug 18 '22 16:08 psanker