From 50da8cd1a94fbcd6456b2528a9db20a5cfc8ff5f Mon Sep 17 00:00:00 2001 From: dalu <25452934+dalugm@users.noreply.github.com> Date: Mon, 2 May 2022 05:51:27 +0800 Subject: [PATCH] Dart format support (#89) * Dart format support * fix: different architexture * Update changelog * Improve installation Co-authored-by: Radon Rosborough --- CHANGELOG.md | 4 +++ apheleia.el | 2 ++ test/formatters/installers/dart-format.bash | 24 +++++++++++++++++ .../formatters/samplecode/dart-format/in.dart | 27 +++++++++++++++++++ .../samplecode/dart-format/out.dart | 17 ++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 test/formatters/installers/dart-format.bash create mode 100644 test/formatters/samplecode/dart-format/in.dart create mode 100644 test/formatters/samplecode/dart-format/out.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index d631f82..6918167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,15 @@ The format is based on [Keep a Changelog]. `apheleia--run-formatter-function`. * Emacs 25 is no longer supported. +### Formatters +* [dart-format](https://dart.dev/tools/dart-format) for Dart ([#89]). + ### Features * Support remote files and buffers that were opened through TRAMP ([#33]). [#33]: https://github.com/raxod502/apheleia/issues/33 +[#89]: https://github.com/raxod502/apheleia/pull/89 ## 2.0 ### Breaking changes diff --git a/apheleia.el b/apheleia.el index 854cc5c..3e9ca48 100644 --- a/apheleia.el +++ b/apheleia.el @@ -913,6 +913,7 @@ being run, for diagnostic purposes." '((black . ("black" "-")) (brittany . ("brittany")) (clang-format . ("clang-format")) + (dart-format . ("dart" "format")) (fish-indent . ("fish_indent")) (gofmt . ("gofmt")) (google-java-format . ("google-java-format" "-")) @@ -1028,6 +1029,7 @@ function: %s" command))) (c-mode . clang-format) (c++-mode . clang-format) (css-mode . prettier) + (dart-mode . dart-format) (elixir-mode . mix-format) (fish-mode . fish-indent) (go-mode . gofmt) diff --git a/test/formatters/installers/dart-format.bash b/test/formatters/installers/dart-format.bash new file mode 100644 index 0000000..0c164ec --- /dev/null +++ b/test/formatters/installers/dart-format.bash @@ -0,0 +1,24 @@ +arch="$(uname -m)" +case "${arch}" in + "x86_64") + arch="x64" + ;; + "i386") + arch="ia32" + ;; + "aarch64") + arch="arm64" + ;; + *) + echo >&2 "unsupported architecture: ${arch}" + exit 1 + ;; +esac + +wget "https://storage.googleapis.com/dart-archive/channels/stable/release/latest/sdk/dartsdk-linux-${arch}-release.zip" -O dart.zip +unzip dart.zip +chmod a=u,go-w -R dart-sdk + +sudo mkdir /opt/dart +sudo cp -R dart-sdk/. /opt/dart/. +sudo ln -s /opt/dart/bin/dart /usr/local/bin/ diff --git a/test/formatters/samplecode/dart-format/in.dart b/test/formatters/samplecode/dart-format/in.dart new file mode 100644 index 0000000..1b58920 --- /dev/null +++ b/test/formatters/samplecode/dart-format/in.dart @@ -0,0 +1,27 @@ +void main() { + Function addNumbers = ( + a, + b + ) => print(a + b); + someOtherFunction("addNumbers",addNumbers); + + var myFunc = taskToPerform(); + print(myFunc(10)); +} + +void someOtherFunction(String + message, + Function myFunction) + { + print(message); + myFunction( + 2, + 4 + ); +} + +Function taskToPerform() { + Function multiplyFour = (int number) => number*4; + return + multiplyFour; +} diff --git a/test/formatters/samplecode/dart-format/out.dart b/test/formatters/samplecode/dart-format/out.dart new file mode 100644 index 0000000..fb871a9 --- /dev/null +++ b/test/formatters/samplecode/dart-format/out.dart @@ -0,0 +1,17 @@ +void main() { + Function addNumbers = (a, b) => print(a + b); + someOtherFunction("addNumbers", addNumbers); + + var myFunc = taskToPerform(); + print(myFunc(10)); +} + +void someOtherFunction(String message, Function myFunction) { + print(message); + myFunction(2, 4); +} + +Function taskToPerform() { + Function multiplyFour = (int number) => number * 4; + return multiplyFour; +}