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

{rlang} name injection on LHS of := causes "object_name_linter" #1926

Closed
psychelzh opened this issue Mar 2, 2023 · 4 comments · Fixed by #2545
Closed

{rlang} name injection on LHS of := causes "object_name_linter" #1926

psychelzh opened this issue Mar 2, 2023 · 4 comments · Fixed by #2545
Labels
false-positive code that shouldn't lint, but does

Comments

@psychelzh
Copy link

psychelzh commented Mar 2, 2023

According to this "name injection" rule, the following code is legal:

library(tibble)
name <- "susan"
tibble("{name}" := 2)
#> # A tibble: 1 × 1
#>   susan
#>   <dbl>
#> 1     2
lintr::lint(text = 'tibble("{name}" := 2)')
#> <text>:1:8: style: [object_name_linter] Variable and function name style should be snake_case or symbols.
#> tibble("{name}" := 2)
#>        ^~~~~~~~

Created on 2023-03-02 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.2 (2022-10-31 ucrt)
#>  os       Windows 10 x64 (build 22621)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Chinese (Simplified)_China.utf8
#>  ctype    Chinese (Simplified)_China.utf8
#>  tz       Asia/Taipei
#>  date     2023-03-02
#>  pandoc   2.19.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version date (UTC) lib source
#>  callr          3.7.3   2022-11-02 [1] CRAN (R 4.2.2)
#>  cli            3.6.0   2023-01-09 [1] CRAN (R 4.2.2)
#>  crayon         1.5.2   2022-09-29 [1] CRAN (R 4.2.1)
#>  cyclocomp      1.1.0   2016-09-10 [1] CRAN (R 4.2.1)
#>  desc           1.4.2   2022-09-08 [1] CRAN (R 4.2.1)
#>  digest         0.6.31  2022-12-11 [1] CRAN (R 4.2.2)
#>  evaluate       0.20    2023-01-17 [1] CRAN (R 4.2.2)
#>  fansi          1.0.4   2023-01-22 [1] CRAN (R 4.2.2)
#>  fastmap        1.1.1   2023-02-24 [1] CRAN (R 4.2.2)
#>  fs             1.6.1   2023-02-06 [1] CRAN (R 4.2.2)
#>  glue           1.6.2   2022-02-24 [1] CRAN (R 4.2.1)
#>  htmltools      0.5.4   2022-12-07 [1] CRAN (R 4.2.2)
#>  knitr          1.42    2023-01-25 [1] CRAN (R 4.2.2)
#>  lazyeval       0.2.2   2019-03-15 [1] CRAN (R 4.2.1)
#>  lifecycle      1.0.3   2022-10-07 [1] CRAN (R 4.2.1)
#>  lintr          3.0.2   2022-10-19 [1] CRAN (R 4.2.1)
#>  magrittr       2.0.3   2022-03-30 [1] CRAN (R 4.2.1)
#>  pillar         1.8.1   2022-08-19 [1] CRAN (R 4.2.1)
#>  pkgconfig      2.0.3   2019-09-22 [1] CRAN (R 4.2.1)
#>  processx       3.8.0   2022-10-26 [1] CRAN (R 4.2.2)
#>  ps             1.7.2   2022-10-26 [1] CRAN (R 4.2.2)
#>  purrr          1.0.1   2023-01-10 [1] CRAN (R 4.2.2)
#>  R.cache        0.16.0  2022-07-21 [1] CRAN (R 4.2.1)
#>  R.methodsS3    1.8.2   2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo           1.25.0  2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils        2.12.2  2022-11-11 [1] CRAN (R 4.2.2)
#>  R6             2.5.1   2021-08-19 [1] CRAN (R 4.2.1)
#>  remotes        2.4.2   2021-11-30 [1] CRAN (R 4.2.1)
#>  reprex         2.0.2   2022-08-17 [1] CRAN (R 4.2.1)
#>  rex            1.2.1   2021-11-26 [1] CRAN (R 4.2.1)
#>  rlang          1.0.6   2022-09-24 [1] CRAN (R 4.2.1)
#>  rmarkdown      2.20    2023-01-19 [1] CRAN (R 4.2.2)
#>  rprojroot      2.0.3   2022-04-02 [1] CRAN (R 4.2.1)
#>  rstudioapi     0.14    2022-08-22 [1] CRAN (R 4.2.1)
#>  sessioninfo    1.2.2   2021-12-06 [1] CRAN (R 4.2.1)
#>  styler         1.9.0   2023-01-15 [1] CRAN (R 4.2.2)
#>  tibble       * 3.1.8   2022-07-22 [1] CRAN (R 4.2.1)
#>  utf8           1.2.3   2023-01-31 [1] CRAN (R 4.2.2)
#>  vctrs          0.5.2   2023-01-23 [1] CRAN (R 4.2.2)
#>  withr          2.5.0   2022-03-03 [1] CRAN (R 4.2.1)
#>  xfun           0.37    2023-01-31 [1] CRAN (R 4.2.2)
#>  xml2           1.3.3   2021-11-30 [1] CRAN (R 4.2.1)
#>  xmlparsedata   1.0.5   2021-03-06 [1] CRAN (R 4.2.1)
#>  yaml           2.3.7   2023-01-23 [1] CRAN (R 4.2.2)
#> 
#>  [1] C:/Users/lenovo/AppData/Local/R/win-library/4.2
#>  [2] C:/Program Files/R/R-4.2.2/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
psychelzh added a commit to psychelzh/preproc.iquizoo that referenced this issue Mar 3, 2023
Perhaps see r-lib/lintr#1926

Signed-off-by: Liang Zhang <psychelzh@outlook.com>
psychelzh added a commit to psychelzh/preproc.iquizoo that referenced this issue Mar 4, 2023
Perhaps see r-lib/lintr#1926

Signed-off-by: Liang Zhang <psychelzh@outlook.com>
@IndrajeetPatil IndrajeetPatil added the false-positive code that shouldn't lint, but does label Mar 22, 2023
@MichaelChirico
Copy link
Collaborator

NB: per ?rlang::"dyn-dots", this applies to the LHS of := for any rlang code.

That means this is in conflict with {data.table}'s :=, where we likely do want to throw object name lints:

DT[, "myPooRNAme_" := 1]

That leaves us with a few options:

  1. Always skip :=
  2. Skip := according to a new argument to object_name_linter()
  3. Check if := is in a call or in [, and check accordingly.

@MichaelChirico MichaelChirico changed the title Name injection causes "object_name_linter" {rlang} name injection on LHS of := causes "object_name_linter" Aug 4, 2023
@AshesITR
Copy link
Collaborator

AshesITR commented Aug 5, 2023

Since we also want to lint badName := 42 in plain code, maybe only (optionally) skip it in function calls?

@ramiromagno
Copy link

Meanwhile, is there a reasonable workaround?

@MichaelChirico
Copy link
Collaborator

You could:

  • disable object_name_linter
  • add a hacky workaround to just pass any name starting with {: object_name_linter(regexes = "^[{]")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants