Skip to content

Fix alignment detection for quoted keys #882

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

Merged
merged 2 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# styler 1.6.2.9000 (Development version)

* Piped function without brackets `substitute(x %>% y)` don't get `()` added
anymore, as this can change outcome of the code (#876).
* Alignment detection respects stylerignore (#850).
* Add vignette on distributing style guide (#846, #861).
* Enable pre-commit.ci (#843).
**API changes**

* new R option `styler.cache_root` (defaulting to `"styler"`) that determines
the sub-directory under the {R.cache} cache directory that {styler} uses. Non-
default caches won't be cleaned up by {styler}. We suggest `"styler-perm"`
(also used by {precommit}).
* rename default branch to main (#859).
* Fix argument name `filetype` in Example for `style_dir()` (#855).
* ensure a trailing blank line also if the input is cached (#867).
* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which
allowed to remove the dependency at {backports} and some exception handling.
* Remove dependency on {xfun} (#866).
* use pre-commit via GitHub Actions (#872).

* stylerignore markers are now interpreted as regular expressions instead of
comments that must match exactly. This allows to specify multiple markers in
Expand All @@ -33,6 +23,28 @@
`styler.ignore_stop` omit the `#` (#849).


* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which
allowed to remove the dependency at {backports} and some exception handling.

**Other changes**

* Piped function without brackets `substitute(x %>% y)` don't get `()` added
anymore, as this can change outcome of the code (#876).
* Alignment detection respects stylerignore (#850).
* Unaligned expressions with quoted key (e.g. `c("x" = 2)`) are now correctly
detected (#881).
* Add vignette on distributing style guide (#846, #861).
* ensure a trailing blank line also if the input is cached (#867).
* Fix argument name `filetype` in Example for `style_dir()` (#855).

**Infrastructure**

* Remove dependency on {xfun} (#866).
* rename default branch to main (#859).
* Enable pre-commit.ci (#843).
* use pre-commit via GitHub Actions (#872).


# styler 1.6.2

* clean up cache files older than one week (#842).
Expand Down
3 changes: 2 additions & 1 deletion R/detect-alignment-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ alignment_col1_all_named <- function(relevant_pd_by_line) {
if (nrow(x) < 3) {
return(FALSE)
}
identical(x$token[c(1, 3)], c("SYMBOL_SUB", "expr")) &&
x$token[3] == "expr" &&
x$token[1] %in% c("SYMBOL_SUB", "STR_CONST") &&
x$token[2] %in% c(
"EQ_SUB", "SPECIAL-IN", "LT", "GT", "EQ", "NE"
)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/alignment/quoted-names-in.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
df <- dplyr::rename(df,
"xValues" = "Time",
"xUnit" = "TimeUnit",
"yValues" = "simulationValues",
"yUnit" = "unit",
"yDimension" = "dimension"
)
39 changes: 39 additions & 0 deletions tests/testthat/alignment/quoted-names-in_tree

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/alignment/quoted-names-out.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
df <- dplyr::rename(df,
"xValues" = "Time",
"xUnit" = "TimeUnit",
"yValues" = "simulationValues",
"yUnit" = "unit",
"yDimension" = "dimension"
)