diff options
| author | Martin Edström <meedstrom91@gmail.com> | 2025-11-11 12:40:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-11 12:40:33 +0100 |
| commit | e7892adc8a23612b219513ea56f62cdb825afe8f (patch) | |
| tree | 2369d675723b6a4ae1a70abef227ccd3d5ce8186 | |
| parent | f1d36031fc162f541f77d4f6c6c0fd6197aba077 (diff) | |
Add styleR for ess-r-mode (#377)
Hi! My first time adding a formatter, please let me know if I missed
anything.
Some things I'm unclear about:
1. How to fail gracefully when [styleR](https://styler.r-lib.org/)
package is absent from the system
2. Whether the formatter should be named `ess-r` or something more
general like `rlang`
## Test case
FYI, there are loads of tests to pick from on
https://github.com/r-lib/styler/tree/main/tests/testthat.
I picked
[unindention/mixed-in.R](https://github.com/r-lib/styler/blob/main/tests/testthat/unindention/mixed-in.R),
but oddly, the output
[unindention/mixed-out.R](https://github.com/r-lib/styler/blob/main/tests/testthat/unindention/mixed-out.R)
isn't quite the same as we got!
I don't know if that's an upstream issue, or that upstream changed style
since that test was written, or that perhaps the file is meant to be
concatenated into something else.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | apheleia-formatters.el | 2 | ||||
| -rw-r--r-- | test/formatters/installers/r-styler.bash | 2 | ||||
| -rw-r--r-- | test/formatters/samplecode/r-styler/in.R | 15 | ||||
| -rw-r--r-- | test/formatters/samplecode/r-styler/out.R | 12 |
5 files changed, 32 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a0e5b83..43746aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog]. * [hurlfmt](https://hurl.dev) for hurl files. * [csharpier](https://github.com/belav/csharpier) for C#. * [taplo](https://taplo.tamasfe.dev/) for TOML. +* [styler](https://styler.r-lib.org/) for R. ## 4.4.1 (released 2025-05-13) ### Enhancements diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 581a9a1..e847716 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -174,6 +174,8 @@ (robotidy . ("robotidy" "--no-color" "-" (apheleia-formatters-indent nil "--indent") (apheleia-formatters-fill-column "--line-length"))) + (r-styler . ("R" "--no-echo" "--no-save" "--no-restore" "-e" + "styler::style_text(readLines(file('stdin')))")) (python3-json . ("python3" "-m" "json.tool" (apheleia-formatters-indent "--tab" "--indent"))) diff --git a/test/formatters/installers/r-styler.bash b/test/formatters/installers/r-styler.bash new file mode 100644 index 0000000..3e7f41d --- /dev/null +++ b/test/formatters/installers/r-styler.bash @@ -0,0 +1,2 @@ +apt-get install -y r-base-core +R --no-echo --no-save --no-restore -e "install.packages('styler')" diff --git a/test/formatters/samplecode/r-styler/in.R b/test/formatters/samplecode/r-styler/in.R new file mode 100644 index 0000000..5a00a8b --- /dev/null +++ b/test/formatters/samplecode/r-styler/in.R @@ -0,0 +1,15 @@ +{ + ((( + 2 + ))) + } + +{ +{ + call( + call1(2, 3), + { + sin(cos(pi)) + } ) + } +} diff --git a/test/formatters/samplecode/r-styler/out.R b/test/formatters/samplecode/r-styler/out.R new file mode 100644 index 0000000..988599b --- /dev/null +++ b/test/formatters/samplecode/r-styler/out.R @@ -0,0 +1,12 @@ +{ + ((( + 2 + ))) +} + +{{ call( + call1(2, 3), + { + sin(cos(pi)) + } +) }} |
