diff options
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | README.md | 213 | ||||
-rw-r--r-- | ale_linters/javascript/jshint.vim | 34 | ||||
-rw-r--r-- | ale_linters/markdown/mdl.vim | 35 | ||||
-rw-r--r-- | ale_linters/matlab/mlint.vim | 55 | ||||
-rw-r--r-- | doc/ale.txt | 19 |
6 files changed, 266 insertions, 93 deletions
diff --git a/.travis.yml b/.travis.yml index d6da2530..d4e6cf3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ sudo: required services: - docker +branches: + only: + - master language: python script: | make test @@ -15,7 +15,25 @@ back to a filesystem. In other words, this plugin allows you to lint while you type. -## Supported Languages and Tools +## Table of Contents + +1. [Supported Languages and Tools](#supported-languages) +2. [Usage](#usage) +3. [Installation](#installation) + 1. [Installation with Pathogen](#installation-with-pathogen) + 2. [Installation with Vundle](#installation-with-vundle) + 3. [Manual Installation](#manual-installation) +4. [FAQ](#faq) + 1. [How do I disable particular linters?](#faq-disable-linters) + 2. [How can I keep the sign gutter open?](#faq-disable-linters) + 3. [How can I change the signs ALE uses?](#faq-change-signs) + 4. [How can I show errors or warnings in my statusline?](#faq-statusline) + 5. [How can I change the format for echo messages?](#faq-echo-format) + 6. [How can I execute some code when ALE stops linting?](#faq-autocmd) + +<a name="supported-languages"></a> + +## 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. @@ -45,6 +63,8 @@ name. That seems to be the fairest way to arrange this table. | JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/) | | JSON | [jsonlint](http://zaa.ch/jsonlint/) | | Lua | [luacheck](https://github.com/mpeterv/luacheck) | +| Markdown | [mdl](https://github.com/mivok/markdownlint) | +| MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | | PHP | [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | @@ -66,7 +86,9 @@ or [create a pull request](https://github.com/w0rp/ale/pulls). If your tool can read from stdin or you have code to suggest which is good, support can be happily added for more tools. -## Usage +<a name="usage"></a> + +## 2. Usage Once this plugin is installed, while editing your files in supported languages and tools which have been correctly installed, @@ -75,32 +97,90 @@ 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. -### Options - -A full list of options supported for configuring this plugin in your -vimrc file for all given linters is as follows: - -| Option | Description | Default | -| ------ | ----------- | ------- | -| `g:ale_echo_cursor` | echo errors when the cursor is over them | `1` | -| `g:ale_echo_msg_format` | string format to use for the echoed message | `'%s'` | -| `g:ale_echo_msg_error_str` | string used for error severity in echoed message | `'Error'` | -| `g:ale_echo_msg_warning_str` | string used for warning severity in echoed message | `'Warning'` | -| `g:ale_lint_delay` | milliseconds to wait before linting | `200` | -| `g:ale_linters` | a dictionary of linters to whitelist | _not set_ | -| `g:ale_lint_on_enter` | lint when opening a file | `1` | -| `g:ale_lint_on_save` | lint when saving a file | `0` | -| `g:ale_lint_on_text_changed` | lint while typing | `1` | -| `g:ale_set_loclist` | set the loclist with errors | `1` | -| `g:ale_set_signs` | set gutter signs with error markers | `has('signs')` | -| `g:ale_sign_column_always` | always show the sign gutter | `0` | -| `g:ale_sign_error` | the text to use for errors in the gutter | `'>>'` | -| `g:ale_sign_offset` | an offset for sign ids | `1000000` | -| `g:ale_sign_warning` | the text to use for warnings in the gutter | `'--'` | -| `g:ale_statusline_format` | string format to use in statusline flag | `['%d error(s)', '%d warning(s)', 'OK']` | -| `g:ale_warn_about_trailing_whitespace` | enable trailing whitespace warnings for some linters | `1` | - -### Selecting Particular Linters +The behaviour of linting can be configured with a variety of options, +documented in [the Vim help file](doc/ale.txt). 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. + +<a name="installation"></a> + +## 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`. + +<a name="installation-with-pathogen"></a> + +### 3.i. Installation with Pathogen + +To install this module with [Pathogen](https://github.com/tpope/vim-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: + +```bash +cd ~/.vim/bundle +git clone https://github.com/w0rp/ale.git +``` + +<a name="installation-with-vundle"></a> + +### 3.ii. Installation with Vundle + +You can install this plugin using [Vundle](https://github.com/VundleVim/Vundle.vim) +by using the path on GitHub for this repository. + +```vim +Plugin 'w0rp/ale' +``` + +See the Vundle documentation for more information. + +<a name="manual-installation"></a> + +### 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. + +```bash +cd ~/.vim/bundle +git clone https://github.com/w0rp/ale.git +``` + +Then, modify your `~/.vimrc` file to add this plugin to your runtime path. + +```vim +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: + +```vim +silent! helptags ALL +``` + +Because the author of this plugin is a weird nerd, this is his preferred +installation method. + +<a name="faq"></a> + +## 4. FAQ + +<a name="faq-disable-linters"></a> + +### 4.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 @@ -122,15 +202,20 @@ This plugin will look for linters in the [`ale_linters`](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. -### Always showing gutter +<a name="faq-keep-signs"></a> -You can keep the sign gutter open at all times by setting the `g:ale_sign_column_always` to 1 +### 4.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 ```vim let g:ale_sign_column_always = 1 ``` -### Customize signs +<a name="faq-change-signs"></a> + +### 4.iii. How can I change the signs ALE uses? Use these options to specify what text should be used for signs: @@ -139,7 +224,9 @@ let g:ale_sign_error = '>>' let g:ale_sign_warning = '--' ``` -### Statusline +<a name="faq-statusline"></a> + +### 4.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 @@ -164,8 +251,9 @@ let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok'] ![Statusline with issues](img/issues.png) ![Statusline with no issues](img/no_issues.png) +<a name="faq-echo-format"></a> -### Customize echoed message +### 4.v. How can I change the format for echo messages? There are 3 global options that allow customizing the echoed message. @@ -188,58 +276,17 @@ Will give you: ![Echoed message](img/echo.png) -## Installation +<a name="faq-autocmd"></a> -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`. - -### Installation with Pathogen - -To install this module with [Pathogen](https://github.com/tpope/vim-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: +### 4.vi. How can I execute some code when ALE stops linting? -```bash -cd ~/.vim/bundle -git clone https://github.com/w0rp/ale.git -``` - -### Installation with Vundle - -You can install this plugin using [Vundle](https://github.com/VundleVim/Vundle.vim) -by using the path on GitHub for this repository. - -```vim -Plugin 'w0rp/ale' -``` - -See the Vundle documentation for more information. - -### 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. - -```bash -cd ~/.vim/bundle -git clone https://github.com/w0rp/ale.git -``` - -Then, modify your `~/.vimrc` file to add this plugin to your runtime path. +ALE runs its own [autocmd](http://vimdoc.sourceforge.net/htmldoc/autocmd.html) +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. ```vim -set nocompatible -filetype off - -let &runtimepath.=',~/.vim/bundle/ale' - -filetype plugin on +augroup YourGroup + autocmd! + autocmd User ALELint call YourFunction() +augroup END ``` - -Because the author of this plugin is a weird nerd, this is his preferred -installation method. diff --git a/ale_linters/javascript/jshint.vim b/ale_linters/javascript/jshint.vim index 327158a8..f82011dd 100644 --- a/ale_linters/javascript/jshint.vim +++ b/ale_linters/javascript/jshint.vim @@ -4,17 +4,31 @@ let g:ale_javascript_jshint_executable = \ get(g:, 'ale_javascript_jshint_executable', 'jshint') -function! ale_linters#javascript#jshint#GetCommand(buffer) - " Set this to the location of the jshint configuration file to - " use a fixed location for .jshintrc - if exists('g:ale_jshint_config_loc') - let l:jshint_config = g:ale_jshint_config_loc - else - " Look for the JSHint config in parent directories. - let l:jshint_config = ale#util#FindNearestFile(a:buffer, '.jshintrc') +let g:ale_javascript_jshint_use_global = +\ get(g:, 'ale_javascript_jshint_use_global', 0) + +function! ale_linters#javascript#jshint#GetExecutable(buffer) abort + if g:ale_javascript_jshint_use_global + return g:ale_javascript_jshint_executable endif - let l:command = g:ale_javascript_jshint_executable . ' --reporter unix' + return ale#util#ResolveLocalPath( + \ a:buffer, + \ 'node_modules/.bin/jshint', + \ g:ale_javascript_jshint_executable + \) +endfunction + +function! ale_linters#javascript#jshint#GetCommand(buffer) + " Search for a local JShint config locaation, and default to a global one. + let l:jshint_config = ale#util#ResolveLocalPath( + \ a:buffer, + \ '.jshintrc', + \ get(g:, 'ale_jshint_config_loc', '') + \) + + let l:command = ale_linters#javascript#jshint#GetExecutable(a:buffer) + let l:command .= ' --reporter unix' if !empty(l:jshint_config) let l:command .= ' --config ' . fnameescape(l:jshint_config) @@ -27,7 +41,7 @@ endfunction call ale#linter#Define('javascript', { \ 'name': 'jshint', -\ 'executable': g:ale_javascript_jshint_executable, +\ 'executable_callback': 'ale_linters#javascript#jshint#GetExecutable', \ 'command_callback': 'ale_linters#javascript#jshint#GetCommand', \ 'callback': 'ale#handlers#HandleUnixFormatAsError', \}) diff --git a/ale_linters/markdown/mdl.vim b/ale_linters/markdown/mdl.vim new file mode 100644 index 00000000..c984252e --- /dev/null +++ b/ale_linters/markdown/mdl.vim @@ -0,0 +1,35 @@ +" Author: Steve Dignam <steve@dignam.xyz> +" Description: Support for mdl, a markdown linter + +function! ale_linters#markdown#mdl#Handle(buffer, lines) abort + " matches: '(stdin):173: MD004 Unordered list style' + let l:pattern = ':\(\d*\): \(.*\)$' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + if len(l:match) == 0 + continue + endif + + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:match[1] + 0, + \ 'vcol': 0, + \ 'col': 0, + \ 'text': l:match[2], + \ 'type': 'W', + \ 'nr': -1, + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('markdown', { +\ 'name': 'mdl', +\ 'executable': 'mdl', +\ 'command': 'mdl', +\ 'callback': 'ale_linters#markdown#mdl#Handle' +\}) diff --git a/ale_linters/matlab/mlint.vim b/ale_linters/matlab/mlint.vim new file mode 100644 index 00000000..e1e6cf05 --- /dev/null +++ b/ale_linters/matlab/mlint.vim @@ -0,0 +1,55 @@ +" Author: awlayton <alex@layton.in> +" Description: mlint for MATLAB files + +let g:ale_matlab_mlint_executable = +\ get(g:, 'ale_matlab_mlint_executable', 'mlint') + +function! ale_linters#matlab#mlint#Handle(buffer, lines) + " Matches patterns like the following: + " + " L 27 (C 1): FNDEF: Terminate statement with semicolon to suppress output. + " L 30 (C 13-15): FNDEF: A quoted string is unterminated. + let l:pattern = '^L \(\d\+\) (C \([0-9-]\+\)): \([A-Z]\+\): \(.\+\)$' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + if len(l:match) == 0 + continue + endif + + let l:lnum = l:match[1] + 0 + let l:col = l:match[2] + 0 + let l:code = l:match[3] + let l:text = l:match[4] + + " Suppress erroneous waring about filename + " TODO: Enable this error when copying filename is supported + if l:code ==# 'FNDEF' + continue + endif + + " vcol is needed to indicate that the column is a character. + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:lnum, + \ 'vcol': 0, + \ 'col': l:col, + \ 'text': l:text, + \ 'type': 'W', + \ 'nr': -1, + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('matlab', { +\ 'name': 'mlint', +\ 'executable': 'mlint', +\ 'command': g:ale#util#stdin_wrapper . +\ ' .m ' . g:ale_matlab_mlint_executable . ' -id', +\ 'output_stream': 'stderr', +\ 'callback': 'ale_linters#matlab#mlint#Handle', +\}) diff --git a/doc/ale.txt b/doc/ale.txt index ca558f26..16d55f6b 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -67,6 +67,8 @@ The following languages and tools are supported. * JavaScript: 'eslint', 'jscs', 'jshint' * JSON: 'jsonlint' * Lua: 'luacheck' +* Markdown: 'mdl' +* MATLAB: 'mlint' * Perl: 'perl' (-c flag), 'perlcritic' * PHP: 'php' (-l flag), 'phpcs' * Pug: 'pug-lint' @@ -382,8 +384,25 @@ g:ale_javascript_jshint_executable *g:ale_javascript_jshint_executable* Type: |String| Default: `'jshint'` + ALE will first discover the jshint path in an ancestor node_modules + directory. If no such path exists, this variable will be used instead. + This variable can be changed to change the path to jshint. + If you wish to use only a globally installed version of jshint, set + |g:ale_javascript_jshint_use_global| to `1`. + + +g:ale_javascript_jshint_use_global *g:ale_javascript_jshint_use_global* + + Type: |String| + Default: `0` + + This variable controls whether or not ALE will search for a local path for + jshint first. If this variable is set to `1`, then ALE will always use the + global version of jshint, in preference to locally installed versions of + jshint in node_modules. + ------------------------------------------------------------------------------- 4.3. phpcs *ale-linter-options-phpcs* |