summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoastal <561087+toastal@users.noreply.github.com>2021-08-08 13:09:21 +0000
committerGitHub <noreply@github.com>2021-08-08 22:09:21 +0900
commit775d121d46b2b2cf61997598e4dc664476fd470d (patch)
treed4f7a63dfd500a511e43b8c20402e4d36ef392e4
parenta793db7399e786b8c882b10e6a8540718d5cdbf1 (diff)
downloadale-775d121d46b2b2cf61997598e4dc664476fd470d.zip
`purs-tidy` for PureScript (#3863)
* purs-tidy * update email address for toastal
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/dhall_format.vim2
-rw-r--r--autoload/ale/fixers/dhall_freeze.vim2
-rw-r--r--autoload/ale/fixers/dhall_lint.vim2
-rw-r--r--autoload/ale/fixers/purs_tidy.vim26
-rw-r--r--doc/ale-purescript.txt27
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_purs_tidy_fixer_callback.vader21
10 files changed, 85 insertions, 3 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 7a4d964e..597dfe6c 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -301,6 +301,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['haskell'],
\ 'description': 'Refactor Haskell files with stylish-haskell.',
\ },
+\ 'purs-tidy': {
+\ 'function': 'ale#fixers#purs_tidy#Fix',
+\ 'suggested_filetypes': ['purescript'],
+\ 'description': 'Format PureScript files with purs-tidy.',
+\ },
\ 'purty': {
\ 'function': 'ale#fixers#purty#Fix',
\ 'suggested_filetypes': ['purescript'],
diff --git a/autoload/ale/fixers/dhall_format.vim b/autoload/ale/fixers/dhall_format.vim
index d4021983..0812a186 100644
--- a/autoload/ale/fixers/dhall_format.vim
+++ b/autoload/ale/fixers/dhall_format.vim
@@ -1,4 +1,4 @@
-" Author: toastal <toastal@protonmail.com>
+" Author: toastal <toastal@posteo.net>
" Description: Dhall’s built-in formatter
"
function! ale#fixers#dhall_format#Fix(buffer) abort
diff --git a/autoload/ale/fixers/dhall_freeze.vim b/autoload/ale/fixers/dhall_freeze.vim
index d1447b31..e029a83d 100644
--- a/autoload/ale/fixers/dhall_freeze.vim
+++ b/autoload/ale/fixers/dhall_freeze.vim
@@ -1,4 +1,4 @@
-" Author: toastal <toastal@protonmail.com>
+" Author: toastal <toastal@posteo.net>
" Description: Dhall's package freezing
call ale#Set('dhall_freeze_options', '')
diff --git a/autoload/ale/fixers/dhall_lint.vim b/autoload/ale/fixers/dhall_lint.vim
index 2abbe6f7..18fe9788 100644
--- a/autoload/ale/fixers/dhall_lint.vim
+++ b/autoload/ale/fixers/dhall_lint.vim
@@ -1,4 +1,4 @@
-" Author: toastal <toastal@protonmail.com>
+" Author: toastal <toastal@posteo.net>
" Description: Dhall’s built-in linter/formatter
function! ale#fixers#dhall_lint#Fix(buffer) abort
diff --git a/autoload/ale/fixers/purs_tidy.vim b/autoload/ale/fixers/purs_tidy.vim
new file mode 100644
index 00000000..0183fd73
--- /dev/null
+++ b/autoload/ale/fixers/purs_tidy.vim
@@ -0,0 +1,26 @@
+" Author: toastal <toastal@posteo.net>
+" Description: Integration of purs-tidy with ALE.
+
+call ale#Set('purescript_tidy_executable', 'purs-tidy')
+call ale#Set('purescript_tidy_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('purescript_tidy_options', '')
+
+function! ale#fixers#purs_tidy#GetExecutable(buffer) abort
+ return ale#path#FindExecutable(a:buffer, 'purescript_tidy', [
+ \ 'node_modules/purescript-tidy/bin/index.js',
+ \ 'node_modules/.bin/purs-tidy',
+ \])
+endfunction
+
+function! ale#fixers#purs_tidy#Fix(buffer) abort
+ let l:executable = ale#fixers#purs_tidy#GetExecutable(a:buffer)
+ let l:options = ale#Var(a:buffer, 'purescript_tidy_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . ale#Pad(l:options)
+ \ . ' %s',
+ \ 'read_temporary_file': 0,
+ \}
+endfunction
+
diff --git a/doc/ale-purescript.txt b/doc/ale-purescript.txt
index 454bb7e4..91bef558 100644
--- a/doc/ale-purescript.txt
+++ b/doc/ale-purescript.txt
@@ -30,6 +30,33 @@ g:ale_purescript_ls_config g:ale_purescript_ls_config
\ }
\}
===============================================================================
+purs-tidy *ale-purescript-tidy*
+
+g:ale_purescript_tidy_executable *g:ale_purescript_tidy_executable*
+ *b:ale_purescript_tidy_executable*
+ Type: |String|
+ Default: `'purs-tidy'`
+
+ This variable can be changed to use a different executable for purs-tidy.
+
+g:ale_purescript_tidy_use_global *g:ale_purescript_tidy_use_global*
+ *b:ale_purescript_tidy_use_global*
+ Type: |Number|
+ Default: `get(g:, 'ale_use_global_executables', 0)`
+
+ See |ale-integrations-local-executables|
+
+g:ale_purescript_tidy_options *g:ale_purescript_tidy_options*
+ *b:ale_purescript_tidy_options*
+ Type: String
+ Default: `''`
+
+ This variable can be set to pass in additional option to the 'purs-tidy'
+ executable.
+>
+ let g:ale_purescript_options = '--indent 3'
+<
+===============================================================================
purty *ale-purescript-purty*
g:ale_purescript_purty_executable *g:ale_purescript_purty_executable*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index eaad7411..dcf705ad 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -399,6 +399,7 @@ Notes:
* `puppet-lint`
* PureScript
* `purescript-language-server`
+ * `purs-tidy`
* `purty`
* Python
* `autoflake`!!
diff --git a/doc/ale.txt b/doc/ale.txt
index 2f77e7c1..e871f1ff 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2933,6 +2933,7 @@ documented in additional help files.
puppet-languageserver.................|ale-puppet-languageserver|
purescript..............................|ale-purescript-options|
purescript-language-server............|ale-purescript-language-server|
+ purs-tidy.............................|ale-purescript-tidy|
purty.................................|ale-purescript-purty|
pyrex (cython)..........................|ale-pyrex-options|
cython................................|ale-pyrex-cython|
diff --git a/supported-tools.md b/supported-tools.md
index 5f36287e..f19a57ea 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -408,6 +408,7 @@ formatting.
* [puppet-lint](https://puppet-lint.com)
* PureScript
* [purescript-language-server](https://github.com/nwolverson/purescript-language-server)
+ * [purs-tidy](https://github.com/natefaubion/purescript-tidy)
* [purty](https://gitlab.com/joneshf/purty)
* Python
* [autoflake](https://github.com/myint/autoflake)
diff --git a/test/fixers/test_purs_tidy_fixer_callback.vader b/test/fixers/test_purs_tidy_fixer_callback.vader
new file mode 100644
index 00000000..7debd434
--- /dev/null
+++ b/test/fixers/test_purs_tidy_fixer_callback.vader
@@ -0,0 +1,21 @@
+Before:
+ Save g:ale_purescript_tidy_executable
+ Save g:ale_purescript_tidy_options
+
+ " Use an invalid global executable, so we don’t match it.
+ let g:ale_purescript_tidy_executable = 'odd-purs-tidy'
+ let g:ale_purescript_tidy_options = '--indent 3'
+
+ call ale#assert#SetUpFixerTest('purescript', 'purs-tidy')
+
+After:
+ call ale#assert#TearDownFixerTest()
+
+Execute(The purs-tidy callback should return the correct custom options):
+ AssertFixer
+ \ {
+ \ 'command': ale#Escape('odd-purs-tidy')
+ \ . ' --indent 3'
+ \ . ' %s',
+ \ 'read_temporary_file': 0,
+ \ }