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

add format methods for lint and lints #1790

Merged
merged 3 commits into from
Dec 9, 2022
Merged

Conversation

AshesITR
Copy link
Collaborator

@AshesITR AshesITR commented Dec 3, 2022

fixes #1784

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2022

Codecov Report

Merging #1790 (004882a) into main (42b31ae) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1790   +/-   ##
=======================================
  Coverage   98.85%   98.85%           
=======================================
  Files         112      112           
  Lines        4796     4797    +1     
=======================================
+ Hits         4741     4742    +1     
  Misses         55       55           
Impacted Files Coverage Δ
R/expect_lint.R 100.00% <100.00%> (ø)
R/methods.R 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@AshesITR
Copy link
Collaborator Author

AshesITR commented Dec 3, 2022

This ran successfully when based against #1788; tabling for now.

@IndrajeetPatil IndrajeetPatil added this to the 3.1.0 milestone Dec 5, 2022
@IndrajeetPatil
Copy link
Collaborator

I don't find the current format output easy to navigate:

library(lintr)

l <- lint(
  text = "x=1+1",
  linters = linters_with_tags(NULL)
)

class(l)
#> [1] "lints" "list"

print(l)
#> <text>:1:2: style: [assignment_linter] Use <-, not =, for assignment.
#> x=1+1
#>  ^
#> <text>:1:2: style: [infix_spaces_linter] Put spaces around all infix operators.
#> x=1+1
#>  ^
#> <text>:1:4: style: [infix_spaces_linter] Put spaces around all infix operators.
#> x=1+1
#>    ^
#> <text>:1:4: style: [implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.
#> x=1+1
#>   ~^
#> <text>:1:6: style: [implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.
#> x=1+1
#>     ~^

format(l)
#> [1] "<text>:1:2: style: [assignment_linter] Use <-, not =, for assignment.\nx=1+1\n ^\n\n<text>:1:2: style: [infix_spaces_linter] Put spaces around all infix operators.\nx=1+1\n ^\n\n<text>:1:4: style: [infix_spaces_linter] Put spaces around all infix operators.\nx=1+1\n   ^\n\n<text>:1:4: style: [implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.\nx=1+1\n  ~^\n\n<text>:1:6: style: [implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.\nx=1+1\n    ~^\n"

Created on 2022-12-08 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.2 (2022-10-31)
#>  os       macOS Ventura 13.0.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Berlin
#>  date     2022-12-08
#>  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version       date (UTC) lib source
#>  backports      1.4.1         2021-12-13 [1] CRAN (R 4.2.0)
#>  callr          3.7.3         2022-11-02 [1] CRAN (R 4.2.0)
#>  cli            3.4.1         2022-09-23 [1] CRAN (R 4.2.0)
#>  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.0)
#>  desc           1.4.2         2022-09-08 [1] CRAN (R 4.2.1)
#>  digest         0.6.30        2022-10-18 [1] CRAN (R 4.2.1)
#>  evaluate       0.18          2022-11-07 [1] CRAN (R 4.2.2)
#>  fastmap        1.1.0         2021-01-25 [1] CRAN (R 4.2.0)
#>  fs             1.5.2         2021-12-08 [1] CRAN (R 4.2.0)
#>  glue           1.6.2         2022-02-24 [1] CRAN (R 4.2.0)
#>  highr          0.9           2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools      0.5.4         2022-12-07 [1] CRAN (R 4.2.2)
#>  knitr          1.41          2022-11-18 [1] CRAN (R 4.2.2)
#>  lazyeval       0.2.2         2019-03-15 [1] CRAN (R 4.2.0)
#>  lifecycle      1.0.3         2022-10-07 [1] CRAN (R 4.2.1)
#>  lintr        * 3.0.2.9000    2022-12-08 [1] local
#>  magrittr       2.0.3         2022-03-30 [1] CRAN (R 4.2.0)
#>  processx       3.8.0         2022-10-26 [1] CRAN (R 4.2.1)
#>  ps             1.7.2         2022-10-26 [1] CRAN (R 4.2.0)
#>  purrr          0.9000.0.9000 2022-11-30 [1] Github (tidyverse/purrr@55c9a8a)
#>  R.cache        0.16.0        2022-07-21 [1] CRAN (R 4.2.0)
#>  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.9000    2022-10-27 [1] local
#>  remotes        2.4.2         2021-11-30 [1] CRAN (R 4.2.0)
#>  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.0)
#>  rlang          1.0.6         2022-09-24 [1] CRAN (R 4.2.1)
#>  rmarkdown      2.18          2022-11-09 [1] CRAN (R 4.2.2)
#>  rprojroot      2.0.3         2022-04-02 [1] CRAN (R 4.2.0)
#>  rstudioapi     0.14          2022-08-22 [1] CRAN (R 4.2.1)
#>  sessioninfo    1.2.2         2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi        1.7.8         2022-07-11 [1] CRAN (R 4.2.1)
#>  stringr        1.5.0         2022-12-02 [1] CRAN (R 4.2.2)
#>  styler         1.8.1.9000    2022-11-26 [1] Github (r-lib/styler@44d4787)
#>  vctrs          0.5.1         2022-11-16 [1] CRAN (R 4.2.2)
#>  withr          2.5.0         2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun           0.35          2022-11-16 [1] CRAN (R 4.2.2)
#>  xml2           1.3.3.9000    2022-10-10 [1] local
#>  xmlparsedata   1.0.5         2021-03-06 [1] CRAN (R 4.2.0)
#>  yaml           2.3.6         2022-10-18 [1] CRAN (R 4.2.1)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

@MichaelChirico
Copy link
Collaborator

MichaelChirico commented Dec 8, 2022

that's not a problem IMO, you can always pipe to writeLines()

format(l) |> writeLines() should look ok.

is there any precedence on whether format returns a single or multiple character strings?

off the top of my head I think of RProtoBuf's toString() method which has similar output, but toString() is a scalar method.

@AshesITR
Copy link
Collaborator Author

AshesITR commented Dec 8, 2022

tmp <- R6::R6Class("testing")
format(tmp)
#> [1] "<testing> object generator\n  Public:\n    clone: function (deep = FALSE) \n  Parent env: <environment: R_GlobalEnv>\n  Locked objects: TRUE\n  Locked class: FALSE\n  Portable: TRUE"

Created on 2022-12-08 with reprex v2.0.2

Copy link
Collaborator

@IndrajeetPatil IndrajeetPatil left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

library(lintr)

l <- lint(
  text = "x=1+1",
  linters = linters_with_tags(NULL)
)

cat(format(l)) 
#> <text>:1:2: style: [assignment_linter] Use <-, not =, for assignment.
#> x=1+1
#>  ^
#> 
#> <text>:1:2: style: [infix_spaces_linter] Put spaces around all infix operators.
#> x=1+1
#>  ^
#> 
#> <text>:1:4: style: [infix_spaces_linter] Put spaces around all infix operators.
#> x=1+1
#>    ^
#> 
#> <text>:1:4: style: [implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.
#> x=1+1
#>   ~^
#> 
#> <text>:1:6: style: [implicit_integer_linter] Integers should not be implicit. Use the form 1L for integers or 1.0 for doubles.
#> x=1+1
#>     ~^

Created on 2022-12-09 with reprex v2.0.2

@IndrajeetPatil IndrajeetPatil merged commit 7c483e6 into main Dec 9, 2022
@IndrajeetPatil IndrajeetPatil deleted the fix/1784-format-lints branch December 9, 2022 07:14
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.

Make failure message of expect_lint_free() more actionable
4 participants