Skip to content

Commit

Permalink
Revert "Add support for formatters locally installed via yarn 2+ pnp …
Browse files Browse the repository at this point in the history
…mode (radian-software#200)"

This reverts commit 54a192c.
  • Loading branch information
alternateved committed Nov 6, 2023
1 parent 54a192c commit 9d48c14
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 140 deletions.
7 changes: 0 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ The format is based on [Keep a Changelog].
* Prettier is now enabled in `svelte-mode`.
* More tree-sitter based major modes have been added to
`apheleia-mode-alist` ([#191]).
* Built-in formatters now use a new `"apheleia-npx"` built-in script
instead of the legacy `npx` keyword. The effect of the new script is
the same, except that it also works with Yarn PNP projects as well
as `node_modules` style projects ([#200]).
* Autoload the apheleia-goto-error command ([#215]).
* Use `lisp-indent` as default formatter for `emacs-lisp-mode` ([#223])
* Use `hclfmt` for formatting hashicorp HCL files ([#231])

### Internal Changes
* Refactored the organisation of the apheleia package for ease of
understanding and usability ([#215]).
* The new `scripts/pnp-bin.js` script is standalone minified nodejs built
from the [`pnp-bin`](https://github.com/PuddleByteComputing/pnp-bin) repo,
extracted from apheleia PR [#200].

### Bugs fixed
* `ktlint` would emit log messages into its stdout when formatting,
Expand Down
60 changes: 26 additions & 34 deletions apheleia-formatters.el
Original file line number Diff line number Diff line change
Expand Up @@ -81,45 +81,42 @@
(perltidy . ("perltidy" "--quiet" "--standard-error-output"))
(phpcs . ("apheleia-phpcs"))
(prettier
. ("apheleia-npx" "prettier" "--stdin-filepath" filepath
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-css
. ("apheleia-npx" "prettier" "--parser=css"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=css"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-html
. ("apheleia-npx" "prettier" "--parser=html"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=html"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-graphql
. ("apheleia-npx" "prettier" "--parser=graphql"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=graphql"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-javascript
. ("apheleia-npx" "prettier" "--parser=babel-flow"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=babel-flow"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-json
. ("apheleia-npx" "prettier" "--parser=json"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=json"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-markdown
. ("apheleia-npx" "prettier" "--parser=markdown"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=markdown"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-ruby
. ("apheleia-npx" "prettier" "--stdin-filepath" "dummy.rb"
"--plugin=@prettier/plugin-ruby"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=ruby"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-scss
. ("apheleia-npx" "prettier" "--stdin-filepath" filepath
"--parser=scss"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=scss"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-svelte
. ("apheleia-npx" "prettier" "--stdin-filepath" filepath
"--plugin=prettier-plugin-svelte"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=svelte"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-typescript
. ("apheleia-npx" "prettier" "--parser=typescript"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
. (npx "prettier" "--stdin-filepath" filepath "--parser=typescript"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(prettier-yaml
. ("apheleia-npx" "prettier" "--parser=yaml"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(purs-tidy . ("apheleia-npx" "purs-tidy" "format"))
. (npx "prettier" "--stdin-filepath" filepath "--parser=yaml"
(apheleia-formatters-js-indent "--use-tabs" "--tab-width")))
(purs-tidy . (npx "purs-tidy" "format"))
(rubocop . ("rubocop" "--stdin" filepath "--auto-correct"
"--stderr" "--format" "quiet" "--fail-level" "fatal"))
(ruby-standard . ("standardrb" "--stdin" filepath "--fix" "--stderr"
Expand Down Expand Up @@ -188,11 +185,6 @@ then the first string element of the command list is resolved
inside node_modules/.bin if such a directory exists anywhere
above the current `default-directory'.
\(However, instead of using `npx', consider using
\"apheleia-npx\", which is a built-in script that will replicate
the effect, but will also work with Yarn PNP projects and other
npm project types that may exist in the future.)
Any list elements that are not strings and not any of the special
symbols mentioned above will be evaluated when the formatter is
invoked, and spliced into the list. A form can evaluate either to
Expand Down Expand Up @@ -842,7 +834,7 @@ it's first in the sequence"))
(unless remote-match
(error "Formatter uses `file' but process will run on different \
machine from the machine file is available on"))
(setq stdin nil)
(setq stdin nil)
;; If `buffer-file-name' is nil then there is no backing
;; file, so `buffer-modified-p' should be ignored (it always
;; returns non-nil).
Expand Down
1 change: 0 additions & 1 deletion scripts/check-line-length.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ find=(
find .
-name .git -prune -o
-name .log -prune -o
-path ./scripts/pnp-bin.js -prune -o
-path ./test/formatters -prune -o
-name "*.elc" -o
-type f -print
Expand Down
71 changes: 0 additions & 71 deletions scripts/formatters/apheleia-npx

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/pnp-bin.js

This file was deleted.

16 changes: 6 additions & 10 deletions test/formatters/apheleia-ft.el
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ relative to repo root, as returned by git diff --name-only."
((string-match
"^scripts/formatters/\\([^/]+\\)$" changed-file)
(let ((script (match-string 1 changed-file)))
(mapcar #'symbol-name
(map-keys
(map-filter
(lambda (fmt def)
(and (listp def) (member script def)))
apheleia-formatters))))))))
(map-keys
(map-filter
(lambda (fmt def)
(member script def))
apheleia-formatters)))))))

(defun apheleia-ft--get-formatters-for-pull-request ()
"Return list of formatter string names that were touched in this PR.
Expand Down Expand Up @@ -134,10 +133,7 @@ main."
"Print to stdout a comma-delimited list of formatters changed in this PR."
(princ (concat
(string-join
(cl-remove-duplicates
(apheleia-ft--get-formatters-for-pull-request)
:test 'string=)
",")
(apheleia-ft--get-formatters-for-pull-request) ",")
"\n")))

(defun apheleia-ft--read-file (filename)
Expand Down
15 changes: 11 additions & 4 deletions test/formatters/install-common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y ca-certificates curl gnupg lsb-release software-properties-common

mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -

ubuntu_name="$(lsb_release -cs)"
node_repo="$(curl -fsSL https://deb.nodesource.com/setup_current.x | grep NODEREPO= | grep -Eo 'node_[0-9]+\.x' | head -n1)"

tee -a /etc/apt/sources.list.d/nodejs.list >/dev/null <<EOF
deb [arch=amd64] https://deb.nodesource.com/${node_repo} ${ubuntu_name} main
EOF

add-apt-repository -n ppa:longsleep/golang-backports

Expand All @@ -26,6 +30,9 @@ nodejs
sudo
unzip
wget
sudo
unzip
wget
"

Expand Down
17 changes: 8 additions & 9 deletions test/formatters/installers/prettier-ruby.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Need ruby for gem, need gcc and ruby headers for native gem deps
apt-get install -y ruby ruby-dev gcc

# Apparently rubygems does not know how to do dependency resolution.
# So we have to manually install an old version of this dependency to
# avoid the latest version getting installed and then failing to build
# because it does not support ruby 2.7 which is what we have.
gem install rbs -v 3.1.3
# Install the plugin
npm install -g prettier @prettier/plugin-ruby

# Have to install from source because release not tagged yet
# https://github.com/ruby-syntax-tree/syntax_tree-rbs/pull/34
# https://stackoverflow.com/a/11767563
gem install specific_install
gem specific_install -l https://github.com/ruby-syntax-tree/syntax_tree-rbs.git

# These are required dependencies documented at
# https://www.npmjs.com/package/@prettier/plugin-ruby
gem install prettier_print syntax_tree syntax_tree-haml syntax_tree-rbs

# Install the plugin
cd /tmp
npm install --save-dev prettier @prettier/plugin-ruby
3 changes: 1 addition & 2 deletions test/formatters/installers/prettier-svelte.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cd /tmp
npm install --save-dev prettier-plugin-svelte prettier
npm install -g prettier-plugin-svelte prettier

0 comments on commit 9d48c14

Please sign in to comment.