Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
Go to file
Johannes Wienke 79aaec5a99 Missing warning level 'suggestion' for vale
Vale can also, optionally, raise suggestions. These weren't covered yet.
2017-12-18 17:10:57 +01:00
after/plugin
ale_linters Make alex a file linter 2017-12-18 15:26:52 +01:00
autoload Missing warning level 'suggestion' for vale 2017-12-18 17:10:57 +01:00
doc Make alex a file linter 2017-12-18 15:26:52 +01:00
ftplugin Fix #757 - Show :ALEDetail messages in a window 2017-11-14 23:25:01 +00:00
img Update the example GIF so it looks a bit nicer 2017-05-07 15:17:30 +01:00
plugin Fix #1176 - Add an option for caching failing executable checks 2017-11-30 10:34:51 +00:00
syntax Support fixer aliases, and make prettier-eslint and prettier-standard just work 2017-11-22 15:31:39 +00:00
test Missing warning level 'suggestion' for vale 2017-12-18 17:10:57 +01:00
.appveyor.yml Get all tests to pass on Windows 2017-10-23 23:09:40 +01:00
.editorconfig Add editorconfig (#997) 2017-10-14 15:55:33 +01:00
.gitattributes Move scripts for tests into the test directory, and do not export the Batch script for running tests 2017-09-10 13:19:08 +01:00
.gitignore Add editorconfig (#997) 2017-10-14 15:55:33 +01:00
.travis.yml Drop "only master branch" travis restriction 2017-07-03 10:54:47 -05:00
CODE_OF_CONDUCT.md Add a non Code of Conduct 2017-06-18 18:24:44 +01:00
CONTRIBUTING.md Fix typo 2017-10-21 08:16:59 -04:00
Dockerfile Update the Dockerfile for experimenting with NeoVim testing 2017-05-11 08:32:45 +01:00
ISSUE_TEMPLATE.md Ask for the first two lines for :version in the issue template 2017-12-08 13:07:32 +00:00
LICENSE Update the license year 2017-07-08 13:50:10 +01:00
PULL_REQUEST_TEMPLATE.md Stress the need for tests even further 2017-08-19 13:14:53 +01:00
README.md Make alex a file linter 2017-12-18 15:26:52 +01:00
run-tests Run tests in parallel 2017-12-07 20:07:45 +00:00
run-tests.bat Add a Batch script for running tests on Windows 2017-09-08 22:15:39 +01:00

Asynchronous Lint Engine Travis CI Build Status AppVeyor Build Status

ALE Logo by Mark Grealish - https://www.bhalash.com/

ALE (Asynchronous Lint Engine) is a plugin for providing linting in NeoVim and Vim 8 while you edit your text files.

linting example

ALE makes use of NeoVim and Vim 8 job control functions and timers to run linters on the contents of text buffers and return errors as text is changed in Vim. This allows for displaying warnings and errors in files being edited in Vim before files have been saved back to a filesystem.

In other words, this plugin allows you to lint while you type.

In addition to linting support, ALE offers some support for fixing code with formatting tools, and some Language Server Protocol and tsserver features.

Table of Contents

  1. Supported Languages and Tools
  2. Usage
    1. Linting
    2. Fixing
    3. Completion
    4. Go To Definition
  3. Installation
    1. Installation with Vim package management
    2. Installation with Pathogen
    3. Installation with Vundle
  4. Contributing
  5. FAQ
    1. How do I disable particular linters?
    2. How can I keep the sign gutter open?
    3. How can I change the signs ALE uses?
    4. How can I change or disable the highlights ALE uses?
    5. How can I show errors or warnings in my statusline?
    6. How can I show errors or warnings in my lightline?
    7. How can I change the format for echo messages?
    8. How can I execute some code when ALE starts or stops linting?
    9. How can I navigate between errors quickly?
    10. How can I run linters only when I save files?
    11. How can I use the quickfix list instead of the loclist?
    12. How can I check JSX files with both stylelint and eslint?
    13. Will this plugin eat all of my laptop battery power?
    14. How can I configure my C or C++ project?
    15. How can I configure ALE differently for different buffers?

1. Supported Languages and Tools

This plugin supports the following languages and tools. All available tools will be run in combination, so they can be complementary.

Notes:

  • ^ No linters for text or Vim help filetypes are enabled by default.
  • !! These linters check only files on disk. See :help ale-lint-file-linters
Language Tools
ASM gcc
Ansible ansible-lint
API Blueprint drafter
AsciiDoc alex !!, proselint, redpen, write-good
Awk gawk
Bash shell -n flag, shellcheck, shfmt
Bourne Shell shell -n flag, shellcheck, shfmt
C cppcheck, cpplint, gcc, clang, clangtidy !!, clang-format
C++ (filetype cpp) clang, clangcheck !!, clangtidy !!, clang-format, cppcheck, cpplint !!, gcc
CUDA nvcc
C# mcs see:help ale-cs-mcs for details, mcsc !! see:help ale-cs-mcsc for details and configuration
Chef foodcritic
Clojure joker
CMake cmakelint
CoffeeScript coffee, coffeelint
Crystal crystal !!
CSS csslint, prettier, stylelint
Cython (pyrex filetype) cython
D dmd
Dafny dafny !!
Dart dartanalyzer !!, language_server
Dockerfile hadolint
Elixir credo, dogma !!
Elm elm-format, elm-make
Erb erb, erubis
Erlang erlc, SyntaxErl
Fortran gcc
FusionScript fusion-lint
GLSL glslang, glslls
Go gofmt, goimports, go vet, golint, gometalinter !!, go build !!, gosimple !!, staticcheck !!
GraphQL eslint, gqlint
Haml haml-lint
Handlebars ember-template-lint
Haskell brittany, ghc, stack-ghc, stack-build !!, ghc-mod, stack-ghc-mod, hlint, hdevtools, hfmt
HTML alex !!, HTMLHint, proselint, tidy, write-good
Idris idris
Java checkstyle, javac, google-java-format
JavaScript eslint, flow, jscs, jshint, prettier, prettier-eslint, prettier-standard, standard, xo
JSON jsonlint, prettier
Kotlin kotlinc !!, ktlint !! see :help ale-integration-kotlin for configuration instructions
LaTeX alex !!, chktex, lacheck, proselint, redpen, vale, write-good
Less lessc, prettier, stylelint
LLVM llc
Lua luacheck
Mail alex !!, proselint, vale
Make checkmake
Markdown alex !!, mdl, proselint, redpen, remark-lint !!, vale, write-good
MATLAB mlint
Nim nim check !!
nix nix-instantiate
nroff alex !!, proselint, write-good
Objective-C clang
Objective-C++ clang
OCaml merlin see :help ale-ocaml-merlin for configuration instructions, ols
Perl perl -c, perl-critic
PHP hack, hackfmt, langserver, phan see :help ale-php-phan to instructions, php -l, phpcs, phpmd, phpstan, phpcbf
Pod alex !!, proselint, write-good
proto protoc-gen-lint
Pug pug-lint
Puppet puppet, puppet-lint
Python autopep8, flake8, isort, mypy, prospector, pycodestyle, pyls, pylint !!, yapf
R lintr
ReasonML merlin see :help ale-integration-reason-merlin for configuration instructions, ols, refmt
reStructuredText alex !!, proselint, redpen, rstcheck, vale, write-good
Re:VIEW redpen
RPM spec rpmlint (disabled by default; see :help ale-integration-spec)
Ruby brakeman !!, rails_best_practices !!, reek, rubocop, ruby
Rust cargo !! (see :help ale-integration-rust for configuration instructions), rls, rustc, rustfmt
SASS sass-lint, stylelint
SCSS prettier, sass-lint, scss-lint, stylelint
Scala scalac, scalastyle
Slim slim-lint
SML smlnj
Solidity solhint, solium
Stylus stylelint
SQL sqlint
Swift swiftlint, swiftformat
Tcl nagelfar !!
Terraform tflint
Texinfo alex !!, proselint, write-good
Text^ alex !!, proselint, vale, write-good, redpen
Thrift thrift
TypeScript eslint, prettier, tslint, tsserver, typecheck
Verilog iverilog, verilator
Vim vint
Vim help^ alex !!, proselint, write-good
XHTML alex !!, proselint, write-good
XML xmllint
YAML swaglint, yamllint

2. Usage

2.i Linting

Once this plugin is installed, while editing your files in supported languages and tools which have been correctly installed, this plugin will send the contents of your text buffers to a variety of programs for checking the syntax and semantics of your programs. By default, linters will be re-run in the background to check your syntax when you open new buffers or as you make edits to your files.

The behaviour of linting can be configured with a variety of options, documented in the Vim help file. For more information on the options ALE offers, consult :help ale-options for global options and :help ale-linter-options for options specified to particular linters.

2.ii Fixing

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 following code can be used to fix JavaScript code with ESLint:

" Put this in vimrc or a plugin file of your own.
" After this is configured, :ALEFix will try and fix your JS code with ESLint.
let g:ale_fixers = {
\   'javascript': ['eslint'],
\}

" Set this setting in vimrc if you want to fix files automatically on save.
" This is off by default.
let g:ale_fix_on_save = 1

The :ALEFixSuggest command will suggest some supported tools for fixing code, but fixers can be also implemented with functions, including lambda functions too. See :help ale-fix for detailed information.

2.iii Completion

ALE offers some support for completion via hijacking of omnicompletion while you type. All of ALE's completion information must come from Language Server Protocol linters, or similar protocols. At the moment, completion is only supported for TypeScript code with tsserver, when tsserver is enabled. You can enable completion like so:

" Enable completion where available.
let g:ale_completion_enabled = 1

See :help ale-completion for more information.

2.iv Go To Definition

ALE supports jumping to the definition of words under your cursor with the :ALEGoToDefinition command using any enabled LSP linters and tsserver.

See :help ale-go-to-definition for more information.

3. Installation

To install this plugin, you should use one of the following methods. For Windows users, replace usage of the Unix ~/.vim directory with %USERPROFILE%\vimfiles, or another directory if you have configured Vim differently. On Windows, your ~/.vimrc file will be similarly stored in %USERPROFILE%\_vimrc.

3.i. Installation with Vim package management

In Vim 8 and NeoVim, you can install plugins easily without needing to use any other tools. Simply clone the plugin into your pack directory.

Vim 8 on Unix

mkdir -p ~/.vim/pack/git-plugins/start
git clone https://github.com/w0rp/ale.git ~/.vim/pack/git-plugins/start/ale

NeoVim on Unix

mkdir -p ~/.local/share/nvim/site/pack/git-plugins/start
git clone https://github.com/w0rp/ale.git ~/.local/share/nvim/site/pack/git-plugins/start/ale

Vim 8 on Windows

# Run these commands in the "Git for Windows" Bash terminal
mkdir -p ~/vimfiles/pack/git-plugins/start
git clone https://github.com/w0rp/ale.git ~/vimfiles/pack/git-plugins/start/ale

Generating Vim help files

You can add the following line to your vimrc files to generate documentation tags automatically, if you don't have something similar already, so you can use the :help command to consult ALE's online documentation:

" Put these lines at the very end of your vimrc file.

" Load all plugins now.
" Plugins need to be added to runtimepath before helptags can be generated.
packloadall
" Load all of the helptags now, after plugins have been loaded.
" All messages and errors will be ignored.
silent! helptags ALL

3.ii. Installation with Pathogen

To install this module with Pathogen, you should clone this repository to your bundle directory, and ensure you have the line execute pathogen#infect() in your ~/.vimrc file. You can run the following commands in your terminal to do so:

cd ~/.vim/bundle
git clone https://github.com/w0rp/ale.git

3.iii. Installation with Vundle

You can install this plugin using Vundle by using the path on GitHub for this repository.

Plugin 'w0rp/ale'

See the Vundle documentation for more information.

4. Contributing

If you would like to see support for more languages and tools, please create an issue or create a pull request. If your tool can read from stdin or you have code to suggest which is good, support can be happily added for it.

If you are interested in the general direction of the project, check out the wiki home page. The wiki includes a Roadmap for the future, and more.

If you'd liked to discuss the project more directly, check out the #vim-ale channel on Freenode. Web chat is available here.

5. FAQ

5.i. How do I disable particular linters?

By default, all available tools for all supported languages will be run. If you want to only select a subset of the tools, simply create a g:ale_linters dictionary in your vimrc file mapping filetypes to lists of linters to run.

let g:ale_linters = {
\   'javascript': ['eslint'],
\}

For all languages unspecified in the dictionary, all possible linters will be run for those languages, just as when the dictionary is not defined. Running many linters should not typically obstruct editing in Vim, as they will all be executed in separate processes simultaneously.

This plugin will look for linters in the ale_linters directory. Each directory within corresponds to a particular filetype in Vim, and each file in each directory corresponds to the name of a particular linter.

5.ii. How can I keep the sign gutter open?

You can keep the sign gutter open at all times by setting the g:ale_sign_column_always to 1

let g:ale_sign_column_always = 1

5.iii. How can I change the signs ALE uses?

Use these options to specify what text should be used for signs:

let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'

ALE sets some background colors automatically for warnings and errors in the sign gutter, with the names ALEErrorSign and ALEWarningSign. These colors can be customised, or even removed completely:

highlight clear ALEErrorSign
highlight clear ALEWarningSign

5.iv. How can I change or disable the highlights ALE uses?

ALE's highlights problems with highlight groups which link to SpellBad, SpellCap, error, and todo groups by default. The characters that are highlighted depend on the linters being used, and the information provided to ALE.

Highlighting can be disabled completely by setting g:ale_set_highlights to 0.

" Set this in your vimrc file to disabling highlighting
let g:ale_set_highlights = 0

You can control all of the highlights ALE uses, say if you are using a different color scheme which produces ugly highlights. For example:

highlight ALEWarning ctermbg=DarkMagenta

See :help ale-highlights for more information.

5.v. How can I show errors or warnings in my statusline?

vim-airline integrates with ALE for displaying error information in the status bar. If you want to see the status for ALE in a nice format, it is recommended to use vim-airline with ALE. The airline extension can be enabled by adding the following to your vimrc:

" Set this. Airline will handle the rest.
let g:airline#extensions#ale#enabled = 1

If you don't want to use vim-airline, you can implement your own statusline function without adding any other plugins. ALE provides a function for counting the number of problems for this purpose, named ale#statusline#Count.

Say you want to display all errors as one figure, and all non-errors as another figure. You can do the following:

function! LinterStatus() abort
    let l:counts = ale#statusline#Count(bufnr(''))

    let l:all_errors = l:counts.error + l:counts.style_error
    let l:all_non_errors = l:counts.total - l:all_errors

    return l:counts.total == 0 ? 'OK' : printf(
    \   '%dW %dE',
    \   all_non_errors,
    \   all_errors
    \)
endfunction

set statusline=%{LinterStatus()}

See :help ale#statusline#Count() for more information.

5.vi. How can I show errors or warnings in my lightline?

lightline does not have built-in support for ALE, nevertheless there is a plugin that adds this functionality: maximbaz/lightline-ale.

For more information, check out the sources of that plugin, :help ale#statusline#Count() and lightline documentation.

5.vii. How can I change the format for echo messages?

There are 3 global options that allow customizing the echoed message.

  • g:ale_echo_msg_format where:
    • %s is the error message itself
    • %linter% is the linter name
    • %severity is the severity type
  • g:ale_echo_msg_error_str is the string used for error severity.
  • g:ale_echo_msg_warning_str is the string used for warning severity.

So for example this:

let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'

Will give you:

Echoed message

5.viii. How can I execute some code when ALE starts or stops linting?

ALE runs its own autocmd events whenever has a linter is started and has been successfully executed and processed. These events can be used to call arbitrary functions before and after ALE stops linting.

augroup YourGroup
    autocmd!
    autocmd User ALELintPre  call YourFunction()
    autocmd User ALELintPost call YourFunction()
augroup END

5.ix. How can I navigate between errors quickly?

ALE offers some commands with <Plug> keybinds for moving between warnings and errors quickly. You can map the keys Ctrl+j and Ctrl+k to moving between errors for example:

nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)

For more information, consult the online documentation with :help ale-navigation-commands.

5.x. How can I run linters only when I save files?

ALE offers an option g:ale_lint_on_save for enabling running the linters when files are saved. This option is enabled by default. If you only wish to run linters when files are saved, you can turn the other options off.

" Write this in your vimrc file
let g:ale_lint_on_text_changed = 'never'
" You can disable this option too
" if you don't want linters to run on opening a file
let g:ale_lint_on_enter = 0

If for whatever reason you don't wish to run linters again when you save files, you can set g:ale_lint_on_save to 0.

5.xi. How can I use the quickfix list instead of the loclist?

The quickfix list can be enabled by turning the g:ale_set_quickfix option on. If you wish to also disable the loclist, you can disable the g:ale_set_loclist option.

" Write this in your vimrc file
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1

If you wish to show Vim windows for the loclist or quickfix items when a file contains warnings or errors, g:ale_open_list can be set to 1. g:ale_keep_list_window_open can be set to 1 if you wish to keep the window open even after errors disappear.

let g:ale_open_list = 1
" Set this if you want to.
" This can be useful if you are combining ALE with
" some other plugin which sets quickfix errors, etc.
let g:ale_keep_list_window_open = 1

5.xii. How can I check JSX files with both stylelint and eslint?

If you configure ALE options correctly in your vimrc file, and install the right tools, you can check JSX files with stylelint and eslint.

First, install eslint and install stylelint with stylelint-processor-styled-components.

Supposing you have installed both tools correctly, configure your .jsx files so jsx is included in the filetype. You can use an autocmd for this.

augroup FiletypeGroup
    autocmd!
    au BufNewFile,BufRead *.jsx set filetype=javascript.jsx
augroup END

Supposing the filetype has been set correctly, you can set the following options in your vimrc file:

let g:ale_linters = {'jsx': ['stylelint', 'eslint']}
let g:ale_linter_aliases = {'jsx': 'css'}

ALE will alias the jsx filetype so it uses the css filetype linters, and use the original Array of selected linters for jsx from the g:ale_linters object. All available linters will be used for the filetype javascript, and no linter will be run twice for the same file.

5.xiii. Will this plugin eat all of my laptop battery power?

ALE takes advantage of the power of various tools to check your code. This of course means that CPU time will be used to continuously check your code. If you are concerned about the CPU time ALE will spend, which will of course imply some cost to battery life, you can adjust your settings to make your CPU do less work.

First, consider increasing the delay before which ALE will run any linters while you type. ALE uses a timeout which is cancelled and reset every time you type, and this delay can be increased so linters are run less often. See :help g:ale_lint_delay for more information.

If you don't wish to run linters while you type, you can disable that behaviour. Set g:ale_lint_on_text_changed to never or normal. You won't get as frequent error checking, but ALE shouldn't block your ability to edit a document after you save a file, so the asynchronous nature of the plugin will still be an advantage.

If you are still concerned, you can turn the automatic linting off altogether, including the option g:ale_lint_on_enter, and you can run ALE manually with :ALELint.

5.xiv. How can I configure my C or C++ project?

The structure of C and C++ projects varies wildly from project to project, with many different build tools being used for building them, and many different formats for project configuration files. ALE can run compilers easily, but ALE cannot easily detect which compiler flags to use.

Some tools and build configurations can generate compile_commands.json files. The cppcheck, clangcheck and clangtidy linters can read these files for automatically determining the appropriate compiler flags to use.

For linting with compilers like gcc and clang, and with other tools, you will need to tell ALE which compiler flags to use yourself. You can use different options for different projects with the g:ale_pattern_options setting. Consult the documentation for that setting for more information. b:ale_linters can be used to select which tools you want to run, say if you want to use only gcc for one project, and only clang for another.

You may also configure buffer-local settings for linters with project-specific vimrc files. local_vimrc can be used for executing local vimrc files which can be shared in your project.

5.xv. How can I configure ALE differently for different buffers?

ALE offers various ways to configure which linters or fixers are run, and other settings. For the majority of ALE's settings, they can either be configured globally with a g: variable prefix, or for a specific buffer with a b: variable prefix. For example, you can configure a Python ftplugin file like so.

" In ~/.vim/ftplugin/python.vim

" Check Python files with flake8 and pylint.
let b:ale_linters = ['flake8', 'pylint']
" Fix Python files with autopep8 and yapf.
let b:ale_fixers = ['autopep8', 'yapf']
" Disable warnings about trailing whitespace for Python files.
let b:ale_warn_about_trailing_whitespace = 0

For configuring files based on regular expression patterns matched against the absolute path to a file, you can use g:ale_pattern_options.

" Do not lint or fix minified files.
let g:ale_pattern_options = {
\ '\.min\.js$': {'ale_linters': [], 'ale_fixers': []},
\ '\.min\.css$': {'ale_linters': [], 'ale_fixers': []},
\}
" If you configure g:ale_pattern_options outside of vimrc, you need this.
let g:ale_pattern_options_enabled = 1

Buffer-local variables for settings always override the global settings.