Skip to content

Commit

Permalink
Add cljfmt fixer for clojure files (#4860)
Browse files Browse the repository at this point in the history
  • Loading branch information
casens5 authored Nov 17, 2024
1 parent 5cc6b93 commit defb0ea
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ruby'],
\ 'description': 'A formatter for Ruby source code',
\ },
\ 'cljfmt': {
\ 'function': 'ale#fixers#cljfmt#Fix',
\ 'suggested_filetypes': ['clojure'],
\ 'description': 'formatter and linter for clojure files',
\ },
\}

" Reset the function registry to the default entries.
Expand Down
14 changes: 14 additions & 0 deletions autoload/ale/fixers/cljfmt.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
" Author: rudolf ordoyne <[email protected]>
" Description: Support for cljfmt https://github.com/weavejester/cljfmt

call ale#Set('clojure_cljfmt_executable', 'cljfmt')

function! ale#fixers#cljfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'clojure_cljfmt_executable')

return {
\ 'command': ale#Escape(l:executable) . ' fix %t',
\ 'read_temporary_file': 1,
\}
endfunction

12 changes: 12 additions & 0 deletions doc/ale-clojure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ g:ale_clojure_clj_kondo_options *g:ale_clojure_clj_kondo_options*

This variable can be changed to modify options passed to clj-kondo.

===============================================================================
cljfmt *ale-clojure-cljfmt*

cljfmt is a linter and fixer for Clojure code, with defaults adhering to the
Clojure Style Guide (see https://guide.clojure.style/ )

https://github.com/weavejester/cljfmt

Linting options are not configurable by ale, but instead are controlled by
Leiningen, or a cljfmt file in the current or parent directories.

see https://github.com/weavejester/cljfmt#Configuration for more information.

===============================================================================
joker *ale-clojure-joker*
Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Notes:
* `foodcritic`!!
* Clojure
* `clj-kondo`
* `cljfmt`
* `joker`
* CloudFormation
* `cfn-python-lint`
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2946,6 +2946,7 @@ documented in additional help files.
foodcritic............................|ale-chef-foodcritic|
clojure.................................|ale-clojure-options|
clj-kondo.............................|ale-clojure-clj-kondo|
cljfmt................................|ale-clojure-cljfmt|
joker.................................|ale-clojure-joker|
cloudformation..........................|ale-cloudformation-options|
cfn-python-lint.......................|ale-cloudformation-cfn-python-lint|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ formatting.
* [foodcritic](http://www.foodcritic.io/) :floppy_disk:
* Clojure
* [clj-kondo](https://github.com/borkdude/clj-kondo)
* [cljfmt](https://github.com/weavejester/cljfmt)
* [joker](https://github.com/candid82/joker)
* CloudFormation
* [cfn-python-lint](https://github.com/awslabs/cfn-python-lint)
Expand Down
12 changes: 12 additions & 0 deletions test/fixers/test_cljfmt_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Before:
call ale#assert#SetUpFixerTest('clojure', 'cljfmt')

After:
call ale#assert#TearDownFixerTest()

Execute(The cljfmt callback should return the correct default values):
AssertFixer {
\ 'command': ale#Escape('cljfmt') . ' fix %t',
\ 'read_temporary_file': 1,
\}

0 comments on commit defb0ea

Please sign in to comment.