How to make ESLint and fixers blazingly fast in Neovim
ALE is a solid lint engine for Neovim, but plain eslint is slow because every run pays Node's startup and module-loading cost. I point ALE at eslint_d instead, which keeps a background server per working directory and uses the project's local eslint version. Two lines of config and linting is fast.
How to make ESLint and fixers blazingly fast in Neovim
Recently I switched to Neovim from WebStorm. It wasn’t a smooth transition, but it was enjoyable. Vim is always fun to work with. Basically, you can build your own IDE or working environment. The only thing bugging me during the switch was linting and fixers. I tried a few plugins, including null-ls (now none-ls), which didn’t work as expected in my case. Then I found ALE.
ALE
ALE (Asynchronous Lint Engine) is a stable and powerful linting plugin. Installation is pretty straightforward. You can use whatever package manager you already use. In my case, I used packer:
return require('packer').startup(function(use)
use 'dense-analysis/ale'
end)
By default, ALE is not fast at linting and fixing.
How to make ALE faster
ALE is slow because it has to search for the executable to run. The fix is to set that executable in your Vim config:
let g:ale_javascript_eslint_executable = 'path/to/eslint'
let g:ale_javascript_eslint_use_global = 1
There are two issues with this approach. Hardcoding the eslint path does not always work, because different projects use different versions of eslint. The second is that eslint runs each file separately, so Node.js startup and module loading make it slow. eslint_d fixes both.
eslint_d
eslint_d starts a server in the background and keeps a separate instance for each working directory. It uses the project’s eslint from node_modules. If that is not found, it falls back to the bundled version it ships with.
How to configure ALE with eslint_d
First, install eslint_d:
npm install -g eslint_d
Then set ale_javascript_eslint_executable for ALE:
let g:ale_javascript_eslint_executable = 'eslint_d'
let g:ale_javascript_eslint_use_global = 1
That’s all. Happy coding.