cljstyle
can be integrated into a number of different tools.
If you use zsh
as your shell, you can add completion for cljstyle
by
placing the completion file somewhere on your
$fpath
and naming it _cljstyle
. This will complete the commands and tool
options.
cljstyle
is supported by vim-codefmt.
Once you have vim-codefmt installed, you can set it to use cljstyle
for Clojure
code like this:
autocmd FileType clojure AutoFormatBuffer cljstyle
For a simple vim integration you can use the following function to reformat the current buffer:
" Add to file for vim or neovim:
" ~/.vim/after/ftplugin/clojure.vim
" ~/.config/nvim/after/ftplugin/clojure.vim
" NOTE: typically you'd set these to use a formatter, but in this case it fails
" since cljstyle usually can't run on partial forms.
"setlocal equalprg=cljstyle\ pipe
"setlocal formatprg=cljstyle\ pipe
function CljstyleFix()
let cwd = getcwd()
let winsave = winsaveview()
execute "cd" . expand('%:p:h')
:%!cljstyle pipe
execute "cd" . cwd
call winrestview(winsave)
endfunction
" Example shortcut to fix the current file
nnoremap <leader>cs :call CljstyleFix()<cr>
You can also put the function in autoload/cljstyle.vim
and name it
cljstyle#fix()
if you prefer lazy-loading behavior.
The cljstyle-mode project offers a
cljstyle
integration for Emacs users.
cljstyle pipe
can be used with Doom's
editor/format
module. Add the following to your Doom config.el
to replace Doom's default
Clojure formatter with cljstyle
:
(set-formatter! 'cljstyle "cljstyle pipe" :modes '(clojure-mode))
Cljstyle may be used from Leiningen by adding cljstyle
as a dependency and
running the main namespace:
:aliases
{"cljstyle" ["with-profile" "+cljstyle" "run" "-m" "cljstyle.main"]}
:profiles
{:cljstyle
{:dependencies
[[mvxcvi/cljstyle "0.16.626" :exclusions [org.clojure/clojure]]]}}
Alternately, you can run it directly from the command line:
lein update-in :dependencies \
conj '[mvxcvi/cljstyle "0.16.626" :exclusions [org.clojure/clojure]]' \
-- run -m cljstyle.main \
check
If you would like to use cljstyle
without installing the binary, you can run
it directly with clj
:
clj -Sdeps '{:deps {mvxcvi/cljstyle {:mvn/version "0.16.626"}}}' \
-M -m cljstyle.main \
check
To keep your code well styled, you can run cljstyle
as part of a CircleCI
workflow. The following job snippet will fetch the tool and check your sources:
style:
executor: clojure
steps:
- checkout
- run:
name: Install cljstyle
environment:
CLJSTYLE_VERSION: 0.16.626
CLJSTYLE_PLATFORM: linux_amd64
command: |
wget https://github.com/greglook/cljstyle/releases/download/${CLJSTYLE_VERSION}/cljstyle_${CLJSTYLE_VERSION}_${CLJSTYLE_PLATFORM}.zip
unzip cljstyle_${CLJSTYLE_VERSION}_${CLJSTYLE_PLATFORM}.zip
- run:
name: Check style
command: "./cljstyle check --report"
This assumes you have defined a common executor configuration named clojure
.
An example action is available at 0918nobita/setup-cljstyle
for using cljstyle
in a GitHub workflow.
Can you improve this documentation? These fine people already did:
Greg Look, Rai & Rob HanlonEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close