From 779034d3b81661c18f8592eb05120cfe2295b183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 26 Nov 2023 16:24:22 +0200 Subject: [PATCH 1/2] Add support for Robot Framework files with `robotidy` --- CHANGELOG.md | 3 +++ apheleia-formatters.el | 4 ++++ apheleia-utils.el | 1 + test/formatters/installers/robotidy.bash | 2 ++ test/formatters/samplecode/robotidy/in.robot | 22 ++++++++++++++++++ test/formatters/samplecode/robotidy/out.robot | 23 +++++++++++++++++++ 6 files changed, 55 insertions(+) create mode 100644 test/formatters/installers/robotidy.bash create mode 100644 test/formatters/samplecode/robotidy/in.robot create mode 100644 test/formatters/samplecode/robotidy/out.robot diff --git a/CHANGELOG.md b/CHANGELOG.md index 591468be..8871d12b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,11 @@ The format is based on [Keep a Changelog]. [HTML](https://en.wikipedia.org/wiki/HTML) and [CSS](https://www.google.com/search?q=css) ([#229]) +* [`robotidy`](https://robotidy.readthedocs.io) for Robot Framework files + ([#263]). [#229]: https://github.com/radian-software/apheleia/pull/229 +[#263]: https://github.com/radian-software/apheleia/pull/263 ## 4.0 (released 2023-11-23) ### Breaking changes diff --git a/apheleia-formatters.el b/apheleia-formatters.el index d1947ec8..2996cb66 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -136,6 +136,9 @@ "--parser=yaml" (apheleia-formatters-js-indent "--use-tabs" "--tab-width"))) (purs-tidy . ("apheleia-npx" "purs-tidy" "format")) + (robotidy . ("robotidy" "--no-color" inplace + (apheleia-formatters-indent nil "--indent") + (apheleia-formatters-fill-column "--line-length"))) (rubocop . ("rubocop" "--stdin" filepath "--auto-correct" "--stderr" "--format" "quiet" "--fail-level" "fatal")) (ruby-standard . ("standardrb" "--stdin" filepath "--fix" "--stderr" @@ -306,6 +309,7 @@ rather than using this system." (purescript-mode . purs-tidy) (python-mode . black) (python-ts-mode . black) + (robot-mode . robotidy) (ruby-mode . prettier-ruby) (ruby-ts-mode . prettier-ruby) (rustic-mode . rustfmt) diff --git a/apheleia-utils.el b/apheleia-utils.el index a2061f92..2f9c92e8 100644 --- a/apheleia-utils.el +++ b/apheleia-utils.el @@ -46,6 +46,7 @@ always returns nil to defer to the formatter." (json-mode 'js-indent-level) (json-ts-mode 'json-ts-mode-indent-offset) (nxml-mode 'nxml-child-indent) + (robot-mode 'robot-mode-basic-offset) (scss-mode 'css-indent-offset) (web-mode 'web-mode-indent-style) (tsx-ts-mode 'typescript-ts-mode-indent-offset) diff --git a/test/formatters/installers/robotidy.bash b/test/formatters/installers/robotidy.bash new file mode 100644 index 00000000..88d6ba26 --- /dev/null +++ b/test/formatters/installers/robotidy.bash @@ -0,0 +1,2 @@ +apt-get install -y python3-pip +python3 -m pip install robotframework-tidy diff --git a/test/formatters/samplecode/robotidy/in.robot b/test/formatters/samplecode/robotidy/in.robot new file mode 100644 index 00000000..a12044df --- /dev/null +++ b/test/formatters/samplecode/robotidy/in.robot @@ -0,0 +1,22 @@ +Force Tags tags tag2 +Library Collections +Resource important.robot +Library MyCustomLibrary.py + +Test Setup Setup Keyword + + +*** test case* +Test1 + [ teardown] Teardown Keyword + Keyword + FOR ${var} IN RANGE 10 + Run Keyword If ${var}>5 Other Keyword + END +*** Variables *** +${var}= 2 +${bit_longer} 10 +${var2} a +... b + +*** Keywords *** diff --git a/test/formatters/samplecode/robotidy/out.robot b/test/formatters/samplecode/robotidy/out.robot new file mode 100644 index 00000000..5c144439 --- /dev/null +++ b/test/formatters/samplecode/robotidy/out.robot @@ -0,0 +1,23 @@ +*** Comments *** +Force Tags tags tag2 +Library Collections +Resource important.robot +Library MyCustomLibrary.py + +Test Setup Setup Keyword + + +*** Variables *** +${var}= 2 +${bit_longer} 10 +${var2} a +... b + + +*** Test Cases *** +Test1 + Keyword + FOR ${var} IN RANGE 10 + IF ${var}>5 Other Keyword + END + [Teardown] Teardown Keyword From 72f85c6fdb793d7df0fa305ad0d7d54c7cf0bee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 28 Nov 2023 23:56:46 +0200 Subject: [PATCH 2/2] Format robotidy to stdout --- apheleia-formatters.el | 2 +- test/formatters/samplecode/robotidy/out.robot | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 2996cb66..780da69d 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -136,7 +136,7 @@ "--parser=yaml" (apheleia-formatters-js-indent "--use-tabs" "--tab-width"))) (purs-tidy . ("apheleia-npx" "purs-tidy" "format")) - (robotidy . ("robotidy" "--no-color" inplace + (robotidy . ("robotidy" "--no-color" "-" (apheleia-formatters-indent nil "--indent") (apheleia-formatters-fill-column "--line-length"))) (rubocop . ("rubocop" "--stdin" filepath "--auto-correct" diff --git a/test/formatters/samplecode/robotidy/out.robot b/test/formatters/samplecode/robotidy/out.robot index 5c144439..9a74545e 100644 --- a/test/formatters/samplecode/robotidy/out.robot +++ b/test/formatters/samplecode/robotidy/out.robot @@ -21,3 +21,4 @@ Test1 IF ${var}>5 Other Keyword END [Teardown] Teardown Keyword +