From 56651724ad22f2769bbdaccf54cbe75c1cb35c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 29 Nov 2023 00:50:25 +0200 Subject: [PATCH] Add support for Robot Framework files with `robotidy` (#263) --- 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 | 24 +++++++++++++++++++ 6 files changed, 56 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..780da69d 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" "-" + (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..9a74545e --- /dev/null +++ b/test/formatters/samplecode/robotidy/out.robot @@ -0,0 +1,24 @@ +*** 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 +