dense-analysis / dense-analysis/ale

Elixir mix_format fixer run directory

Open
#2,138 7 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
Vim Script
Stars
14k
Forks
1.5k
Avg merge
17h 49m
Merged PRs (30d)
1

Description

When I try to use mix_format fixer I can see that formatter dependencies are not used to properly format the file.

Basically it is the same issue I have experienced with [vim-mix-format](https://github.com/mhinz/vim-mix-format/issues/19) before found out ALE can also do mix format.

It looks like the problem is that mix format should be run from the directory where `.formatter.exs` file is located (project root).

I can also see there are issues (https://github.com/w0rp/ale/issues/286 , https://github.com/w0rp/ale/issues/384) that suggests to use `ale#util#BufferCdString(a:buffer) . l:rest_of_command`.

Could you suggest me how this could be implemented with the existing mix_format fixer?

For now I do the following which, while works, I am not sure if there is no better way:
```

" ALE configuration {{{1

" You have to use formatter from the root of the elixir project
" or to be precise from the folder where .formatter.exs file exist.
" Otherwise, formatter dependencies will not be used.

" Change working directory to directory where .formatter.exs exists, upwards.
fun! ALE_BEFORE_mix_format(bufnr)
" find path of the .formatter.exs upwards from the current file
let path = fnamemodify(findfile(".formatter.exs", expand("%:p:h").";"), ":p:h")
exe 'lcd '. path
endfu

" Change working directory to directory of the current file
fun! ALE_AFTER_mix_format(bufnr)
lcd %:p:h
endfu

let g:ale_fixers = {}
let g:ale_fixers.elixir = ['ALE_BEFORE_mix_format', 'mix_format', 'ALE_AFTER_mix_format']
let g:ale_fixers['*'] = ['remove_trailing_lines', 'trim_whitespace']

nmap tf (ale_fix)

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.