aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordalu <25452934+dalugm@users.noreply.github.com>2022-05-02 05:51:27 +0800
committerGitHub <noreply@github.com>2022-05-01 14:51:27 -0700
commit50da8cd1a94fbcd6456b2528a9db20a5cfc8ff5f (patch)
tree9bdc03d4a3716c9fe169408d64a0bfc03433f1f8
parentb7251e54a09d8f05fc73127fdeb983229d640bad (diff)
Dart format support (#89)
* Dart format support * fix: different architexture * Update changelog * Improve installation Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
-rw-r--r--CHANGELOG.md4
-rw-r--r--apheleia.el2
-rw-r--r--test/formatters/installers/dart-format.bash24
-rw-r--r--test/formatters/samplecode/dart-format/in.dart27
-rw-r--r--test/formatters/samplecode/dart-format/out.dart17
5 files changed, 74 insertions, 0 deletions
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;
+}