Fix #1610 - Encourage the use of ftplugin files more
This commit is contained in:
parent
db64571b4c
commit
970b62756e
71
README.md
71
README.md
@ -210,24 +210,42 @@ ale-linter-options` for options specified to particular linters.
|
|||||||
### 2.ii Fixing
|
### 2.ii Fixing
|
||||||
|
|
||||||
ALE can fix files with the `ALEFix` command. Functions need to be configured
|
ALE can fix files with the `ALEFix` command. Functions need to be configured
|
||||||
for different filetypes with the `g:ale_fixers` variable. For example, the
|
either in each buffer with a `b:ale_fixers`, or globally with `g:ale_fixers`.
|
||||||
following code can be used to fix JavaScript code with ESLint:
|
|
||||||
|
The recommended way to configure fixers is to define a List in an ftplugin file.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Put this in vimrc or a plugin file of your own.
|
" In ~/.vim/ftplugin/javascript.vim, or somewhere similar.
|
||||||
" After this is configured, :ALEFix will try and fix your JS code with ESLint.
|
|
||||||
|
" Fix files with prettier, and then ESLint.
|
||||||
|
let b:ale_fixers = ['prettier', 'eslint']
|
||||||
|
" Equivalent to the above.
|
||||||
|
let b:ale_fixers = {'javascript': ['prettier', 'eslint']}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also configure your fixers from vimrc using `g:ale_fixers`, before
|
||||||
|
or after ALE has been loaded.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" In ~/.vim/vimrc, or somewhere similar.
|
||||||
let g:ale_fixers = {
|
let g:ale_fixers = {
|
||||||
\ 'javascript': ['eslint'],
|
\ 'javascript': ['eslint'],
|
||||||
\}
|
\}
|
||||||
|
```
|
||||||
|
|
||||||
" Set this setting in vimrc if you want to fix files automatically on save.
|
If you want to automatically fix files when you save them, you need to turn
|
||||||
" This is off by default.
|
a setting on in vimrc.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" Set this variable to 1 to fix files when you save them.
|
||||||
let g:ale_fix_on_save = 1
|
let g:ale_fix_on_save = 1
|
||||||
```
|
```
|
||||||
|
|
||||||
The `:ALEFixSuggest` command will suggest some supported tools for fixing code,
|
The `:ALEFixSuggest` command will suggest some supported tools for fixing code.
|
||||||
but fixers can be also implemented with functions, including lambda functions
|
Both `g:ale_fixers` and `b:ale_fixers` can also accept functions, including
|
||||||
too. See `:help ale-fix` for detailed information.
|
lambda functions, as fixers, for fixing files with custom tools.
|
||||||
|
|
||||||
|
See `:help ale-fix` for complete information on how to fix files with ALE.
|
||||||
|
|
||||||
<a name="usage-completion"></a>
|
<a name="usage-completion"></a>
|
||||||
|
|
||||||
@ -385,12 +403,28 @@ on Freenode. Web chat is available [here](https://webchat.freenode.net/?channels
|
|||||||
|
|
||||||
### 5.i. How do I disable particular linters?
|
### 5.i. How do I disable particular linters?
|
||||||
|
|
||||||
By default, all available tools for all supported languages will be run.
|
By default, all available tools for all supported languages will be run. If you
|
||||||
If you want to only select a subset of the tools, simply create a
|
want to only select a subset of the tools, you can define `b:ale_linters` for a
|
||||||
`g:ale_linters` dictionary in your vimrc file mapping filetypes
|
single buffer, or `g:ale_linters` globally.
|
||||||
to lists of linters to run.
|
|
||||||
|
The recommended way to configure linters is to define a List in an ftplugin
|
||||||
|
file.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
|
" In ~/.vim/ftplugin/javascript.vim, or somewhere similar.
|
||||||
|
|
||||||
|
" Enable ESLint only for JavaScript.
|
||||||
|
let b:ale_linters = ['eslint']
|
||||||
|
|
||||||
|
" Equivalent to the above.
|
||||||
|
let b:ale_linters = {'javascript': ['eslint']}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also declare which linters you want to run in your vimrc file, before or
|
||||||
|
after ALE has been loaded.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" In ~/.vim/vimrc, or somewhere similar.
|
||||||
let g:ale_linters = {
|
let g:ale_linters = {
|
||||||
\ 'javascript': ['eslint'],
|
\ 'javascript': ['eslint'],
|
||||||
\}
|
\}
|
||||||
@ -650,9 +684,18 @@ augroup END
|
|||||||
```
|
```
|
||||||
|
|
||||||
Supposing the filetype has been set correctly, you can set the following
|
Supposing the filetype has been set correctly, you can set the following
|
||||||
options in your vimrc file:
|
options in a jsx.vim ftplugin file.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
|
" In ~/.vim/ftplugin/jsx.vim, or somewhere similar.
|
||||||
|
let b:ale_linters = ['stylelint', 'eslint']
|
||||||
|
let b:ale_linter_aliases = ['css']
|
||||||
|
```
|
||||||
|
|
||||||
|
Or if you want, you can configure the linters from your vimrc file.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" In ~/.vim/vimrc, or somewhere similar.
|
||||||
let g:ale_linters = {'jsx': ['stylelint', 'eslint']}
|
let g:ale_linters = {'jsx': ['stylelint', 'eslint']}
|
||||||
let g:ale_linter_aliases = {'jsx': 'css'}
|
let g:ale_linter_aliases = {'jsx': 'css'}
|
||||||
```
|
```
|
||||||
|
@ -475,6 +475,12 @@ the buffer-local options can be used with external plugins for reading Vim
|
|||||||
project configuration files. Buffer-local settings can also be used in
|
project configuration files. Buffer-local settings can also be used in
|
||||||
ftplugin files for different filetypes.
|
ftplugin files for different filetypes.
|
||||||
|
|
||||||
|
ALE offers several options for controlling which linters are run.
|
||||||
|
|
||||||
|
* Selecting linters to run. - |g:ale_linters|
|
||||||
|
* Aliasing filetypes for linters - |g:ale_linter_aliases|
|
||||||
|
* Only running linters you asked for. - |g:ale_linters_explicit|
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
4. Fixing Problems *ale-fix*
|
4. Fixing Problems *ale-fix*
|
||||||
|
Loading…
Reference in New Issue
Block a user