Giter VIP home page Giter VIP logo

ale's Introduction

Asynchronous Lint Engine 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.

Table of Contents

  1. Supported Languages and Tools
  2. Usage
  3. Installation
  4. Installation with Pathogen
  5. Installation with Vundle
  6. Manual Installation
  7. Contributing
  8. FAQ
  9. How do I disable particular linters?
  10. How can I keep the sign gutter open?
  11. How can I change the signs ALE uses?
  12. How can I show errors or warnings in my statusline?
  13. How can I change the format for echo messages?
  14. How can I execute some code when ALE stops linting?
  15. How can I navigate between errors quickly?
  16. How can I run linters only when I save files?
  17. How can I use the quickfix list instead of the loclist?
  18. How can I check JSX files with both stylelint and eslint?
  19. Will this plugin eat all of my laptop battery power?

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.

Language Tools
Ansible ansible-lint
AsciiDoc proselint
Bash -n flag, shellcheck
Bourne Shell -n flag, shellcheck
C cppcheck, gcc, clang
C++ (filetype cpp) clang, clangtidy, [cppcheck] (http://cppcheck.sourceforge.net), gcc
C# mcs
Chef foodcritic
CMake cmakelint
CoffeeScript coffee, coffeelint
CSS csslint, stylelint
Cython (pyrex filetype) cython
D dmd
Dockerfile hadolint
Elixir credo
Elm elm-make
Erlang erlc
Fortran gcc
Go gofmt -e, go vet, golint, go build
Haml haml-lint
Haskell ghc, hlint
HTML HTMLHint, proselint, tidy
Java javac
JavaScript eslint, jscs, jshint, flow, standard
JSON jsonlint
LaTeX chktex, lacheck
Lua luacheck
Markdown mdl, proselint
MATLAB mlint
Nim nim
nix nix-instantiate
nroff proselint
OCaml merlin see :help ale-integration-ocaml-merlin for configuration instructions
Perl perl -c, perl-critic
PHP hack, php -l, phpcs, phpmd
Pod proselint
Pug pug-lint
Puppet puppet, puppet-lint
Python flake8, mypy, pylint
reStructuredText proselint
Ruby rubocop
Rust rustc, cargo (see :help ale-integration-rust for configuration instructions)
SASS sass-lint, stylelint
SCSS sass-lint, scss-lint, stylelint
Scala scalac
Slim slim-lint
SML smlnj
Swift swiftlint
Tex proselint
Texinfo proselint
Text^ proselint
TypeScript tslint, typecheck
Verilog iverilog, verilator
Vim vint
Vim help^ proselint
XHTML proselint
YAML yamllint
  • ^ No linters for text or Vim help filetypes are enabled by default.

2. Usage

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.

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%\_vim, 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 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.ii. 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.

3.iii. Manual Installation

For installation without a package manager, you can clone this git repository into a bundle directory as with pathogen, and add the repository to your runtime path yourself. First clone the repository.

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

Then, modify your ~/.vimrc file to add this plugin to your runtime path.

set nocompatible
filetype off

let &runtimepath.=',~/.vim/bundle/ale'

filetype plugin on

You can add the following line 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:

silent! helptags ALL

Because the author of this plugin is a weird nerd, this is his preferred installation method.

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.

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 show errors or warnings in my statusline?

You can use ALEGetStatusLine() to integrate ALE into vim statusline. To enable it, you should have in your statusline settings

%{ALEGetStatusLine()}

When errors are detected a string showing the number of errors will be shown. You can customize the output format using the global list g:ale_statusline_format where:

  • The 1st element is for errors
  • The 2nd element is for warnings
  • The 3rd element is for when no errors are detected

e.g

let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']

Statusline with issues Statusline with no issues

5.v. 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.vi. How can I execute some code when ALE stops linting?

ALE runs its own autocmd event whenever has a linter has been successfully executed and processed. This autocmd event can be used to call arbitrary functions after ALE stops linting.

augroup YourGroup
    autocmd!
    autocmd User ALELint call YourFunction()
augroup END

5.vii. 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.viii. 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. If you wish to run linters when files are saved, not as you are editing files, then you can turn the option for linting when text is changed off too.

" Write this in your vimrc file
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 0
" 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

5.ix. 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.x. 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 https://github.com/styled-components/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.xi. 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 0, and consider setting g:ale_lint_on_save to 1 to enable linting when you save files. 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 :call ale#Lint().

ale's People

Contributors

alexmasterov avatar alistairbill avatar andreypopp avatar apuignav avatar ckyrouac avatar deathmaz avatar derekprior avatar dflupu avatar diartyz avatar einfachtoll avatar elehner avatar hauleth avatar jparise avatar jwoudenberg avatar kabbamine avatar keith avatar kyrisu avatar metakirby5 avatar mkusher avatar mshr-h avatar neersighted avatar poohzrn avatar prashcr avatar rob-b avatar s-ol avatar vmarovic avatar w0rp avatar yfery avatar ynonp avatar zefei avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.