Incorrect indentation for comments in function calls

Open
#1,108 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
r
Domain
tooling

Research direction

Start by reproducing the example with styler::style_text(code) and compare the actual output with the expected indentation. Trace how styler handles comments inside the function call, then verify that the comment is indented with the following list and that lintr::indentation_linter() reports no error.

Written by the indexing model from the issue text.

Description

Complexity: Medium Priority: Medium Status: Unassigned Type: Bug

Actual

This produces a lint:

'gghistostats( 
  mtcars,
  wt,
  ggplot.component =
  # modify further with {ggplot2}
    list(
      theme(axis.text.x = element_text(angle = 90))
    )
)' -> code

styler::style_text(code)
#> gghistostats(
#>   mtcars,
#>   wt,
#>   ggplot.component =
#>   # modify further with {ggplot2}
#>     list(
#>       theme(axis.text.x = element_text(angle = 90))
#>     )
#> )

lintr::lint(text = code, linters = lintr::indentation_linter())
#> <text>:5:2: style: [indentation_linter] Indentation should be 4 spaces but is 2 spaces.
#>   # modify further with {ggplot2}
#>  ^~~

Created on 2023-04-06 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.2.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Berlin
#>  date     2023-04-06
#>  pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/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.6.1      2023-03-23 [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.0)
#>  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.0)
#>  fastmap        1.1.1      2023-02-24 [1] CRAN (R 4.2.0)
#>  fs             1.6.1      2023-02-06 [1] CRAN (R 4.2.0)
#>  glue           1.6.2      2022-02-24 [1] CRAN (R 4.2.0)
#>  htmltools      0.5.5      2023-03-23 [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.0)
#>  lifecycle      1.0.3      2022-10-07 [1] CRAN (R 4.2.1)
#>  lintr          3.0.2.9000 2023-04-04 [1] local
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.2.0)
#>  prettycode     1.1.0      2019-12-16 [1] CRAN (R 4.2.0)
#>  processx       3.8.0      2022-10-26 [1] CRAN (R 4.2.1)
#>  ps             1.7.4      2023-04-02 [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.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.1.0      2023-03-14 [1] CRAN (R 4.2.0)
#>  rmarkdown      2.21       2023-03-26 [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)
#>  styler         1.9.1      2023-04-05 [1] Github (r-lib/styler@db9bbed)
#>  vctrs          0.6.1      2023-03-22 [1] CRAN (R 4.2.0)
#>  withr          2.5.0      2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun           0.38       2023-03-24 [1] CRAN (R 4.2.2)
#>  xml2           1.3.3      2021-11-30 [1] CRAN (R 4.2.0)
#>  xmlparsedata   1.0.5      2021-03-06 [1] CRAN (R 4.2.0)
#>  yaml           2.3.7      2023-01-23 [1] CRAN (R 4.2.2)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Expected

styler::style_text(code)
#> gghistostats(
#>   mtcars,
#>   wt,
#>   ggplot.component =
#>     # modify further with {ggplot2}
#>     list(
#>       theme(axis.text.x = element_text(angle = 90))
#>     )
#> )
Dominant language
R
Stars
773
Forks
74
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/styler

All issues in r-lib/styler

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.