aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNolan <strake7@users.noreply.github.com>2023-12-21 19:34:11 -0800
committerGitHub <noreply@github.com>2023-12-21 20:34:11 -0700
commit93f7480c967ef9104933f6e346a562196a670d86 (patch)
tree591b26437e1c712ee38205fdd8a4fd123c092ed6 /scripts
parent3aa747856a53d1108c4009b47e77b48d9f290694 (diff)
Add ruby-syntax-tree format support (#224)
Add [ruby-syntax-tree](https://github.com/ruby-syntax-tree/syntax_tree) as an available formatter. Include support for finding a [`.streerc` file](https://github.com/ruby-syntax-tree/syntax_tree#configuration). --------- Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/formatters/apheleia-from-project-root40
-rwxr-xr-xscripts/formatters/apheleia-mix22
2 files changed, 40 insertions, 22 deletions
diff --git a/scripts/formatters/apheleia-from-project-root b/scripts/formatters/apheleia-from-project-root
new file mode 100755
index 0000000..1c22bed
--- /dev/null
+++ b/scripts/formatters/apheleia-from-project-root
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+
+# USAGE: apheleia-from-project-root ROOT-FNAME CMD...
+#
+# If there is a file called ROOT-FNAME in the current directory or any
+# parent directory up to the root of the filesystem, first change to
+# that directory. If not, no worries, proceed without error. Then
+# execute CMD with provided args.
+#
+# This can be used to make sure that a formatter is executed in the
+# root directory of a project, if the file is within a project. For
+# example, ROOT-FNAME could be ".git" or ".formatter.exs" or
+# "package.json" or "pyproject.toml".
+
+if (( "$#" <= 1 )); then
+ echo >&2 "usage: apheleia-from-project-root ROOT-FNAME CMD..."
+ exit 1
+fi
+
+# This function prints the name of the current directory if it
+# contains a file or directory named after the first argument, or the
+# parent directory if it contains such a file, or the parent's parent,
+# and so on. If no such file is found it returns nonzero.
+# https://unix.stackexchange.com/a/22215
+find_upwards() {
+ fname="$1"
+
+ path="${PWD}"
+ while [[ -n "${path}" && ! -e "${path}/${fname}" ]]; do
+ path="${path%/*}"
+ done
+ [[ -n "${path}" ]] && echo "${path}"
+}
+
+if dir="$(find_upwards "$1")"; then
+ cd -- "${dir}" || exit
+fi
+
+shift
+exec "$@"
diff --git a/scripts/formatters/apheleia-mix b/scripts/formatters/apheleia-mix
deleted file mode 100755
index d2038e1..0000000
--- a/scripts/formatters/apheleia-mix
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env bash
-
-# This function prints the name of the current directory if it
-# contains a file or directory named after the first argument, or the
-# parent directory if it contains such a file, or the parent's parent,
-# and so on. If no such file is found it returns nonzero.
-# https://unix.stackexchange.com/a/22215
-find_upwards() {
- fname="$1"
-
- path="${PWD}"
- while [[ -n "${path}" && ! -e "${path}/${fname}" ]]; do
- path="${path%/*}"
- done
- [[ -n "${path}" ]] && echo "${path}"
-}
-
-if dir="$(find_upwards .formatter.exs)"; then
- cd -- "${dir}" || exit
-fi
-
-exec mix "$@"